Change: restrict altering and creation of superusers to superusers only (#8837)

This commit is contained in:
shamoon
2025-01-20 11:57:22 -08:00
committed by GitHub
parent 475c231c6f
commit 41bcc12cc2
7 changed files with 194 additions and 1 deletions

View File

@@ -160,4 +160,23 @@ describe('UserEditDialogComponent', () => {
})
expect(component.currentUserIsSuperUser).toBeTruthy()
})
it('should disable superuser option if current user is not superuser', () => {
const control: AbstractControl = component.objectForm.get('is_superuser')
permissionsService.initialize([], {
id: 99,
username: 'user99',
is_superuser: false,
})
component.ngOnInit()
expect(control.disabled).toBeTruthy()
permissionsService.initialize([], {
id: 99,
username: 'user99',
is_superuser: true,
})
component.ngOnInit()
expect(control.disabled).toBeFalsy()
})
})

View File

@@ -60,6 +60,11 @@ export class UserEditDialogComponent
ngOnInit(): void {
super.ngOnInit()
this.onToggleSuperUser()
if (!this.currentUserIsSuperUser) {
this.objectForm.get('is_superuser').disable()
} else {
this.objectForm.get('is_superuser').enable()
}
}
getCreateTitle() {