Skip to content

Commit

Permalink
Merge pull request #555 from Vatsim-Scandinavia/misc/frontend-and-more
Browse files Browse the repository at this point in the history
Frontend and onboarding tweaks
  • Loading branch information
blt950 authored Jun 27, 2023
2 parents c2e1d75 + 05b3eb8 commit 435e25a
Show file tree
Hide file tree
Showing 21 changed files with 265 additions and 101 deletions.
2 changes: 1 addition & 1 deletion CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Table with all the variables, default value and explanation. Override the enviro

Control Center supports both VATSIM Connect and other OAuth providers to authenticate and fetch user data. If you're looking for a centrailised login system check out our [Handover](https://github.com/Vatsim-Scandinavia/handover) service. Otherwise you may use VATSIM Connect.

If you use Handover, please use the following values:
If you use Handover, please use the values in the table below. Please note these values will change in a future update of Handover to simplify the process.

| Variable | [Handover](https://github.com/Vatsim-Scandinavia/handover) value | Explanation |
| ------- | --- | --- |
Expand Down
11 changes: 9 additions & 2 deletions CONTRIBUTE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ If you encounter permissions errors you might want to `chown -R www-data:www-dat

### Run unit tests

To run the PHP unit tests use `./vendor/bin/phpunit --color=always --testdox`\
The tests are run in a local sqlite database.
#### First run

On first run you might need to setup the testing sqlite database first.
Run the command `php artisan migrate --database sqlite-testing` to setup the database.

#### Test

To run the PHP unit tests use `php artisan test`\
The tests run with the local SQLite test database, not your development database.

#### Quicker feedback during development

Expand Down
30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ Training Management System created by [Daniel L.](https://github.com/blt950) (13
- MySQL database (or MariaDB) to store data.
- Preferably a reverse proxy setup if you plan to host more than one website on the same server.

In the instructions where we use `docker exec`, we assume your container is named `control-center`. If you have named it differently, please replace this.

### Manual (Unsupported)
If you don't want to use Docker, you need:
- An environment that can host PHP websites, such as Apache, Ngnix or similar.
- MySQL database (or MariaDB) to store data.
- Comply with [Laravel 9 Requirements](https://laravel.com/docs/9.x/deployment#server-requirements)

*Remember to build the composer, npm and setting up cron jobs as well.*
*Remember to build the composer, npm and setting up cron jobs and clearing all caches as well.*

## Setup and install

Expand All @@ -27,17 +30,30 @@ If you don't want to use Docker, you need:
To setup your Docker instance simply follow these steps:
1. Pull the `ghcr.io/vatsim-scandinavia/control-center:v4` Docker image
2. Setup your MySQL database (not included in Docker image)
3. Configure the environment variables as described in the [CONFIGURE.md](CONFIGURE.md)
4. Run the container
5. Setup a crontab outside the container to run `* * * * * docker exec --user www-data -i control-center php artisan schedule:run >/dev/null` every minute. This patches into the container and runs the required cronjobs.
6. Bind the 8080 (HTTP) and/or 8443 (HTTPS) port to your reverse proxy or similar.
3. Configure the environment variables as described in the [CONFIGURE.md](CONFIGURE.md#environment)
4. Start the container in the background.
5. Setup the database.
```sh
docker exec -it control-center php artisan migrate
```
6. To ensure that users will not need to log in after each time you re-deploy or upgrade the container, you need to create and store an application key in your environment.
```sh
docker exec -it control-center php artisan key:get
```
Copy the key and set it as the `APP_KEY` environment variable in your Docker configuration.
7. Setup a crontab outside the container to run `* * * * * docker exec --user www-data -i control-center php artisan schedule:run >/dev/null` every minute. This patches into the container and runs the required cronjobs.
8. Bind the 8080 (HTTP) and/or 8443 (HTTPS) port to your reverse proxy or similar.

## Configuring

To have Control Center reflect your division correctly, you need to do some tweaks.
- Give your user admin access by manipulating the database table `permissions`. Set your `group_id` to `1`. Area need to be specified but can be any.

- Give your user admin access
```sh
docker exec -it control-center php artisan user:makeadmin
```
- You can now access `Administration -> Settings` in the menu to tweak the most basic settings for your division.
- You are also required to configure logic and datasets in the MySQL database as described in [CONFIGURE.md](CONFIGURE.md) with examples
- You are also required to configure logic and datasets in the MySQL database as described in [CONFIGURE.md](CONFIGURE.md#database) with examples

## Using the API

Expand Down
22 changes: 16 additions & 6 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Upgrading

## Upgrading from 3.4.0 to 4.0
## Upgrading from version 3.4 to 4.0

These are the steps required to migrate from 3.4.0 to 4.0, please make sure you've a backup and upgraded to minimum 3.4.0 before starting this process.
To have the smoothest upgrade experience, we highly recommend that you've upgraded to v3.4.0 before upgrading to v4.0.0. This way it'll be easier to isolate issues that might happen on the way.

Make sure you have a manual backup of the database before upgrading.

### Breaking change ⚠️

Expand All @@ -16,18 +18,26 @@ Please note that users need to login again after this update, as it'll create a

We now offer a Docker container that can be used to run Control Center, this is the recommended hosting now that ensures correct environement. If you still prefer to run it without Docker, this is still possible by cloning the repo and building the project manually.

*Note: The included docker-compose.yaml is only for development purposes and should not be used in production.*
In the instructions where we use `docker exec` we assume your container is named `control-center`. If you have named differently, please replace this.

1. Pull the `ghcr.io/vatsim-scandinavia/control-center:v4.0.0` Docker image
1. Pull the `ghcr.io/vatsim-scandinavia/control-center:v4.0.2` Docker image
2. Configure the environment variables as described in the [CONFIGURE.md](CONFIGURE.md)
3. Start the container
4. Setup a crontab outside the container to run `* * * * * docker exec --user www-data -i control-center php artisan schedule:run >/dev/null` every minute. This patches into the container and runs the required cronjobs.
5. Bind the 8080 (HTTP) and/or 8443 (HTTPS) port to your reverse proxy or similar.
5. To ensure that users will not need to log in after each time you re-deploy or upgrade the container, you need to create and store an application key in your environment.
```sh
docker exec -it control-center php artisan key:get
```
Copy the key and set it as the `APP_KEY` environment variable in your Docker configuration.
6. Bind the 8080 (HTTP) and/or 8443 (HTTPS) port to your reverse proxy or similar.

#### Data Migration

1. Make sure that `DB_HANDOVER_` database config is present in your environment file or docker configuration. Do not remove this as it's required for the migration.
2. Run the migration with `php artisan migrate` inside the container, this will copy over the required data fields from Handover so CC can run on it's own
2. Run the migration, this will copy over the required data fields from Handover so CC can run on it's own
```sh
docker exec -it control-center php artisan migrate
```
3. If the migration was successful you may now remove the `DB_HANDOVER_*` environment settings as it'll no longer be used.
4. If you don't want to use Handover at all anymore, you can at this point change the OAUTH environment settings to the VATSIM OAuth settings.

Expand Down
36 changes: 36 additions & 0 deletions app/Console/Commands/KeyGet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class KeyGet extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'key:get';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Get the current application key';

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{

$this->info('Current application key, copy the whole next line:');
$this->info(config('app.key'));

return Command::SUCCESS;
}
}
63 changes: 63 additions & 0 deletions app/Console/Commands/UserMakeAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace App\Console\Commands;

use App\Models\Area;
use App\Models\Group;
use App\Models\User;
use Illuminate\Console\Command;

class UserMakeAdmin extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'user:makeadmin';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Make the specified user into an admin';

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{

// Input user
$cid = $this->ask("What is the user's CID?");
if ($user = User::find($cid)) {
$this->info('User found: ' . $user->name);

$areas = Area::all();
$area = $this->choice('Which area? The admin has access across areas, but an area must be selected regardless.', $areas->pluck('name')->toArray());
if ($area != null) {
$area = Area::where('name', $area)->first();

// Give the user permission to the area
$user->groups()->attach(Group::find(1), ['area_id' => $area->id]);
$this->info('User ' . $user->name . ' has been given admin permissions for ' . $area->name . '.');

return Command::SUCCESS;
} else {
$this->error('No area was selected.');

return Command::FAILURE;
}

} else {
$this->error('No records of ' . $cid . ' was found.');

return Command::FAILURE;
}

return Command::FAILURE;
}
}
11 changes: 10 additions & 1 deletion app/Policies/TrainingExaminationPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public function view(User $user, TrainingExamination $examination)
*/
public function create(User $user, Training $training)
{

if ($user->isAdmin()) {
return true;
}

// If one-time link is used
if (($link = $this->getOneTimeLink($training)) != null) {
return $user->isExaminer($link->training->area) && $user->isNot($training->user);
Expand All @@ -46,6 +51,10 @@ public function create(User $user, Training $training)
*/
public function update(User $user, TrainingExamination $examination)
{
if ($user->isAdmin()) {
return true;
}

return $examination->draft ? ($user->isModeratorOrAbove($examination->training->area) || $user->isExaminer()) : $user->isModeratorOrAbove($examination->training->area);
}

Expand All @@ -56,7 +65,7 @@ public function update(User $user, TrainingExamination $examination)
*/
public function delete(User $user, TrainingExamination $trainingExamination)
{
return $user->isModeratorOrAbove($trainingExamination->training->area);
return $user->isModeratorOrAbove($trainingExamination->training->area) || $user->isAdmin();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
|
*/

'version' => '4.0.1',
'version' => '4.0.2',

/*
|--------------------------------------------------------------------------
Expand Down
22 changes: 22 additions & 0 deletions resources/sass/_global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,28 @@ p {
}
}

.page-title{

flex-direction: row;
flex-wrap: wrap;

h3{
margin-bottom: 1.5rem;
}

@include media-breakpoint-down(sm) {

h3{
margin-bottom: 0.5rem;
margin-right: 1.5rem;
}

div{
margin-bottom: 1.5rem;
}
}
}

form {
input, select {
border-color: $gray-400 !important;
Expand Down
1 change: 1 addition & 0 deletions resources/sass/navs/_topbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
min-height: 25px;
line-height: 1.5rem;
padding: 0 1rem;
text-decoration: none;
}

a:hover{
Expand Down
Loading

0 comments on commit 435e25a

Please sign in to comment.