From: Patrick Nawracay Date: Fri, 12 Jul 2019 11:42:04 +0000 (+0200) Subject: mgr/dashboard: Provide user enable/disable capability in the frontend X-Git-Tag: v15.1.0~1977^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a2a5457a036f641db112c9d942a7b2b2a2193a9d;p=ceph-ci.git mgr/dashboard: Provide user enable/disable capability in the frontend Fixes: http://tracker.ceph.com/issues/25229 Signed-off-by: Patrick Nawracay --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/auth.module.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/auth.module.ts index b26a370b39b..0e9f4590317 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/auth.module.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/auth.module.ts @@ -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(), diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.html b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.html index c1ecff9c7e8..252c2292e2e 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.html @@ -132,7 +132,26 @@ [messages]="messages"> + + +
+ +
+
+ + +
+
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.spec.ts index b91a71fd3a6..603c1986272 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.spec.ts @@ -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']); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.ts index 77a8e75c56d..0b794a8d00f 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.ts @@ -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'); } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.model.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.model.ts index cd3b188ad80..c3e3126a56c 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.model.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.model.ts @@ -4,4 +4,5 @@ export class UserFormModel { name: string; email: string; roles: Array; + enabled: boolean; } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-list/user-list.component.html b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-list/user-list.component.html index 89ed21be833..7ba6a5ade50 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-list/user-list.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-list/user-list.component.html @@ -20,3 +20,8 @@ {{ role }}{{ !isLast ? ", " : "" }} + + + {{ value | booleanText }} + diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-list/user-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-list/user-list.component.ts index 3499dcb2d5f..cdc6181e8bf 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-list/user-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-list/user-list.component.ts @@ -28,6 +28,8 @@ const BASE_URL = 'user-management/users'; export class UserListComponent implements OnInit { @ViewChild('userRolesTpl') userRolesTpl: TemplateRef; + @ViewChild('userEnabledTpl') + userEnabledTpl: TemplateRef; 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 } ]; }