diff --git a/app/Helpers/Options.php b/app/Helpers/Options.php index 9fffca9..dbcace7 100755 --- a/app/Helpers/Options.php +++ b/app/Helpers/Options.php @@ -22,11 +22,33 @@ namespace App\Helpers; use App\Options as Option; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Log; +/** + * The options class. A simple wrapper around the model. Could be a repository, but we're not using that design pattern just yet + */ class Options { + + /** + * Returns an assortment of settings found in the mentioned category + * + * @param $category The category + * @return Collection The settings in this category + */ + public function getCategory(string $category): Collection + { + $options = Option::where('option_category', $category)->get(); + if ($options->isEmpty()) + { + throw new \Exception('There are no options in category ' . $category); + } + return $options; + } + + public function getOption(string $option): string { $value = Cache::get($option); @@ -47,12 +69,14 @@ class Options return $value; } - public function setOption(string $option, string $value, string $description) + // Null categories are settings without categories and will appear ungrouped + public function setOption(string $option, string $value, string $description, string $category = null) { Option::create([ 'option_name' => $option, 'option_value' => $value, 'friendly_name' => $description, + 'option_category' => $category ]); Cache::put($option, $value, now()->addDay()); diff --git a/app/Http/Controllers/OptionsController.php b/app/Http/Controllers/OptionsController.php index 2ffb67b..9e87e2e 100755 --- a/app/Http/Controllers/OptionsController.php +++ b/app/Http/Controllers/OptionsController.php @@ -36,17 +36,17 @@ class OptionsController extends Controller */ public function index() { - // TODO: Obtain this from the facade - $options = Option::all(); return view('dashboard.administration.settings') - ->with('options', $options) - ->with('security', [ - 'secPolicy' => Options::getOption('pw_security_policy'), - 'graceperiod' => Options::getOption('graceperiod'), - 'pwExpiry' => Options::getOption('password_expiry'), - 'requiresPMC' => Options::getOption('requireGameLicense'), - 'enforce2fa' => Options::getOption('force2fa') + ->with([ + 'options' => Options::getCategory('notifications'), + 'security' => [ // We could use the method above, but we need to set these names here for greater control in the template. This would nto be feasible for many options, we'd need to use a loop and the category method. + 'secPolicy' => Options::getOption('pw_security_policy'), + 'graceperiod' => Options::getOption('graceperiod'), + 'pwExpiry' => Options::getOption('password_expiry'), + 'requiresPMC' => Options::getOption('requireGameLicense'), + 'enforce2fa' => Options::getOption('force2fa') + ] ]); } diff --git a/database/migrations/2021_01_06_011207_add_category_to_options.php b/database/migrations/2021_01_06_011207_add_category_to_options.php new file mode 100644 index 0000000..1986f56 --- /dev/null +++ b/database/migrations/2021_01_06_011207_add_category_to_options.php @@ -0,0 +1,32 @@ +string('option_category')->after('friendly_name')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('options', function (Blueprint $table) { + $table->dropColumn('option_category'); + }); + } +} diff --git a/database/seeders/DefaultOptionsSeeder.php b/database/seeders/DefaultOptionsSeeder.php index bffa641..a94e445 100755 --- a/database/seeders/DefaultOptionsSeeder.php +++ b/database/seeders/DefaultOptionsSeeder.php @@ -33,25 +33,25 @@ class DefaultOptionsSeeder extends Seeder */ public function run() { - Options::setOption('notify_new_application_email', true, 'Notify when a new application comes through'); // done - Options::setOption('notify_application_comment', false, 'Notify when someone comments on an application'); // done + Options::setOption('notify_new_application_email', true, 'Notify when a new application comes through', 'notifications'); // done + Options::setOption('notify_application_comment', false, 'Notify when someone comments on an application' , 'notifications'); // done Options::setOption('notify_new_user', true, 'Notify when someone signs up'); // done - Options::setOption('notify_application_status_change', true, 'Notify when an application changes status'); // done - Options::setOption('notify_applicant_approved', true, 'Notify when an applicant is approved'); // done - Options::setOption('notify_vacancystatus_change', false, 'Notify when a vacancy\'s status changes'); // done + Options::setOption('notify_application_status_change', true, 'Notify when an application changes status' , 'notifications'); // done + Options::setOption('notify_applicant_approved', true, 'Notify when an applicant is approved' , 'notifications'); // done + Options::setOption('notify_vacancystatus_change', false, 'Notify when a vacancy\'s status changes' , 'notifications'); // done - Options::setOption('enable_slack_notifications', true, 'Enable slack notifications'); - Options::setOption('enable_email_notifications', true, 'Enable e-mail notifications'); + Options::setOption('enable_slack_notifications', true, 'Enable slack notifications' , 'notifications'); + Options::setOption('enable_email_notifications', true, 'Enable e-mail notifications' , 'notifications'); // added in 0.6.2 - Options::setOption('pw_security_policy', 'low', 'Describes the current password security policy.'); - Options::setOption('graceperiod', 7, '2FA Grace Period'); - Options::setOption('password_expiry', 'disabled', 'Defines wether passwords must be reset after $value'); - Options::setOption('force2fa', false, 'Defines whether 2fa is forced upon users'); - Options::setOption('force2faRole', 'reviewer', 'Defines which role to force 2fa for'); - Options::setOption('requireGameLicense', true, 'Defines whether people need to validate their game license'); + Options::setOption('pw_security_policy', 'low', 'Describes the current password security policy.', 'app_security'); + Options::setOption('graceperiod', 7, '2FA Grace Period', 'app_security'); + Options::setOption('password_expiry', 'disabled', 'Defines wether passwords must be reset after $value', 'app_security'); + Options::setOption('force2fa', false, 'Defines whether 2fa is forced upon users', 'app_security'); + Options::setOption('force2faRole', 'reviewer', 'Defines which role to force 2fa for', 'app_security'); + Options::setOption('requireGameLicense', true, 'Defines whether people need to validate their game license', 'app_security'); - Options::setOption('currentGame', 'MINECRAFT', 'Defines what game we\'re working with'); + Options::setOption('currentGame', 'MINECRAFT', 'Defines what game we\'re working with', 'app_integration'); } } diff --git a/resources/views/dashboard/administration/settings.blade.php b/resources/views/dashboard/administration/settings.blade.php index 514e403..6dbe5f7 100755 --- a/resources/views/dashboard/administration/settings.blade.php +++ b/resources/views/dashboard/administration/settings.blade.php @@ -108,13 +108,17 @@