mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Update webhooks
This commit is contained in:
parent
f0416f5322
commit
10f2cf2481
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Api\V1\Requests\Models\Webhook;
|
namespace FireflyIII\Api\V1\Requests\Models\Webhook;
|
||||||
|
|
||||||
|
use FireflyIII\Models\Webhook;
|
||||||
use FireflyIII\Rules\IsBoolean;
|
use FireflyIII\Rules\IsBoolean;
|
||||||
use FireflyIII\Support\Request\ChecksLogin;
|
use FireflyIII\Support\Request\ChecksLogin;
|
||||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
@ -40,9 +41,10 @@ class CreateRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function getData(): array
|
public function getData(): array
|
||||||
{
|
{
|
||||||
$triggers = array_flip(config('firefly.webhooks.triggers'));
|
|
||||||
$responses = array_flip(config('firefly.webhooks.responses'));
|
$triggers = array_flip(Webhook::getTriggers());
|
||||||
$deliveries = array_flip(config('firefly.webhooks.deliveries'));
|
$responses = array_flip(Webhook::getResponses());
|
||||||
|
$deliveries = array_flip(Webhook::getDeliveries());
|
||||||
|
|
||||||
$fields = [
|
$fields = [
|
||||||
'title' => ['title', 'convertString'],
|
'title' => ['title', 'convertString'],
|
||||||
@ -69,9 +71,9 @@ class CreateRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$triggers = implode(',', array_values(config('firefly.webhooks.triggers')));
|
$triggers = implode(',', Webhook::getTriggers());
|
||||||
$responses = implode(',', array_values(config('firefly.webhooks.responses')));
|
$responses = implode(',', Webhook::getResponses());
|
||||||
$deliveries = implode(',', array_values(config('firefly.webhooks.deliveries')));
|
$deliveries = implode(',', Webhook::getDeliveries());
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'title' => 'required|between:1,512|uniqueObjectForUser:webhooks,title',
|
'title' => 'required|between:1,512|uniqueObjectForUser:webhooks,title',
|
||||||
@ -79,7 +81,9 @@ class CreateRequest extends FormRequest
|
|||||||
'trigger' => sprintf('required|in:%s', $triggers),
|
'trigger' => sprintf('required|in:%s', $triggers),
|
||||||
'response' => sprintf('required|in:%s', $responses),
|
'response' => sprintf('required|in:%s', $responses),
|
||||||
'delivery' => sprintf('required|in:%s', $deliveries),
|
'delivery' => sprintf('required|in:%s', $deliveries),
|
||||||
'url' => ['required', 'url', 'starts_with:https://', 'uniqueWebhook'],
|
'url' => ['required', 'url', 'uniqueWebhook'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Api\V1\Requests\Models\Webhook;
|
namespace FireflyIII\Api\V1\Requests\Models\Webhook;
|
||||||
|
|
||||||
|
use FireflyIII\Models\Webhook;
|
||||||
use FireflyIII\Rules\IsBoolean;
|
use FireflyIII\Rules\IsBoolean;
|
||||||
use FireflyIII\Support\Request\ChecksLogin;
|
use FireflyIII\Support\Request\ChecksLogin;
|
||||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
@ -40,9 +41,9 @@ class UpdateRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function getData(): array
|
public function getData(): array
|
||||||
{
|
{
|
||||||
$triggers = array_flip(config('firefly.webhooks.triggers'));
|
$triggers = array_flip(Webhook::getTriggers());
|
||||||
$responses = array_flip(config('firefly.webhooks.responses'));
|
$responses = array_flip(Webhook::getResponses());
|
||||||
$deliveries = array_flip(config('firefly.webhooks.deliveries'));
|
$deliveries = array_flip(Webhook::getDeliveries());
|
||||||
|
|
||||||
$fields = [
|
$fields = [
|
||||||
'title' => ['title', 'convertString'],
|
'title' => ['title', 'convertString'],
|
||||||
@ -79,9 +80,10 @@ class UpdateRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$triggers = implode(',', array_values(config('firefly.webhooks.triggers')));
|
|
||||||
$responses = implode(',', array_values(config('firefly.webhooks.responses')));
|
$triggers = implode(',', array_values(Webhook::getTriggers()));
|
||||||
$deliveries = implode(',', array_values(config('firefly.webhooks.deliveries')));
|
$responses = implode(',', array_values(Webhook::getResponses()));
|
||||||
|
$deliveries = implode(',', array_values(Webhook::getDeliveries()));
|
||||||
$webhook = $this->route()->parameter('webhook');
|
$webhook = $this->route()->parameter('webhook');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
/*
|
/*
|
||||||
* ListController.php
|
* ListController.php
|
||||||
* Copyright (c) 2022 james@firefly-iii.org
|
* Copyright (c) 2022 james@firefly-iii.org
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
/*
|
/*
|
||||||
* ListController.php
|
* ListController.php
|
||||||
* Copyright (c) 2022 james@firefly-iii.org
|
* Copyright (c) 2022 james@firefly-iii.org
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
/*
|
/*
|
||||||
* UpdateGroupInformation.php
|
* UpdateGroupInformation.php
|
||||||
* Copyright (c) 2022 james@firefly-iii.org
|
* Copyright (c) 2022 james@firefly-iii.org
|
||||||
|
@ -24,5 +24,6 @@ namespace FireflyIII\Enums;
|
|||||||
|
|
||||||
enum WebhookDelivery: int
|
enum WebhookDelivery: int
|
||||||
{
|
{
|
||||||
|
//case XML = 200;
|
||||||
case JSON = 300;
|
case JSON = 300;
|
||||||
}
|
}
|
||||||
|
@ -27,4 +27,5 @@ enum WebhookResponse: int
|
|||||||
case TRANSACTIONS = 200;
|
case TRANSACTIONS = 200;
|
||||||
case ACCOUNTS = 210;
|
case ACCOUNTS = 210;
|
||||||
case NONE = 220;
|
case NONE = 220;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,15 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Enums;
|
namespace FireflyIII\Enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class WebhookTrigger
|
||||||
|
*/
|
||||||
enum WebhookTrigger: int
|
enum WebhookTrigger: int
|
||||||
{
|
{
|
||||||
case STORE_TRANSACTION = 100;
|
case STORE_TRANSACTION = 100;
|
||||||
|
//case BEFORE_STORE_TRANSACTION = 101;
|
||||||
case UPDATE_TRANSACTION = 110;
|
case UPDATE_TRANSACTION = 110;
|
||||||
|
//case BEFORE_UPDATE_TRANSACTION = 111;
|
||||||
case DESTROY_TRANSACTION = 120;
|
case DESTROY_TRANSACTION = 120;
|
||||||
|
//case BEFORE_DESTROY_TRANSACTION = 121;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,9 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Models;
|
namespace FireflyIII\Models;
|
||||||
|
|
||||||
use Eloquent;
|
use Eloquent;
|
||||||
|
use FireflyIII\Enums\WebhookDelivery;
|
||||||
|
use FireflyIII\Enums\WebhookResponse;
|
||||||
|
use FireflyIII\Enums\WebhookTrigger;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
@ -76,17 +79,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
*/
|
*/
|
||||||
class Webhook extends Model
|
class Webhook extends Model
|
||||||
{
|
{
|
||||||
|
|
||||||
// dont forget to update the config in firefly.php
|
|
||||||
public const DELIVERY_JSON = 300;
|
|
||||||
public const RESPONSE_ACCOUNTS = 210;
|
|
||||||
public const RESPONSE_NONE = 220;
|
|
||||||
public const RESPONSE_TRANSACTIONS = 200;
|
|
||||||
public const TRIGGER_DESTROY_TRANSACTION = 120;
|
|
||||||
public const TRIGGER_STORE_TRANSACTION = 100;
|
|
||||||
public const TRIGGER_UPDATE_TRANSACTION = 110;
|
|
||||||
|
|
||||||
|
|
||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
|
|
||||||
protected $casts
|
protected $casts
|
||||||
@ -138,4 +130,42 @@ class Webhook extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasMany(WebhookMessage::class);
|
return $this->hasMany(WebhookMessage::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getTriggers(): array
|
||||||
|
{
|
||||||
|
$array = [];
|
||||||
|
$set = WebhookTrigger::cases();
|
||||||
|
foreach ($set as $item) {
|
||||||
|
$array[$item->value] = $item->name;
|
||||||
|
}
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getResponses(): array
|
||||||
|
{
|
||||||
|
$array = [];
|
||||||
|
$set = WebhookResponse::cases();
|
||||||
|
foreach ($set as $item) {
|
||||||
|
$array[$item->value] = $item->name;
|
||||||
|
}
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getDeliveries(): array
|
||||||
|
{
|
||||||
|
$array = [];
|
||||||
|
$set = WebhookDelivery::cases();
|
||||||
|
foreach ($set as $item) {
|
||||||
|
$array[$item->value] = $item->name;
|
||||||
|
}
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Transformers;
|
namespace FireflyIII\Transformers;
|
||||||
|
|
||||||
|
use FireflyIII\Enums\WebhookDelivery;
|
||||||
|
use FireflyIII\Enums\WebhookResponse;
|
||||||
|
use FireflyIII\Enums\WebhookTrigger;
|
||||||
use FireflyIII\Models\Webhook;
|
use FireflyIII\Models\Webhook;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,8 +41,6 @@ class WebhookTransformer extends AbstractTransformer
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
// array merge kills the keys
|
|
||||||
$this->enums = config('firefly.webhooks.triggers') + config('firefly.webhooks.responses') + config('firefly.webhooks.deliveries');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,9 +59,9 @@ class WebhookTransformer extends AbstractTransformer
|
|||||||
'active' => $webhook->active,
|
'active' => $webhook->active,
|
||||||
'title' => $webhook->title,
|
'title' => $webhook->title,
|
||||||
'secret' => $webhook->secret,
|
'secret' => $webhook->secret,
|
||||||
'trigger' => $this->getEnum($webhook->trigger),
|
'trigger' => $this->getEnum('trigger', $webhook->trigger),
|
||||||
'response' => $this->getEnum($webhook->response),
|
'response' => $this->getEnum('response', $webhook->response),
|
||||||
'delivery' => $this->getEnum($webhook->delivery),
|
'delivery' => $this->getEnum('delivery', $webhook->delivery),
|
||||||
'url' => $webhook->url,
|
'url' => $webhook->url,
|
||||||
'links' => [
|
'links' => [
|
||||||
[
|
[
|
||||||
@ -71,8 +72,19 @@ class WebhookTransformer extends AbstractTransformer
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getEnum(int $value)
|
/**
|
||||||
|
* @param string $type
|
||||||
|
* @param int $value
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getEnum(string $type, int $value): string
|
||||||
{
|
{
|
||||||
return $this->enums[$value] ?? 'UNKNOWN_VALUE';
|
if ('trigger' === $type) {
|
||||||
|
return WebhookTrigger::from($value)->name;
|
||||||
|
}
|
||||||
|
if ('response' === $type) {
|
||||||
|
return WebhookResponse::from($value)->name;
|
||||||
|
}
|
||||||
|
return WebhookDelivery::from($value)->name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -814,10 +814,10 @@ class FireflyValidator extends Validator
|
|||||||
public function validateUniqueWebhook($value, $parameters): bool
|
public function validateUniqueWebhook($value, $parameters): bool
|
||||||
{
|
{
|
||||||
if (auth()->check()) {
|
if (auth()->check()) {
|
||||||
// possible values
|
|
||||||
$triggers = array_flip(config('firefly.webhooks.triggers'));
|
$triggers = array_flip(Webhook::getTriggers());
|
||||||
$responses = array_flip(config('firefly.webhooks.responses'));
|
$responses = array_flip(Webhook::getResponses());
|
||||||
$deliveries = array_flip(config('firefly.webhooks.deliveries'));
|
$deliveries = array_flip(Webhook::getDeliveries());
|
||||||
|
|
||||||
// integers
|
// integers
|
||||||
$trigger = $triggers[$this->data['trigger']] ?? 0;
|
$trigger = $triggers[$this->data['trigger']] ?? 0;
|
||||||
|
@ -82,6 +82,9 @@ use FireflyIII\TransactionRules\Actions\SetNotes;
|
|||||||
use FireflyIII\TransactionRules\Actions\SetSourceAccount;
|
use FireflyIII\TransactionRules\Actions\SetSourceAccount;
|
||||||
use FireflyIII\TransactionRules\Actions\UpdatePiggybank;
|
use FireflyIII\TransactionRules\Actions\UpdatePiggybank;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
|
use FireflyIII\Enums\WebhookResponse as WebhookResponseEnum;
|
||||||
|
use FireflyIII\Enums\WebhookDelivery as WebhookDeliveryEnum;
|
||||||
|
use FireflyIII\Enums\WebhookTrigger as WebhookTriggerEnum;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -727,20 +730,7 @@ return [
|
|||||||
'recurrence_total', 'recurrence_count',
|
'recurrence_total', 'recurrence_count',
|
||||||
],
|
],
|
||||||
'webhooks' => [
|
'webhooks' => [
|
||||||
'max_attempts' => env('WEBHOOK_MAX_ATTEMPTS', 3),
|
'max_attempts' => env('WEBHOOK_MAX_ATTEMPTS', 3)
|
||||||
'triggers' => [
|
|
||||||
Webhook::TRIGGER_STORE_TRANSACTION => 'TRIGGER_STORE_TRANSACTION',
|
|
||||||
Webhook::TRIGGER_UPDATE_TRANSACTION => 'TRIGGER_UPDATE_TRANSACTION',
|
|
||||||
Webhook::TRIGGER_DESTROY_TRANSACTION => 'TRIGGER_DESTROY_TRANSACTION',
|
|
||||||
],
|
|
||||||
'responses' => [
|
|
||||||
Webhook::RESPONSE_TRANSACTIONS => 'RESPONSE_TRANSACTIONS',
|
|
||||||
Webhook::RESPONSE_ACCOUNTS => 'RESPONSE_ACCOUNTS',
|
|
||||||
Webhook::RESPONSE_NONE => 'RESPONSE_NONE',
|
|
||||||
],
|
|
||||||
'deliveries' => [
|
|
||||||
Webhook::DELIVERY_JSON => 'DELIVERY_JSON',
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
'can_have_virtual_amounts' => [AccountType::ASSET],
|
'can_have_virtual_amounts' => [AccountType::ASSET],
|
||||||
'can_have_opening_balance' => [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD],
|
'can_have_opening_balance' => [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD],
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
Loading…
Reference in New Issue
Block a user