Skip to content

Commit 633838b

Browse files
committed
Enhance dashboard resource handling and improve cedar schema validation error reporting
1 parent a916066 commit 633838b

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

backend/src/entities/cedar-authorization/cedar-authorization.service.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,14 @@ export class CedarAuthorizationService implements ICedarAuthorizationService, On
6464
resourceId = `${connectionId}/${tableName}`;
6565
break;
6666
case 'dashboard':
67-
resourceType = CedarResourceType.Dashboard;
68-
resourceId = `${connectionId}/${dashboardId}`;
67+
if (action === CedarAction.DashboardCreate) {
68+
resourceType = CedarResourceType.Connection;
69+
resourceId = connectionId;
70+
} else {
71+
if (!dashboardId) return false;
72+
resourceType = CedarResourceType.Dashboard;
73+
resourceId = `${connectionId}/${dashboardId}`;
74+
}
6975
break;
7076
default:
7177
return false;
@@ -155,8 +161,16 @@ export class CedarAuthorizationService implements ICedarAuthorizationService, On
155161
entities: [],
156162
schema: schema,
157163
};
158-
cedarWasm.isAuthorized(testCall as Parameters<typeof cedarWasm.isAuthorized>[0]);
164+
const result = cedarWasm.isAuthorized(testCall as Parameters<typeof cedarWasm.isAuthorized>[0]);
165+
if (result.type !== 'success') {
166+
const errors = (result as unknown as { type: string; errors: string[] }).errors ?? [];
167+
throw new HttpException(
168+
{ message: `Invalid cedar schema: ${errors.join('; ') || 'unknown validation error'}` },
169+
HttpStatus.BAD_REQUEST,
170+
);
171+
}
159172
} catch (e) {
173+
if (e instanceof HttpException) throw e;
160174
throw new HttpException({ message: `Invalid cedar schema: ${e.message}` }, HttpStatus.BAD_REQUEST);
161175
}
162176
}

0 commit comments

Comments
 (0)