mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
🤖 Auto commit for release 'develop' on 2025-08-22
This commit is contained in:
@@ -137,7 +137,8 @@ class RecurringEnrichment implements EnrichmentInterface
|
||||
// get the (future) occurrences for this specific type of repetition:
|
||||
$amount = 'daily' === $repetition->repetition_type ? 9 : 5;
|
||||
$set = $repository->getXOccurrencesSince($repetition, $fromDate, now(config('app.timezone')), $amount);
|
||||
$occurrences = [];
|
||||
$occurrences = [];
|
||||
|
||||
/** @var Carbon $carbon */
|
||||
foreach ($set as $carbon) {
|
||||
$occurrences[] = $carbon->toAtomString();
|
||||
|
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\JsonApi\Enrichments;
|
||||
|
||||
use FireflyIII\Enums\WebhookDelivery as WebhookDeliveryEnum;
|
||||
@@ -15,22 +17,22 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use stdClass;
|
||||
|
||||
class WebhookEnrichment implements EnrichmentInterface
|
||||
{
|
||||
private Collection $collection;
|
||||
private User $user;
|
||||
private UserGroup $userGroup;
|
||||
private array $ids = [];
|
||||
private array $deliveries = [];
|
||||
private array $responses = [];
|
||||
private array $triggers = [];
|
||||
private array $ids = [];
|
||||
private array $deliveries = [];
|
||||
private array $responses = [];
|
||||
private array $triggers = [];
|
||||
|
||||
private array $webhookDeliveries = [];
|
||||
private array $webhookResponses = [];
|
||||
private array $webhookTriggers = [];
|
||||
|
||||
|
||||
public function enrich(Collection $collection): Collection
|
||||
{
|
||||
$this->collection = $collection;
|
||||
@@ -40,10 +42,11 @@ class WebhookEnrichment implements EnrichmentInterface
|
||||
$this->collectWebhookInfo();
|
||||
$this->appendCollectedInfo();
|
||||
}
|
||||
|
||||
return $this->collection;
|
||||
}
|
||||
|
||||
public function enrichSingle(Model|array $model): array|Model
|
||||
public function enrichSingle(array|Model $model): array|Model
|
||||
{
|
||||
Log::debug(__METHOD__);
|
||||
$collection = new Collection([$model]);
|
||||
@@ -74,16 +77,19 @@ class WebhookEnrichment implements EnrichmentInterface
|
||||
private function collectInfo(): void
|
||||
{
|
||||
$all = WebhookDelivery::get();
|
||||
|
||||
/** @var WebhookDelivery $item */
|
||||
foreach ($all as $item) {
|
||||
$this->deliveries[$item->id] = $item->key;
|
||||
}
|
||||
$all = WebhookResponse::get();
|
||||
|
||||
/** @var WebhookResponse $item */
|
||||
foreach ($all as $item) {
|
||||
$this->responses[$item->id] = $item->key;
|
||||
}
|
||||
$all = WebhookTrigger::get();
|
||||
|
||||
/** @var WebhookTrigger $item */
|
||||
foreach ($all as $item) {
|
||||
$this->triggers[$item->id] = $item->key;
|
||||
@@ -94,7 +100,8 @@ class WebhookEnrichment implements EnrichmentInterface
|
||||
private function collectWebhookInfo(): void
|
||||
{
|
||||
$set = DB::table('webhook_webhook_delivery')->whereIn('webhook_id', $this->ids)->get(['webhook_id', 'webhook_delivery_id']);
|
||||
/** @var \stdClass $item */
|
||||
|
||||
/** @var stdClass $item */
|
||||
foreach ($set as $item) {
|
||||
$id = $item->webhook_id;
|
||||
$deliveryId = $item->webhook_delivery_id;
|
||||
@@ -102,7 +109,8 @@ class WebhookEnrichment implements EnrichmentInterface
|
||||
}
|
||||
|
||||
$set = DB::table('webhook_webhook_response')->whereIn('webhook_id', $this->ids)->get(['webhook_id', 'webhook_response_id']);
|
||||
/** @var \stdClass $item */
|
||||
|
||||
/** @var stdClass $item */
|
||||
foreach ($set as $item) {
|
||||
$id = $item->webhook_id;
|
||||
$responseId = $item->webhook_response_id;
|
||||
@@ -110,7 +118,8 @@ class WebhookEnrichment implements EnrichmentInterface
|
||||
}
|
||||
|
||||
$set = DB::table('webhook_webhook_trigger')->whereIn('webhook_id', $this->ids)->get(['webhook_id', 'webhook_trigger_id']);
|
||||
/** @var \stdClass $item */
|
||||
|
||||
/** @var stdClass $item */
|
||||
foreach ($set as $item) {
|
||||
$id = $item->webhook_id;
|
||||
$triggerId = $item->webhook_trigger_id;
|
||||
@@ -127,8 +136,8 @@ class WebhookEnrichment implements EnrichmentInterface
|
||||
'triggers' => $this->webhookTriggers[$item->id] ?? [],
|
||||
];
|
||||
$item->meta = $meta;
|
||||
|
||||
return $item;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -255,7 +255,7 @@ trait ConvertsDataTypes
|
||||
if (10 === strlen((string) $value)) {
|
||||
// probably a date format.
|
||||
try {
|
||||
$carbon = Carbon::createFromFormat('Y-m-d', $value,config('app.timezone'));
|
||||
$carbon = Carbon::createFromFormat('Y-m-d', $value, config('app.timezone'));
|
||||
} catch (InvalidDateException $e) { // @phpstan-ignore-line
|
||||
Log::error(sprintf('[1] "%s" is not a valid date: %s', $value, $e->getMessage()));
|
||||
|
||||
@@ -276,7 +276,7 @@ trait ConvertsDataTypes
|
||||
|
||||
// is an atom string, I hope?
|
||||
try {
|
||||
$carbon = Carbon::parse($value, $value,config('app.timezone'));
|
||||
$carbon = Carbon::parse($value, $value, config('app.timezone'));
|
||||
} catch (InvalidDateException $e) { // @phpstan-ignore-line
|
||||
Log::error(sprintf('[3] "%s" is not a valid date or time: %s', $value, $e->getMessage()));
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Request;
|
||||
|
||||
use FireflyIII\Enums\WebhookTrigger;
|
||||
@@ -17,9 +19,9 @@ trait ValidatesWebhooks
|
||||
if ($validator->failed()) {
|
||||
return;
|
||||
}
|
||||
$data = $validator->getData();
|
||||
$triggers = $data['triggers'] ?? [];
|
||||
$responses = $data['responses'] ?? [];
|
||||
$data = $validator->getData();
|
||||
$triggers = $data['triggers'] ?? [];
|
||||
$responses = $data['responses'] ?? [];
|
||||
|
||||
if (0 === count($triggers) || 0 === count($responses)) {
|
||||
Log::debug('No trigger or response, return.');
|
||||
@@ -28,19 +30,20 @@ trait ValidatesWebhooks
|
||||
}
|
||||
$validTriggers = array_values(Webhook::getTriggers());
|
||||
$validResponses = array_values(Webhook::getResponses());
|
||||
$containsAny = false;
|
||||
$count = 0;
|
||||
$containsAny = false;
|
||||
$count = 0;
|
||||
foreach ($triggers as $trigger) {
|
||||
if (!in_array($trigger, $validTriggers, true)) {
|
||||
return;
|
||||
}
|
||||
$count++;
|
||||
if($trigger === WebhookTrigger::ANY->name) {
|
||||
++$count;
|
||||
if ($trigger === WebhookTrigger::ANY->name) {
|
||||
$containsAny = true;
|
||||
}
|
||||
}
|
||||
if($containsAny && $count > 1) {
|
||||
if ($containsAny && $count > 1) {
|
||||
$validator->errors()->add('triggers.0', trans('validation.only_any_trigger'));
|
||||
|
||||
return;
|
||||
}
|
||||
foreach ($responses as $response) {
|
||||
@@ -52,13 +55,15 @@ trait ValidatesWebhooks
|
||||
foreach ($triggers as $i => $trigger) {
|
||||
$forbidden = config(sprintf('webhooks.forbidden_responses.%s', $trigger));
|
||||
if (null === $forbidden) {
|
||||
$validator->errors()->add(sprintf('triggers.%d', $i), trans('validation.unknown_webhook_trigger', ['trigger' => $trigger,]));
|
||||
$validator->errors()->add(sprintf('triggers.%d', $i), trans('validation.unknown_webhook_trigger', ['trigger' => $trigger]));
|
||||
|
||||
continue;
|
||||
}
|
||||
foreach ($responses as $ii => $response) {
|
||||
if (in_array($response, $forbidden, true)) {
|
||||
Log::debug(sprintf('Trigger %s and response %s are forbidden.', $trigger, $response));
|
||||
$validator->errors()->add(sprintf('responses.%d', $ii), trans('validation.bad_webhook_combination', ['trigger' => $trigger, 'response' => $response,]));
|
||||
$validator->errors()->add(sprintf('responses.%d', $ii), trans('validation.bad_webhook_combination', ['trigger' => $trigger, 'response' => $response]));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user