Skip to content

Commit

Permalink
mgr/dashboard: Provide user enable/disable capability in the frontend
Browse files Browse the repository at this point in the history
Fixes: http://tracker.ceph.com/issues/25229

Signed-off-by: Patrick Nawracay <[email protected]>
  • Loading branch information
p-se authored and rjfd committed Aug 1, 2019
1 parent 2b76d76 commit a2a5457
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -23,6 +24,7 @@ import { UserTabsComponent } from './user-tabs/user-tabs.component';
@NgModule({
imports: [
BsDropdownModule.forRoot(),
ButtonsModule.forRoot(),
CommonModule,
FormsModule,
PopoverModule.forRoot(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,26 @@
[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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -48,7 +49,8 @@ describe('UserFormComponent', () => {
ReactiveFormsModule,
ComponentsModule,
ToastrModule.forRoot(),
SharedModule
SharedModule,
ButtonsModule.forRoot()
],
declarations: [UserFormComponent, FakeComponent],
providers: i18nProviders
Expand Down Expand Up @@ -113,7 +115,8 @@ describe('UserFormComponent', () => {
password: 'pass0',
name: 'User 0',
email: '[email protected]',
roles: ['administrator']
roles: ['administrator'],
enabled: true
};
formHelper.setMultipleValues(user);
formHelper.setValue('confirmpassword', user.password);
Expand All @@ -132,7 +135,8 @@ describe('UserFormComponent', () => {
password: undefined,
name: 'User 1',
email: '[email protected]',
roles: ['administrator']
roles: ['administrator'],
enabled: true
};
const roles = [
{
Expand Down Expand Up @@ -222,7 +226,8 @@ describe('UserFormComponent', () => {
password: '',
name: 'User 1',
email: '[email protected]',
roles: ['administrator']
roles: ['administrator'],
enabled: true
});
userReq.flush({});
expect(router.navigate).toHaveBeenCalledWith(['/user-management/users']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -169,7 +172,7 @@ export class UserFormComponent implements OnInit {
}
}

private isCurrentUser(): boolean {
public isCurrentUser(): boolean {
return this.authStorageService.getUsername() === this.userForm.getValue('username');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export class UserFormModel {
name: string;
email: string;
roles: Array<string>;
enabled: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@
{{ role }}{{ !isLast ? ", " : "" }}
</span>
</ng-template>

<ng-template #userEnabledTpl
let-value="value">
<span>{{ value | booleanText }}</span>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -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
}
];
}
Expand Down

0 comments on commit a2a5457

Please sign in to comment.