Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console;

use App\FeatureToggle;
use App\Enums\FeatureToggles;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

Expand Down Expand Up @@ -44,7 +44,7 @@ protected function schedule(Schedule $schedule): void {
$schedule->command('OnlineControllers:GetControllers')->everyMinute()->monitorName('Get Online Controllers');
$schedule->command('RosterUpdate:UpdateAcademyExams')->cron('17 */2 * * *')->monitorName('Active Controller Exam Update');
$schedule->command('Events:UpdateSupportEvents')->dailyAt('05:09')->monitorName('Sync Support Events')->when(function () {
return FeatureToggle::isEnabled('auto_support_events');
return toggleEnabled(FeatureToggles::AUTO_SUPPORT_EVENTS);
});
$schedule->command('PilotPassport:ActivityUpdate')->everyFiveMinutes()->monitorName('Update Pilot Passport Activity');
}
Expand Down
13 changes: 13 additions & 0 deletions app/Enums/FeatureToggles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Enums;

enum FeatureToggles: string {
case REALOPS = 'realops';
case REALOPS_BIDDING = 'realops_bidding';
case MOODLE = 'moodle';
case MERCH_STORE = 'merch-store';
case CUSTOM_THEME_LOGO = 'custom_theme_logo';
case LOCAL_HERO = 'local-hero';
case AUTO_SUPPORT_EVENTS = 'auto_support_events';
}
11 changes: 11 additions & 0 deletions app/Enums/SessionVariables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Enums;

enum SessionVariables: string {
case SUCCESS = 'success';
case ERROR = 'error';
case VATSIM_AUTH_STATE = 'vatsimauthstate';
case REALOPS_PILOT_REDIRECT = 'pilot_redirect';
case REALOPS_PILOT_REDIRECT_PATH = 'pilot_redirect_path';
}
20 changes: 11 additions & 9 deletions app/FeatureToggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App;

use App\Enums\FeatureToggles;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;

