]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: fix error while accessing roles tab when policy attached 55462/head
authorAfreen <afreen23.git@gmail.com>
Tue, 6 Feb 2024 09:43:58 +0000 (15:13 +0530)
committerAfreen <afreen23.git@gmail.com>
Thu, 8 Feb 2024 09:22:37 +0000 (14:52 +0530)
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 <afreen23.git@gmail.com>
src/pybind/mgr/dashboard/controllers/rgw.py
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/crud-table/crud-table.component.html
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/crud-table/crud-table.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/models/crud-table-metadata.ts

index e7e0da181a6fa58c77d9a04eebaf756aad75cd99..92148aaf3ac789aa2addd3ae6af08e2c35b4ac6c 100644 (file)
@@ -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)
index 7e1a7f2b341862dc90dc90db80daabefb042a6a2..a1edf253c01251427854d0d72d75e6ed06b98eed 100644 (file)
@@ -36,7 +36,7 @@
           <tr *ngFor="let column of meta.detail_columns">
             <td i18n
                 class="bold">{{ column }}</td>
-            <td> {{ expandedRow[column] }} </td>
+            <td><pre>{{ expandedRow[column] }}</pre></td>
           </tr>
         </tbody>
       </table>
index 6881e373b588a4ad1ac24f8a77a8df81e79da15a..098a454b1d7b5dd8e7e23bae0e194e4c82a0481f 100644 (file)
@@ -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;
+  }
 }
index dc33e6236ae2705c0c602e77deeb942a47bd8dd6..fb6970d1ccbb2498767bbce640995054a57ec28c 100644 (file)
@@ -15,4 +15,5 @@ export class CrudMetadata {
   forms: any;
   columnKey: string;
   resource: string;
+  detail_columns: string[];
 }