chore(authentication): multiple roles

CB-109
This commit is contained in:
Wroud
2020-05-29 14:12:55 +03:00
parent 66f02a6867
commit 7bfac2b95a
3 changed files with 19 additions and 7 deletions
@@ -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'
@@ -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) {