Fix user role edition
authorChocobozzz <me@florianbigard.com>
Wed, 18 Mar 2020 09:22:36 +0000 (10:22 +0100)
committerChocobozzz <me@florianbigard.com>
Wed, 18 Mar 2020 09:22:36 +0000 (10:22 +0100)
client/src/app/+admin/users/user-edit/user-edit.component.html
client/src/app/+admin/users/user-edit/user-edit.ts

index 2aca5ddca150a4afa108de19efd69a3ebc347c0d..dbb0e36b903dd97a1e273fa77907df0681f51091 100644 (file)
@@ -49,7 +49,7 @@
     <label i18n for="role">Role</label>
     <div class="peertube-select-container">
       <select id="role" formControlName="role">
-        <option *ngFor="let role of getRoles()" [value]="role.value">
+        <option *ngFor="let role of roles" [value]="role.value">
           {{ role.label }}
         </option>
       </select>
index 02f1dcd42cae6d3e0bd8e363dc73a2d13286d016..47b57d2ec6e696250a7ab78fd09bd3aaa4cf30b3 100644 (file)
@@ -11,6 +11,8 @@ export abstract class UserEdit extends FormReactive implements OnInit {
   username: string
   userId: number
 
+  roles: { value: string, label: string }[] = []
+
   protected serverConfig: ServerConfig
 
   protected abstract serverService: ServerService
@@ -23,17 +25,20 @@ export abstract class UserEdit extends FormReactive implements OnInit {
     this.serverConfig = this.serverService.getTmpConfig()
     this.serverService.getConfig()
         .subscribe(config => this.serverConfig = config)
+
+    this.buildRoles()
   }
 
-  getRoles () {
+  buildRoles () {
     const authUser = this.auth.getUser()
 
     if (authUser.role === UserRole.ADMINISTRATOR) {
-      return Object.keys(USER_ROLE_LABELS)
+      this.roles = Object.keys(USER_ROLE_LABELS)
             .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
+      return
     }
 
-    return [
+    this.roles = [
       { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] }
     ]
   }