feat(overrides): check if value to modify is feature
Signed-off-by: miguel456 <me@nogueira.codes>
This commit is contained in:
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;
|
namespace App\Helpers;
|
||||||
|
|
||||||
|
use App\Enums\OverridableFeatures;
|
||||||
use App\Enums\Overrides;
|
use App\Enums\Overrides;
|
||||||
use App\Exceptions\EmptyOptionsException;
|
use App\Exceptions\EmptyOptionsException;
|
||||||
use App\Exceptions\OptionNotFoundException;
|
use App\Exceptions\OptionNotFoundException;
|
||||||
@@ -71,6 +72,13 @@ class Options
|
|||||||
return $this->modifyResponse($option, $value);
|
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
|
* CHeck if given option is locallu overriden
|
||||||
@@ -193,12 +201,16 @@ class Options
|
|||||||
/**
|
/**
|
||||||
* Modifies the outgoing option value according to its override value
|
* 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
|
* @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;
|
$modifiedValue = $value;
|
||||||
|
|
||||||
try {
|
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('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('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('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');
|
Options::setOption('currentGame', 'MINECRAFT', 'Defines what game we\'re working with', 'app_integration');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user