Skip to content

Commit ff6d095

Browse files
authored
Merge pull request ceph#55462 from afreen23/fix-64270
mgr/dashboard: fix error while accessing roles tab when policy attached Reviewed-by: Nizamudeen A <[email protected]>
2 parents c656228 + 5247d7d commit ff6d095

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

src/pybind/mgr/dashboard/controllers/rgw.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,9 +850,10 @@ def model(role_name: str):
850850
"CreateDate": {'cellTemplate': 'date'},
851851
"MaxSessionDuration": {'cellTemplate': 'duration'},
852852
"RoleId": {'isHidden': True},
853-
"AssumeRolePolicyDocument": {'isHidden': True}
853+
"AssumeRolePolicyDocument": {'isHidden': True},
854+
"PermissionPolicies": {'isHidden': True}
854855
},
855-
detail_columns=['RoleId', 'AssumeRolePolicyDocument'],
856+
detail_columns=['RoleId', 'AssumeRolePolicyDocument', 'PermissionPolicies'],
856857
meta=CRUDMeta()
857858
)
858859
class RgwUserRole(NamedTuple):
@@ -863,6 +864,7 @@ class RgwUserRole(NamedTuple):
863864
CreateDate: str
864865
MaxSessionDuration: int
865866
AssumeRolePolicyDocument: str
867+
PermissionPolicies: List
866868

867869

868870
@APIRouter('/rgw/realm', Scope.RGW)

src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/crud-table/crud-table.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<tr *ngFor="let column of meta.detail_columns">
3737
<td i18n
3838
class="bold">{{ column }}</td>
39-
<td> {{ expandedRow[column] }} </td>
39+
<td><pre>{{ expandedRow[column] }}</pre></td>
4040
</tr>
4141
</tbody>
4242
</table>

src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/crud-table/crud-table.component.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class CRUDTableComponent implements OnInit {
3939
permissions: Permissions;
4040
permission: Permission;
4141
selection = new CdTableSelection();
42-
expandedRow: any = null;
42+
expandedRow: { [key: string]: any } = {};
4343
modalRef: NgbModalRef;
4444
tabs = {};
4545
resource: string;
@@ -145,7 +145,11 @@ export class CRUDTableComponent implements OnInit {
145145
}
146146

147147
setExpandedRow(event: any) {
148-
this.expandedRow = event;
148+
for (let i = 0; i < this.meta.detail_columns.length; i++) {
149+
let column = this.meta.detail_columns[i];
150+
let columnDetail = event[column];
151+
this.expandedRow[column] = this.formatColumnDetails(columnDetail);
152+
}
149153
}
150154

151155
edit() {
@@ -176,4 +180,30 @@ export class CRUDTableComponent implements OnInit {
176180
this.modalRef = this.modalService.show(ConfirmationModalComponent, modalVariables);
177181
});
178182
}
183+
184+
/**
185+
* Custom string replacer function for JSON.stringify
186+
*
187+
* This is specifically for objects inside an array.
188+
* The custom replacer recursively stringifies deep nested objects
189+
**/
190+
stringReplacer(_key: string, value: any) {
191+
try {
192+
const parsedValue = JSON.parse(value);
193+
return parsedValue;
194+
} catch (e) {
195+
return value;
196+
}
197+
}
198+
199+
/**
200+
* returns a json string for arrays and string
201+
* returns the same value for the rest
202+
**/
203+
formatColumnDetails(details: any) {
204+
if (Array.isArray(details) || typeof details === 'string') {
205+
return JSON.stringify(details, this.stringReplacer, 2);
206+
}
207+
return details;
208+
}
179209
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ export class CrudMetadata {
1515
forms: any;
1616
columnKey: string;
1717
resource: string;
18+
detail_columns: string[];
1819
}

0 commit comments

Comments
 (0)