]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Provide user enable/disable capability in the frontend
authorPatrick Nawracay <pnawracay@suse.com>
Fri, 12 Jul 2019 11:42:04 +0000 (13:42 +0200)
committerRicardo Dias <rdias@suse.com>
Thu, 1 Aug 2019 08:34:53 +0000 (09:34 +0100)
Fixes: http://tracker.ceph.com/issues/25229
Signed-off-by: Patrick Nawracay <pnawracay@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/core/auth/auth.module.ts
src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.html
src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.ts
src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.model.ts
src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-list/user-list.component.html
src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-list/user-list.component.ts

index b26a370b39bcfdffe976e9aa8af82c106e548208..0e9f45903171dbfecfa74cacb815eba7e51aea0d 100644 (file)
@@ -4,6 +4,7 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
 import { RouterModule, Routes } from '@angular/router';
 
 import { NgBootstrapFormValidationModule } from 'ng-bootstrap-form-validation';
+import { ButtonsModule } from 'ngx-bootstrap/buttons';
 import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
 import { PopoverModule } from 'ngx-bootstrap/popover';
 import { TabsModule } from 'ngx-bootstrap/tabs';
@@ -23,6 +24,7 @@ import { UserTabsComponent } from './user-tabs/user-tabs.component';
 @NgModule({
   imports: [
     BsDropdownModule.forRoot(),
+    ButtonsModule.forRoot(),
     CommonModule,
     FormsModule,
     PopoverModule.forRoot(),
index c1ecff9c7e881d9fc2868f9340ed69abb8aa9ec2..252c2292e2e83f95c144581cba0de5c0d2ccf9c3 100644 (file)
                                 [messages]="messages"></cd-select-badges>
             </span>
           </div>
+        </div>
 
+        <!-- Enabled -->
+        <div class="form-group row" *ngIf="!isCurrentUser()">
+          <label class="col-sm-3 col-form-label"
+                 i18n>Enabled</label>
+          <div class="col-sm-9">
+            <div class="btn-group"
+                 btnRadioGroup
+                 formControlName="enabled">
+              <label [btnRadio]="true"
+                     class="btn btn-primary"
+                     tabindex="0"
+                     role="button">Enabled</label>
+              <label [btnRadio]="false"
+                     class="btn btn-primary"
+                     tabindex="0"
+                     role="button">Disabled</label>
+            </div>
+          </div>
         </div>
 
       </div>
index b91a71fd3a6d54974c4bbd4e1e08c43ece759954..603c19862726f49b18e2fd934b170ecaeaa31503 100644 (file)
@@ -5,6 +5,7 @@ import { ReactiveFormsModule } from '@angular/forms';
 import { Router, Routes } from '@angular/router';
 import { RouterTestingModule } from '@angular/router/testing';
 
+import { ButtonsModule } from 'ngx-bootstrap/buttons';
 import { BsModalService } from 'ngx-bootstrap/modal';
 import { ToastrModule } from 'ngx-toastr';
 import { of } from 'rxjs';
@@ -48,7 +49,8 @@ describe('UserFormComponent', () => {
         ReactiveFormsModule,
         ComponentsModule,
         ToastrModule.forRoot(),
-        SharedModule
+        SharedModule,
+        ButtonsModule.forRoot()
       ],
       declarations: [UserFormComponent, FakeComponent],
       providers: i18nProviders
@@ -113,7 +115,8 @@ describe('UserFormComponent', () => {
         password: 'pass0',
         name: 'User 0',
         email: 'user0@email.com',
-        roles: ['administrator']
+        roles: ['administrator'],
+        enabled: true
       };
       formHelper.setMultipleValues(user);
       formHelper.setValue('confirmpassword', user.password);
@@ -132,7 +135,8 @@ describe('UserFormComponent', () => {
       password: undefined,
       name: 'User 1',
       email: 'user1@email.com',
-      roles: ['administrator']
+      roles: ['administrator'],
+      enabled: true
     };
     const roles = [
       {
@@ -222,7 +226,8 @@ describe('UserFormComponent', () => {
         password: '',
         name: 'User 1',
         email: 'user1@email.com',
-        roles: ['administrator']
+        roles: ['administrator'],
+        enabled: true
       });
       userReq.flush({});
       expect(router.navigate).toHaveBeenCalledWith(['/user-management/users']);
index 77a8e75c56dd189b5c86429f15c0f0d1b53f975f..0b794a8d00fa36bf88514ca7f84552fe63cc5b31 100644 (file)
@@ -76,7 +76,10 @@ export class UserFormComponent implements OnInit {
         email: new FormControl('', {
           validators: [Validators.email]
         }),
-        roles: new FormControl([])
+        roles: new FormControl([]),
+        enabled: new FormControl(true, {
+          validators: [Validators.required]
+        })
       },
       {
         validators: [CdValidators.match('password', 'confirmpassword')]
@@ -119,14 +122,14 @@ export class UserFormComponent implements OnInit {
   }
 
   setResponse(response: UserFormModel) {
-    ['username', 'name', 'email', 'roles'].forEach((key) =>
+    ['username', 'name', 'email', 'roles', 'enabled'].forEach((key) =>
       this.userForm.get(key).setValue(response[key])
     );
   }
 
   getRequest(): UserFormModel {
     const userFormModel = new UserFormModel();
-    ['username', 'password', 'name', 'email', 'roles'].forEach(
+    ['username', 'password', 'name', 'email', 'roles', 'enabled'].forEach(
       (key) => (userFormModel[key] = this.userForm.get(key).value)
     );
     return userFormModel;
@@ -169,7 +172,7 @@ export class UserFormComponent implements OnInit {
     }
   }
 
-  private isCurrentUser(): boolean {
+  public isCurrentUser(): boolean {
     return this.authStorageService.getUsername() === this.userForm.getValue('username');
   }
 
index cd3b188ad804922173b3342f9fbe48383d5a1684..c3e3126a56cf9dc3aafb871b84074e3174aca25d 100644 (file)
@@ -4,4 +4,5 @@ export class UserFormModel {
   name: string;
   email: string;
   roles: Array<string>;
+  enabled: boolean;
 }
index 89ed21be83313028405b17d53ad2700805195132..7ba6a5ade50268aea8289cabe83e5ce4b272c75e 100644 (file)
@@ -20,3 +20,8 @@
     {{ role }}{{ !isLast ? ", " : "" }}
   </span>
 </ng-template>
+
+<ng-template #userEnabledTpl
+             let-value="value">
+  <span>{{ value | booleanText }}</span>
+</ng-template>
index 3499dcb2d5f5536f72bb4fcd7b02e7addc6e68e8..cdc6181e8bf8a93e65994e509bab1e9992c7c569 100644 (file)
@@ -28,6 +28,8 @@ const BASE_URL = 'user-management/users';
 export class UserListComponent implements OnInit {
   @ViewChild('userRolesTpl')
   userRolesTpl: TemplateRef<any>;
+  @ViewChild('userEnabledTpl')
+  userEnabledTpl: TemplateRef<any>;
 
   permission: Permission;
   tableActions: CdTableAction[];
@@ -94,6 +96,12 @@ export class UserListComponent implements OnInit {
         prop: 'roles',
         flexGrow: 1,
         cellTemplate: this.userRolesTpl
+      },
+      {
+        name: this.i18n('Enabled'),
+        prop: 'enabled',
+        flexGrow: 1,
+        cellTemplate: this.userEnabledTpl
       }
     ];
   }