feat(overrides): check if value to modify is feature
Signed-off-by: miguel456 <me@nogueira.codes>
This commit is contained in:
parent
2b1caeb80c
commit
57346f49e0
10
app/Enums/OverridableFeatures.php
Normal file
10
app/Enums/OverridableFeatures.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum OverridableFeatures:string
|
||||
{
|
||||
|
||||
case REQUIRE_LICENSE = 'requireGameLicense';
|
||||
|
||||
}
|
@ -21,6 +21,7 @@
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use App\Enums\OverridableFeatures;
|
||||
use App\Enums\Overrides;
|
||||
use App\Exceptions\EmptyOptionsException;
|
||||
use App\Exceptions\OptionNotFoundException;
|
||||
@ -71,6 +72,13 @@ class Options
|
||||
return $this->modifyResponse($option, $value);
|
||||
}
|
||||
|
||||
public function isFeature(string $optionName): bool
|
||||
{
|
||||
if ($this->getCategory('app_features')->contains('option_name', $optionName)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* CHeck if given option is locallu overriden
|
||||
@ -193,12 +201,16 @@ class Options
|
||||
/**
|
||||
* Modifies the outgoing option value according to its override value
|
||||
*
|
||||
* @param int $value Setting value
|
||||
* @param string $option
|
||||
* @param int|string $value Setting value
|
||||
* @return int Modified setting value accordidng to business rules
|
||||
*/
|
||||
private function modifyResponse(string $option, int $value): int
|
||||
private function modifyResponse(string $option, int|string $value): int|string
|
||||
{
|
||||
|
||||
// TODO: This method should handle bools (feature on/off), we need to move this to getOption, but only after its been refactored. (this is a quick fix)
|
||||
if (!$this->isFeature($option)) {
|
||||
return $value;
|
||||
}
|
||||
$modifiedValue = $value;
|
||||
|
||||
try {
|
||||
|
@ -46,7 +46,9 @@ class DefaultOptionsSeeder extends Seeder
|
||||
Options::setOption('password_expiry', '0', '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('requireGameLicense', true, 'Defines whether people need to validate their game license', 'app_features');
|
||||
|
||||
Options::setOption('currentGame', 'MINECRAFT', 'Defines what game we\'re working with', 'app_integration');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user