X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/21f2a7087c7ef1af1e30e1997bce77cc64ede76e..refs/pull/3850/head:/app/Http/Controllers/RoleController.php diff --git a/app/Http/Controllers/RoleController.php b/app/Http/Controllers/RoleController.php index 7c72b5970..a9be19e0c 100644 --- a/app/Http/Controllers/RoleController.php +++ b/app/Http/Controllers/RoleController.php @@ -3,19 +3,18 @@ namespace BookStack\Http\Controllers; use BookStack\Auth\Permissions\PermissionsRepo; +use BookStack\Auth\Queries\RolesAllPaginatedAndSorted; use BookStack\Auth\Role; use BookStack\Exceptions\PermissionsException; +use BookStack\Util\SimpleListOptions; use Exception; use Illuminate\Http\Request; use Illuminate\Validation\ValidationException; class RoleController extends Controller { - protected $permissionsRepo; + protected PermissionsRepo $permissionsRepo; - /** - * PermissionController constructor. - */ public function __construct(PermissionsRepo $permissionsRepo) { $this->permissionsRepo = $permissionsRepo; @@ -24,12 +23,27 @@ class RoleController extends Controller /** * Show a listing of the roles in the system. */ - public function index() + public function index(Request $request) { $this->checkPermission('user-roles-manage'); - $roles = $this->permissionsRepo->getAllRoles(); - return view('settings.roles.index', ['roles' => $roles]); + $listOptions = SimpleListOptions::fromRequest($request, 'roles')->withSortOptions([ + 'display_name' => trans('common.sort_name'), + 'users_count' => trans('settings.roles_assigned_users'), + 'permissions_count' => trans('settings.roles_permissions_provided'), + 'created_at' => trans('common.sort_created_at'), + 'updated_at' => trans('common.sort_updated_at'), + ]); + + $roles = (new RolesAllPaginatedAndSorted())->run(20, $listOptions); + $roles->appends($listOptions->getPaginationAppends()); + + $this->setPageTitle(trans('settings.roles')); + + return view('settings.roles.index', [ + 'roles' => $roles, + 'listOptions' => $listOptions, + ]); } /** @@ -49,6 +63,8 @@ class RoleController extends Controller $role->display_name .= ' (' . trans('common.copy') . ')'; } + $this->setPageTitle(trans('settings.role_create')); + return view('settings.roles.create', ['role' => $role]); } @@ -71,16 +87,13 @@ class RoleController extends Controller /** * Show the form for editing a user role. - * - * @throws PermissionsException */ public function edit(string $id) { $this->checkPermission('user-roles-manage'); $role = $this->permissionsRepo->getRoleById($id); - if ($role->hidden) { - throw new PermissionsException(trans('errors.role_cannot_be_edited')); - } + + $this->setPageTitle(trans('settings.role_edit')); return view('settings.roles.edit', ['role' => $role]); } @@ -116,6 +129,8 @@ class RoleController extends Controller $blankRole = $role->newInstance(['display_name' => trans('settings.role_delete_no_migration')]); $roles->prepend($blankRole); + $this->setPageTitle(trans('settings.role_delete')); + return view('settings.roles.delete', ['role' => $role, 'roles' => $roles]); }