7067f6ef88
## Summary - Agent tools were built with the agent’s `rolePermissionConfig`, but record CRUD ignored it and re-resolved permissions from `authContext` (app `defaultRoleId`) - CRUD services now pass `rolePermissionConfig` through `CommonApiContextBuilder` and the common query runner, so repository access matches the agent role - Workflow/chat paths already use the same role for auth and `rolePermissionConfig`, so their behavior should be unchanged <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/twentyhq/twenty/pull/23248?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
34 lines
958 B
TypeScript
34 lines
958 B
TypeScript
import {
|
|
type ObjectsPermissions,
|
|
type ObjectsPermissionsByRoleId,
|
|
} from 'twenty-shared/types';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
|
|
import { type RolePermissionConfig } from 'src/engine/twenty-orm/types/role-permission-config';
|
|
|
|
// Multi-role union/intersection is not ready — use the first assigned role only.
|
|
export const getObjectsPermissionsFromRolePermissionConfig = ({
|
|
rolesPermissions,
|
|
rolePermissionConfig,
|
|
}: {
|
|
rolesPermissions: ObjectsPermissionsByRoleId;
|
|
rolePermissionConfig: RolePermissionConfig;
|
|
}): ObjectsPermissions => {
|
|
if ('shouldBypassPermissionChecks' in rolePermissionConfig) {
|
|
return {};
|
|
}
|
|
|
|
const roleId =
|
|
'intersectionOf' in rolePermissionConfig
|
|
? rolePermissionConfig.intersectionOf[0]
|
|
: 'unionOf' in rolePermissionConfig
|
|
? rolePermissionConfig.unionOf[0]
|
|
: undefined;
|
|
|
|
if (!isDefined(roleId)) {
|
|
return {};
|
|
}
|
|
|
|
return rolesPermissions[roleId] ?? {};
|
|
};
|