mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 19:53:44 +00:00
This commit is contained in:
@@ -454,6 +454,35 @@ class RuleRepository implements RuleRepositoryInterface
|
|||||||
$type = sprintf('-%s', $type);
|
$type = sprintf('-%s', $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// empty the value in case the rule needs no context
|
||||||
|
// TODO create a helper to automatically return these.
|
||||||
|
$needTrue = [
|
||||||
|
'reconciled',
|
||||||
|
'has_attachments',
|
||||||
|
'has_any_category',
|
||||||
|
'has_any_budget',
|
||||||
|
'has_any_bill',
|
||||||
|
'has_any_tag',
|
||||||
|
'any_notes',
|
||||||
|
'any_external_url',
|
||||||
|
'has_no_attachments',
|
||||||
|
'has_no_category',
|
||||||
|
'has_no_budget',
|
||||||
|
'has_no_bill',
|
||||||
|
'has_no_tag',
|
||||||
|
'no_notes',
|
||||||
|
'no_external_url',
|
||||||
|
'source_is_cash',
|
||||||
|
'destination_is_cash',
|
||||||
|
'account_is_cash',
|
||||||
|
'exists',
|
||||||
|
'no_external_id',
|
||||||
|
'any_external_id',
|
||||||
|
];
|
||||||
|
if(in_array($type, $needTrue, true)) {
|
||||||
|
$value = '';
|
||||||
|
}
|
||||||
|
|
||||||
$triggerValues = [
|
$triggerValues = [
|
||||||
'action' => $type,
|
'action' => $type,
|
||||||
'value' => $value,
|
'value' => $value,
|
||||||
|
@@ -109,12 +109,18 @@ class RuleTransformer extends AbstractTransformer
|
|||||||
if ('user_action' === $ruleTrigger->trigger_type) {
|
if ('user_action' === $ruleTrigger->trigger_type) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
$triggerValue = (string)$ruleTrigger->trigger_value;
|
||||||
|
$needsContext = config(sprintf('search.operators.%s.needs_context', $ruleTrigger->trigger_type), true);
|
||||||
|
if (false === $needsContext) {
|
||||||
|
$triggerValue = 'true';
|
||||||
|
}
|
||||||
|
|
||||||
$result[] = [
|
$result[] = [
|
||||||
'id' => (string)$ruleTrigger->id,
|
'id' => (string)$ruleTrigger->id,
|
||||||
'created_at' => $ruleTrigger->created_at->toAtomString(),
|
'created_at' => $ruleTrigger->created_at->toAtomString(),
|
||||||
'updated_at' => $ruleTrigger->updated_at->toAtomString(),
|
'updated_at' => $ruleTrigger->updated_at->toAtomString(),
|
||||||
'type' => $ruleTrigger->trigger_type,
|
'type' => $ruleTrigger->trigger_type,
|
||||||
'value' => $ruleTrigger->trigger_value,
|
'value' => $triggerValue,
|
||||||
'order' => $ruleTrigger->order,
|
'order' => $ruleTrigger->order,
|
||||||
'active' => $ruleTrigger->active,
|
'active' => $ruleTrigger->active,
|
||||||
'stop_processing' => $ruleTrigger->stop_processing,
|
'stop_processing' => $ruleTrigger->stop_processing,
|
||||||
|
@@ -339,7 +339,37 @@ class FireflyValidator extends Validator
|
|||||||
return is_numeric($value);
|
return is_numeric($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// these triggers need just the word "true":
|
||||||
|
// TODO create a helper to automatically return these.
|
||||||
|
$needTrue = [
|
||||||
|
'reconciled',
|
||||||
|
'has_attachments',
|
||||||
|
'has_any_category',
|
||||||
|
'has_any_budget',
|
||||||
|
'has_any_bill',
|
||||||
|
'has_any_tag',
|
||||||
|
'any_notes',
|
||||||
|
'any_external_url',
|
||||||
|
'has_no_attachments',
|
||||||
|
'has_no_category',
|
||||||
|
'has_no_budget',
|
||||||
|
'has_no_bill',
|
||||||
|
'has_no_tag',
|
||||||
|
'no_notes',
|
||||||
|
'no_external_url',
|
||||||
|
'source_is_cash',
|
||||||
|
'destination_is_cash',
|
||||||
|
'account_is_cash',
|
||||||
|
'exists',
|
||||||
|
'no_external_id',
|
||||||
|
'any_external_id',
|
||||||
|
];
|
||||||
|
if (in_array($triggerType, $needTrue, true)) {
|
||||||
|
return 'true' === $value;
|
||||||
|
}
|
||||||
|
|
||||||
// these trigger types need a simple strlen check:
|
// these trigger types need a simple strlen check:
|
||||||
|
// TODO create a helper to automatically return these.
|
||||||
$length = [
|
$length = [
|
||||||
'source_account_starts',
|
'source_account_starts',
|
||||||
'source_account_ends',
|
'source_account_ends',
|
||||||
@@ -367,18 +397,21 @@ class FireflyValidator extends Validator
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if it's an existing account.
|
// check if it's an existing account.
|
||||||
|
// TODO create a helper to automatically return these.
|
||||||
if (in_array($triggerType, ['destination_account_id', 'source_account_id'], true)) {
|
if (in_array($triggerType, ['destination_account_id', 'source_account_id'], true)) {
|
||||||
return is_numeric($value) && (int)$value > 0;
|
return is_numeric($value) && (int)$value > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check transaction type.
|
// check transaction type.
|
||||||
|
// TODO create a helper to automatically return these.
|
||||||
if ('transaction_type' === $triggerType) {
|
if ('transaction_type' === $triggerType) {
|
||||||
$count = TransactionType::where('type', ucfirst($value))->count();
|
$count = TransactionType::where('type', ucfirst($value))->count();
|
||||||
|
|
||||||
return 1 === $count;
|
return 1 === $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the type is date, the simply try to parse it and throw error when it's bad.
|
// if the type is date, then simply try to parse it and throw error when it's bad.
|
||||||
|
// TODO create a helper to automatically return these.
|
||||||
if (in_array($triggerType, ['date_is', 'created_on', 'updated_on', 'date_before', 'date_after'], true)) {
|
if (in_array($triggerType, ['date_is', 'created_on', 'updated_on', 'date_before', 'date_after'], true)) {
|
||||||
/** @var ParseDateString $parser */
|
/** @var ParseDateString $parser */
|
||||||
$parser = app(ParseDateString::class);
|
$parser = app(ParseDateString::class);
|
||||||
@@ -483,8 +516,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.
|
||||||
@@ -591,8 +623,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;
|
||||||
@@ -628,8 +659,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.
|
||||||
}
|
}
|
||||||
@@ -651,8 +681,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);
|
||||||
}
|
}
|
||||||
@@ -671,8 +700,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);
|
||||||
}
|
}
|
||||||
@@ -705,8 +733,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;
|
||||||
@@ -745,8 +772,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;
|
||||||
}
|
}
|
||||||
@@ -763,8 +789,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;
|
||||||
}
|
}
|
||||||
@@ -782,8 +807,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;
|
||||||
}
|
}
|
||||||
@@ -801,8 +825,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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user