mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 03:43:07 +00:00
Convert GET routes to POST.
This commit is contained in:
@@ -213,53 +213,60 @@ class CurrencyController extends Controller
|
||||
* @return RedirectResponse|Redirector
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function disableCurrency(Request $request, TransactionCurrency $currency)
|
||||
public function disableCurrency(Request $request)
|
||||
{
|
||||
app('preferences')->mark();
|
||||
$currencyId = (int)$request->get('id');
|
||||
if ($currencyId > 0) {
|
||||
// valid currency?
|
||||
$currency = $this->repository->find($currencyId);
|
||||
if (null !== $currency) {
|
||||
app('preferences')->mark();
|
||||
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
if (!$this->userRepository->hasRole($user, '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));
|
||||
$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 redirect(route('currencies.index'));
|
||||
return redirect(route('currencies.index'));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->repository->currencyInUse($currency)) {
|
||||
if ($this->repository->currencyInUse($currency)) {
|
||||
|
||||
$location = $this->repository->currencyInUseAt($currency);
|
||||
$message = (string)trans(sprintf('firefly.cannot_disable_currency_%s', $location), ['name' => e($currency->name)]);
|
||||
$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));
|
||||
$request->session()->flash('error', $message);
|
||||
Log::channel('audit')->info(sprintf('Tried to disable currency %s but is in use.', $currency->code));
|
||||
|
||||
return redirect(route('currencies.index'));
|
||||
}
|
||||
return redirect(route('currencies.index'));
|
||||
}
|
||||
|
||||
$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.');
|
||||
$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]));
|
||||
}
|
||||
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]));
|
||||
|
||||
return redirect(route('currencies.index'));
|
||||
}
|
||||
|
||||
@@ -311,13 +318,20 @@ class CurrencyController extends Controller
|
||||
*
|
||||
* @return RedirectResponse|Redirector
|
||||
*/
|
||||
public function enableCurrency(TransactionCurrency $currency)
|
||||
public function enableCurrency(Request $request)
|
||||
{
|
||||
app('preferences')->mark();
|
||||
$currencyId = (int)$request->get('id');
|
||||
if ($currencyId > 0) {
|
||||
// valid currency?
|
||||
$currency = $this->repository->find($currencyId);
|
||||
if (null !== $currency) {
|
||||
app('preferences')->mark();
|
||||
|
||||
$this->repository->enable($currency);
|
||||
session()->flash('success', (string)trans('firefly.currency_is_now_enabled', ['name' => $currency->name]));
|
||||
Log::channel('audit')->info(sprintf('Enabled currency %s.', $currency->code));
|
||||
$this->repository->enable($currency);
|
||||
session()->flash('success', (string)trans('firefly.currency_is_now_enabled', ['name' => $currency->name]));
|
||||
Log::channel('audit')->info(sprintf('Enabled currency %s.', $currency->code));
|
||||
}
|
||||
}
|
||||
|
||||
return redirect(route('currencies.index'));
|
||||
}
|
||||
|
@@ -28,17 +28,20 @@ use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
|
||||
use FireflyIII\Services\Internal\Update\GroupCloneService;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Class CreateController
|
||||
*/
|
||||
class CreateController extends Controller
|
||||
{
|
||||
private TransactionGroupRepositoryInterface $repository;
|
||||
|
||||
/**
|
||||
* CreateController constructor.
|
||||
*
|
||||
@@ -49,9 +52,10 @@ class CreateController extends Controller
|
||||
parent::__construct();
|
||||
|
||||
$this->middleware(
|
||||
static function ($request, $next) {
|
||||
function ($request, $next) {
|
||||
app('view')->share('title', (string)trans('firefly.transactions'));
|
||||
app('view')->share('mainTitleIcon', 'fa-exchange');
|
||||
$this->repository = app(TransactionGroupRepositoryInterface::class);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
@@ -59,28 +63,35 @@ class CreateController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionGroup $group
|
||||
* @param Request $request
|
||||
*
|
||||
* @return RedirectResponse|Redirector
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function cloneGroup(TransactionGroup $group)
|
||||
public function cloneGroup(Request $request): JsonResponse
|
||||
{
|
||||
$groupId = (int)$request->get('id');
|
||||
if (0 !== $groupId) {
|
||||
$group = $this->repository->find($groupId);
|
||||
if (null !== $group) {
|
||||
/** @var GroupCloneService $service */
|
||||
$service = app(GroupCloneService::class);
|
||||
$newGroup = $service->cloneGroup($group);
|
||||
|
||||
/** @var GroupCloneService $service */
|
||||
$service = app(GroupCloneService::class);
|
||||
$newGroup = $service->cloneGroup($group);
|
||||
// event!
|
||||
event(new StoredTransactionGroup($newGroup));
|
||||
|
||||
// event!
|
||||
event(new StoredTransactionGroup($newGroup));
|
||||
app('preferences')->mark();
|
||||
|
||||
app('preferences')->mark();
|
||||
$title = $newGroup->title ?? $newGroup->transactionJournals->first()->description;
|
||||
$link = route('transactions.show', [$newGroup->id]);
|
||||
session()->flash('success', trans('firefly.stored_journal', ['description' => $title]));
|
||||
session()->flash('success_url', $link);
|
||||
|
||||
$title = $newGroup->title ?? $newGroup->transactionJournals->first()->description;
|
||||
$link = route('transactions.show', [$newGroup->id]);
|
||||
session()->flash('success', trans('firefly.stored_journal', ['description' => $title]));
|
||||
session()->flash('success_url', $link);
|
||||
return response()->json(['redirect' => route('transactions.show', [$newGroup->id])]);
|
||||
}
|
||||
}
|
||||
|
||||
return redirect(route('transactions.show', [$newGroup->id]));
|
||||
return response()->json(['redirect' => route('transactions.show', [$groupId])]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user