mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-24 06:43:23 +00:00
Expand user group pages.
This commit is contained in:
@@ -54,6 +54,12 @@ class UpdateController extends Controller
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function useUserGroup(UserGroup $userGroup): JsonResponse {
|
||||||
|
// group validation is already in place, so can just update the user.
|
||||||
|
$this->repository->useUserGroup($userGroup);
|
||||||
|
return response()->json([], 422);
|
||||||
|
}
|
||||||
|
|
||||||
public function update(UpdateRequest $request, UserGroup $userGroup): JsonResponse
|
public function update(UpdateRequest $request, UserGroup $userGroup): JsonResponse
|
||||||
{
|
{
|
||||||
$all = $request->getAll();
|
$all = $request->getAll();
|
||||||
|
@@ -26,6 +26,7 @@ namespace FireflyIII\Api\V2\Request\UserGroup;
|
|||||||
|
|
||||||
use FireflyIII\Enums\UserRoleEnum;
|
use FireflyIII\Enums\UserRoleEnum;
|
||||||
use FireflyIII\Models\UserGroup;
|
use FireflyIII\Models\UserGroup;
|
||||||
|
use FireflyIII\Rules\IsDefaultUserGroupName;
|
||||||
use FireflyIII\Support\Request\ChecksLogin;
|
use FireflyIII\Support\Request\ChecksLogin;
|
||||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
@@ -53,7 +54,7 @@ class UpdateRequest extends FormRequest
|
|||||||
$userGroup = $this->route()->parameter('userGroup');
|
$userGroup = $this->route()->parameter('userGroup');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'title' => sprintf('required|min:1|max:255|unique:user_groups,title,%d', $userGroup->id),
|
'title' => ['required', 'min:1', 'max:255', sprintf('unique:user_groups,title,%d', $userGroup->id), new IsDefaultUserGroupName($userGroup)],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -36,7 +36,7 @@ class CreateController extends Controller
|
|||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
$title = (string)trans('firefly.administrations_page_title');
|
$title = (string)trans('firefly.administrations_page_title');
|
||||||
$subTitle = (string)trans('firefly.administrations_page_sub_title');
|
$subTitle = (string)trans('firefly.administrations_page_create_sub_title');
|
||||||
$mainTitleIcon = 'fa-book';
|
$mainTitleIcon = 'fa-book';
|
||||||
app('log')->debug(sprintf('Now at %s', __METHOD__));
|
app('log')->debug(sprintf('Now at %s', __METHOD__));
|
||||||
|
|
||||||
|
46
app/Http/Controllers/UserGroup/EditController.php
Normal file
46
app/Http/Controllers/UserGroup/EditController.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* CreateController.php
|
||||||
|
* Copyright (c) 2024 james@firefly-iii.org.
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace FireflyIII\Http\Controllers\UserGroup;
|
||||||
|
|
||||||
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
|
use FireflyIII\Models\UserGroup;
|
||||||
|
use Illuminate\Contracts\View\Factory;
|
||||||
|
use Illuminate\Contracts\View\View;
|
||||||
|
use Illuminate\Foundation\Application;
|
||||||
|
|
||||||
|
class EditController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return Application|Factory|\Illuminate\Contracts\Foundation\Application|View
|
||||||
|
*/
|
||||||
|
public function edit(UserGroup $userGroup)
|
||||||
|
{
|
||||||
|
$title = (string)trans('firefly.administrations_page_title');
|
||||||
|
$subTitle = (string)trans('firefly.administrations_page_edit_sub_title', ['title' => $userGroup->title]);
|
||||||
|
$mainTitleIcon = 'fa-book';
|
||||||
|
app('log')->debug(sprintf('Now at %s', __METHOD__));
|
||||||
|
|
||||||
|
return view('administrations.edit')->with(compact('title', 'subTitle', 'mainTitleIcon'));
|
||||||
|
}
|
||||||
|
}
|
@@ -288,4 +288,10 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
|||||||
|
|
||||||
return $roles;
|
return $roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[\Override] public function useUserGroup(UserGroup $userGroup): void
|
||||||
|
{
|
||||||
|
$this->user->user_group_id = $userGroup->id;
|
||||||
|
$this->user->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -38,6 +38,8 @@ interface UserGroupRepositoryInterface
|
|||||||
|
|
||||||
public function get(): Collection;
|
public function get(): Collection;
|
||||||
|
|
||||||
|
public function useUserGroup(UserGroup $userGroup): void;
|
||||||
|
|
||||||
public function getAll(): Collection;
|
public function getAll(): Collection;
|
||||||
|
|
||||||
public function setUser(null|Authenticatable|User $user): void;
|
public function setUser(null|Authenticatable|User $user): void;
|
||||||
|
63
app/Rules/IsDefaultUserGroupName.php
Normal file
63
app/Rules/IsDefaultUserGroupName.php
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IsTransferAccount.php
|
||||||
|
* Copyright (c) 2020 james@firefly-iii.org
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace FireflyIII\Rules;
|
||||||
|
|
||||||
|
use FireflyIII\Models\TransactionType;
|
||||||
|
use FireflyIII\Models\UserGroup;
|
||||||
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\UserGroup\UserGroupRepositoryInterface;
|
||||||
|
use FireflyIII\User;
|
||||||
|
use FireflyIII\Validation\AccountValidator;
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class IsDefaultUserGroupName
|
||||||
|
*/
|
||||||
|
class IsDefaultUserGroupName implements ValidationRule
|
||||||
|
{
|
||||||
|
private UserGroup $userGroup;
|
||||||
|
public function __construct(UserGroup $userGroup) {
|
||||||
|
$this->userGroup =$userGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
|
*/
|
||||||
|
public function validate(string $attribute, mixed $value, \Closure $fail): void
|
||||||
|
{
|
||||||
|
app('log')->debug(sprintf('Now in %s(%s)', __METHOD__, $value));
|
||||||
|
|
||||||
|
// are you owner of this group and the name is the same? fail.
|
||||||
|
/** @var User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
/** @var UserRepositoryInterface $userRepos */
|
||||||
|
$userRepos = app(UserRepositoryInterface::class);
|
||||||
|
|
||||||
|
$roles = $userRepos->getRolesInGroup($user, $this->userGroup->id);
|
||||||
|
if($this->userGroup->title === $user->email && in_array('owner', $roles, true)) {
|
||||||
|
$fail('validation.administration_owner_rename')->translate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -53,6 +53,8 @@ export default defineConfig({
|
|||||||
|
|
||||||
// administrations
|
// administrations
|
||||||
'resources/assets/v2/pages/administrations/index.js',
|
'resources/assets/v2/pages/administrations/index.js',
|
||||||
|
'resources/assets/v2/pages/administrations/create.js',
|
||||||
|
'resources/assets/v2/pages/administrations/edit.js',
|
||||||
|
|
||||||
// transactions
|
// transactions
|
||||||
'resources/assets/v2/pages/transactions/create.js',
|
'resources/assets/v2/pages/transactions/create.js',
|
||||||
|
Reference in New Issue
Block a user