From: Afreen Date: Tue, 6 Feb 2024 09:43:58 +0000 (+0530) Subject: mgr/dashboard: fix error while accessing roles tab when policy attached X-Git-Tag: v19.3.0~52^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F55462%2Fhead;p=ceph.git mgr/dashboard: fix error while accessing roles tab when policy attached Fixes https://tracker.ceph.com/issues/64270 Issue: ====== Accessing Object->Users-Roles tab causing 500 internal servor error. This is due to the "PermissionPolicies" which are attached to role and backend was not handling this field for rgw roles. Fix: ==== Added "PermissionPolicies" as the valid field in backend and updated frontend to render the attached policy in formatted JSON Signed-off-by: Afreen --- diff --git a/src/pybind/mgr/dashboard/controllers/rgw.py b/src/pybind/mgr/dashboard/controllers/rgw.py index e7e0da181a6f..92148aaf3ac7 100644 --- a/src/pybind/mgr/dashboard/controllers/rgw.py +++ b/src/pybind/mgr/dashboard/controllers/rgw.py @@ -850,9 +850,10 @@ edit_role_form = Form(path='/edit', "CreateDate": {'cellTemplate': 'date'}, "MaxSessionDuration": {'cellTemplate': 'duration'}, "RoleId": {'isHidden': True}, - "AssumeRolePolicyDocument": {'isHidden': True} + "AssumeRolePolicyDocument": {'isHidden': True}, + "PermissionPolicies": {'isHidden': True} }, - detail_columns=['RoleId', 'AssumeRolePolicyDocument'], + detail_columns=['RoleId', 'AssumeRolePolicyDocument', 'PermissionPolicies'], meta=CRUDMeta() ) class RgwUserRole(NamedTuple): @@ -863,6 +864,7 @@ class RgwUserRole(NamedTuple): CreateDate: str MaxSessionDuration: int AssumeRolePolicyDocument: str + PermissionPolicies: List @APIRouter('/rgw/realm', Scope.RGW) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/crud-table/crud-table.component.html b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/crud-table/crud-table.component.html index 7e1a7f2b3418..a1edf253c012 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/crud-table/crud-table.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/crud-table/crud-table.component.html @@ -36,7 +36,7 @@ {{ column }} - {{ expandedRow[column] }} +
{{ expandedRow[column] }}
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/crud-table/crud-table.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/crud-table/crud-table.component.ts index 6881e373b588..098a454b1d7b 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/crud-table/crud-table.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/crud-table/crud-table.component.ts @@ -39,7 +39,7 @@ export class CRUDTableComponent implements OnInit { permissions: Permissions; permission: Permission; selection = new CdTableSelection(); - expandedRow: any = null; + expandedRow: { [key: string]: any } = {}; modalRef: NgbModalRef; tabs = {}; resource: string; @@ -145,7 +145,11 @@ export class CRUDTableComponent implements OnInit { } setExpandedRow(event: any) { - this.expandedRow = event; + for (let i = 0; i < this.meta.detail_columns.length; i++) { + let column = this.meta.detail_columns[i]; + let columnDetail = event[column]; + this.expandedRow[column] = this.formatColumnDetails(columnDetail); + } } edit() { @@ -176,4 +180,30 @@ export class CRUDTableComponent implements OnInit { this.modalRef = this.modalService.show(ConfirmationModalComponent, modalVariables); }); } + + /** + * Custom string replacer function for JSON.stringify + * + * This is specifically for objects inside an array. + * The custom replacer recursively stringifies deep nested objects + **/ + stringReplacer(_key: string, value: any) { + try { + const parsedValue = JSON.parse(value); + return parsedValue; + } catch (e) { + return value; + } + } + + /** + * returns a json string for arrays and string + * returns the same value for the rest + **/ + formatColumnDetails(details: any) { + if (Array.isArray(details) || typeof details === 'string') { + return JSON.stringify(details, this.stringReplacer, 2); + } + return details; + } } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/models/crud-table-metadata.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/models/crud-table-metadata.ts index dc33e6236ae2..fb6970d1ccbb 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/models/crud-table-metadata.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/models/crud-table-metadata.ts @@ -15,4 +15,5 @@ export class CrudMetadata { forms: any; columnKey: string; resource: string; + detail_columns: string[]; }