mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-17 07:08:19 +00:00
Improve test coverage and efficiency for accounts and budgets.
This commit is contained in:
@@ -37,13 +37,14 @@ class ConfigurationController extends Controller
|
||||
{
|
||||
/**
|
||||
* ConfigurationController constructor.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
static function ($request, $next) {
|
||||
app('view')->share('title', (string)trans('firefly.administration'));
|
||||
app('view')->share('mainTitleIcon', 'fa-hand-spock-o');
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* ConfigurationController constructor.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
@@ -36,8 +36,13 @@ use View;
|
||||
*/
|
||||
class LinkController extends Controller
|
||||
{
|
||||
|
||||
/** @var LinkTypeRepositoryInterface */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* LinkController constructor.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -47,6 +52,7 @@ class LinkController extends Controller
|
||||
function ($request, $next) {
|
||||
app('view')->share('title', (string)trans('firefly.administration'));
|
||||
app('view')->share('mainTitleIcon', 'fa-hand-spock-o');
|
||||
$this->repository = app(LinkTypeRepositoryInterface::class);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
@@ -61,11 +67,11 @@ class LinkController extends Controller
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Log::channel('audit')->info('User visits link index.');
|
||||
|
||||
$subTitle = (string)trans('firefly.create_new_link_type');
|
||||
$subTitleIcon = 'fa-link';
|
||||
|
||||
Log::channel('audit')->info('User visits link index.');
|
||||
|
||||
// put previous url in session if not redirect from store (not "create another").
|
||||
if (true !== session('link-types.create.fromStore')) {
|
||||
$this->rememberPreviousUri('link-types.create.uri');
|
||||
@@ -77,13 +83,12 @@ class LinkController extends Controller
|
||||
/**
|
||||
* Delete a link form.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param LinkTypeRepositoryInterface $repository
|
||||
* @param LinkType $linkType
|
||||
* @param Request $request
|
||||
* @param LinkType $linkType
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
|
||||
*/
|
||||
public function delete(Request $request, LinkTypeRepositoryInterface $repository, LinkType $linkType)
|
||||
public function delete(Request $request, LinkType $linkType)
|
||||
{
|
||||
if (!$linkType->editable) {
|
||||
$request->session()->flash('error', (string)trans('firefly.cannot_edit_link_type', ['name' => $linkType->name]));
|
||||
@@ -92,18 +97,19 @@ class LinkController extends Controller
|
||||
}
|
||||
|
||||
Log::channel('audit')->info(sprintf('User wants to delete link type #%d', $linkType->id));
|
||||
|
||||
$subTitle = (string)trans('firefly.delete_link_type', ['name' => $linkType->name]);
|
||||
$otherTypes = $repository->get();
|
||||
$count = $repository->countJournals($linkType);
|
||||
$otherTypes = $this->repository->get();
|
||||
$count = $this->repository->countJournals($linkType);
|
||||
$moveTo = [];
|
||||
$moveTo[0] = (string)trans('firefly.do_not_save_connection');
|
||||
|
||||
/** @var LinkType $otherType */
|
||||
foreach ($otherTypes as $otherType) {
|
||||
if ($otherType->id !== $linkType->id) {
|
||||
$moveTo[$otherType->id] = sprintf('%s (%s / %s)', $otherType->name, $otherType->inward, $otherType->outward);
|
||||
}
|
||||
}
|
||||
|
||||
// put previous url in session
|
||||
$this->rememberPreviousUri('link-types.delete.uri');
|
||||
|
||||
@@ -113,18 +119,17 @@ class LinkController extends Controller
|
||||
/**
|
||||
* Actually destroy the link.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param LinkTypeRepositoryInterface $repository
|
||||
* @param LinkType $linkType
|
||||
* @param Request $request
|
||||
* @param LinkType $linkType
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function destroy(Request $request, LinkTypeRepositoryInterface $repository, LinkType $linkType)
|
||||
public function destroy(Request $request, LinkType $linkType)
|
||||
{
|
||||
Log::channel('audit')->info(sprintf('User destroyed link type #%d', $linkType->id));
|
||||
$name = $linkType->name;
|
||||
$moveTo = $repository->findNull((int)$request->get('move_link_type_before_delete'));
|
||||
$repository->destroy($linkType, $moveTo);
|
||||
$moveTo = $this->repository->findNull((int)$request->get('move_link_type_before_delete'));
|
||||
$this->repository->destroy($linkType, $moveTo);
|
||||
|
||||
$request->session()->flash('success', (string)trans('firefly.deleted_link_type', ['name' => $name]));
|
||||
app('preferences')->mark();
|
||||
@@ -135,7 +140,7 @@ class LinkController extends Controller
|
||||
/**
|
||||
* Edit a link form.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Request $request
|
||||
* @param LinkType $linkType
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||
@@ -164,20 +169,18 @@ class LinkController extends Controller
|
||||
/**
|
||||
* Show index of all links.
|
||||
*
|
||||
* @param LinkTypeRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index(LinkTypeRepositoryInterface $repository)
|
||||
public function index()
|
||||
{
|
||||
$subTitle = (string)trans('firefly.journal_link_configuration');
|
||||
$subTitleIcon = 'fa-link';
|
||||
$linkTypes = $repository->get();
|
||||
$linkTypes = $this->repository->get();
|
||||
|
||||
Log::channel('audit')->info('User on index of link types in admin.');
|
||||
$linkTypes->each(
|
||||
function (LinkType $linkType) use ($repository) {
|
||||
$linkType->journalCount = $repository->countJournals($linkType);
|
||||
function (LinkType $linkType) {
|
||||
$linkType->journalCount = $this->repository->countJournals($linkType);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -195,7 +198,7 @@ class LinkController extends Controller
|
||||
{
|
||||
$subTitle = (string)trans('firefly.overview_for_link', ['name' => $linkType->name]);
|
||||
$subTitleIcon = 'fa-link';
|
||||
$links = $linkType->transactionJournalLinks()->get();
|
||||
$links = $this->repository->getJournalLinks($linkType);
|
||||
|
||||
Log::channel('audit')->info(sprintf('User viewing link type #%d', $linkType->id));
|
||||
|
||||
@@ -205,19 +208,18 @@ class LinkController extends Controller
|
||||
/**
|
||||
* Store the new link.
|
||||
*
|
||||
* @param LinkTypeFormRequest $request
|
||||
* @param LinkTypeRepositoryInterface $repository
|
||||
* @param LinkTypeFormRequest $request
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function store(LinkTypeFormRequest $request, LinkTypeRepositoryInterface $repository)
|
||||
public function store(LinkTypeFormRequest $request)
|
||||
{
|
||||
$data = [
|
||||
'name' => $request->string('name'),
|
||||
'inward' => $request->string('inward'),
|
||||
'outward' => $request->string('outward'),
|
||||
];
|
||||
$linkType = $repository->store($data);
|
||||
$linkType = $this->repository->store($data);
|
||||
|
||||
Log::channel('audit')->info('User stored new link type.', $linkType->toArray());
|
||||
|
||||
@@ -237,13 +239,12 @@ class LinkController extends Controller
|
||||
/**
|
||||
* Update an existing link.
|
||||
*
|
||||
* @param LinkTypeFormRequest $request
|
||||
* @param LinkTypeRepositoryInterface $repository
|
||||
* @param LinkType $linkType
|
||||
* @param LinkTypeFormRequest $request
|
||||
* @param LinkType $linkType
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function update(LinkTypeFormRequest $request, LinkTypeRepositoryInterface $repository, LinkType $linkType)
|
||||
public function update(LinkTypeFormRequest $request, LinkType $linkType)
|
||||
{
|
||||
if (!$linkType->editable) {
|
||||
$request->session()->flash('error', (string)trans('firefly.cannot_edit_link_type', ['name' => $linkType->name]));
|
||||
@@ -256,7 +257,7 @@ class LinkController extends Controller
|
||||
'inward' => $request->string('inward'),
|
||||
'outward' => $request->string('outward'),
|
||||
];
|
||||
$repository->update($linkType, $data);
|
||||
$this->repository->update($linkType, $data);
|
||||
|
||||
Log::channel('audit')->info(sprintf('User update link type #%d.', $linkType->id), $data);
|
||||
|
||||
|
||||
@@ -35,6 +35,9 @@ use Log;
|
||||
*/
|
||||
class UserController extends Controller
|
||||
{
|
||||
/** @var UserRepositoryInterface */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* UserController constructor.
|
||||
*/
|
||||
@@ -46,7 +49,7 @@ class UserController extends Controller
|
||||
function ($request, $next) {
|
||||
app('view')->share('title', (string)trans('firefly.administration'));
|
||||
app('view')->share('mainTitleIcon', 'fa-hand-spock-o');
|
||||
|
||||
$this->repository = app(UserRepositoryInterface::class);
|
||||
return $next($request);
|
||||
}
|
||||
);
|
||||
@@ -72,13 +75,12 @@ class UserController extends Controller
|
||||
* Destroy a user.
|
||||
*
|
||||
* @param User $user
|
||||
* @param UserRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function destroy(User $user, UserRepositoryInterface $repository)
|
||||
public function destroy(User $user)
|
||||
{
|
||||
$repository->destroy($user);
|
||||
$this->repository->destroy($user);
|
||||
session()->flash('success', (string)trans('firefly.user_deleted'));
|
||||
|
||||
return redirect(route('admin.users'));
|
||||
@@ -114,22 +116,20 @@ class UserController extends Controller
|
||||
/**
|
||||
* Show index of user manager.
|
||||
*
|
||||
* @param UserRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index(UserRepositoryInterface $repository)
|
||||
public function index()
|
||||
{
|
||||
$subTitle = (string)trans('firefly.user_administration');
|
||||
$subTitleIcon = 'fa-users';
|
||||
$users = $repository->all();
|
||||
$users = $this->repository->all();
|
||||
|
||||
// add meta stuff.
|
||||
$users->each(
|
||||
function (User $user) use ($repository) {
|
||||
function (User $user) {
|
||||
$list = ['twoFactorAuthEnabled', 'twoFactorAuthSecret'];
|
||||
$preferences = app('preferences')->getArrayForUser($user, $list);
|
||||
$user->isAdmin = $repository->hasRole($user, 'owner');
|
||||
$user->isAdmin = $this->repository->hasRole($user, 'owner');
|
||||
$is2faEnabled = 1 === $preferences['twoFactorAuthEnabled'];
|
||||
$has2faSecret = null !== $preferences['twoFactorAuthSecret'];
|
||||
$user->has2FA = ($is2faEnabled && $has2faSecret);
|
||||
@@ -143,18 +143,17 @@ class UserController extends Controller
|
||||
/**
|
||||
* Show single user.
|
||||
*
|
||||
* @param UserRepositoryInterface $repository
|
||||
* @param User $user
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function show(UserRepositoryInterface $repository, User $user)
|
||||
public function show(User $user)
|
||||
{
|
||||
$title = (string)trans('firefly.administration');
|
||||
$mainTitleIcon = 'fa-hand-spock-o';
|
||||
$subTitle = (string)trans('firefly.single_user_administration', ['email' => $user->email]);
|
||||
$subTitleIcon = 'fa-user';
|
||||
$information = $repository->getUserData($user);
|
||||
$information = $this->repository->getUserData($user);
|
||||
|
||||
return view(
|
||||
'admin.users.show', compact(
|
||||
@@ -168,22 +167,21 @@ class UserController extends Controller
|
||||
*
|
||||
* @param UserFormRequest $request
|
||||
* @param User $user
|
||||
* @param UserRepositoryInterface $repository
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function update(UserFormRequest $request, User $user, UserRepositoryInterface $repository)
|
||||
public function update(UserFormRequest $request, User $user)
|
||||
{
|
||||
Log::debug('Actually here');
|
||||
$data = $request->getUserData();
|
||||
|
||||
// update password
|
||||
if ('' !== $data['password']) {
|
||||
$repository->changePassword($user, $data['password']);
|
||||
$this->repository->changePassword($user, $data['password']);
|
||||
}
|
||||
|
||||
$repository->changeStatus($user, $data['blocked'], $data['blocked_code']);
|
||||
$repository->updateEmail($user, $data['email']);
|
||||
$this->repository->changeStatus($user, $data['blocked'], $data['blocked_code']);
|
||||
$this->repository->updateEmail($user, $data['email']);
|
||||
|
||||
session()->flash('success', (string)trans('firefly.updated_user', ['email' => $user->email]));
|
||||
app('preferences')->mark();
|
||||
|
||||
Reference in New Issue
Block a user