mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Restore missing methods and fix silly bugs.
This commit is contained in:
parent
64b9234207
commit
32a36bbb12
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace FireflyIII\Console\Commands\Upgrade;
|
namespace FireflyIII\Console\Commands\Upgrade;
|
||||||
|
|
||||||
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
|
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
|
||||||
|
@ -45,7 +45,6 @@ class TransactionCurrencyFactory
|
|||||||
$data['symbol'] = e($data['symbol']);
|
$data['symbol'] = e($data['symbol']);
|
||||||
$data['name'] = e($data['name']);
|
$data['name'] = e($data['name']);
|
||||||
$data['decimal_places'] = (int)$data['decimal_places'];
|
$data['decimal_places'] = (int)$data['decimal_places'];
|
||||||
$data['enabled'] = (bool)$data['enabled'];
|
|
||||||
// if the code already exists (deleted)
|
// if the code already exists (deleted)
|
||||||
// force delete it and then create the transaction:
|
// force delete it and then create the transaction:
|
||||||
$count = TransactionCurrency::withTrashed()->whereCode($data['code'])->count();
|
$count = TransactionCurrency::withTrashed()->whereCode($data['code'])->count();
|
||||||
@ -63,7 +62,7 @@ class TransactionCurrencyFactory
|
|||||||
'code' => $data['code'],
|
'code' => $data['code'],
|
||||||
'symbol' => $data['symbol'],
|
'symbol' => $data['symbol'],
|
||||||
'decimal_places' => $data['decimal_places'],
|
'decimal_places' => $data['decimal_places'],
|
||||||
'enabled' => $data['enabled'],
|
'enabled' => false,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
} catch (QueryException $e) {
|
} catch (QueryException $e) {
|
||||||
|
@ -45,259 +45,4 @@ use Psr\Container\NotFoundExceptionInterface;
|
|||||||
*/
|
*/
|
||||||
class CurrencyController extends Controller
|
class CurrencyController extends Controller
|
||||||
{
|
{
|
||||||
protected CurrencyRepositoryInterface $repository;
|
|
||||||
protected UserRepositoryInterface $userRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CurrencyController constructor.
|
|
||||||
*
|
|
||||||
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
|
|
||||||
$this->middleware(
|
|
||||||
function ($request, $next) {
|
|
||||||
app('view')->share('title', (string)trans('firefly.currencies'));
|
|
||||||
app('view')->share('mainTitleIcon', 'fa-usd');
|
|
||||||
$this->repository = app(CurrencyRepositoryInterface::class);
|
|
||||||
$this->userRepository = app(UserRepositoryInterface::class);
|
|
||||||
|
|
||||||
return $next($request);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a currency.
|
|
||||||
*
|
|
||||||
* @param Request $request
|
|
||||||
*
|
|
||||||
* @return Factory|RedirectResponse|Redirector|View
|
|
||||||
*/
|
|
||||||
public function create(Request $request)
|
|
||||||
{
|
|
||||||
/** @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'))]));
|
|
||||||
|
|
||||||
return redirect(route('currencies.index'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$subTitleIcon = 'fa-plus';
|
|
||||||
$subTitle = (string)trans('firefly.create_currency');
|
|
||||||
|
|
||||||
// put previous url in session if not redirect from store (not "create another").
|
|
||||||
if (true !== session('currencies.create.fromStore')) {
|
|
||||||
$this->rememberPreviousUrl('currencies.create.url');
|
|
||||||
}
|
|
||||||
$request->session()->forget('currencies.create.fromStore');
|
|
||||||
|
|
||||||
Log::channel('audit')->info('Create new currency.');
|
|
||||||
|
|
||||||
return view('currencies.create', compact('subTitleIcon', 'subTitle'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes a currency.
|
|
||||||
*
|
|
||||||
* @param Request $request
|
|
||||||
* @param TransactionCurrency $currency
|
|
||||||
*
|
|
||||||
* @return Factory|RedirectResponse|Redirector|View
|
|
||||||
*/
|
|
||||||
public function delete(Request $request, TransactionCurrency $currency)
|
|
||||||
{
|
|
||||||
/** @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 visit page to delete currency %s but is not site owner.', $currency->code));
|
|
||||||
|
|
||||||
return redirect(route('currencies.index'));
|
|
||||||
}
|
|
||||||
|
|
||||||
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 visit page to delete currency %s but currency is in use.', $currency->code));
|
|
||||||
|
|
||||||
return redirect(route('currencies.index'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// put previous url in session
|
|
||||||
$this->rememberPreviousUrl('currencies.delete.url');
|
|
||||||
$subTitle = (string)trans('form.delete_currency', ['name' => $currency->name]);
|
|
||||||
Log::channel('audit')->info(sprintf('Visit page to delete currency %s.', $currency->code));
|
|
||||||
|
|
||||||
return view('currencies.delete', compact('currency', 'subTitle'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroys a currency.
|
|
||||||
*
|
|
||||||
* @param Request $request
|
|
||||||
* @param TransactionCurrency $currency
|
|
||||||
*
|
|
||||||
* @return RedirectResponse|Redirector
|
|
||||||
*/
|
|
||||||
public function destroy(Request $request, TransactionCurrency $currency)
|
|
||||||
{
|
|
||||||
/** @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 delete currency %s but is not site owner.', $currency->code));
|
|
||||||
|
|
||||||
return redirect(route('currencies.index'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->repository->currencyInUse($currency)) {
|
|
||||||
$request->session()->flash('error', (string)trans('firefly.cannot_delete_currency', ['name' => e($currency->name)]));
|
|
||||||
Log::channel('audit')->info(sprintf('Tried to delete currency %s but is in use.', $currency->code));
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
$request->session()->flash('success', (string)trans('firefly.deleted_currency', ['name' => $currency->name]));
|
|
||||||
|
|
||||||
return redirect($this->getPreviousUrl('currencies.delete.url'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Edit a currency.
|
|
||||||
*
|
|
||||||
* @param Request $request
|
|
||||||
* @param TransactionCurrency $currency
|
|
||||||
*
|
|
||||||
* @return Factory|RedirectResponse|Redirector|View
|
|
||||||
*/
|
|
||||||
public function edit(Request $request, TransactionCurrency $currency)
|
|
||||||
{
|
|
||||||
/** @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 edit currency %s but is not owner.', $currency->code));
|
|
||||||
|
|
||||||
return redirect(route('currencies.index'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$subTitleIcon = 'fa-pencil';
|
|
||||||
$subTitle = (string)trans('breadcrumbs.edit_currency', ['name' => $currency->name]);
|
|
||||||
$currency->symbol = htmlentities($currency->symbol);
|
|
||||||
|
|
||||||
// code to handle active-checkboxes
|
|
||||||
$hasOldInput = null !== $request->old('_token');
|
|
||||||
$preFilled = [
|
|
||||||
'enabled' => $hasOldInput ? (bool)$request->old('enabled') : $currency->enabled,
|
|
||||||
];
|
|
||||||
|
|
||||||
$request->session()->flash('preFilled', $preFilled);
|
|
||||||
Log::channel('audit')->info('Edit currency.', $currency->toArray());
|
|
||||||
|
|
||||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
|
||||||
if (true !== session('currencies.edit.fromUpdate')) {
|
|
||||||
$this->rememberPreviousUrl('currencies.edit.url');
|
|
||||||
}
|
|
||||||
$request->session()->forget('currencies.edit.fromUpdate');
|
|
||||||
|
|
||||||
return view('currencies.edit', compact('currency', 'subTitle', 'subTitleIcon'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store new currency.
|
|
||||||
*
|
|
||||||
* @param CurrencyFormRequest $request
|
|
||||||
*
|
|
||||||
* @return $this|RedirectResponse|Redirector
|
|
||||||
*/
|
|
||||||
public function store(CurrencyFormRequest $request)
|
|
||||||
{
|
|
||||||
/** @var User $user */
|
|
||||||
$user = auth()->user();
|
|
||||||
$data = $request->getCurrencyData();
|
|
||||||
if (!$this->userRepository->hasRole($user, 'owner')) {
|
|
||||||
Log::error('User ' . auth()->user()->id . ' is not admin, but tried to store a currency.');
|
|
||||||
Log::channel('audit')->info('Tried to create (POST) currency without admin rights.', $data);
|
|
||||||
|
|
||||||
return redirect($this->getPreviousUrl('currencies.create.url'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$data['enabled'] = true;
|
|
||||||
try {
|
|
||||||
$currency = $this->repository->store($data);
|
|
||||||
} catch (FireflyException $e) {
|
|
||||||
Log::error($e->getMessage());
|
|
||||||
Log::channel('audit')->info('Could not store (POST) currency without admin rights.', $data);
|
|
||||||
$request->session()->flash('error', (string)trans('firefly.could_not_store_currency'));
|
|
||||||
$currency = null;
|
|
||||||
}
|
|
||||||
$redirect = redirect($this->getPreviousUrl('currencies.create.url'));
|
|
||||||
|
|
||||||
if (null !== $currency) {
|
|
||||||
$request->session()->flash('success', (string)trans('firefly.created_currency', ['name' => $currency->name]));
|
|
||||||
Log::channel('audit')->info('Created (POST) currency.', $data);
|
|
||||||
if (1 === (int)$request->get('create_another')) {
|
|
||||||
$request->session()->put('currencies.create.fromStore', true);
|
|
||||||
|
|
||||||
$redirect = redirect(route('currencies.create'))->withInput();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $redirect;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates a currency.
|
|
||||||
*
|
|
||||||
* @param CurrencyFormRequest $request
|
|
||||||
* @param TransactionCurrency $currency
|
|
||||||
*
|
|
||||||
* @return RedirectResponse|Redirector
|
|
||||||
*/
|
|
||||||
public function update(CurrencyFormRequest $request, TransactionCurrency $currency)
|
|
||||||
{
|
|
||||||
/** @var User $user */
|
|
||||||
$user = auth()->user();
|
|
||||||
$data = $request->getCurrencyData();
|
|
||||||
|
|
||||||
if (false === $data['enabled'] && $this->repository->currencyInUse($currency)) {
|
|
||||||
$data['enabled'] = true;
|
|
||||||
}
|
|
||||||
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('Tried to update (POST) currency without admin rights.', $data);
|
|
||||||
|
|
||||||
return redirect(route('currencies.index'));
|
|
||||||
}
|
|
||||||
$currency = $this->repository->update($currency, $data);
|
|
||||||
Log::channel('audit')->info('Updated (POST) currency.', $data);
|
|
||||||
$request->session()->flash('success', (string)trans('firefly.updated_currency', ['name' => $currency->name]));
|
|
||||||
app('preferences')->mark();
|
|
||||||
|
|
||||||
if (1 === (int)$request->get('return_to_edit')) {
|
|
||||||
$request->session()->put('currencies.edit.fromUpdate', true);
|
|
||||||
|
|
||||||
return redirect(route('currencies.edit', [$currency->id]));
|
|
||||||
}
|
|
||||||
|
|
||||||
return redirect($this->getPreviousUrl('currencies.edit.url'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,6 @@ use Illuminate\View\View;
|
|||||||
*/
|
*/
|
||||||
class EditController extends Controller
|
class EditController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
private JournalRepositoryInterface $repository;
|
private JournalRepositoryInterface $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
121
app/Http/Controllers/TransactionCurrency/CreateController.php
Normal file
121
app/Http/Controllers/TransactionCurrency/CreateController.php
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace FireflyIII\Http\Controllers\TransactionCurrency;
|
||||||
|
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
|
use FireflyIII\Http\Requests\CurrencyFormRequest;
|
||||||
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Contracts\View\Factory;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Routing\Redirector;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class CreateController
|
||||||
|
*/
|
||||||
|
class CreateController extends Controller
|
||||||
|
{
|
||||||
|
protected CurrencyRepositoryInterface $repository;
|
||||||
|
protected UserRepositoryInterface $userRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CurrencyController constructor.
|
||||||
|
*
|
||||||
|
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->middleware(
|
||||||
|
function ($request, $next) {
|
||||||
|
app('view')->share('title', (string)trans('firefly.currencies'));
|
||||||
|
app('view')->share('mainTitleIcon', 'fa-usd');
|
||||||
|
$this->repository = app(CurrencyRepositoryInterface::class);
|
||||||
|
$this->userRepository = app(UserRepositoryInterface::class);
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Create a currency.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
*
|
||||||
|
* @return Factory|RedirectResponse|Redirector|View
|
||||||
|
*/
|
||||||
|
public function create(Request $request)
|
||||||
|
{
|
||||||
|
/** @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'))]));
|
||||||
|
|
||||||
|
return redirect(route('currencies.index'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$subTitleIcon = 'fa-plus';
|
||||||
|
$subTitle = (string)trans('firefly.create_currency');
|
||||||
|
|
||||||
|
// put previous url in session if not redirect from store (not "create another").
|
||||||
|
if (true !== session('currencies.create.fromStore')) {
|
||||||
|
$this->rememberPreviousUrl('currencies.create.url');
|
||||||
|
}
|
||||||
|
$request->session()->forget('currencies.create.fromStore');
|
||||||
|
|
||||||
|
Log::channel('audit')->info('Create new currency.');
|
||||||
|
|
||||||
|
return view('currencies.create', compact('subTitleIcon', 'subTitle'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store new currency.
|
||||||
|
*
|
||||||
|
* @param CurrencyFormRequest $request
|
||||||
|
*
|
||||||
|
* @return $this|RedirectResponse|Redirector
|
||||||
|
*/
|
||||||
|
public function store(CurrencyFormRequest $request)
|
||||||
|
{
|
||||||
|
/** @var User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
$data = $request->getCurrencyData();
|
||||||
|
if (!$this->userRepository->hasRole($user, 'owner')) {
|
||||||
|
Log::error('User ' . auth()->user()->id . ' is not admin, but tried to store a currency.');
|
||||||
|
Log::channel('audit')->info('Tried to create (POST) currency without admin rights.', $data);
|
||||||
|
|
||||||
|
return redirect($this->getPreviousUrl('currencies.create.url'))->withInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['enabled'] = true;
|
||||||
|
try {
|
||||||
|
$currency = $this->repository->store($data);
|
||||||
|
} catch (FireflyException $e) {
|
||||||
|
Log::error($e->getMessage());
|
||||||
|
Log::channel('audit')->info('Could not store (POST) currency without admin rights.', $data);
|
||||||
|
$request->session()->flash('error', (string)trans('firefly.could_not_store_currency'));
|
||||||
|
$currency = null;
|
||||||
|
}
|
||||||
|
$redirect = redirect($this->getPreviousUrl('currencies.create.url'));
|
||||||
|
|
||||||
|
if (null !== $currency) {
|
||||||
|
$request->session()->flash('success', (string)trans('firefly.created_currency', ['name' => $currency->name]));
|
||||||
|
Log::channel('audit')->info('Created (POST) currency.', $data);
|
||||||
|
if (1 === (int)$request->get('create_another')) {
|
||||||
|
$request->session()->put('currencies.create.fromStore', true);
|
||||||
|
|
||||||
|
$redirect = redirect(route('currencies.create'))->withInput();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $redirect;
|
||||||
|
}
|
||||||
|
}
|
127
app/Http/Controllers/TransactionCurrency/DeleteController.php
Normal file
127
app/Http/Controllers/TransactionCurrency/DeleteController.php
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace FireflyIII\Http\Controllers\TransactionCurrency;
|
||||||
|
|
||||||
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Contracts\View\Factory;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Routing\Redirector;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DeleteController
|
||||||
|
*/
|
||||||
|
class DeleteController extends Controller
|
||||||
|
{
|
||||||
|
protected CurrencyRepositoryInterface $repository;
|
||||||
|
protected UserRepositoryInterface $userRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CurrencyController constructor.
|
||||||
|
*
|
||||||
|
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->middleware(
|
||||||
|
function ($request, $next) {
|
||||||
|
app('view')->share('title', (string)trans('firefly.currencies'));
|
||||||
|
app('view')->share('mainTitleIcon', 'fa-usd');
|
||||||
|
$this->repository = app(CurrencyRepositoryInterface::class);
|
||||||
|
$this->userRepository = app(UserRepositoryInterface::class);
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a currency.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param TransactionCurrency $currency
|
||||||
|
*
|
||||||
|
* @return Factory|RedirectResponse|Redirector|View
|
||||||
|
*/
|
||||||
|
public function delete(Request $request, TransactionCurrency $currency)
|
||||||
|
{
|
||||||
|
/** @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 visit page to delete currency %s but is not site owner.', $currency->code));
|
||||||
|
|
||||||
|
return redirect(route('currencies.index'));
|
||||||
|
}
|
||||||
|
|
||||||
|
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 visit page to delete currency %s but currency is in use.', $currency->code));
|
||||||
|
|
||||||
|
return redirect(route('currencies.index'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// put previous url in session
|
||||||
|
$this->rememberPreviousUrl('currencies.delete.url');
|
||||||
|
$subTitle = (string)trans('form.delete_currency', ['name' => $currency->name]);
|
||||||
|
Log::channel('audit')->info(sprintf('Visit page to delete currency %s.', $currency->code));
|
||||||
|
|
||||||
|
return view('currencies.delete', compact('currency', 'subTitle'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroys a currency.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param TransactionCurrency $currency
|
||||||
|
*
|
||||||
|
* @return RedirectResponse|Redirector
|
||||||
|
*/
|
||||||
|
public function destroy(Request $request, TransactionCurrency $currency)
|
||||||
|
{
|
||||||
|
/** @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 delete currency %s but is not site owner.', $currency->code));
|
||||||
|
|
||||||
|
return redirect(route('currencies.index'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->repository->currencyInUse($currency)) {
|
||||||
|
$request->session()->flash('error', (string)trans('firefly.cannot_delete_currency', ['name' => e($currency->name)]));
|
||||||
|
Log::channel('audit')->info(sprintf('Tried to delete currency %s but is in use.', $currency->code));
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
$request->session()->flash('success', (string)trans('firefly.deleted_currency', ['name' => $currency->name]));
|
||||||
|
|
||||||
|
return redirect($this->getPreviousUrl('currencies.delete.url'));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
130
app/Http/Controllers/TransactionCurrency/EditController.php
Normal file
130
app/Http/Controllers/TransactionCurrency/EditController.php
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace FireflyIII\Http\Controllers\TransactionCurrency;
|
||||||
|
|
||||||
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
|
use FireflyIII\Http\Requests\CurrencyFormRequest;
|
||||||
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Contracts\View\Factory;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Routing\Redirector;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
class EditController extends Controller
|
||||||
|
{
|
||||||
|
protected CurrencyRepositoryInterface $repository;
|
||||||
|
protected UserRepositoryInterface $userRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CurrencyController constructor.
|
||||||
|
*
|
||||||
|
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->middleware(
|
||||||
|
function ($request, $next) {
|
||||||
|
app('view')->share('title', (string)trans('firefly.currencies'));
|
||||||
|
app('view')->share('mainTitleIcon', 'fa-usd');
|
||||||
|
$this->repository = app(CurrencyRepositoryInterface::class);
|
||||||
|
$this->userRepository = app(UserRepositoryInterface::class);
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit a currency.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param TransactionCurrency $currency
|
||||||
|
*
|
||||||
|
* @return Factory|RedirectResponse|Redirector|View
|
||||||
|
*/
|
||||||
|
public function edit(Request $request, TransactionCurrency $currency)
|
||||||
|
{
|
||||||
|
/** @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 edit currency %s but is not owner.', $currency->code));
|
||||||
|
|
||||||
|
return redirect(route('currencies.index'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$subTitleIcon = 'fa-pencil';
|
||||||
|
$subTitle = (string)trans('breadcrumbs.edit_currency', ['name' => $currency->name]);
|
||||||
|
$currency->symbol = htmlentities($currency->symbol);
|
||||||
|
|
||||||
|
// is currently enabled (for this user?)
|
||||||
|
$userCurrencies = $this->repository->get()->pluck('id')->toArray();
|
||||||
|
$enabled = in_array($currency->id, $userCurrencies, true);
|
||||||
|
|
||||||
|
// code to handle active-checkboxes
|
||||||
|
$hasOldInput = null !== $request->old('_token');
|
||||||
|
$preFilled = [
|
||||||
|
'enabled' => $hasOldInput ? (bool)$request->old('enabled') : $enabled,
|
||||||
|
];
|
||||||
|
|
||||||
|
$request->session()->flash('preFilled', $preFilled);
|
||||||
|
Log::channel('audit')->info('Edit currency.', $currency->toArray());
|
||||||
|
|
||||||
|
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||||
|
if (true !== session('currencies.edit.fromUpdate')) {
|
||||||
|
$this->rememberPreviousUrl('currencies.edit.url');
|
||||||
|
}
|
||||||
|
$request->session()->forget('currencies.edit.fromUpdate');
|
||||||
|
|
||||||
|
return view('currencies.edit', compact('currency', 'subTitle', 'subTitleIcon'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates a currency.
|
||||||
|
*
|
||||||
|
* @param CurrencyFormRequest $request
|
||||||
|
* @param TransactionCurrency $currency
|
||||||
|
*
|
||||||
|
* @return RedirectResponse|Redirector
|
||||||
|
*/
|
||||||
|
public function update(CurrencyFormRequest $request, TransactionCurrency $currency)
|
||||||
|
{
|
||||||
|
/** @var User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
$data = $request->getCurrencyData();
|
||||||
|
|
||||||
|
if (false === $data['enabled'] && $this->repository->currencyInUse($currency)) {
|
||||||
|
$data['enabled'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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('Tried to update (POST) currency without admin rights.', $data);
|
||||||
|
|
||||||
|
return redirect(route('currencies.index'));
|
||||||
|
}
|
||||||
|
$currency = $this->repository->update($currency, $data);
|
||||||
|
Log::channel('audit')->info('Updated (POST) currency.', $data);
|
||||||
|
$request->session()->flash('success', (string)trans('firefly.updated_currency', ['name' => $currency->name]));
|
||||||
|
app('preferences')->mark();
|
||||||
|
|
||||||
|
if (1 === (int)$request->get('return_to_edit')) {
|
||||||
|
$request->session()->put('currencies.edit.fromUpdate', true);
|
||||||
|
|
||||||
|
return redirect(route('currencies.edit', [$currency->id]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect($this->getPreviousUrl('currencies.edit.url'));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace FireflyIII\Http\Controllers\TransactionCurrency;
|
namespace FireflyIII\Http\Controllers\TransactionCurrency;
|
||||||
@ -69,7 +70,7 @@ class IndexController extends Controller
|
|||||||
function (TransactionCurrency $currency) {
|
function (TransactionCurrency $currency) {
|
||||||
$default = true === $currency->userDefault ? 0 : 1;
|
$default = true === $currency->userDefault ? 0 : 1;
|
||||||
$enabled = true === $currency->userEnabled ? 0 : 1;
|
$enabled = true === $currency->userEnabled ? 0 : 1;
|
||||||
return sprintf('%s-%s-%s',$default, $enabled, $currency->code);
|
return sprintf('%s-%s-%s', $default, $enabled, $currency->code);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -81,7 +82,7 @@ class IndexController extends Controller
|
|||||||
$isOwner = false;
|
$isOwner = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('currencies.index', compact('currencies', 'isOwner'));
|
return view('currencies.index', compact('currencies', 'isOwner'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -546,13 +546,12 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function store(array $data): TransactionCurrency
|
public function store(array $data): TransactionCurrency
|
||||||
{
|
{
|
||||||
throw new FireflyException(sprintf('Method "%s" needs a refactor.', __METHOD__));
|
|
||||||
/** @var TransactionCurrencyFactory $factory */
|
/** @var TransactionCurrencyFactory $factory */
|
||||||
$factory = app(TransactionCurrencyFactory::class);
|
$factory = app(TransactionCurrencyFactory::class);
|
||||||
$result = $factory->create($data);
|
$result = $factory->create($data);
|
||||||
|
|
||||||
if (null === $result) {
|
if (true === $data['enabled']) {
|
||||||
throw new FireflyException('400004: Could not store new currency.');
|
$this->user->currencies()->attach($result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -37,7 +37,6 @@ use Illuminate\Support\Collection;
|
|||||||
*/
|
*/
|
||||||
interface CurrencyRepositoryInterface
|
interface CurrencyRepositoryInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the complete set of transactions but needs
|
* Returns the complete set of transactions but needs
|
||||||
* no user object.
|
* no user object.
|
||||||
|
@ -110,7 +110,7 @@ class Amount
|
|||||||
{
|
{
|
||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
return $user->currencies()->orderBy('code','ASC')->get();
|
return $user->currencies()->orderBy('code', 'ASC')->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,8 +48,7 @@ trait GroupValidation
|
|||||||
{
|
{
|
||||||
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
||||||
|
|
||||||
$count = Transaction
|
$count = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', 'transactions.transaction_journal_id')
|
||||||
::leftJoin('transaction_journals', 'transaction_journals.id', 'transactions.transaction_journal_id')
|
|
||||||
->leftJoin('transaction_groups', 'transaction_groups.id', 'transaction_journals.transaction_group_id')
|
->leftJoin('transaction_groups', 'transaction_groups.id', 'transaction_journals.transaction_group_id')
|
||||||
->where('transaction_journals.transaction_group_id', $transactionGroup->id)
|
->where('transaction_journals.transaction_group_id', $transactionGroup->id)
|
||||||
->where('transactions.reconciled', 1)->where('transactions.amount', '<', 0)->count(['transactions.id']);
|
->where('transactions.reconciled', 1)->where('transactions.amount', '<', 0)->count(['transactions.id']);
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration {
|
return new class () extends Migration {
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*/
|
*/
|
||||||
@ -21,7 +23,7 @@ return new class extends Migration {
|
|||||||
$table->boolean('user_default')->default(false);
|
$table->boolean('user_default')->default(false);
|
||||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||||
$table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade');
|
$table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade');
|
||||||
$table->unique(['user_id', 'transaction_currency_id'],'unique_combo');
|
$table->unique(['user_id', 'transaction_currency_id'], 'unique_combo');
|
||||||
});
|
});
|
||||||
} catch (QueryException $e) {
|
} catch (QueryException $e) {
|
||||||
app('log')->error(sprintf('Could not create table "transaction_currency_user": %s', $e->getMessage()));
|
app('log')->error(sprintf('Could not create table "transaction_currency_user": %s', $e->getMessage()));
|
||||||
@ -40,7 +42,7 @@ return new class extends Migration {
|
|||||||
$table->boolean('group_default')->default(false);
|
$table->boolean('group_default')->default(false);
|
||||||
$table->foreign('user_group_id')->references('id')->on('user_groups')->onDelete('cascade');
|
$table->foreign('user_group_id')->references('id')->on('user_groups')->onDelete('cascade');
|
||||||
$table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade');
|
$table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade');
|
||||||
$table->unique(['user_group_id', 'transaction_currency_id'],'unique_combo');
|
$table->unique(['user_group_id', 'transaction_currency_id'], 'unique_combo');
|
||||||
});
|
});
|
||||||
} catch (QueryException $e) {
|
} catch (QueryException $e) {
|
||||||
app('log')->error(sprintf('Could not create table "transaction_currency_user_group": %s', $e->getMessage()));
|
app('log')->error(sprintf('Could not create table "transaction_currency_user_group": %s', $e->getMessage()));
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
{{ ExpandedForm.text('symbol', currency.symbol,{'maxlength' : 51}) }}
|
{{ ExpandedForm.text('symbol', currency.symbol,{'maxlength' : 51}) }}
|
||||||
{{ ExpandedForm.text('code', currency.code,{'maxlength' : 51}) }}
|
{{ ExpandedForm.text('code', currency.code,{'maxlength' : 51}) }}
|
||||||
{{ ExpandedForm.integer('decimal_places', currency.decimal_places,{'maxlength' : 2,'min': 0,'max': 12}) }}
|
{{ ExpandedForm.integer('decimal_places', currency.decimal_places,{'maxlength' : 2,'min': 0,'max': 12}) }}
|
||||||
{{ ExpandedForm.checkbox('enabled', currency.enabled) }}
|
{{ ExpandedForm.checkbox('enabled', null, currency.enabled) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -342,7 +342,7 @@ Route::group(
|
|||||||
|
|
||||||
Route::post('store', ['uses' => 'CreateController@store', 'as' => 'store']);
|
Route::post('store', ['uses' => 'CreateController@store', 'as' => 'store']);
|
||||||
Route::post('update/{currency}', ['uses' => 'EditController@update', 'as' => 'update']);
|
Route::post('update/{currency}', ['uses' => 'EditController@update', 'as' => 'update']);
|
||||||
Route::post('destroy/{currency}', ['uses' => 'EditController@destroy', 'as' => 'destroy']);
|
Route::post('destroy/{currency}', ['uses' => 'DeleteController@destroy', 'as' => 'destroy']);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Tests\integration\Support;
|
namespace Tests\integration\Support;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
@ -8,7 +10,6 @@ use Tests\integration\TestCase;
|
|||||||
|
|
||||||
class NavigationCustomEndOfPeriodTest extends TestCase
|
class NavigationCustomEndOfPeriodTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @preserveGlobalState disabled
|
* @preserveGlobalState disabled
|
||||||
|
Loading…
Reference in New Issue
Block a user