Expand webhook options, allow for budgets.

This commit is contained in:
James Cole
2025-08-17 07:40:19 +02:00
parent 52abe3bbc2
commit 7771b0311c
20 changed files with 3279 additions and 3046 deletions

View File

@@ -24,15 +24,18 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\System; namespace FireflyIII\Api\V1\Controllers\System;
use FireflyIII\Support\Facades\FireflyConfig;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\System\UpdateRequest; use FireflyIII\Api\V1\Requests\System\UpdateRequest;
use FireflyIII\Enums\WebhookDelivery;
use FireflyIII\Enums\WebhookResponse;
use FireflyIII\Enums\WebhookTrigger;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Support\Binder\EitherConfigKey; use FireflyIII\Support\Binder\EitherConfigKey;
use FireflyIII\Support\Facades\FireflyConfig;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
/** /**
@@ -139,7 +142,18 @@ class ConfigurationController extends Controller
'value' => $dynamic[$shortKey], 'value' => $dynamic[$shortKey],
'editable' => true, 'editable' => true,
]; ];
return response()->api(['data' => $data])->header('Content-Type', self::JSON_CONTENT_TYPE);
} }
if (str_starts_with($configKey, 'webhook.')) {
$data = [
'title' => $configKey,
'value' => $this->getWebhookConfiguration($configKey),
'editable' => false,
];
return response()->api(['data' => $data])->header('Content-Type', self::JSON_CONTENT_TYPE);
}
// fallback
if (!str_starts_with($configKey, 'configuration.')) { if (!str_starts_with($configKey, 'configuration.')) {
$data = [ $data = [
'title' => $configKey, 'title' => $configKey,
@@ -182,4 +196,33 @@ class ConfigurationController extends Controller
return response()->api(['data' => $data])->header('Content-Type', self::CONTENT_TYPE); return response()->api(['data' => $data])->header('Content-Type', self::CONTENT_TYPE);
} }
private function getWebhookConfiguration(string $configKey): array
{
switch ($configKey) {
case 'webhook.triggers':
$cases = WebhookTrigger::cases();
$data = [];
foreach ($cases as $c) {
$data[$c->name] = $c->value;
}
return $data;
case 'webhook.responses':
$cases = WebhookResponse::cases();
$data = [];
foreach ($cases as $c) {
$data[$c->name] = $c->value;
}
return $data;
case 'webhook.deliveries':
$cases = WebhookDelivery::cases();
$data = [];
foreach ($cases as $c) {
$data[$c->name] = $c->value;
}
return $data;
default:
throw new FireflyException(sprintf('Unknown webhook configuration key "%s".', $configKey));
}
}
} }

View File

@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Webhook; namespace FireflyIII\Api\V1\Controllers\Webhook;
use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Enums\WebhookTrigger;
use FireflyIII\Events\RequestedSendWebhookMessages; use FireflyIII\Events\RequestedSendWebhookMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Generator\Webhook\MessageGeneratorInterface; use FireflyIII\Generator\Webhook\MessageGeneratorInterface;
@@ -146,7 +147,7 @@ class ShowController extends Controller
$engine->setUser(auth()->user()); $engine->setUser(auth()->user());
// tell the generator which trigger it should look for // tell the generator which trigger it should look for
$engine->setTrigger($webhook->trigger); $engine->setTrigger(WebhookTrigger::tryFrom($webhook->trigger));
// tell the generator which objects to process // tell the generator which objects to process
$engine->setObjects(new Collection([$group])); $engine->setObjects(new Collection([$group]));
// set the webhook to trigger // set the webhook to trigger

View File

@@ -24,11 +24,15 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests\Models\Webhook; namespace FireflyIII\Api\V1\Requests\Models\Webhook;
use FireflyIII\Enums\WebhookResponse;
use FireflyIII\Enums\WebhookTrigger;
use FireflyIII\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;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Log;
/** /**
* Class CreateRequest * Class CreateRequest
@@ -81,4 +85,44 @@ class CreateRequest extends FormRequest
'url' => ['required', sprintf('url:%s', $validProtocols), 'uniqueWebhook'], 'url' => ['required', sprintf('url:%s', $validProtocols), 'uniqueWebhook'],
]; ];
} }
public function withValidator(Validator $validator): void
{
$validator->after(
function (Validator $validator): void {
Log::debug('Validating webhook');
$data = $validator->getData();
$trigger = $data['trigger'] ?? null;
$response = $data['response'] ?? null;
if (null === $trigger || null === $response) {
Log::debug('No trigger or response, return.');
return;
}
$triggers = array_keys(Webhook::getTriggersForValidation());
$responses = array_keys(Webhook::getResponsesForValidation());
if (!in_array($trigger, $triggers) || !in_array($response, $responses)) {
return;
}
// cannot deliver budget info.
if (is_int($trigger)) {
Log::debug(sprintf('Trigger was integer (%d).', $trigger));
$trigger = WebhookTrigger::from($trigger)->name;
}
if (is_int($response)) {
Log::debug(sprintf('Response was integer (%d).', $response));
$response = WebhookResponse::from($response)->name;
}
Log::debug(sprintf('Trigger is %s, response is %s', $trigger, $response));
if (str_contains($trigger, 'TRANSACTION') && str_contains($response, 'BUDGET')) {
$validator->errors()->add('response', trans('validation.webhook_budget_info'));
}
if (str_contains($trigger, 'BUDGET') && str_contains($response, 'ACCOUNT')) {
$validator->errors()->add('response', trans('validation.webhook_account_info'));
}
if (str_contains($trigger, 'BUDGET') && str_contains($response, 'TRANSACTION')) {
$validator->errors()->add('response', trans('validation.webhook_transaction_info'));
}
}
);
}
} }

View File

@@ -24,11 +24,15 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests\Models\Webhook; namespace FireflyIII\Api\V1\Requests\Models\Webhook;
use FireflyIII\Enums\WebhookResponse;
use FireflyIII\Enums\WebhookTrigger;
use FireflyIII\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;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Log;
/** /**
* Class UpdateRequest * Class UpdateRequest
@@ -94,4 +98,43 @@ class UpdateRequest extends FormRequest
'url' => [sprintf('url:%s', $validProtocols), sprintf('uniqueExistingWebhook:%d', $webhook->id)], 'url' => [sprintf('url:%s', $validProtocols), sprintf('uniqueExistingWebhook:%d', $webhook->id)],
]; ];
} }
public function withValidator(Validator $validator): void
{
$validator->after(
function (Validator $validator): void {
Log::debug('Validating webhook');
$data = $validator->getData();
$trigger = $data['trigger'] ?? null;
$response = $data['response'] ?? null;
if (null === $trigger || null === $response) {
Log::debug('No trigger or response, return.');
return;
}
$triggers = array_keys(Webhook::getTriggersForValidation());
$responses = array_keys(Webhook::getResponsesForValidation());
if (!in_array($trigger, $triggers) || !in_array($response, $responses)) {
return;
}
// cannot deliver budget info.
if (is_int($trigger)) {
Log::debug(sprintf('Trigger was integer (%d).', $trigger));
$trigger = WebhookTrigger::from($trigger)->name;
}
if (is_int($response)) {
Log::debug(sprintf('Response was integer (%d).', $response));
$response = WebhookResponse::from($response)->name;
}
Log::debug(sprintf('Trigger is %s, response is %s', $trigger, $response));
if (str_contains($trigger, 'TRANSACTION') && str_contains($response, 'BUDGET')) {
$validator->errors()->add('response', trans('validation.webhook_budget_info'));
}
if (str_contains($trigger, 'BUDGET') && str_contains($response, 'ACCOUNT')) {
$validator->errors()->add('response', trans('validation.webhook_account_info'));
}
if (str_contains($trigger, 'BUDGET') && str_contains($response, 'TRANSACTION')) {
$validator->errors()->add('response', trans('validation.webhook_transaction_info'));
}
}
);
}
} }

View File

@@ -31,5 +31,6 @@ enum WebhookResponse: int
{ {
case TRANSACTIONS = 200; case TRANSACTIONS = 200;
case ACCOUNTS = 210; case ACCOUNTS = 210;
case BUDGET = 230;
case NONE = 220; case NONE = 220;
} }

View File

@@ -30,9 +30,10 @@ namespace FireflyIII\Enums;
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; case STORE_BUDGET = 200;
case UPDATE_BUDGET = 210;
case DESTROY_BUDGET = 220;
case STORE_UPDATE_BUDGET_LIMIT = 230;
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Generator\Webhook; namespace FireflyIII\Generator\Webhook;
use FireflyIII\Enums\WebhookTrigger;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
@@ -38,7 +39,7 @@ interface MessageGeneratorInterface
public function setObjects(Collection $objects): void; public function setObjects(Collection $objects): void;
public function setTrigger(int $trigger): void; public function setTrigger(WebhookTrigger $trigger): void;
public function setUser(User $user): void; public function setUser(User $user): void;

View File

@@ -48,7 +48,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
class StandardMessageGenerator implements MessageGeneratorInterface class StandardMessageGenerator implements MessageGeneratorInterface
{ {
private Collection $objects; private Collection $objects;
private int $trigger; private WebhookTrigger $trigger;
private User $user; private User $user;
private int $version = 0; private int $version = 0;
private Collection $webhooks; private Collection $webhooks;
@@ -68,9 +68,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface
} }
// do some debugging // do some debugging
Log::debug( Log::debug(sprintf('StandardMessageGenerator will generate messages for %d object(s) and %d webhook(s).', $this->objects->count(), $this->webhooks->count()));
sprintf('StandardMessageGenerator will generate messages for %d object(s) and %d webhook(s).', $this->objects->count(), $this->webhooks->count())
);
$this->run(); $this->run();
} }
@@ -79,6 +77,9 @@ class StandardMessageGenerator implements MessageGeneratorInterface
return $this->user->webhooks()->where('active', true)->where('trigger', $this->trigger)->get(['webhooks.*']); return $this->user->webhooks()->where('active', true)->where('trigger', $this->trigger)->get(['webhooks.*']);
} }
/**
* @throws FireflyException
*/
private function run(): void private function run(): void
{ {
Log::debug('Now in StandardMessageGenerator::run'); Log::debug('Now in StandardMessageGenerator::run');
@@ -116,7 +117,8 @@ class StandardMessageGenerator implements MessageGeneratorInterface
$basicMessage = [ $basicMessage = [
'uuid' => $uuid->toString(), 'uuid' => $uuid->toString(),
'user_id' => 0, 'user_id' => 0,
'trigger' => WebhookTrigger::from($webhook->trigger)->name, 'user_group_id' => 0,
'trigger' => $webhook->trigger->name,
'response' => WebhookResponse::from($webhook->response)->name, 'response' => WebhookResponse::from($webhook->response)->name,
'url' => $webhook->url, 'url' => $webhook->url,
'version' => sprintf('v%d', $this->getVersion()), 'version' => sprintf('v%d', $this->getVersion()),
@@ -127,15 +129,14 @@ class StandardMessageGenerator implements MessageGeneratorInterface
switch ($class) { switch ($class) {
default: default:
// Line is ignored because all of Firefly III's Models have an id property. // Line is ignored because all of Firefly III's Models have an id property.
Log::error( Log::error(sprintf('Webhook #%d was given %s#%d to deal with but can\'t extract user ID from it.', $webhook->id, $class, $model->id));
sprintf('Webhook #%d was given %s#%d to deal with but can\'t extract user ID from it.', $webhook->id, $class, $model->id)
);
return; return;
case TransactionGroup::class: case TransactionGroup::class:
/** @var TransactionGroup $model */ /** @var TransactionGroup $model */
$basicMessage['user_id'] = $model->user->id; $basicMessage['user_id'] = $model->user_id;
$basicMessage['user_group_id'] = $model->user_group_id;
break; break;
} }
@@ -143,9 +144,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface
// then depends on the response what to put in the message: // then depends on the response what to put in the message:
switch ($webhook->response) { switch ($webhook->response) {
default: default:
Log::error( Log::error(sprintf('The response code for webhook #%d is "%d" and the message generator cant handle it. Soft fail.', $webhook->id, $webhook->response));
sprintf('The response code for webhook #%d is "%d" and the message generator cant handle it. Soft fail.', $webhook->id, $webhook->response)
);
return; return;
@@ -224,7 +223,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface
$this->objects = $objects; $this->objects = $objects;
} }
public function setTrigger(int $trigger): void public function setTrigger(WebhookTrigger $trigger): void
{ {
$this->trigger = $trigger; $this->trigger = $trigger;
} }

View File

@@ -53,7 +53,7 @@ class DestroyedGroupEventHandler
$engine = app(MessageGeneratorInterface::class); $engine = app(MessageGeneratorInterface::class);
$engine->setUser($user); $engine->setUser($user);
$engine->setObjects(new Collection([$group])); $engine->setObjects(new Collection([$group]));
$engine->setTrigger(WebhookTrigger::DESTROY_TRANSACTION->value); $engine->setTrigger(WebhookTrigger::DESTROY_TRANSACTION);
$engine->generateMessages(); $engine->generateMessages();
event(new RequestedSendWebhookMessages()); event(new RequestedSendWebhookMessages());

View File

@@ -32,6 +32,7 @@ use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Services\Internal\Support\CreditRecalculateService; use FireflyIII\Services\Internal\Support\CreditRecalculateService;
use FireflyIII\TransactionRules\Engine\RuleEngineInterface; use FireflyIII\TransactionRules\Engine\RuleEngineInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
/** /**
* Class StoredGroupEventHandler * Class StoredGroupEventHandler
@@ -51,11 +52,11 @@ class StoredGroupEventHandler
private function processRules(StoredTransactionGroup $storedGroupEvent): void private function processRules(StoredTransactionGroup $storedGroupEvent): void
{ {
if (false === $storedGroupEvent->applyRules) { if (false === $storedGroupEvent->applyRules) {
app('log')->info(sprintf('Will not run rules on group #%d', $storedGroupEvent->transactionGroup->id)); Log::info(sprintf('Will not run rules on group #%d', $storedGroupEvent->transactionGroup->id));
return; return;
} }
app('log')->debug('Now in StoredGroupEventHandler::processRules()'); Log::debug('Now in StoredGroupEventHandler::processRules()');
$journals = $storedGroupEvent->transactionGroup->transactionJournals; $journals = $storedGroupEvent->transactionGroup->transactionJournals;
$array = []; $array = [];
@@ -65,7 +66,7 @@ class StoredGroupEventHandler
$array[] = $journal->id; $array[] = $journal->id;
} }
$journalIds = implode(',', $array); $journalIds = implode(',', $array);
app('log')->debug(sprintf('Add local operator for journal(s): %s', $journalIds)); Log::debug(sprintf('Add local operator for journal(s): %s', $journalIds));
// collect rules: // collect rules:
$ruleGroupRepository = app(RuleGroupRepositoryInterface::class); $ruleGroupRepository = app(RuleGroupRepositoryInterface::class);
@@ -98,10 +99,10 @@ class StoredGroupEventHandler
*/ */
private function triggerWebhooks(StoredTransactionGroup $storedGroupEvent): void private function triggerWebhooks(StoredTransactionGroup $storedGroupEvent): void
{ {
app('log')->debug(__METHOD__); Log::debug(__METHOD__);
$group = $storedGroupEvent->transactionGroup; $group = $storedGroupEvent->transactionGroup;
if (false === $storedGroupEvent->fireWebhooks) { if (false === $storedGroupEvent->fireWebhooks) {
app('log')->info(sprintf('Will not fire webhooks for transaction group #%d', $group->id)); Log::info(sprintf('Will not fire webhooks for transaction group #%d', $group->id));
return; return;
} }
@@ -113,7 +114,7 @@ class StoredGroupEventHandler
$engine->setUser($user); $engine->setUser($user);
// tell the generator which trigger it should look for // tell the generator which trigger it should look for
$engine->setTrigger(WebhookTrigger::STORE_TRANSACTION->value); $engine->setTrigger(WebhookTrigger::STORE_TRANSACTION);
// tell the generator which objects to process // tell the generator which objects to process
$engine->setObjects(new Collection([$group])); $engine->setObjects(new Collection([$group]));
// tell the generator to generate the messages // tell the generator to generate the messages

View File

@@ -164,7 +164,7 @@ class UpdatedGroupEventHandler
$engine = app(MessageGeneratorInterface::class); $engine = app(MessageGeneratorInterface::class);
$engine->setUser($user); $engine->setUser($user);
$engine->setObjects(new Collection([$group])); $engine->setObjects(new Collection([$group]));
$engine->setTrigger(WebhookTrigger::UPDATE_TRANSACTION->value); $engine->setTrigger(WebhookTrigger::UPDATE_TRANSACTION);
$engine->generateMessages(); $engine->generateMessages();
event(new RequestedSendWebhookMessages()); event(new RequestedSendWebhookMessages());

View File

@@ -57,6 +57,11 @@ class EitherConfigKey
'firefly.rule-actions', 'firefly.rule-actions',
'firefly.context-rule-actions', 'firefly.context-rule-actions',
'search.operators', 'search.operators',
// webhooks
'webhook.triggers',
'webhook.responses',
'webhook.deliveries',
]; ];
/** /**

View File

@@ -57,6 +57,7 @@ return [
'liability_direction_credit_short', 'liability_direction_credit_short',
'liability_direction_null_short', 'liability_direction_null_short',
'interest_calc_yearly', 'interest_calc_yearly',
'loading',
'interest_calc_', 'interest_calc_',
'interest_calc_null', 'interest_calc_null',
'interest_calc_daily', 'interest_calc_daily',
@@ -246,12 +247,19 @@ return [
'multi_account_warning_withdrawal', 'multi_account_warning_withdrawal',
'multi_account_warning_deposit', 'multi_account_warning_deposit',
'multi_account_warning_transfer', 'multi_account_warning_transfer',
'webhook_trigger_STORE_TRANSACTION', 'webhook_trigger_STORE_TRANSACTION',
'webhook_trigger_UPDATE_TRANSACTION', 'webhook_trigger_UPDATE_TRANSACTION',
'webhook_trigger_DESTROY_TRANSACTION', 'webhook_trigger_DESTROY_TRANSACTION',
'webhook_trigger_STORE_BUDGET',
'webhook_trigger_UPDATE_BUDGET',
'webhook_trigger_DESTROY_BUDGET',
'webhook_trigger_STORE_UPDATE_BUDGET_LIMIT',
'webhook_response_TRANSACTIONS', 'webhook_response_TRANSACTIONS',
'webhook_response_ACCOUNTS', 'webhook_response_ACCOUNTS',
'webhook_response_none_NONE', 'webhook_response_NONE',
'webhook_delivery_JSON', 'webhook_delivery_JSON',
'actions', 'actions',
'meta_data', 'meta_data',

0
public/v1/js/.gitkeep Normal file → Executable file
View File

View File

@@ -24,7 +24,10 @@
{{ $t('form.webhook_delivery') }} {{ $t('form.webhook_delivery') }}
</label> </label>
<div class="col-sm-8"> <div class="col-sm-8">
<select <div v-if="loading" class="form-control-static">
<em class="fa fa-spinner fa-spin"></em> {{ $t('firefly.loading') }}
</div>
<select v-if="!loading"
ref="bill" ref="bill"
v-model="delivery" v-model="delivery"
:title="$t('form.webhook_delivery')" :title="$t('form.webhook_delivery')"
@@ -49,6 +52,7 @@ export default {
name: "WebhookDelivery", name: "WebhookDelivery",
data() { data() {
return { return {
loading: true,
delivery : 0, delivery : 0,
deliveries: [ deliveries: [
@@ -71,8 +75,24 @@ export default {
mounted() { mounted() {
this.delivery = this.value; this.delivery = this.value;
this.deliveries = [ this.deliveries = [
{id: 300, name: this.$t('firefly.webhook_delivery_JSON')}, //{id: 300, name: this.$t('firefly.webhook_delivery_JSON')},
]; ];
axios.get('./api/v1/configuration/webhook.deliveries').then((response) => {
for (let key in response.data.data.value) {
if (!response.data.data.value.hasOwnProperty(key)) {
continue;
}
this.deliveries.push(
{
id: response.data.data.value[key],
name: this.$t('firefly.webhook_delivery_' + key),
}
);
}
this.loading = false;
}).catch((error) => {
this.loading = false;
});
}, },
watch: { watch: {
value() { value() {

View File

@@ -24,8 +24,11 @@
{{ $t('form.webhook_response') }} {{ $t('form.webhook_response') }}
</label> </label>
<div class="col-sm-8"> <div class="col-sm-8">
<select <div v-if="loading" class="form-control-static">
ref="bill" <em class="fa fa-spinner fa-spin"></em> {{ $t('firefly.loading') }}
</div>
<select v-if="!loading"
ref="response"
v-model="response" v-model="response"
:title="$t('form.webhook_response')" :title="$t('form.webhook_response')"
class="form-control" class="form-control"
@@ -49,6 +52,7 @@ export default {
name: "WebhookResponse", name: "WebhookResponse",
data() { data() {
return { return {
loading: true,
response: 0, response: 0,
responses: [], responses: [],
}; };
@@ -76,11 +80,23 @@ export default {
}, },
mounted() { mounted() {
this.response = this.value; this.response = this.value;
this.responses = [ this.responses = [];
{id: 200, name: this.$t('firefly.webhook_response_TRANSACTIONS')}, axios.get('./api/v1/configuration/webhook.responses').then((response) => {
{id: 210, name: this.$t('firefly.webhook_response_ACCOUNTS')}, for (let key in response.data.data.value) {
{id: 220, name: this.$t('firefly.webhook_response_none_NONE')}, if (!response.data.data.value.hasOwnProperty(key)) {
]; continue;
}
this.responses.push(
{
id: response.data.data.value[key],
name: this.$t('firefly.webhook_response_' + key),
}
);
}
this.loading = false;
}).catch((error) => {
this.loading = false;
});
}, },
methods: { methods: {
hasError() { hasError() {

View File

@@ -24,8 +24,11 @@
{{ $t('form.webhook_trigger') }} {{ $t('form.webhook_trigger') }}
</label> </label>
<div class="col-sm-8"> <div class="col-sm-8">
<select <div v-if="loading" class="form-control-static">
ref="bill" <em class="fa fa-spinner fa-spin"></em> {{ $t('firefly.loading') }}
</div>
<select v-if="!loading"
ref="trigger"
v-model="trigger" v-model="trigger"
:title="$t('form.webhook_trigger')" :title="$t('form.webhook_trigger')"
class="form-control" class="form-control"
@@ -50,6 +53,7 @@ export default {
data() { data() {
return { return {
trigger: 0, trigger: 0,
loading: true,
triggers: [], triggers: [],
}; };
}, },
@@ -68,11 +72,24 @@ export default {
}, },
mounted() { mounted() {
this.trigger = this.value; this.trigger = this.value;
this.triggers = [ this.triggers = [];
{id: 100, name: this.$t('firefly.webhook_trigger_STORE_TRANSACTION')}, axios.get('./api/v1/configuration/webhook.triggers').then((response) => {
{id: 110, name: this.$t('firefly.webhook_trigger_UPDATE_TRANSACTION')}, for (let key in response.data.data.value) {
{id: 120, name: this.$t('firefly.webhook_trigger_DESTROY_TRANSACTION')}, if (!response.data.data.value.hasOwnProperty(key)) {
]; continue;
}
this.triggers.push(
{
id: response.data.data.value[key],
name: this.$t('firefly.webhook_trigger_' + key),
}
);
console.log('webhook trigger: id=' + response.data.data.value[key] + ', name=' + key);
}
this.loading = false;
}).catch((error) => {
this.loading = false;
});
}, },
watch: { watch: {
value() { value() {

View File

@@ -29,7 +29,8 @@
</div> </div>
<div class="box-body no-padding"> <div class="box-body no-padding">
<div style="padding:8px;"> <div style="padding:8px;">
<a href="webhooks/create" class="btn btn-success"><span class="fa fa-plus fa-fw"></span>{{ $t('firefly.create_new_webhook') }}</a> <a href="webhooks/create" class="btn btn-success"><span
class="fa fa-plus fa-fw"></span>{{ $t('firefly.create_new_webhook') }}</a>
</div> </div>
<table class="table table-responsive table-hover" v-if="webhooks.length > 0" aria-label="A table."> <table class="table table-responsive table-hover" v-if="webhooks.length > 0" aria-label="A table.">
@@ -50,14 +51,17 @@
</td> </td>
<td> <td>
<span v-if="webhook.active">{{ triggers[webhook.trigger] }}</span> <span v-if="webhook.active">{{ triggers[webhook.trigger] }}</span>
<span v-if="!webhook.active" class="text-muted"><s>{{ triggers[webhook.trigger] }}</s> ({{ $t('firefly.inactive') }})</span> <span v-if="!webhook.active" class="text-muted"><s>{{ triggers[webhook.trigger] }}</s> ({{
$t('firefly.inactive')
}})</span>
</td> </td>
<td>{{ responses[webhook.response] }} ({{ deliveries[webhook.delivery] }})</td> <td>{{ responses[webhook.response] }} ({{ deliveries[webhook.delivery] }})</td>
<td> <td>
<em style="cursor:pointer" <em style="cursor:pointer"
v-if="webhook.show_secret" class="fa fa-eye" @click="toggleSecret(webhook)"></em> v-if="webhook.show_secret" class="fa fa-eye" @click="toggleSecret(webhook)"></em>
<em style="cursor:pointer" <em style="cursor:pointer"
v-if="!webhook.show_secret" class="fa fa-eye-slash" @click="toggleSecret(webhook)"></em> v-if="!webhook.show_secret" class="fa fa-eye-slash"
@click="toggleSecret(webhook)"></em>
<code v-if="webhook.show_secret">{{ webhook.secret }}</code> <code v-if="webhook.show_secret">{{ webhook.secret }}</code>
<code v-if="!webhook.show_secret">********</code> <code v-if="!webhook.show_secret">********</code>
</td> </td>
@@ -67,12 +71,16 @@
</td> </td>
<td class="hidden-sm hidden-xs"> <td class="hidden-sm hidden-xs">
<div class="btn-group btn-group-xs pull-right"> <div class="btn-group btn-group-xs pull-right">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
{{ $t('firefly.actions') }} <span class="caret"></span></button> {{ $t('firefly.actions') }} <span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right" role="menu"> <ul class="dropdown-menu dropdown-menu-right" role="menu">
<li><a :href="'webhooks/show/' + webhook.id"><span class="fa fa-fw fa-search"></span> {{ $t('firefly.inspect') }}</a></li> <li><a :href="'webhooks/show/' + webhook.id"><span
<li><a :href="'webhooks/edit/' + webhook.id"><span class="fa fa-fw fa-pencil"></span> {{$t( 'firefly.edit') }}</a></li> class="fa fa-fw fa-search"></span> {{ $t('firefly.inspect') }}</a></li>
<li><a :href="'webhooks/delete/' + webhook.id"><span class="fa fa-fw fa-trash"></span> {{ $t('firefly.delete') }}</a></li> <li><a :href="'webhooks/edit/' + webhook.id"><span
class="fa fa-fw fa-pencil"></span> {{ $t('firefly.edit') }}</a></li>
<li><a :href="'webhooks/delete/' + webhook.id"><span
class="fa fa-fw fa-trash"></span> {{ $t('firefly.delete') }}</a></li>
</ul> </ul>
</div> </div>
</td> </td>
@@ -81,7 +89,8 @@
</table> </table>
<div v-if="webhooks.length > 0" style="padding:8px;"> <div v-if="webhooks.length > 0" style="padding:8px;">
<a href="webhooks/create" class="btn btn-success"><span class="fa fa-plus fa-fw"></span>{{ $t('firefly.create_new_webhook') }}</a> <a href="webhooks/create" class="btn btn-success"><span
class="fa fa-plus fa-fw"></span>{{ $t('firefly.create_new_webhook') }}</a>
</div> </div>
</div> </div>
</div> </div>
@@ -96,24 +105,49 @@ export default {
return { return {
webhooks: [], webhooks: [],
triggers: { triggers: {
STORE_TRANSACTION: this.$t('firefly.webhook_trigger_STORE_TRANSACTION'),
UPDATE_TRANSACTION: this.$t('firefly.webhook_trigger_UPDATE_TRANSACTION'),
DESTROY_TRANSACTION: this.$t('firefly.webhook_trigger_DESTROY_TRANSACTION'),
}, },
responses: { responses: {
TRANSACTIONS: this.$t('firefly.webhook_response_TRANSACTIONS'),
ACCOUNTS: this.$t('firefly.webhook_response_ACCOUNTS'),
NONE: this.$t('firefly.webhook_response_none_NONE'),
}, },
deliveries: { deliveries: {
JSON: this.$t('firefly.webhook_delivery_JSON'),
}, },
}; };
}, },
mounted() { mounted() {
this.getWebhooks(); this.getOptions();
}, },
methods: { methods: {
getOptions: function () {
// get triggers
axios.get('./api/v1/configuration/webhook.triggers').then((response) => {
for (let key in response.data.data.value) {
if (!response.data.data.value.hasOwnProperty(key)) {
continue;
}
this.triggers[key] = this.$t('firefly.webhook_trigger_' + key);
}
// get responses
axios.get('./api/v1/configuration/webhook.responses').then((response) => {
for (let key in response.data.data.value) {
if (!response.data.data.value.hasOwnProperty(key)) {
continue;
}
this.responses[key] = this.$t('firefly.webhook_response_' + key);
}
// get deliveries
axios.get('./api/v1/configuration/webhook.deliveries').then((response) => {
for (let key in response.data.data.value) {
if (!response.data.data.value.hasOwnProperty(key)) {
continue;
}
this.deliveries[key] = this.$t('firefly.webhook_delivery_' + key);
}
// get webhooks
this.getWebhooks();
})
})
});
},
getWebhooks: function () { getWebhooks: function () {
this.webhooks = []; this.webhooks = [];
this.downloadWebhooks(1); this.downloadWebhooks(1);

View File

@@ -23,7 +23,6 @@
declare(strict_types=1); declare(strict_types=1);
return [ return [
// general stuff: // general stuff:
'stored_in_tz' => 'stored in ":timezone"', 'stored_in_tz' => 'stored in ":timezone"',
@@ -31,6 +30,7 @@ return [
'close' => 'Close', 'close' => 'Close',
'actions' => 'Actions', 'actions' => 'Actions',
'edit' => 'Edit', 'edit' => 'Edit',
'loading' => 'Loading',
'transaction_journal_id' => 'Transaction journal ID', 'transaction_journal_id' => 'Transaction journal ID',
'delete' => 'Delete', 'delete' => 'Delete',
'split' => 'Split', 'split' => 'Split',
@@ -244,9 +244,15 @@ return [
'webhook_trigger_STORE_TRANSACTION' => 'After transaction creation', 'webhook_trigger_STORE_TRANSACTION' => 'After transaction creation',
'webhook_trigger_UPDATE_TRANSACTION' => 'After transaction update', 'webhook_trigger_UPDATE_TRANSACTION' => 'After transaction update',
'webhook_trigger_DESTROY_TRANSACTION' => 'After transaction delete', 'webhook_trigger_DESTROY_TRANSACTION' => 'After transaction delete',
'webhook_trigger_STORE_BUDGET' => 'After budget creation',
'webhook_trigger_UPDATE_BUDGET' => 'After budget update',
'webhook_trigger_DESTROY_BUDGET' => 'After budget delete',
'webhook_trigger_STORE_UPDATE_BUDGET_LIMIT' => 'After budgeted amount change',
'webhook_response_TRANSACTIONS' => 'Transaction details', 'webhook_response_TRANSACTIONS' => 'Transaction details',
'webhook_response_ACCOUNTS' => 'Account details', 'webhook_response_ACCOUNTS' => 'Account details',
'webhook_response_none_BUDGET' => 'Budget details',
'webhook_response_none_NONE' => 'No details', 'webhook_response_none_NONE' => 'No details',
'webhook_response_NONE' => 'No details',
'webhook_delivery_JSON' => 'JSON', 'webhook_delivery_JSON' => 'JSON',
'inspect' => 'Inspect', 'inspect' => 'Inspect',
'create_new_webhook' => 'Create new webhook', 'create_new_webhook' => 'Create new webhook',
@@ -339,7 +345,6 @@ return [
// old // old
'search_modifier_date_on' => 'Transaction date is ":value"', 'search_modifier_date_on' => 'Transaction date is ":value"',
'search_modifier_not_date_on' => 'Transaction date is not ":value"', 'search_modifier_not_date_on' => 'Transaction date is not ":value"',
'search_modifier_reconciled' => 'Transaction is reconciled', 'search_modifier_reconciled' => 'Transaction is reconciled',
@@ -730,8 +735,6 @@ return [
'search_modifier_not_source_balance_gt' => 'Source account balance is less than or equal to ":value"', 'search_modifier_not_source_balance_gt' => 'Source account balance is less than or equal to ":value"',
// END // END
'general_search_error' => 'An error occurred while searching. Please check the log files for more information.', 'general_search_error' => 'An error occurred while searching. Please check the log files for more information.',
'search_box' => 'Search', 'search_box' => 'Search',
@@ -1265,7 +1268,6 @@ return [
'rule_trigger_not_source_balance_lte' => 'Source account balance is more than :trigger_value', 'rule_trigger_not_source_balance_lte' => 'Source account balance is more than :trigger_value',
// actions // actions
// set, clear, add, remove, append/prepend // set, clear, add, remove, append/prepend
'rule_action_delete_transaction_choice' => 'DELETE transaction(!)', 'rule_action_delete_transaction_choice' => 'DELETE transaction(!)',
@@ -1665,7 +1667,6 @@ return [
'multi_account_warning_transfer' => 'Keep in mind that the source + destination account of subsequent splits will be overruled by whatever is defined in the first split of the transfer.', 'multi_account_warning_transfer' => 'Keep in mind that the source + destination account of subsequent splits will be overruled by whatever is defined in the first split of the transfer.',
// export data: // export data:
'export_data_title' => 'Export data from Firefly III', 'export_data_title' => 'Export data from Firefly III',
'export_data_menu' => 'Export data', 'export_data_menu' => 'Export data',
@@ -2087,7 +2088,6 @@ return [
'without_category_between' => 'Without category between :start and :end', 'without_category_between' => 'Without category between :start and :end',
// transactions: // transactions:
'wait_loading_transaction' => 'Please wait for the form to load', 'wait_loading_transaction' => 'Please wait for the form to load',
'wait_loading_data' => 'Please wait for your information to load...', 'wait_loading_data' => 'Please wait for your information to load...',
@@ -2331,7 +2331,6 @@ return [
'store_transaction' => 'Store transaction', 'store_transaction' => 'Store transaction',
// reports: // reports:
'quick_link_needs_accounts' => 'In order to generate reports, you need to add at least one asset account to Firefly III.', 'quick_link_needs_accounts' => 'In order to generate reports, you need to add at least one asset account to Firefly III.',
'report_default' => 'Default financial report between :start and :end', 'report_default' => 'Default financial report between :start and :end',
@@ -2439,7 +2438,6 @@ return [
'net_filtered_prefs' => 'This chart will never include accounts that have the "Include in net worth"-option unchecked.', 'net_filtered_prefs' => 'This chart will never include accounts that have the "Include in net worth"-option unchecked.',
// charts: // charts:
'chart' => 'Chart', 'chart' => 'Chart',
'month' => 'Month', 'month' => 'Month',
@@ -2547,7 +2545,6 @@ return [
'number_of_decimals' => 'Number of decimals', 'number_of_decimals' => 'Number of decimals',
// administration // administration
'invite_is_already_redeemed' => 'The invite to ":address" has already been redeemed.', 'invite_is_already_redeemed' => 'The invite to ":address" has already been redeemed.',
'invite_is_deleted' => 'The invite to ":address" has been deleted.', 'invite_is_deleted' => 'The invite to ":address" has been deleted.',
@@ -2850,7 +2847,6 @@ return [
'recurrence_deleted' => 'Recurring transaction ":title" deleted', 'recurrence_deleted' => 'Recurring transaction ":title" deleted',
// new lines for summary controller. // new lines for summary controller.
'box_balance_in_currency' => 'Balance (:currency)', 'box_balance_in_currency' => 'Balance (:currency)',
'box_spent_in_currency' => 'Spent (:currency)', 'box_spent_in_currency' => 'Spent (:currency)',

View File

@@ -24,6 +24,9 @@
declare(strict_types=1); declare(strict_types=1);
return [ return [
'webhook_budget_info' => 'Cannot deliver budget information for transaction related webhooks.',
'webhook_account_info' => 'Cannot deliver account information for budget related webhooks.',
'webhook_transaction_info' => 'Cannot deliver transaction information for budget related webhooks.',
'invalid_account_type' => 'A piggy bank can only be linked to asset accounts and liabilities', 'invalid_account_type' => 'A piggy bank can only be linked to asset accounts and liabilities',
'invalid_account_currency' => 'This account does not use the currency you have selected', 'invalid_account_currency' => 'This account does not use the currency you have selected',
'current_amount_too_much' => 'The combined amount in "current_amount" cannot exceed the "target_amount".', 'current_amount_too_much' => 'The combined amount in "current_amount" cannot exceed the "target_amount".',