Add feature flag for expression engine and disable it by default.

This commit is contained in:
James Cole
2024-03-10 06:46:24 +01:00
parent 8a2c520b11
commit 5746ac3247
4 changed files with 87 additions and 88 deletions

View File

@@ -78,6 +78,9 @@ class RuleAction extends Model
public function getValue(array $journal): string public function getValue(array $journal): string
{ {
if (false === config('firefly.feature_flags.expression_engine')) {
return (string)$this->action_value;
}
$expr = new ActionExpression($this->action_value); $expr = new ActionExpression($this->action_value);
return $expr->evaluate($journal); return $expr->evaluate($journal);
@@ -91,14 +94,14 @@ class RuleAction extends Model
protected function order(): Attribute protected function order(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: static fn ($value) => (int)$value, get: static fn($value) => (int)$value,
); );
} }
protected function ruleId(): Attribute protected function ruleId(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: static fn ($value) => (int)$value, get: static fn($value) => (int)$value,
); );
} }
} }

View File

@@ -40,13 +40,18 @@ class IsValidActionExpression implements ValidationRule
*/ */
public function validate(string $attribute, mixed $value, \Closure $fail): void public function validate(string $attribute, mixed $value, \Closure $fail): void
{ {
if (false === config('firefly.feature_flags.expression_engine')) {
return;
}
$value ??= ''; $value ??= '';
$expr = new ActionExpression($value); $expr = new ActionExpression($value);
if (!$expr->isValid()) { if (!$expr->isValid()) {
$fail('validation.rule_action_expression')->translate([ $fail('validation.rule_action_expression')->translate(
[
'error' => $expr->getValidationError()->getMessage(), 'error' => $expr->getValidationError()->getMessage(),
]); ]
);
} }
} }
} }

View File

@@ -185,7 +185,7 @@ class FireflyValidator extends Validator
// take // take
$first = substr($value, 0, 4); $first = substr($value, 0, 4);
$last = substr($value, 4); $last = substr($value, 4);
$iban = $last.$first; $iban = $last . $first;
$iban = trim(str_replace($search, $replace, $iban)); $iban = trim(str_replace($search, $replace, $iban));
if ('' === $iban) { if ('' === $iban) {
return false; return false;
@@ -269,7 +269,7 @@ class FireflyValidator extends Validator
} }
// if value is an expression, assume valid // if value is an expression, assume valid
if (str_starts_with($value, '=')) { if (true === config('firefly.feature_flags.expression_engine') && str_starts_with($value, '=') && strlen($value) > 1) {
return true; return true;
} }
@@ -509,7 +509,7 @@ class FireflyValidator extends Validator
private function validateByAccountTypeString(string $value, array $parameters, string $type): bool private function validateByAccountTypeString(string $value, array $parameters, string $type): bool
{ {
/** @var null|array $search */ /** @var null|array $search */
$search = \Config::get('firefly.accountTypeByIdentifier.'.$type); $search = \Config::get('firefly.accountTypeByIdentifier.' . $type);
if (null === $search) { if (null === $search) {
return false; return false;
@@ -522,8 +522,7 @@ class FireflyValidator extends Validator
/** @var null|Account $result */ /** @var null|Account $result */
$result = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore) $result = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore)
->where('name', $value) ->where('name', $value)
->first() ->first();
;
return null === $result; return null === $result;
} }
@@ -540,8 +539,7 @@ class FireflyValidator extends Validator
/** @var null|Account $result */ /** @var null|Account $result */
$result = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore) $result = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
->where('name', $value) ->where('name', $value)
->first() ->first();
;
return null === $result; return null === $result;
} }
@@ -559,8 +557,7 @@ class FireflyValidator extends Validator
$entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore) $entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
->where('name', $value) ->where('name', $value)
->first() ->first();
;
return null === $entry; return null === $entry;
} }
@@ -578,8 +575,7 @@ class FireflyValidator extends Validator
$entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore) $entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
->where('name', $value) ->where('name', $value)
->first() ->first();
;
return null === $entry; return null === $entry;
} }
@@ -607,8 +603,7 @@ class FireflyValidator extends Validator
->whereNull('accounts.deleted_at') ->whereNull('accounts.deleted_at')
->where('accounts.user_id', auth()->user()->id) ->where('accounts.user_id', auth()->user()->id)
->where('account_meta.name', 'account_number') ->where('account_meta.name', 'account_number')
->where('account_meta.data', json_encode($value)) ->where('account_meta.data', json_encode($value));
;
if ($accountId > 0) { if ($accountId > 0) {
// exclude current account from check. // exclude current account from check.
@@ -715,8 +710,7 @@ class FireflyValidator extends Validator
->where('response', $response) ->where('response', $response)
->where('delivery', $delivery) ->where('delivery', $delivery)
->where('id', '!=', $existingId) ->where('id', '!=', $existingId)
->where('url', $url)->count() ->where('url', $url)->count();
;
} }
return false; return false;
@@ -752,8 +746,7 @@ class FireflyValidator extends Validator
$result = \DB::table($table)->where('user_id', auth()->user()->id)->whereNull('deleted_at') $result = \DB::table($table)->where('user_id', auth()->user()->id)->whereNull('deleted_at')
->where('id', '!=', $exclude) ->where('id', '!=', $exclude)
->where($field, $value) ->where($field, $value)
->first([$field]) ->first([$field]);
;
if (null === $result) { if (null === $result) {
return true; // not found, so true. return true; // not found, so true.
} }
@@ -775,8 +768,7 @@ class FireflyValidator extends Validator
$query = \DB::table('object_groups') $query = \DB::table('object_groups')
->whereNull('object_groups.deleted_at') ->whereNull('object_groups.deleted_at')
->where('object_groups.user_id', auth()->user()->id) ->where('object_groups.user_id', auth()->user()->id)
->where('object_groups.title', $value) ->where('object_groups.title', $value);
;
if (null !== $exclude) { if (null !== $exclude) {
$query->where('object_groups.id', '!=', (int)$exclude); $query->where('object_groups.id', '!=', (int)$exclude);
} }
@@ -795,8 +787,7 @@ class FireflyValidator extends Validator
{ {
$exclude = $parameters[0] ?? null; $exclude = $parameters[0] ?? null;
$query = \DB::table('piggy_banks')->whereNull('piggy_banks.deleted_at') $query = \DB::table('piggy_banks')->whereNull('piggy_banks.deleted_at')
->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', auth()->user()->id) ->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', auth()->user()->id);
;
if (null !== $exclude) { if (null !== $exclude) {
$query->where('piggy_banks.id', '!=', (int)$exclude); $query->where('piggy_banks.id', '!=', (int)$exclude);
} }
@@ -829,8 +820,7 @@ class FireflyValidator extends Validator
->where('trigger', $trigger) ->where('trigger', $trigger)
->where('response', $response) ->where('response', $response)
->where('delivery', $delivery) ->where('delivery', $delivery)
->where('url', $url)->count() ->where('url', $url)->count();
;
} }
return false; return false;

View File

@@ -113,6 +113,7 @@ return [
'telemetry' => false, 'telemetry' => false,
'webhooks' => true, 'webhooks' => true,
'handle_debts' => true, 'handle_debts' => true,
'expression_engine' => false,
// see cer.php for exchange rates feature flag. // see cer.php for exchange rates feature flag.
], ],
'version' => 'develop/2024-03-07', 'version' => 'develop/2024-03-07',