Răsfoiți Sursa

Make the admin role name configurable

The name of the admin role is now configurable. As a reminder, the admin
role name is used to check if a user is allowed to do certain admin
operations (Projects, Users pages among others).
Sergiu Miclea 6 ani în urmă
părinte
comite
dff8df5cca
3 a modificat fișierele cu 9 adăugiri și 2 ștergeri
  1. 4 0
      config.ts
  2. 1 0
      src/@types/Config.ts
  3. 4 2
      src/sources/UserSource.ts

+ 4 - 0
config.ts

@@ -17,6 +17,10 @@ const conf: Config = {
   // The default user domain name used for logging in
   defaultUserDomain: 'default',
 
+  // The name of the admin role, used for checking
+  // if a user is allowed to do certain admin operations
+  adminRoleName: 'admin',
+
   // Shows the 'Use Current User/Project/Domain for Authentification' switch
   // when creating a new openstack endpoint
   showOpenstackCurrentUserSwitch: false,

+ 1 - 0
src/@types/Config.ts

@@ -23,6 +23,7 @@ export type Config = {
   disabledPages: string[],
   showUserDomainInput: boolean,
   defaultUserDomain: string,
+  adminRoleName: string,
   showOpenstackCurrentUserSwitch: boolean,
   useBarbicanSecrets: boolean,
   requestPollTimeout: number,

+ 4 - 2
src/sources/UserSource.ts

@@ -295,7 +295,7 @@ class UserSource {
 
   async getAdminRoleId(): Promise<string> {
     const roles: { id: string, name: string }[] = await this.getRoles()
-    const role = roles.find(r => r.name.toLowerCase() === 'admin')
+    const role = roles.find(r => r.name.toLowerCase() === configLoader.config.adminRoleName)
     const roleId = role ? role.id : ''
     return roleId
   }
@@ -330,7 +330,9 @@ class UserSource {
     const roleAssignments: RoleAssignment[] = response.data.role_assignments
     return roleAssignments
       .filter(a => a && a.user && a.user.id === userId)
-      .filter(a => a && a.role && a.role.name && a.role.name.toLowerCase() === 'admin').length > 0
+      .filter(a => a && a.role && a.role.name
+        && a.role.name.toLowerCase() === configLoader.config.adminRoleName)
+      .length > 0
   }
 }