mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-30 04:23:11 +03:00
Added check for last admin on role change
Will show error message if last admin and admin role is removed. Closes #1124 Also cleaned up user controller a little.
This commit is contained in:
@ -78,6 +78,28 @@ class RolesTest extends BrowserKitTest
|
||||
->dontSee($testRoleUpdateName);
|
||||
}
|
||||
|
||||
public function test_admin_role_cannot_be_removed_if_last_admin()
|
||||
{
|
||||
$adminRole = Role::where('system_name', '=', 'admin')->first();
|
||||
$adminUser = $this->getAdmin();
|
||||
$adminRole->users()->where('id', '!=', $adminUser->id)->delete();
|
||||
$this->assertEquals($adminRole->users()->count(), 1);
|
||||
|
||||
$viewerRole = $this->getViewer()->roles()->first();
|
||||
|
||||
$editUrl = '/settings/users/' . $adminUser->id;
|
||||
$this->actingAs($adminUser)->put($editUrl, [
|
||||
'name' => $adminUser->name,
|
||||
'email' => $adminUser->email,
|
||||
'roles' => [
|
||||
'viewer' => strval($viewerRole->id),
|
||||
]
|
||||
])->followRedirects();
|
||||
|
||||
$this->seePageIs($editUrl);
|
||||
$this->see('This user is the only user assigned to the administrator role');
|
||||
}
|
||||
|
||||
public function test_manage_user_permission()
|
||||
{
|
||||
$this->actingAs($this->user)->visit('/settings/users')
|
||||
|
Reference in New Issue
Block a user