Skip to content

Commit 228f1a9

Browse files
authored
feat(rbac): nested condition (#1814)
* feat(rbac): nested condition Signed-off-by: Yi Cai <[email protected]> * Bug fix Signed-off-by: Yi Cai <[email protected]> * Updated remove button disabled condition Signed-off-by: Yi Cai <[email protected]> * Bug fix and updates to address comments Signed-off-by: Yi Cai <[email protected]> * Sonarcloud fix 1 Signed-off-by: Yi Cai <[email protected]> * Fixed tsc issues Signed-off-by: Yi Cai <[email protected]> * Fixed tsc and sonarcloud issue Signed-off-by: Yi Cai <[email protected]> * Sonarcloud issue fix Signed-off-by: Yi Cai <[email protected]> * updates Signed-off-by: Yi Cai <[email protected]> * Updated CLI link url Signed-off-by: Yi Cai <[email protected]> * Fixed sonarcloud issues Signed-off-by: Yi Cai <[email protected]> * Fixed sonarcloud issues Signed-off-by: Yi Cai <[email protected]> * Refactored code to reduce line numbers Signed-off-by: Yi Cai <[email protected]> * Code refactor Signed-off-by: Yi Cai <[email protected]> * Fix sonarcloud issue Signed-off-by: Yi Cai <[email protected]> * Removed CLI link Signed-off-by: Yi Cai <[email protected]> --------- Signed-off-by: Yi Cai <[email protected]>
1 parent ec1419e commit 228f1a9

22 files changed

+2257
-352
lines changed

plugins/rbac/src/__fixtures__/mockConditions.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,106 @@ export const mockConditions: RoleConditionalPolicyDecision<PermissionAction>[] =
5353
id: 2,
5454
...mockNewConditions[1],
5555
},
56+
{
57+
id: 3,
58+
result: AuthorizeResult.CONDITIONAL,
59+
pluginId: 'catalog',
60+
resourceType: 'catalog-entity',
61+
conditions: {
62+
anyOf: [
63+
{
64+
rule: 'IS_ENTITY_OWNER',
65+
resourceType: 'catalog-entity',
66+
params: {
67+
claims: ['user:default/ciiay'],
68+
},
69+
},
70+
{
71+
rule: 'IS_ENTITY_KIND',
72+
resourceType: 'catalog-entity',
73+
params: { kinds: ['Group'] },
74+
},
75+
{
76+
allOf: [
77+
{
78+
rule: 'IS_ENTITY_OWNER',
79+
resourceType: 'catalog-entity',
80+
params: {
81+
claims: ['user:default/ciiay'],
82+
},
83+
},
84+
{
85+
rule: 'IS_ENTITY_KIND',
86+
resourceType: 'catalog-entity',
87+
params: {
88+
kinds: ['User'],
89+
},
90+
},
91+
{
92+
not: {
93+
rule: 'HAS_LABEL',
94+
resourceType: 'catalog-entity',
95+
params: { label: 'temp' },
96+
},
97+
},
98+
{
99+
anyOf: [
100+
{
101+
rule: 'HAS_TAG',
102+
resourceType: 'catalog-entity',
103+
params: { tag: 'dev' },
104+
},
105+
{
106+
rule: 'HAS_TAG',
107+
resourceType: 'catalog-entity',
108+
params: { tag: 'test' },
109+
},
110+
],
111+
},
112+
],
113+
},
114+
],
115+
},
116+
roleEntityRef: 'role:default/rbac_admin',
117+
permissionMapping: ['read', 'delete', 'update'],
118+
},
119+
{
120+
id: 4,
121+
result: AuthorizeResult.CONDITIONAL,
122+
pluginId: 'catalog',
123+
resourceType: 'catalog-entity',
124+
conditions: {
125+
not: {
126+
rule: 'HAS_LABEL',
127+
resourceType: 'catalog-entity',
128+
params: { label: 'temp' },
129+
},
130+
},
131+
roleEntityRef: 'role:default/rbac_admin',
132+
permissionMapping: ['delete', 'update'],
133+
},
134+
{
135+
id: 5,
136+
result: AuthorizeResult.CONDITIONAL,
137+
pluginId: 'scaffolder',
138+
resourceType: 'scaffolder-template',
139+
conditions: {
140+
not: {
141+
anyOf: [
142+
{
143+
rule: 'HAS_TAG',
144+
resourceType: 'scaffolder-template',
145+
params: { tag: 'dev' },
146+
},
147+
{
148+
rule: 'HAS_TAG',
149+
resourceType: 'scaffolder-template',
150+
params: { tag: 'test' },
151+
},
152+
],
153+
},
154+
},
155+
roleEntityRef: 'role:default/rbac_admin',
156+
permissionMapping: ['read'],
157+
},
56158
];
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react';
2+
3+
import { Box } from '@material-ui/core';
4+
import Tooltip from '@material-ui/core/Tooltip';
5+
import HelpOutlineIcon from '@material-ui/icons/HelpOutline';
6+
7+
export const AddNestedConditionButton = () => {
8+
const tooltipTitle = () => (
9+
<div>
10+
<p style={{ textAlign: 'center' }}>
11+
Nested conditions are <b>1 layer rules within a main condition</b>. It
12+
lets you allow appropriate access by using detailed permissions based on
13+
various conditions. You can add multiple nested conditions.
14+
</p>
15+
<p style={{ textAlign: 'center' }}>
16+
For example, you can allow access to all entity types in the main
17+
condition and use a nested condition to limit the access to entities
18+
owned by the user.
19+
</p>
20+
</div>
21+
);
22+
return (
23+
<Box
24+
style={{
25+
display: 'flex',
26+
justifyContent: 'center',
27+
alignItems: 'center',
28+
}}
29+
>
30+
<span>Add Nested Condition</span>
31+
<Tooltip title={tooltipTitle()} placement="top">
32+
<HelpOutlineIcon fontSize="inherit" style={{ marginLeft: '0.25rem' }} />
33+
</Tooltip>
34+
</Box>
35+
);
36+
};

0 commit comments

Comments
 (0)