mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
chore(authentication): multiple roles
CB-109
This commit is contained in:
+3
-3
@@ -71,7 +71,7 @@ export const CreateUserDialog: DialogComponent<null, null> = observer(
|
||||
[]
|
||||
);
|
||||
const handleRoleChange = useCallback(
|
||||
(value: string) => controller.credentials.role = value,
|
||||
(value: string) => controller.credentials.roles = value,
|
||||
[]
|
||||
);
|
||||
|
||||
@@ -117,8 +117,8 @@ export const CreateUserDialog: DialogComponent<null, null> = observer(
|
||||
<InputField
|
||||
type='role'
|
||||
name='text'
|
||||
value={controller.credentials.role}
|
||||
placeholder={controller.roles.join(', ')}
|
||||
value={controller.credentials.roles}
|
||||
placeholder={controller.roles.join(' ')}
|
||||
onChange={handleRoleChange}
|
||||
disabled={controller.isCreating}
|
||||
mod='surface'
|
||||
|
||||
+12
-2
@@ -24,7 +24,7 @@ export class CreateUserDialogController implements IInitializableController, IDe
|
||||
@observable credentials = {
|
||||
login: '',
|
||||
password: '',
|
||||
role: '',
|
||||
roles: '',
|
||||
};
|
||||
|
||||
@computed get roles() {
|
||||
@@ -61,7 +61,17 @@ export class CreateUserDialogController implements IInitializableController, IDe
|
||||
const user = await this.usersManagerService.create(this.credentials.login, false);
|
||||
isUserCreated = !!user;
|
||||
await this.usersManagerService.updateCredentials(user.userId, { password: this.credentials.password });
|
||||
await this.usersManagerService.grantRole(user.userId, this.credentials.role);
|
||||
if (this.credentials.roles) {
|
||||
const roles = this.credentials.roles
|
||||
.trim()
|
||||
.replace(/\s+/g, ' ')
|
||||
.split(' ');
|
||||
|
||||
for (const role of roles) {
|
||||
await this.usersManagerService.grantRole(user.userId, role);
|
||||
}
|
||||
}
|
||||
await this.usersManagerService.users.refresh(user.userId);
|
||||
this.close();
|
||||
} catch (exception) {
|
||||
if (isUserCreated) {
|
||||
|
||||
@@ -36,9 +36,11 @@ export class UsersManagerService {
|
||||
return user as AdminUserInfo;
|
||||
}
|
||||
|
||||
async grantRole(userId: string, roleId: string) {
|
||||
async grantRole(userId: string, roleId: string, update?: boolean) {
|
||||
await this.graphQLService.gql.grantUserRole({ userId, roleId });
|
||||
await this.users.refresh(userId);
|
||||
if (update) {
|
||||
await this.users.refresh(userId);
|
||||
}
|
||||
}
|
||||
|
||||
async delete(userId: string, update?: boolean) {
|
||||
|
||||
Reference in New Issue
Block a user