11# RbacApiHelper API
22
3- Manages RBAC roles and policies via the RHDH Permission API.
3+ Manages RBAC roles, policies, and conditional permission policies via the RHDH Permission API.
44
55## Import
66
@@ -53,6 +53,30 @@ async getPoliciesByRole(role: string): Promise<APIResponse>
5353| --------- | -------- | ------------------------------------ |
5454| ` role ` | ` string ` | Role name in the ` default ` namespace |
5555
56+ #### ` getConditions() `
57+
58+ ``` typescript
59+ async getConditions (): Promise < APIResponse >
60+ ```
61+
62+ Fetches all conditional policies across every role.
63+
64+ #### ` getConditionsByRole() `
65+
66+ ``` typescript
67+ async getConditionsByRole (
68+ role : string ,
69+ remainingConditions : RoleConditionalPolicyDecision < PermissionAction > []
70+ ): Promise < RoleConditionalPolicyDecision < PermissionAction > []>
71+ ```
72+
73+ | Parameter | Type | Description |
74+ | --------------------- | --------------------------------------------------- | --------------------------------------------------------- |
75+ | ` role ` | ` string ` | Full role entity reference, e.g. ` "role:default/my-role" ` |
76+ | ` remainingConditions ` | ` RoleConditionalPolicyDecision<PermissionAction>[] ` | Conditions array fetched from ` getConditions() ` |
77+
78+ Filters locally — no additional HTTP request is made.
79+
5680#### ` deleteRole() `
5781
5882``` typescript
@@ -74,6 +98,16 @@ async deletePolicy(role: string, policies: Policy[]): Promise<APIResponse>
7498| ` role ` | ` string ` | Role name in the ` default ` namespace |
7599| ` policies ` | ` Policy[] ` | Array of policy objects to delete |
76100
101+ #### ` deleteCondition() `
102+
103+ ``` typescript
104+ async deleteCondition (id : string ): Promise < APIResponse >
105+ ```
106+
107+ | Parameter | Type | Description |
108+ | --------- | -------- | ------------------------------------------------------------ |
109+ | ` id ` | ` string ` | The ` id ` field from a ` RoleConditionalPolicyDecision ` object |
110+
77111## ` Response `
78112
79113### Static Methods
@@ -104,13 +138,22 @@ const authApiHelper = new AuthApiHelper(page);
104138const token = await authApiHelper .getToken ();
105139const rbacApiHelper = await RbacApiHelper .build (token );
106140
107- // Get policies for a role
141+ // Delete conditional policies for a role
142+ const conditionsResponse = await rbacApiHelper .getConditions ();
143+ const allConditions = await conditionsResponse .json ();
144+ const roleConditions = await rbacApiHelper .getConditionsByRole (
145+ ' role:default/my-role' ,
146+ allConditions ,
147+ );
148+ for (const condition of roleConditions ) {
149+ await rbacApiHelper .deleteCondition (condition .id );
150+ }
151+
152+ // Delete standard policies and role
108153const apiResponse = await rbacApiHelper .getPoliciesByRole (' my-role' );
109154const policies = (await Response .removeMetadataFromResponse (
110155 apiResponse ,
111156)) as Policy [];
112-
113- // Delete policies and role
114157await rbacApiHelper .deletePolicy (' my-role' , policies );
115158await rbacApiHelper .deleteRole (' my-role' );
116159```
0 commit comments