Skip to content

Firefly III: a personal finances manager

Fix various sonatype issues.

James Cole8f98be32f959
diff --git a/app/Api/V1/Requests/Data/Bulk/MoveTransactionsRequest.php b/app/Api/V1/Requests/Data/Bulk/MoveTransactionsRequest.php
index 4cd1b85675..47ddfb65f9 100644
--- a/app/Api/V1/Requests/Data/Bulk/MoveTransactionsRequest.php
+++ b/app/Api/V1/Requests/Data/Bulk/MoveTransactionsRequest.php
@@ -74,32 +74,45 @@ class MoveTransactionsRequest extends FormRequest
// validate start before end only if both are there.
$data = $validator->getData();
if (array_key_exists('original_account', $data) && array_key_exists('destination_account', $data)) {
- $repository = app(AccountRepositoryInterface::class);
- $repository->setUser(auth()->user());
- $original = $repository->find((int) $data['original_account']);
- $destination = $repository->find((int) $data['destination_account']);
- if ($original->accountType->type !== $destination->accountType->type) {
- $validator->errors()->add('title', (string) trans('validation.same_account_type'));
-
- return;
- }
- // get currency pref:
- $originalCurrency = $repository->getAccountCurrency($original);
- $destinationCurrency = $repository->getAccountCurrency($destination);
- if (null === $originalCurrency xor null === $destinationCurrency) {
- $validator->errors()->add('title', (string) trans('validation.same_account_currency'));
-
- return;
- }
- if (null === $originalCurrency && null === $destinationCurrency) {
- // this is OK
- return;
- }
- if ($originalCurrency->code !== $destinationCurrency->code) {
- $validator->errors()->add('title', (string) trans('validation.same_account_currency'));
- }
+ $this->validateMove($validator);
}
}
);
}
+
+ /**
+ * @param Validator $validator
+ * @return void
+ */
+ private function validateMove(Validator $validator): void {
+ $data = $validator->getData();
+ $repository = app(AccountRepositoryInterface::class);
+ $repository->setUser(auth()->user());
+ $original = $repository->find((int) $data['original_account']);
+ $destination = $repository->find((int) $data['destination_account']);
+
+ // not the same type:
+ if ($original->accountType->type !== $destination->accountType->type) {
+ $validator->errors()->add('title', (string) trans('validation.same_account_type'));
+
+ return;
+ }
+ // get currency pref:
+ $originalCurrency = $repository->getAccountCurrency($original);
+ $destinationCurrency = $repository->getAccountCurrency($destination);
+
+ // check different scenario's.
+ if (null === $originalCurrency xor null === $destinationCurrency) {
+ $validator->errors()->add('title', (string) trans('validation.same_account_currency'));
+
+ return;
+ }
+ if (null === $originalCurrency && null === $destinationCurrency) {
+ // this is OK
+ return;
+ }
+ if ($originalCurrency->code !== $destinationCurrency->code) {
+ $validator->errors()->add('title', (string) trans('validation.same_account_currency'));
+ }
+ }
}
diff --git a/app/Http/Controllers/CurrencyController.php b/app/Http/Controllers/CurrencyController.php
index 82b03a8c3f..f8b7c71e50 100644
--- a/app/Http/Controllers/CurrencyController.php
+++ b/app/Http/Controllers/CurrencyController.php
@@ -215,56 +215,50 @@ class CurrencyController extends Controller
public function disableCurrency(Request $request): JsonResponse
{
$currencyId = (int) $request->get('id');
- if ($currencyId > 0) {
- // valid currency?
- $currency = $this->repository->find($currencyId);
- if (null !== $currency) {
- app('preferences')->mark();
+ $currency = $this->repository->find($currencyId);
- /** @var User $user */
- $user = auth()->user();
- if (!$this->userRepository->hasRole($user, 'owner')) {
-
- $request->session()->flash('error', (string) trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))]));
- Log::channel('audit')->info(sprintf('Tried to disable currency %s but is not site owner.', $currency->code));
- return response()->json([]);
-
- }
-
- if ($this->repository->currencyInUse($currency)) {
-
- $location = $this->repository->currencyInUseAt($currency);
- $message = (string) trans(sprintf('firefly.cannot_disable_currency_%s', $location), ['name' => e($currency->name)]);
-
- $request->session()->flash('error', $message);
- Log::channel('audit')->info(sprintf('Tried to disable currency %s but is in use.', $currency->code));
- return response()->json([]);
- }
-
- $this->repository->disable($currency);
- Log::channel('audit')->info(sprintf('Disabled currency %s.', $currency->code));
- // if no currencies are enabled, enable the first one in the DB (usually the EUR)
- if (0 === $this->repository->get()->count()) {
- /** @var TransactionCurrency $first */
- $first = $this->repository->getAll()->first();
- if (null === $first) {
- throw new FireflyException('No currencies found.');
- }
- Log::channel('audit')->info(sprintf('Auto-enabled currency %s.', $first->code));
- $this->repository->enable($first);
- app('preferences')->set('currencyPreference', $first->code);
- app('preferences')->mark();
- }
-
- if ('EUR' === $currency->code) {
- session()->flash('warning', (string) trans('firefly.disable_EUR_side_effects'));
- }
-
- session()->flash('success', (string) trans('firefly.currency_is_now_disabled', ['name' => $currency->name]));
- }
+ // valid currency?
+ if (null === $currency) {
+ return response()->json([]);
}
- return response()->json([]);
+ app('preferences')->mark();
+
+ // user must be "owner"
+ /** @var User $user */
+ $user = auth()->user();
+ if (!$this->userRepository->hasRole($user, 'owner')) {
+
+ $request->session()->flash('error', (string) trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))]));
+ Log::channel('audit')->info(sprintf('Tried to disable currency %s but is not site owner.', $currency->code));
+ return response()->json([]);
+
+ }
+
+ // currency cannot be in use.
+ if ($this->repository->currencyInUse($currency)) {
+
+ $location = $this->repository->currencyInUseAt($currency);
+ $message = (string) trans(sprintf('firefly.cannot_disable_currency_%s', $location), ['name' => e($currency->name)]);
+
+ $request->session()->flash('error', $message);
+ Log::channel('audit')->info(sprintf('Tried to disable currency %s but is in use.', $currency->code));
+ return response()->json([]);
+ }
+
+ // currency disabled!
+ $this->repository->disable($currency);
+ Log::channel('audit')->info(sprintf('Disabled currency %s.', $currency->code));
+
+ $this->repository->ensureMinimalEnabledCurrencies();
+
+ // extra warning
+ if ('EUR' === $currency->code) {
+ session()->flash('warning', (string) trans('firefly.disable_EUR_side_effects'));
+ }
+
+ session()->flash('success', (string) trans('firefly.currency_is_now_disabled', ['name' => $currency->name]));
+
}
/**
diff --git a/app/Repositories/Currency/CurrencyRepository.php b/app/Repositories/Currency/CurrencyRepository.php
index c93b81b22f..4619703cfc 100644
--- a/app/Repositories/Currency/CurrencyRepository.php
+++ b/app/Repositories/Currency/CurrencyRepository.php
@@ -39,6 +39,7 @@ use FireflyIII\Services\Internal\Destroy\CurrencyDestroyService;
use FireflyIII\Services\Internal\Update\CurrencyUpdateService;
use FireflyIII\User;
use Illuminate\Support\Collection;
+use JsonException;
use Log;
/**
@@ -200,6 +201,25 @@ class CurrencyRepository implements CurrencyRepositoryInterface
$currency->save();
}
+ /**
+ * @inheritDoc
+ */
+ public function ensureMinimalEnabledCurrencies(): void
+ {
+ // if no currencies are enabled, enable the first one in the DB (usually the EUR)
+ if (0 === $this->get()->count()) {
+ /** @var TransactionCurrency $first */
+ $first = $this->getAll()->first();
+ if (null === $first) {
+ throw new FireflyException('No currencies found. You broke Firefly III');
+ }
+ Log::channel('audit')->info(sprintf('Auto-enabled currency %s.', $first->code));
+ $this->enable($first);
+ app('preferences')->set('currencyPreference', $first->code);
+ app('preferences')->mark();
+ }
+ }
+
/**
* Find by currency code, return NULL if unfound.
* Used in Import Currency!
@@ -274,7 +294,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
*
* @return TransactionCurrency
* @throws FireflyException
- * @throws \JsonException
+ * @throws JsonException
*/
public function findCurrency(?int $currencyId, ?string $currencyCode): TransactionCurrency
{
diff --git a/app/Repositories/Currency/CurrencyRepositoryInterface.php b/app/Repositories/Currency/CurrencyRepositoryInterface.php
index 7c50d812de..35efcb3b76 100644
--- a/app/Repositories/Currency/CurrencyRepositoryInterface.php
+++ b/app/Repositories/Currency/CurrencyRepositoryInterface.php
@@ -35,7 +35,6 @@ use Illuminate\Support\Collection;
*/
interface CurrencyRepositoryInterface
{
-
/**
* @param TransactionCurrency $currency
*
@@ -80,6 +79,11 @@ interface CurrencyRepositoryInterface
*/
public function enable(TransactionCurrency $currency): void;
+ /**
+ * @return void
+ */
+ public function ensureMinimalEnabledCurrencies(): void;
+
/**
* Find by ID, return NULL if not found.
*
diff --git a/resources/views/auth/lost-two-factor.twig b/resources/views/auth/lost-two-factor.twig
index 07089c0f5e..530a6cf94f 100644
--- a/resources/views/auth/lost-two-factor.twig
+++ b/resources/views/auth/lost-two-factor.twig
@@ -1,5 +1,5 @@
<!DOCTYPE html>
-<html>
+<html lang="{{ trans('config.html_language') }}">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex, nofollow, noarchive, noodp, NoImageIndex, noydir">
@@ -18,7 +18,7 @@
<body class="container">
<div class="row">
<div class="col-lg-10 col-lg-offset-1 col-md-12 col-sm-12 col-xs-12">
- <h1><a href="{{ route('index') }}"><b>Firefly</b>III</a></h1>
+ <h1><a href="{{ route('index') }}"><strong>Firefly</strong>III</a></h1>
</div>
</div>
diff --git a/resources/views/debug.twig b/resources/views/debug.twig
index c770abad9e..6f1de2a4f0 100644
--- a/resources/views/debug.twig
+++ b/resources/views/debug.twig
@@ -1,4 +1,5 @@
-<html>
+<!DOCTYPE html>
+<html lang="{{ trans('config.html_language') }}">
<head>
<title>{{ trans('firefly.debug_page') }}</title>
</head>
diff --git a/resources/views/emails/header-html.twig b/resources/views/emails/header-html.twig
index d4e89e3255..42583e2128 100644
--- a/resources/views/emails/header-html.twig
+++ b/resources/views/emails/header-html.twig
@@ -1,8 +1,8 @@
<!DOCTYPE html>
-<html xmlns="http://www.w3.org/1999/xhtml">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="{{ trans('config.html_language') }}">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
-
+ <title>Message</title>
</head>
<body>
<p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;">
diff --git a/resources/views/errors/404.twig b/resources/views/errors/404.twig
index 28845e45f8..ae4c2f0dd0 100644
--- a/resources/views/errors/404.twig
+++ b/resources/views/errors/404.twig
@@ -1,5 +1,5 @@
<!DOCTYPE html>
-<html>
+<html lang="{{ trans('config.html_language') }}">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex, nofollow, noarchive, noodp, NoImageIndex, noydir">
@@ -29,7 +29,7 @@
<body class="container">
<div class="row">
<div class="col-lg-10 col-lg-offset-1 col-md-12 col-sm-12 col-xs-12">
- <h1><s><b>Firefly</b>III</s> 404 Not Found :(</h1>
+ <h1><s><strong>Firefly</strong>III</s> 404 Not Found :(</h1>
</div>
</div>
<div class="row">
diff --git a/resources/views/errors/500.twig b/resources/views/errors/500.twig
index f01b0f0f95..34d7b3a6da 100644
--- a/resources/views/errors/500.twig
+++ b/resources/views/errors/500.twig
@@ -1,5 +1,5 @@
<!DOCTYPE html>
-<html>
+<html lang="{{ trans('config.html_language') }}">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex, nofollow, noarchive, noodp, NoImageIndex, noydir">
@@ -29,7 +29,7 @@
<body class="container">
<div class="row">
<div class="col-lg-10 col-lg-offset-1 col-md-12 col-sm-12 col-xs-12">
- <h1><a href="{{ route('index') }}"><b>Firefly</b>III</a></h1>
+ <h1><a href="{{ route('index') }}"><strong>Firefly</strong>III</a></h1>
</div>
</div>
<div class="row">
diff --git a/resources/views/errors/503.twig b/resources/views/errors/503.twig
index cb206bebb4..d669d11821 100644
--- a/resources/views/errors/503.twig
+++ b/resources/views/errors/503.twig
@@ -1,5 +1,5 @@
<!DOCTYPE html>
-<html>
+<html lang="{{ trans('config.html_language') }}">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex, nofollow, noarchive, noodp, NoImageIndex, noydir">
@@ -25,7 +25,7 @@
<body class="container">
<div class="row">
<div class="col-lg-10 col-lg-offset-1 col-md-12 col-sm-12 col-xs-12">
- <h1><a href="{{ route('index') }}"><b>Firefly</b>III</a></h1>
+ <h1><a href="{{ route('index') }}"><strong>Firefly</strong>III</a></h1>
</div>
</div>
<div class="row">
diff --git a/resources/views/errors/FireflyException.twig b/resources/views/errors/FireflyException.twig
index df85b70dff..824bee2605 100644
--- a/resources/views/errors/FireflyException.twig
+++ b/resources/views/errors/FireflyException.twig
@@ -1,5 +1,5 @@
<!DOCTYPE html>
-<html>
+<html lang="{{ trans('config.html_language') }}">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex, nofollow, noarchive, noodp, NoImageIndex, noydir">
@@ -29,7 +29,7 @@
<body class="container">
<div class="row">
<div class="col-lg-10 col-lg-offset-1 col-md-12 col-sm-12 col-xs-12">
- <h1><a href="{{ route('index') }}"><b>Firefly</b>III</a></h1>
+ <h1><a href="{{ route('index') }}"><strong>Firefly</strong>III</a></h1>
</div>
</div>
<div class="row">
diff --git a/resources/views/errors/offline.twig b/resources/views/errors/offline.twig
index b1130978ee..6e98cb6943 100644
--- a/resources/views/errors/offline.twig
+++ b/resources/views/errors/offline.twig
@@ -1,5 +1,5 @@
<!DOCTYPE html>
-<html>
+<html lang="{{ trans('config.html_language') }}">
<head>
<base href="{{ route('index') }}/">
<meta charset="utf-8">
diff --git a/resources/views/layout/default.twig b/resources/views/layout/default.twig
index 02edacd333..a558b85f6f 100644
--- a/resources/views/layout/default.twig
+++ b/resources/views/layout/default.twig
@@ -62,7 +62,7 @@
{# mini logo for sidebar mini 50x50 pixels #}
<span class="logo-mini">FF</span>
{# logo for regular state and mobile devices #}
- <span class="logo-lg"><b>Firefly</b>III</span>
+ <span class="logo-lg"><strong>Firefly</strong>III</span>
</a>
<nav class="navbar navbar-static-top" role="navigation">
diff --git a/resources/views/layout/empty.twig b/resources/views/layout/empty.twig
index 66d336b59c..c72672279f 100644
--- a/resources/views/layout/empty.twig
+++ b/resources/views/layout/empty.twig
@@ -36,7 +36,7 @@
<body class="login-page">
<div class="login-box">
<div class="login-logo">
- <a href="{{ route('index') }}"><b>Firefly</b>III</a>
+ <a href="{{ route('index') }}"><strong>Firefly</strong>III</a>
</div>
{% block content %}{% endblock %}
</div>
diff --git a/resources/views/layout/guest.twig b/resources/views/layout/guest.twig
index 8e2ce34b15..50177b2b95 100644
--- a/resources/views/layout/guest.twig
+++ b/resources/views/layout/guest.twig
@@ -46,7 +46,7 @@
<body class="login-page">
<div class="login-box">
<div class="login-logo">
- <a href="{{ route('index') }}"><b>Firefly</b>III</a>
+ <a href="{{ route('index') }}"><strong>Firefly</strong>III</a>
</div>
{% block content %}{% endblock %}
</div>
diff --git a/resources/views/layout/install.twig b/resources/views/layout/install.twig
index 459e3f03dd..edb8564ca0 100644
--- a/resources/views/layout/install.twig
+++ b/resources/views/layout/install.twig
@@ -29,7 +29,7 @@
<body class="login-page">
<div class="login-box">
<div class="login-logo">
- <b>Firefly</b>III<br />
+ <strong>Firefly</strong>III<br />
<span style="font-family: monospace;font-size:16pt;">installation and upgrade</span>
</div>
{% block content %}{% endblock %}