Fix various sonatype issues.

This commit is contained in:
James Cole 2022-03-30 06:54:59 +02:00
parent 65764199fe
commit 8f98be32f9
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
16 changed files with 123 additions and 91 deletions

View File

@ -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'));
}
}
}

View File

@ -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]));
}
/**

View File

@ -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
{

View File

@ -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.
*

View File

@ -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>

View File

@ -1,4 +1,5 @@
<html>
<!DOCTYPE html>
<html lang="{{ trans('config.html_language') }}">
<head>
<title>{{ trans('firefly.debug_page') }}</title>
</head>

View File

@ -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;">

View File

@ -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">

View File

@ -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">

View File

@ -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">

View File

@ -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">

View File

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="{{ trans('config.html_language') }}">
<head>
<base href="{{ route('index') }}/">
<meta charset="utf-8">

View File

@ -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">

View File

@ -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>

View File

@ -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>

View File

@ -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 %}