Skip to content

Commit 451b572

Browse files
guguclaude
andcommitted
Rename table full access label and use action like for table:*
- Rename "Full access" to "Full table access" for table:* action - Generate single permit with action like RocketAdmin::Action::"table:*" - Fix duplicate action == in permit template - Parser handles table:* action and action like operator Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 66f35c2 commit 451b572

3 files changed

Lines changed: 16 additions & 18 deletions

File tree

frontend/src/app/components/users/cedar-policy-list/cedar-policy-list.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe('CedarPolicyListComponent', () => {
119119
expect(component.getActionLabel('*')).toBe('Full access (all permissions)');
120120
expect(component.getActionLabel('connection:read')).toBe('Read');
121121
expect(component.getActionLabel('table:edit')).toBe('Edit');
122-
expect(component.getActionLabel('table:*')).toBe('Full access');
122+
expect(component.getActionLabel('table:*')).toBe('Full table access');
123123
});
124124

125125
it('should return correct table display names', () => {

frontend/src/app/lib/cedar-policy-items.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const POLICY_ACTION_GROUPS: PolicyActionGroup[] = [
3838
{
3939
group: 'Table',
4040
actions: [
41-
{ value: 'table:*', label: 'Full access', needsTable: true },
41+
{ value: 'table:*', label: 'Full table access', needsTable: true },
4242
{ value: 'table:read', label: 'Read', needsTable: true },
4343
{ value: 'table:add', label: 'Add', needsTable: true },
4444
{ value: 'table:edit', label: 'Edit', needsTable: true },
@@ -120,20 +120,10 @@ export function policyItemsToCedarPolicy(items: CedarPolicyItem[], connectionId:
120120
return policies.join('\n\n');
121121
}
122122

123-
// table:* expands to 4 individual table action permits
124-
if (item.action === 'table:*') {
125-
const tableResource =
126-
item.tableName === '*'
127-
? `resource like RocketAdmin::Table::"${connectionId}/*"`
128-
: `resource == RocketAdmin::Table::"${connectionId}/${item.tableName}"`;
129-
for (const subAction of ['table:read', 'table:add', 'table:edit', 'table:delete']) {
130-
const ref = `RocketAdmin::Action::"${subAction}"`;
131-
policies.push(`permit(\n principal,\n action == ${ref},\n ${tableResource}\n);`);
132-
}
133-
continue;
134-
}
135-
136-
const actionRef = `RocketAdmin::Action::"${item.action}"`;
123+
const actionRef =
124+
item.action === 'table:*'
125+
? `action like RocketAdmin::Action::"table:*"`
126+
: `action == RocketAdmin::Action::"${item.action}"`;
137127
let resource: string;
138128

139129
if (item.action.startsWith('table:')) {
@@ -148,7 +138,7 @@ export function policyItemsToCedarPolicy(items: CedarPolicyItem[], connectionId:
148138
resource = `resource == RocketAdmin::Connection::"${connectionId}"`;
149139
}
150140

151-
policies.push(`permit(\n principal,\n action == ${actionRef},\n ${resource}\n);`);
141+
policies.push(`permit(\n principal,\n ${actionRef},\n ${resource}\n);`);
152142
}
153143

154144
return policies.join('\n\n');

frontend/src/app/lib/cedar-policy-parser.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export function parseCedarPolicy(
5151
case 'group:edit':
5252
result.group.accessLevel = AccessLevel.Edit;
5353
break;
54+
case 'table:*':
5455
case 'table:read':
5556
case 'table:add':
5657
case 'table:edit':
@@ -176,7 +177,7 @@ function parsePermitBody(body: string): ParsedPermitStatement {
176177
isWildcard: false,
177178
};
178179

179-
const actionMatch = body.match(/action\s*==\s*RocketAdmin::Action::"([^"]+)"/);
180+
const actionMatch = body.match(/action\s*(?:==|like)\s*RocketAdmin::Action::"([^"]+)"/);
180181
if (actionMatch) {
181182
result.action = actionMatch[1];
182183
} else {
@@ -230,6 +231,13 @@ function getOrCreateTableEntry(map: Map<string, TablePermission>, tableName: str
230231

231232
function applyTableAction(entry: TablePermission, action: string): void {
232233
switch (action) {
234+
case 'table:*':
235+
entry.accessLevel.visibility = true;
236+
entry.accessLevel.readonly = true;
237+
entry.accessLevel.add = true;
238+
entry.accessLevel.edit = true;
239+
entry.accessLevel.delete = true;
240+
break;
233241
case 'table:read':
234242
entry.accessLevel.visibility = true;
235243
entry.accessLevel.readonly = true;

0 commit comments

Comments
 (0)