diff options
Diffstat (limited to 'src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details')
4 files changed, 166 insertions, 0 deletions
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.html b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.html new file mode 100644 index 000000000..ca4b6781b --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.html @@ -0,0 +1,11 @@ +<ng-container *ngIf="selection"> + <cd-table [data]="scopes_permissions" + [columns]="columns" + columnMode="flex" + [toolHeader]="false" + [autoReload]="false" + [autoSave]="false" + [footer]="false" + [limit]="0"> + </cd-table> +</ng-container> diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.scss b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.scss new file mode 100644 index 000000000..2ec160998 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.scss @@ -0,0 +1,9 @@ +@use './src/styles/vendor/variables' as vv; + +.fa { + font-size: large; + + &.fa-square-o { + color: vv.$gray-400; + } +} diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.spec.ts new file mode 100644 index 000000000..b62cd32eb --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.spec.ts @@ -0,0 +1,67 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; + +import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap'; + +import { SharedModule } from '~/app/shared/shared.module'; +import { configureTestBed } from '~/testing/unit-test-helper'; +import { RoleDetailsComponent } from './role-details.component'; + +describe('RoleDetailsComponent', () => { + let component: RoleDetailsComponent; + let fixture: ComponentFixture<RoleDetailsComponent>; + + configureTestBed({ + imports: [SharedModule, RouterTestingModule, HttpClientTestingModule, NgbNavModule], + declarations: [RoleDetailsComponent] + }); + + beforeEach(() => { + fixture = TestBed.createComponent(RoleDetailsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); + + it('should create scopes permissions [1/2]', () => { + component.scopes = ['log', 'rgw']; + component.selection = { + description: 'RGW Manager', + name: 'rgw-manager', + scopes_permissions: { + rgw: ['read', 'create', 'update', 'delete'] + }, + system: true + }; + expect(component.scopes_permissions.length).toBe(0); + component.ngOnChanges(); + expect(component.scopes_permissions).toEqual([ + { scope: 'log', read: false, create: false, update: false, delete: false }, + { scope: 'rgw', read: true, create: true, update: true, delete: true } + ]); + }); + + it('should create scopes permissions [2/2]', () => { + component.scopes = ['cephfs', 'log', 'rgw']; + component.selection = { + description: 'Test', + name: 'test', + scopes_permissions: { + log: ['read', 'update'], + rgw: ['read', 'create', 'update'] + }, + system: false + }; + expect(component.scopes_permissions.length).toBe(0); + component.ngOnChanges(); + expect(component.scopes_permissions).toEqual([ + { scope: 'cephfs', read: false, create: false, update: false, delete: false }, + { scope: 'log', read: true, create: false, update: true, delete: false }, + { scope: 'rgw', read: true, create: true, update: true, delete: false } + ]); + }); +}); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.ts new file mode 100644 index 000000000..244a7861b --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.ts @@ -0,0 +1,79 @@ +import { Component, Input, OnChanges, OnInit } from '@angular/core'; + +import _ from 'lodash'; + +import { CellTemplate } from '~/app/shared/enum/cell-template.enum'; +import { CdTableColumn } from '~/app/shared/models/cd-table-column'; + +@Component({ + selector: 'cd-role-details', + templateUrl: './role-details.component.html', + styleUrls: ['./role-details.component.scss'] +}) +export class RoleDetailsComponent implements OnChanges, OnInit { + @Input() + selection: any; + @Input() + scopes: Array<string>; + selectedItem: any; + + columns: CdTableColumn[]; + scopes_permissions: Array<any> = []; + + ngOnInit() { + this.columns = [ + { + prop: 'scope', + name: $localize`Scope`, + flexGrow: 2 + }, + { + prop: 'read', + name: $localize`Read`, + flexGrow: 1, + cellClass: 'text-center', + cellTransformation: CellTemplate.checkIcon + }, + { + prop: 'create', + name: $localize`Create`, + flexGrow: 1, + cellClass: 'text-center', + cellTransformation: CellTemplate.checkIcon + }, + { + prop: 'update', + name: $localize`Update`, + flexGrow: 1, + cellClass: 'text-center', + cellTransformation: CellTemplate.checkIcon + }, + { + prop: 'delete', + name: $localize`Delete`, + flexGrow: 1, + cellClass: 'text-center', + cellTransformation: CellTemplate.checkIcon + } + ]; + } + + ngOnChanges() { + if (this.selection) { + this.selectedItem = this.selection; + // Build the scopes/permissions data used by the data table. + const scopes_permissions: any[] = []; + _.each(this.scopes, (scope) => { + const scope_permission: any = { read: false, create: false, update: false, delete: false }; + scope_permission['scope'] = scope; + if (scope in this.selectedItem['scopes_permissions']) { + _.each(this.selectedItem['scopes_permissions'][scope], (permission) => { + scope_permission[permission] = true; + }); + } + scopes_permissions.push(scope_permission); + }); + this.scopes_permissions = scopes_permissions; + } + } +} |