mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-29 10:21:25 -06:00
Move stuff to request classes for #339
This commit is contained in:
parent
83f48418f6
commit
9a30fbd05a
@ -66,10 +66,10 @@ class ConfigurationController extends Controller
|
||||
public function store(ConfigurationRequest $request)
|
||||
{
|
||||
// get config values:
|
||||
$singleUserMode = intval($request->get('single_user_mode')) === 1 ? true : false;
|
||||
$data = $request->getConfigurationData();
|
||||
|
||||
// store config values
|
||||
FireflyConfig::set('single_user_mode', $singleUserMode);
|
||||
FireflyConfig::set('single_user_mode', $data['single_user_mode']);
|
||||
|
||||
// flash message
|
||||
Session::flash('success', strval(trans('firefly.configuration_updated')));
|
||||
|
@ -15,6 +15,7 @@ namespace FireflyIII\Http\Controllers\Admin;
|
||||
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\Support\Facades\FireflyConfig;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Http\Request;
|
||||
@ -83,6 +84,7 @@ class DomainController extends Controller
|
||||
*/
|
||||
public function toggleDomain(string $domain)
|
||||
{
|
||||
$domain = strtolower($domain);
|
||||
$blocked = FireflyConfig::get('blocked-domains', [])->data;
|
||||
|
||||
if (in_array($domain, $blocked)) {
|
||||
@ -111,15 +113,16 @@ class DomainController extends Controller
|
||||
*/
|
||||
private function getKnownDomains(): array
|
||||
{
|
||||
$users = User::get();
|
||||
$set = [];
|
||||
$filtered = [];
|
||||
/** @var UserRepositoryInterface $repository */
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
$users = $repository->all();
|
||||
$set = [];
|
||||
$filtered = [];
|
||||
/** @var User $user */
|
||||
foreach ($users as $user) {
|
||||
$email = $user->email;
|
||||
$parts = explode('@', $email);
|
||||
$domain = $parts[1];
|
||||
$set[] = $domain;
|
||||
$email = $user->email;
|
||||
$parts = explode('@', $email);
|
||||
$set[] = strtolower($parts[1]);
|
||||
}
|
||||
$set = array_unique($set);
|
||||
// filter for already banned domains:
|
||||
@ -131,7 +134,6 @@ class DomainController extends Controller
|
||||
$filtered[] = $domain;
|
||||
}
|
||||
}
|
||||
asort($filtered);
|
||||
|
||||
return $filtered;
|
||||
}
|
||||
|
@ -264,11 +264,8 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function store(CategoryFormRequest $request, CRI $repository)
|
||||
{
|
||||
$categoryData = [
|
||||
'name' => trim($request->input('name')),
|
||||
'user' => auth()->user()->id,
|
||||
];
|
||||
$category = $repository->store($categoryData);
|
||||
$data = $request->getCategoryData();
|
||||
$category = $repository->store($data);
|
||||
|
||||
Session::flash('success', strval(trans('firefly.stored_category', ['name' => e($category->name)])));
|
||||
Preferences::mark();
|
||||
@ -292,11 +289,8 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function update(CategoryFormRequest $request, CRI $repository, Category $category)
|
||||
{
|
||||
$categoryData = [
|
||||
'name' => $request->input('name'),
|
||||
];
|
||||
|
||||
$repository->update($category, $categoryData);
|
||||
$data = $request->getCategoryData();
|
||||
$repository->update($category, $data);
|
||||
|
||||
Session::flash('success', strval(trans('firefly.updated_category', ['name' => e($category->name)])));
|
||||
Preferences::mark();
|
||||
|
@ -364,18 +364,8 @@ class PiggyBankController extends Controller
|
||||
*/
|
||||
public function store(PiggyBankFormRequest $request, PiggyBankRepositoryInterface $repository)
|
||||
{
|
||||
|
||||
$piggyBankData = [
|
||||
'name' => $request->get('name'),
|
||||
'startdate' => new Carbon,
|
||||
'account_id' => intval($request->get('account_id')),
|
||||
'targetamount' => round($request->get('targetamount'), 2),
|
||||
'order' => $repository->getMaxOrder() + 1,
|
||||
'targetdate' => strlen($request->get('targetdate')) > 0 ? new Carbon($request->get('targetdate')) : null,
|
||||
'note' => $request->get('note'),
|
||||
];
|
||||
|
||||
$piggyBank = $repository->store($piggyBankData);
|
||||
$data = $request->getPiggyBankData();
|
||||
$piggyBank = $repository->store($data);
|
||||
|
||||
Session::flash('success', strval(trans('firefly.stored_piggy_bank', ['name' => e($piggyBank->name)])));
|
||||
Preferences::mark();
|
||||
@ -400,16 +390,8 @@ class PiggyBankController extends Controller
|
||||
*/
|
||||
public function update(PiggyBankRepositoryInterface $repository, PiggyBankFormRequest $request, PiggyBank $piggyBank)
|
||||
{
|
||||
$piggyBankData = [
|
||||
'name' => $request->get('name'),
|
||||
'startdate' => is_null($piggyBank->startdate) ? $piggyBank->created_at : $piggyBank->startdate,
|
||||
'account_id' => intval($request->get('account_id')),
|
||||
'targetamount' => round($request->get('targetamount'), 2),
|
||||
'targetdate' => strlen($request->get('targetdate')) > 0 ? new Carbon($request->get('targetdate')) : null,
|
||||
'note' => $request->get('note'),
|
||||
];
|
||||
|
||||
$piggyBank = $repository->update($piggyBank, $piggyBankData);
|
||||
$data = $request->getPiggyBankData();
|
||||
$piggyBank = $repository->update($piggyBank, $data);
|
||||
|
||||
Session::flash('success', strval(trans('firefly.updated_piggy_bank', ['name' => e($piggyBank->name)])));
|
||||
Preferences::mark();
|
||||
|
@ -238,23 +238,9 @@ class RuleController extends Controller
|
||||
*/
|
||||
public function store(RuleFormRequest $request, RuleRepositoryInterface $repository, RuleGroup $ruleGroup)
|
||||
{
|
||||
|
||||
|
||||
// process the rule itself:
|
||||
$data = [
|
||||
'rule_group_id' => $ruleGroup->id,
|
||||
'title' => $request->get('title'),
|
||||
'user_id' => auth()->user()->id,
|
||||
'trigger' => $request->get('trigger'),
|
||||
'description' => $request->get('description'),
|
||||
'rule-triggers' => $request->get('rule-trigger'),
|
||||
'rule-trigger-values' => $request->get('rule-trigger-value'),
|
||||
'rule-trigger-stop' => $request->get('rule-trigger-stop'),
|
||||
'rule-actions' => $request->get('rule-action'),
|
||||
'rule-action-values' => $request->get('rule-action-value'),
|
||||
'rule-action-stop' => $request->get('rule-action-stop'),
|
||||
'stop_processing' => $request->get('stop_processing'),
|
||||
];
|
||||
$data = $request->getRuleData();
|
||||
$data['rule_group_id'] = $ruleGroup->id;
|
||||
$data['user_id'] = auth()->user()->id;
|
||||
|
||||
$rule = $repository->store($data);
|
||||
Session::flash('success', trans('firefly.stored_new_rule', ['title' => $rule->title]));
|
||||
@ -341,21 +327,7 @@ class RuleController extends Controller
|
||||
*/
|
||||
public function update(RuleRepositoryInterface $repository, RuleFormRequest $request, Rule $rule)
|
||||
{
|
||||
|
||||
// process the rule itself:
|
||||
$data = [
|
||||
'title' => $request->get('title'),
|
||||
'active' => intval($request->get('active')) == 1,
|
||||
'trigger' => $request->get('trigger'),
|
||||
'description' => $request->get('description'),
|
||||
'rule-triggers' => $request->get('rule-trigger'),
|
||||
'rule-trigger-values' => $request->get('rule-trigger-value'),
|
||||
'rule-trigger-stop' => $request->get('rule-trigger-stop'),
|
||||
'rule-actions' => $request->get('rule-action'),
|
||||
'rule-action-values' => $request->get('rule-action-value'),
|
||||
'rule-action-stop' => $request->get('rule-action-stop'),
|
||||
'stop_processing' => intval($request->get('stop_processing')) == 1,
|
||||
];
|
||||
$data = $request->getRuleData();
|
||||
$repository->update($rule, $data);
|
||||
|
||||
Session::flash('success', trans('firefly.updated_rule', ['title' => $rule->title]));
|
||||
@ -410,7 +382,7 @@ class RuleController extends Controller
|
||||
{
|
||||
|
||||
/** @var RuleGroupRepositoryInterface $repository */
|
||||
$repository = app('FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface');
|
||||
$repository = app(RuleGroupRepositoryInterface::class);
|
||||
|
||||
if ($repository->count() === 0) {
|
||||
$data = [
|
||||
|
@ -204,13 +204,9 @@ class RuleGroupController extends Controller
|
||||
*/
|
||||
public function store(RuleGroupFormRequest $request, RuleGroupRepositoryInterface $repository)
|
||||
{
|
||||
$data = [
|
||||
'title' => $request->input('title'),
|
||||
'description' => $request->input('description'),
|
||||
'user_id' => auth()->user()->id,
|
||||
];
|
||||
|
||||
$ruleGroup = $repository->store($data);
|
||||
$data = $request->getRuleGroupData();
|
||||
$data['user_id'] = auth()->user()->id;
|
||||
$ruleGroup = $repository->store($data);
|
||||
|
||||
Session::flash('success', strval(trans('firefly.created_new_rule_group', ['title' => $ruleGroup->title])));
|
||||
Preferences::mark();
|
||||
|
@ -33,6 +33,17 @@ class CategoryFormRequest extends Request
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCategoryData(): array
|
||||
{
|
||||
return [
|
||||
'name' => trim($this->input('name')),
|
||||
'user' => auth()->user()->id,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
@ -30,6 +30,16 @@ class ConfigurationRequest extends Request
|
||||
return auth()->check() && auth()->user()->hasRole('owner');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getConfigurationData(): array
|
||||
{
|
||||
return [
|
||||
'single_user_mode' => intval($this->get('single_user_mode')) === 1,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
@ -13,6 +13,7 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Input;
|
||||
|
||||
/**
|
||||
@ -32,6 +33,21 @@ class PiggyBankFormRequest extends Request
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getPiggyBankData(): array
|
||||
{
|
||||
return [
|
||||
'name' => trim($this->get('name')),
|
||||
'startdate' => new Carbon,
|
||||
'account_id' => intval($this->get('account_id')),
|
||||
'targetamount' => round($this->get('targetamount'), 2),
|
||||
'targetdate' => strlen($this->get('targetdate')) > 0 ? new Carbon($this->get('targetdate')) : null,
|
||||
'note' => trim($this->get('note')),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
@ -33,6 +33,26 @@ class RuleFormRequest extends Request
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getRuleData(): array
|
||||
{
|
||||
return [
|
||||
'title' => trim($this->get('title')),
|
||||
'active' => intval($this->get('active')) == 1,
|
||||
'trigger' => trim($this->get('trigger')),
|
||||
'description' => trim($this->get('description')),
|
||||
'rule-triggers' => $this->get('rule-trigger'),
|
||||
'rule-trigger-values' => $this->get('rule-trigger-value'),
|
||||
'rule-trigger-stop' => $this->get('rule-trigger-stop'),
|
||||
'rule-actions' => $this->get('rule-action'),
|
||||
'rule-action-values' => $this->get('rule-action-value'),
|
||||
'rule-action-stop' => $this->get('rule-action-stop'),
|
||||
'stop_processing' => intval($this->get('stop_processing')) === 1,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
@ -20,8 +20,7 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use Input;
|
||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class RuleGroupFormRequest
|
||||
@ -40,15 +39,27 @@ class RuleGroupFormRequest extends Request
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getRuleGroupData(): array
|
||||
{
|
||||
return [
|
||||
'title' => trim($this->input('title')),
|
||||
'description' => trim($this->input('description')),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
|
||||
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title';
|
||||
if (RuleGroup::find(Input::get('id'))) {
|
||||
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title,' . intval(Input::get('id'));
|
||||
/** @var RuleGroupRepositoryInterface $repository */
|
||||
$repository = app(RuleGroupRepositoryInterface::class, [auth()->user()]);
|
||||
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title';
|
||||
if (!is_null($repository->find(intval($this->get('id')))->id)) {
|
||||
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title,' . intval($this->get('id'));
|
||||
}
|
||||
|
||||
return [
|
||||
|
@ -175,7 +175,8 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
*/
|
||||
public function store(array $data): PiggyBank
|
||||
{
|
||||
$piggyBank = PiggyBank::create($data);
|
||||
$data['order'] = $this->getMaxOrder() + 1;
|
||||
$piggyBank = PiggyBank::create($data);
|
||||
|
||||
$this->updateNote($piggyBank, $data['note']);
|
||||
|
||||
@ -232,9 +233,9 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
|
||||
return true;
|
||||
}
|
||||
$dbNote= $piggyBank->notes()->first();
|
||||
$dbNote = $piggyBank->notes()->first();
|
||||
if (is_null($dbNote)) {
|
||||
$dbNote= new Note();
|
||||
$dbNote = new Note();
|
||||
$dbNote->noteable()->associate($piggyBank);
|
||||
}
|
||||
$dbNote->text = trim($note);
|
||||
|
@ -79,6 +79,21 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $ruleGroupId
|
||||
*
|
||||
* @return RuleGroup
|
||||
*/
|
||||
public function find(int $ruleGroupId): RuleGroup
|
||||
{
|
||||
$group = $this->user->ruleGroups()->find($ruleGroupId);
|
||||
if (is_null($group)) {
|
||||
return new RuleGroup;
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
|
@ -42,6 +42,13 @@ interface RuleGroupRepositoryInterface
|
||||
*/
|
||||
public function destroy(RuleGroup $ruleGroup, RuleGroup $moveTo = null): bool;
|
||||
|
||||
/**
|
||||
* @param int $ruleGroupId
|
||||
*
|
||||
* @return RuleGroup
|
||||
*/
|
||||
public function find(int $ruleGroupId): RuleGroup;
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
|
@ -9,6 +9,7 @@
|
||||
<form method="POST" action="{{ route('rules.rule.store', ruleGroup.id) }}" accept-charset="UTF-8" class="form-horizontal" id="store">
|
||||
<input name="_token" type="hidden" value="{{ csrf_token() }}">
|
||||
<input type="hidden" name="rule_group_id" value="{{ ruleGroup.id }}"/>
|
||||
<input type="hidden" name="active" value="1"/>
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||
<div class="box box-primary">
|
||||
|
Loading…
Reference in New Issue
Block a user