Bladeren bron

Hide a list of Coriolis users in the UI

A configurable list of users (`config.js` -> `hiddenUsers`) to hide in
the UI.
Sergiu Miclea 6 jaren geleden
bovenliggende
commit
71e5acc70c
4 gewijzigde bestanden met toevoegingen van 22 en 4 verwijderingen
  1. 3 0
      config.js
  2. 10 1
      src/sources/UserSource.js
  3. 1 0
      src/types/Config.js
  4. 8 3
      src/utils/ObjectUtils.js

+ 3 - 0
config.js

@@ -60,6 +60,9 @@ const conf: Config = {
       envRequiredFields: ['compartment', 'availability_domain'],
     },
   ],
+
+  // The list of the users to hide in the UI
+  hiddenUsers: ['barbican', 'coriolis'],
 }
 
 export const config = conf

+ 10 - 1
src/sources/UserSource.js

@@ -21,6 +21,7 @@ import { servicesUrl, coriolisUrl } from '../constants'
 import configLoader from '../utils/Config'
 import type { Credentials, User } from '../types/User'
 import type { Role, Project, RoleAssignment } from '../types/Project'
+import utils from '../utils/ObjectUtils'
 
 class UserModel {
   static parseUserData(data: any) {
@@ -177,8 +178,16 @@ class UserSource {
   }
 
   static getAllUsers(): Promise<User[]> {
+    let users: User[] = []
     return Api.get(`${servicesUrl.users}`)
-      .then(response => response.data.users.sort((u1, u2) => u1.name.localeCompare(u2.name)))
+      .then(response => {
+        users = response.data.users
+        return utils.waitFor(() => Boolean(configLoader.config))
+      }).then(() => {
+        users = users.filter(u => !configLoader.config.hiddenUsers.find(hu => hu === u.name))
+          .sort((u1, u2) => u1.name.localeCompare(u2.name))
+        return users
+      })
   }
 
   static update(userId: string, user: User, oldUser: ?User): Promise<User> {

+ 1 - 0
src/types/Config.js

@@ -11,4 +11,5 @@ export type Config = {
   instancesListBackgroundLoading: { default: number, [string]: number },
   sourceProvidersWithExtraOptions: Array<string | { name: string, envRequiredFields: string[] }>,
   destinationProvidersWithExtraOptions: Array<string | { name: string, envRequiredFields: string[] }>,
+  hiddenUsers: string[],
 }

+ 8 - 3
src/utils/ObjectUtils.js

@@ -55,14 +55,19 @@ class ObjectUtils {
     return result
   }
 
-  static waitFor(predicate: () => boolean): Promise<void> {
-    let test = () => new Promise((resolve) => {
+  static waitFor(predicate: () => boolean, timeout?: number = 15000): Promise<void> {
+    let start = new Date().getTime()
+    let test = () => new Promise((resolve, reject) => {
       if (predicate()) {
         resolve()
         return
       }
       setTimeout(() => {
-        test()
+        if (new Date().getTime() - start < timeout) {
+          test()
+        } else {
+          reject(`Timeout: waiting for more than ${timeout} ms`)
+        }
       }, 1000)
     })
     return test()