From 5247d7d19455a5ab7d1bb56b9586c6b08843b15d Mon Sep 17 00:00:00 2001 From: Afreen Date: Tue, 6 Feb 2024 15:13:58 +0530 Subject: [PATCH] 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 --- src/pybind/mgr/dashboard/controllers/rgw.py | 6 ++-- .../crud-table/crud-table.component.html | 2 +- .../crud-table/crud-table.component.ts | 34 +++++++++++++++++-- .../app/shared/models/crud-table-metadata.ts | 1 + 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/pybind/mgr/dashboard/controllers/rgw.py b/src/pybind/mgr/dashboard/controllers/rgw.py index e7e0da181a6fa..92148aaf3ac78 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 7e1a7f2b34186..a1edf253c0125 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 6881e373b588a..098a454b1d7b5 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 dc33e6236ae27..fb6970d1ccbb2 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[]; } -- 2.39.5