Expand All @@ -11,29 +12,30 @@ class FeatureToggle extends Model {
protected $keyType = 'string';
public $incrementing = false;

public static function isEnabled($toggle_name) {
return FeatureToggle::getToggleValue($toggle_name);
public static function isEnabled($toggle_enum) {
return FeatureToggle::getToggleValue($toggle_enum);
}

public static function toggle($toggle_name) {
$toggle = FeatureToggle::find($toggle_name);
$toggle_value = FeatureToggle::getToggleValue($toggle_name);
$toggle_enum = FeatureToggles::from($toggle_name);
$toggle_value = FeatureToggle::getToggleValue($toggle_enum);

if ($toggle) {
$toggle->is_enabled = ! $toggle_value;
$toggle->save();
}

Cache::put(FeatureToggle::generateToggleCacheName($toggle_name), $toggle->is_enabled);
Cache::put(FeatureToggle::generateToggleCacheName($toggle_enum), $toggle->is_enabled);
}

private static function generateToggleCacheName($toggle_name) {
return 'FeatureToggle_' . $toggle_name;
private static function generateToggleCacheName($toggle_enum) {
return 'FeatureToggle_' . $toggle_enum->value;
}

private static function getToggleValue($toggle_name) {
return Cache::rememberForever(FeatureToggle::generateToggleCacheName($toggle_name), function () use ($toggle_name) {
$toggle = FeatureToggle::find($toggle_name);
private static function getToggleValue($toggle_enum) {
return Cache::rememberForever(FeatureToggle::generateToggleCacheName($toggle_enum), function () use ($toggle_enum) {
$toggle = FeatureToggle::find($toggle_enum->value);
return $toggle != null && $toggle->is_enabled;
});
}
Expand Down
4 changes: 2 additions & 2 deletions app/Helpers/FeatureToggleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

use App\FeatureToggle;

function toggleEnabled($toggle_name) {
return FeatureToggle::isEnabled($toggle_name);
function toggleEnabled($toggle_enum) {
return FeatureToggle::isEnabled($toggle_enum);
}
157 changes: 79 additions & 78 deletions app/Http/Controllers/AdminDash.php

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions app/Http/Controllers/AtcBookingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\AtcBooking;
use App\Enums\SessionVariables;
use Auth;
use Carbon\Carbon;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -65,20 +66,20 @@ public function createBooking(Request $request) {
})->count() > 0;

if ($existing) {
return redirect()->back()->with('error', 'A booking already exists for ' . $callsign . ' at this time')->withInput();
return redirect()->back()->with(SessionVariables::ERROR->value, 'A booking already exists for ' . $callsign . ' at this time')->withInput();
}

$type = $request->type;
if ($type == AtcBooking::TYPES["EVENT"] && ! (Auth::user()->isAbleTo('events') || Auth::user()->hasRole('events-team'))) {
return redirect()->back()->with('error', 'Only the EC and events team can create event bookings')->withInput();
return redirect()->back()->with(SessionVariables::ERROR->value, 'Only the EC and events team can create event bookings')->withInput();
}

if ($type == AtcBooking::TYPES["EXAM"] && ! (Auth::user()->hasRole('ins') || Auth::user()->isAbleTo('snrStaff'))) {
return redirect()->back()->with('error', 'Only instructors can create exam bookings')->withInput();
return redirect()->back()->with(SessionVariables::ERROR->value, 'Only instructors can create exam bookings')->withInput();
}

if ($type == AtcBooking::TYPES["MONITORING"] && ! (Auth::user()->isAbleTo('train') || Auth::user()->isAbleTo('snrStaff'))) {
return redirect()->back()->with('error', 'Only mentors and instructors can create monitoring bookings')->withInput();
return redirect()->back()->with(SessionVariables::ERROR->value, 'Only mentors and instructors can create monitoring bookings')->withInput();
}

$booking = new AtcBooking;
Expand All @@ -89,18 +90,18 @@ public function createBooking(Request $request) {
$booking->end = $end;
$booking->save();

return redirect('/dashboard/controllers/bookings')->with('success', 'Your booking has been created successfully');
return redirect('/dashboard/controllers/bookings')->with(SessionVariables::SUCCESS->value, 'Your booking has been created successfully');
}

public function deleteBooking($id) {
$booking = AtcBooking::find($id);

if (! ($booking->cid == Auth::id() || Auth::user()->isAbleTo('snrStaff'))) {
return redirect()->back()->with('error', 'You can only delete your own bookings');
return redirect()->back()->with(SessionVariables::ERROR->value, 'You can only delete your own bookings');
}

$booking->delete();

return redirect()->back()->with('success', 'Your booking has been deleted successfully');
return redirect()->back()->with(SessionVariables::SUCCESS->value, 'Your booking has been deleted successfully');
}
}
31 changes: 16 additions & 15 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers\Auth;

use App\Enums\SessionVariables;
use App\Http\Controllers\Controller;
use App\Http\Controllers\VatsimOAuthController;
use App\Opt;
Expand Down Expand Up @@ -36,9 +37,9 @@ public function __construct() {
public function login(Request $request) {
if (!$request->has('code') || !$request->has('state')) { // User has clicked "login", redirect to Connect
$authorizationUrl = $this->provider->getAuthorizationUrl(); // Generates state
$request->session()->put('vatsimauthstate', $this->provider->getState());
$request->session()->put(SessionVariables::VATSIM_AUTH_STATE->value, $this->provider->getState());
return redirect()->away($authorizationUrl);
} elseif ($request->input('state') !== session()->pull('vatsimauthstate')) { // State mismatch, error
} elseif ($request->input('state') !== session()->pull(SessionVariables::VATSIM_AUTH_STATE->value)) { // State mismatch, error
return redirect('/')->withError("Something went wrong, please try again.");
} else { // Callback (user has just logged in Connect)
return $this->verifyLogin($request);
Expand All @@ -63,7 +64,7 @@ protected function verifyLogin(Request $request) {
) {
return redirect('/')->withError("We need you to grant us all marked permissions");
}
if (session('pilot_redirect')) {
if (session(SessionVariables::REALOPS_PILOT_REDIRECT->value)) {
return $this->externalPilotLogin(
$resourceOwner->data->cid,
$resourceOwner->data->personal->name_first,
Expand Down Expand Up @@ -95,14 +96,14 @@ protected function vatusaAuth($resourceOwner, $accessToken) {
}

if (!App::environment('local')) {
return redirect('/')->with('error', 'We are unable to verify your access at this time. Please try again in a few minutes.');
return redirect('/')->with(SessionVariables::ERROR->value, 'We are unable to verify your access at this time. Please try again in a few minutes.');
}
}

$resu = json_decode($result->getBody()->__toString(), true);

if (! isset($resu['data'])) {
return redirect('/')->with('error', 'We are unable to verify your access at this time. Please try again in a few minutes.');
return redirect('/')->with(SessionVariables::ERROR->value, 'We are unable to verify your access at this time. Please try again in a few minutes.');
}

$res = $resu['data'];
Expand All @@ -129,13 +130,13 @@ protected function vatusaAuth($resourceOwner, $accessToken) {

$message = 'You have been logged in successfully via the dev mode login. A webmaster role has been automatically attached.';

return redirect()->intended('/dashboard')->with('success', $message);
return redirect()->intended('/dashboard')->with(SessionVariables::SUCCESS->value, $message);
} else {
$userstatuscheck = User::find($res['cid']);
}

if (! $userstatuscheck || $userstatuscheck->status == 2) {
return redirect('/')->with('error', 'You have not been found on the roster. If you have recently joined, please allow up to an hour for the roster to update.');
return redirect('/')->with(SessionVariables::ERROR->value, 'You have not been found on the roster. If you have recently joined, please allow up to an hour for the roster to update.');
}

$userstatuscheck->fname = $res['fname'];
Expand Down Expand Up @@ -179,7 +180,7 @@ protected function vatusaAuth($resourceOwner, $accessToken) {
$message = 'You have been logged in successfully. Please note that you are on an LOA and should not control until off the LOA. If this is an error, please let the DATM know.';
}

return redirect()->intended('/dashboard')->with('success', $message);
return redirect()->intended('/dashboard')->with(SessionVariables::SUCCESS->value, $message);
}

public function logout() {
Expand All @@ -190,9 +191,9 @@ public function logout() {
}

public function realopsLogin() {
session(['pilot_redirect_path' => '/realops']);
session()->put(SessionVariables::REALOPS_PILOT_REDIRECT_PATH->value, '/realops');
if (! auth()->check()) {
session(['pilot_redirect' => true]);
session()->put(SessionVariables::REALOPS_PILOT_REDIRECT->value, true);
return redirect('/login');
}

Expand All @@ -213,9 +214,9 @@ public function realopsLogin() {
}

public function pilotPassportLogin() {
session(['pilot_redirect_path' => '/pilot_passport']);
session()->put(SessionVariables::REALOPS_PILOT_REDIRECT_PATH->value, '/pilot_passport');
if (! auth()->check()) {
session(['pilot_redirect' => true]);
session()->put(SessionVariables::REALOPS_PILOT_REDIRECT->value, true);
return redirect('/login');
}

Expand Down Expand Up @@ -253,9 +254,9 @@ private function externalPilotLogin($cid, $fname, $lname, $email) {

private function completePilotLogin($pilot) {
auth()->guard('realops')->login($pilot);
$redirect_path = session('pilot_redirect_path');
session()->forget('pilot_redirect');
session()->forget('pilot_redirect_path');
$redirect_path = session(SessionVariables::REALOPS_PILOT_REDIRECT_PATH->value);
session()->forget(SessionVariables::REALOPS_PILOT_REDIRECT->value);
session()->forget(SessionVariables::REALOPS_PILOT_REDIRECT_PATH->value);
return redirect($redirect_path);
}
}
Loading