]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.ts
1ed0568f773bff6c020730de7ea1c93a81b51dc7
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / auth / role-details / role-details.component.ts
1 import { Component, Input, OnChanges, OnInit } from '@angular/core';
2
3 import { I18n } from '@ngx-translate/i18n-polyfill';
4 import * as _ from 'lodash';
5
6 import { CellTemplate } from '../../../shared/enum/cell-template.enum';
7 import { CdTableColumn } from '../../../shared/models/cd-table-column';
8 import { CdTableSelection } from '../../../shared/models/cd-table-selection';
9
10 @Component({
11 selector: 'cd-role-details',
12 templateUrl: './role-details.component.html',
13 styleUrls: ['./role-details.component.scss']
14 })
15 export class RoleDetailsComponent implements OnChanges, OnInit {
16 @Input()
17 selection: CdTableSelection;
18 @Input()
19 scopes: Array<string>;
20 selectedItem: any;
21
22 columns: CdTableColumn[];
23 scopes_permissions: Array<any> = [];
24
25 constructor(private i18n: I18n) {}
26
27 ngOnInit() {
28 this.columns = [
29 {
30 prop: 'scope',
31 name: this.i18n('Scope'),
32 flexGrow: 2
33 },
34 {
35 prop: 'read',
36 name: this.i18n('Read'),
37 flexGrow: 1,
38 cellClass: 'text-center',
39 cellTransformation: CellTemplate.checkIcon
40 },
41 {
42 prop: 'create',
43 name: this.i18n('Create'),
44 flexGrow: 1,
45 cellClass: 'text-center',
46 cellTransformation: CellTemplate.checkIcon
47 },
48 {
49 prop: 'update',
50 name: this.i18n('Update'),
51 flexGrow: 1,
52 cellClass: 'text-center',
53 cellTransformation: CellTemplate.checkIcon
54 },
55 {
56 prop: 'delete',
57 name: this.i18n('Delete'),
58 flexGrow: 1,
59 cellClass: 'text-center',
60 cellTransformation: CellTemplate.checkIcon
61 }
62 ];
63 }
64
65 ngOnChanges() {
66 if (this.selection.hasSelection) {
67 this.selectedItem = this.selection.first();
68 // Build the scopes/permissions data used by the data table.
69 const scopes_permissions: any[] = [];
70 _.each(this.scopes, (scope) => {
71 const scope_permission: any = { read: false, create: false, update: false, delete: false };
72 scope_permission['scope'] = scope;
73 if (scope in this.selectedItem['scopes_permissions']) {
74 _.each(this.selectedItem['scopes_permissions'][scope], (permission) => {
75 scope_permission[permission] = true;
76 });
77 }
78 scopes_permissions.push(scope_permission);
79 });
80 this.scopes_permissions = scopes_permissions;
81 }
82 }
83 }