mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Do error catching etc.
This commit is contained in:
@@ -26,6 +26,7 @@ namespace FireflyIII\Http\Middleware;
|
|||||||
use Closure;
|
use Closure;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Models\TransactionGroup;
|
use FireflyIII\Models\TransactionGroup;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\Webhook;
|
use FireflyIII\Models\Webhook;
|
||||||
@@ -68,6 +69,10 @@ class InterestingMessage
|
|||||||
Preferences::mark();
|
Preferences::mark();
|
||||||
$this->handleWebhookMessage($request);
|
$this->handleWebhookMessage($request);
|
||||||
}
|
}
|
||||||
|
if ($this->currencyMessage($request)) {
|
||||||
|
Preferences::mark();
|
||||||
|
$this->handleCurrencyMessage($request);
|
||||||
|
}
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
@@ -221,10 +226,57 @@ class InterestingMessage
|
|||||||
private function webhookMessage(Request $request): bool
|
private function webhookMessage(Request $request): bool
|
||||||
{
|
{
|
||||||
// get parameters from request.
|
// get parameters from request.
|
||||||
$billId = $request->get('webhook_id');
|
$webhookId = $request->get('webhook_id');
|
||||||
|
$message = $request->get('message');
|
||||||
|
|
||||||
|
return null !== $webhookId && null !== $message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function currencyMessage(Request $request): bool
|
||||||
|
{
|
||||||
|
// get parameters from request.
|
||||||
|
$code = $request->get('code');
|
||||||
$message = $request->get('message');
|
$message = $request->get('message');
|
||||||
|
|
||||||
return null !== $billId && null !== $message;
|
return null !== $code && null !== $message;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function handleCurrencyMessage(Request $request): void
|
||||||
|
{
|
||||||
|
// params:
|
||||||
|
// get parameters from request.
|
||||||
|
$code = $request->get('code');
|
||||||
|
$message = $request->get('message');
|
||||||
|
|
||||||
|
/** @var TransactionCurrency $webhook */
|
||||||
|
$currency = TransactionCurrency::whereCode($code)->first();
|
||||||
|
|
||||||
|
if (null === $currency) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ('enabled' === $message) {
|
||||||
|
session()->flash('success', (string)trans('firefly.currency_is_now_enabled', ['name' => $currency->name]));
|
||||||
|
}
|
||||||
|
if ('enable_failed' === $message) {
|
||||||
|
session()->flash('error', (string)trans('firefly.could_not_enable_currency', ['name' => $currency->name]));
|
||||||
|
}
|
||||||
|
if ('disabled' === $message) {
|
||||||
|
session()->flash('success', (string)trans('firefly.currency_is_now_disabled', ['name' => $currency->name]));
|
||||||
|
}
|
||||||
|
if ('disable_failed' === $message) {
|
||||||
|
session()->flash('error', (string)trans('firefly.could_not_disable_currency', ['name' => $currency->name]));
|
||||||
|
}
|
||||||
|
if ('default' === $message) {
|
||||||
|
session()->flash('success', (string)trans('firefly.new_default_currency', ['name' => $currency->name]));
|
||||||
|
}
|
||||||
|
if ('default_failed' === $message) {
|
||||||
|
session()->flash('error', (string)trans('firefly.default_currency_failed', ['name' => $currency->name]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -45,8 +45,13 @@ function setDefaultCurrency(e) {
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content'),
|
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content'),
|
||||||
},
|
},
|
||||||
|
error: function () {
|
||||||
|
window.location = redirectUrl + '?message=default_failed&code=' + currencyCode;
|
||||||
|
},
|
||||||
|
success: function () {
|
||||||
|
window.location = redirectUrl + '?message=default&code=' + currencyCode;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
window.location = redirectUrl + '?message=default&code=' + currencyCode;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,8 +71,13 @@ function enableCurrency(e) {
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content'),
|
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content'),
|
||||||
},
|
},
|
||||||
|
error: function () {
|
||||||
|
window.location = redirectUrl + '?message=enable_failed&code=' + currencyCode;
|
||||||
|
},
|
||||||
|
success: function () {
|
||||||
|
window.location = redirectUrl + '?message=enabled&code=' + currencyCode;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
window.location = redirectUrl + '?message=enabled&code=' + currencyCode;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +86,7 @@ function disableCurrency(e) {
|
|||||||
var currencyCode = button.data('code');
|
var currencyCode = button.data('code');
|
||||||
|
|
||||||
var params = {
|
var params = {
|
||||||
enabled: true
|
enabled: false
|
||||||
}
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@@ -87,7 +97,12 @@ function disableCurrency(e) {
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content'),
|
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content'),
|
||||||
},
|
},
|
||||||
|
error: function () {
|
||||||
|
window.location = redirectUrl + '?message=disable_failed&code=' + currencyCode;
|
||||||
|
},
|
||||||
|
success: function () {
|
||||||
|
window.location = redirectUrl + '?message=disabled&code=' + currencyCode;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
window.location = redirectUrl + '?message=disabled&code=' + currencyCode;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -1582,7 +1582,8 @@ return [
|
|||||||
'create_currency' => 'Create a new currency',
|
'create_currency' => 'Create a new currency',
|
||||||
'store_currency' => 'Store new currency',
|
'store_currency' => 'Store new currency',
|
||||||
'update_currency' => 'Update currency',
|
'update_currency' => 'Update currency',
|
||||||
'new_default_currency' => ':name is now the default currency.',
|
'new_default_currency' => '":name" is now the default currency.',
|
||||||
|
'default_currency_failed' => 'Could not make ":name" the default currency. Please check the logs.',
|
||||||
'cannot_delete_currency' => 'Cannot delete :name because it is still in use.',
|
'cannot_delete_currency' => 'Cannot delete :name because it is still in use.',
|
||||||
'cannot_delete_fallback_currency' => ':name is the system fallback currency and can\'t be deleted.',
|
'cannot_delete_fallback_currency' => ':name is the system fallback currency and can\'t be deleted.',
|
||||||
'cannot_disable_currency_journals' => 'Cannot disable :name because transactions are still using it.',
|
'cannot_disable_currency_journals' => 'Cannot disable :name because transactions are still using it.',
|
||||||
@@ -1608,7 +1609,9 @@ return [
|
|||||||
'disable_currency' => 'Disable',
|
'disable_currency' => 'Disable',
|
||||||
'currencies_default_disabled' => 'Most of these currencies are disabled by default. To use them, you must enable them first.',
|
'currencies_default_disabled' => 'Most of these currencies are disabled by default. To use them, you must enable them first.',
|
||||||
'currency_is_now_enabled' => 'Currency ":name" has been enabled',
|
'currency_is_now_enabled' => 'Currency ":name" has been enabled',
|
||||||
|
'could_not_enable_currency' => 'Could not enable currency ":name". Please review the logs.',
|
||||||
'currency_is_now_disabled' => 'Currency ":name" has been disabled',
|
'currency_is_now_disabled' => 'Currency ":name" has been disabled',
|
||||||
|
'could_not_disable_currency' => 'Could not disable currency ":name". Perhaps it is still in use?',
|
||||||
|
|
||||||
// forms:
|
// forms:
|
||||||
'mandatoryFields' => 'Mandatory fields',
|
'mandatoryFields' => 'Mandatory fields',
|
||||||
|
Reference in New Issue
Block a user