]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: fix error while accessing roles tab when policy attached 55515/head
authorAfreen <afreen23.git@gmail.com>
Tue, 6 Feb 2024 09:43:58 +0000 (15:13 +0530)
committerAfreen <afreen23.git@gmail.com>
Fri, 9 Feb 2024 12:38:04 +0000 (18:08 +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>
(cherry picked from commit 5247d7d19455a5ab7d1bb56b9586c6b08843b15d)

 Conflicts:
src/pybind/mgr/dashboard/frontend/src/app/shared/models/crud-table-metadata.ts

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 9bc1b489edee03c9c3d0d2d619343af21394512d..fc4c2f48eb1cad88f4b876c4d98f9321e5f8792f 100644 (file)
@@ -762,9 +762,10 @@ create_role_form = Form(path='/rgw/roles/create',
         "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):
@@ -775,6 +776,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 750152161c246e0a4d88b6c8d824d83bdaa14fa2..fa3a9d76a0b156cf424a6b9bc3709af05d240d0b 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() {
@@ -174,4 +178,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 140fa5b5f8ea40fca2d05e371b38fd570c665a9c..5ff77031c4e0858cb643a2f011963b6e496c4197 100644 (file)
@@ -14,4 +14,5 @@ export class CrudMetadata {
   actions: CdTableAction[];
   forms: any;
   columnKey: string;
+  detail_columns: string[];
 }