This commit is contained in:
James Cole 2020-02-13 20:09:27 +01:00
parent 8d806e6a1d
commit 529cb3d387
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
4 changed files with 28 additions and 0 deletions

View File

@ -318,6 +318,10 @@ class CurrencyController extends Controller
if ($this->repository->currencyInUse($currency)) {
throw new FireflyException('200006: Currency in use.'); // @codeCoverageIgnore
}
if ($this->repository->isFallbackCurrency($currency)) {
throw new FireflyException('200026: Currency is fallback.'); // @codeCoverageIgnore
}
$this->repository->destroy($currency);
return response()->json([], 204);

View File

@ -183,6 +183,14 @@ class CurrencyController extends Controller
return redirect(route('currencies.index'));
}
if ($this->repository->isFallbackCurrency($currency)) {
$request->session()->flash('error', (string)trans('firefly.cannot_delete_fallback_currency', ['name' => e($currency->name)]));
Log::channel('audit')->info(sprintf('Tried to delete currency %s but is FALLBACK.', $currency->code));
return redirect(route('currencies.index'));
}
Log::channel('audit')->info(sprintf('Deleted currency %s.', $currency->code));
$this->repository->destroy($currency);

View File

@ -537,4 +537,12 @@ class CurrencyRepository implements CurrencyRepositoryInterface
return $service->update($currency, $data);
}
/**
* @inheritDoc
*/
public function isFallbackCurrency(TransactionCurrency $currency): bool
{
return $currency->code === config('firefly.default_currency', 'EUR');
}
}

View File

@ -35,6 +35,14 @@ use Illuminate\Support\Collection;
*/
interface CurrencyRepositoryInterface
{
/**
* @param TransactionCurrency $currency
*
* @return bool
*/
public function isFallbackCurrency(TransactionCurrency $currency): bool;
/**
* @param TransactionCurrency $currency
*