Some checks failed
App Prod-Parity E2E Dispatch / dispatch (push) Failing after 10s
CD Storybook UI / build (push) Failing after 3m25s
CD Storybook UI / dispatch (push) Has been skipped
CD deploy main / website-changed-files (push) Successful in 18m8s
CI Agent Skills / changed-files-check (push) Successful in 18m9s
CI Create App E2E minimal / changed-files-check (push) Successful in 24s
CI Create App / changed-files-check (push) Successful in 26s
CI Docs / changed-files-check (push) Successful in 26s
CI Emails / changed-files-check (push) Successful in 28s
CI Example App Hello World / changed-files-check (push) Successful in 23s
CI Front / changed-files-check (push) Has been skipped
CI Example App Postcard / changed-files-check (push) Successful in 27s
CI UI / changed-files-check (push) Has been skipped
CI Utils Test / changed-files-check (push) Successful in 45s
CI Twenty Apps / discover (push) Successful in 1m3s
CD deploy main / deploy-main (push) Failing after 3s
CI Agent Skills / agent-skills-validate (push) Has been skipped
CI Create App / create-app-test (lint) (push) Has been skipped
CI Emails / emails-test (push) Has been skipped
CI Front / front-task (lingui:compile) (push) Has been skipped
CI Front / front-task (lint) (push) Has been skipped
CI Example App Postcard / example-app-postcard (push) Has been skipped
CI UI / ui-task (lint) (push) Has been skipped
CI UI / ui-task (pack-size) (push) Has been skipped
CI UI / ui-task (size) (push) Has been skipped
CI UI / ui-task (test) (push) Has been skipped
CI UI / ui-task (typecheck) (push) Has been skipped
CI Utils Test / utils-test (push) Has been skipped
CI Twenty Apps / ${{ matrix.app.name }} (push) Has been skipped
CI Emails / ci-emails-status-check (push) Successful in 2s
CI Example App Hello World / ci-example-app-hello-world-status-check (push) Successful in 2s
CI Example App Postcard / ci-example-app-postcard-status-check (push) Successful in 3s
CI UI / ui-sb-test (push) Has been skipped
CI Utils Test / ci-utils-test-status-check (push) Successful in 2s
CI Twenty Apps / ci-twenty-apps-status-check (push) Successful in 2s
CI UI / ci-ui-status-check (push) Successful in 2s
CI Desktop / desktop (push) Failing after 1m8s
Push docs to Crowdin / Push documentation to Crowdin (push) Failing after 55s
Push translations to Crowdin / Extract and upload translations (push) Failing after 5s
Push website translations to Crowdin / Extract and upload website translations (push) Failing after 5s
CI Create App / create-app-test (test) (push) Has been skipped
CI Create App / create-app-test (typecheck) (push) Has been skipped
CI Docs / docs-lint (push) Has been skipped
CI Example App Hello World / example-app-hello-world (push) Has been skipped
CI Front / front-task (lingui:extract) (push) Has been skipped
CI Front / front-task (test) (push) Has been skipped
CI Front / front-task (typecheck) (push) Has been skipped
CI UI / ui-sb-build (push) Failing after 1m32s
CI Twenty Apps / ${{ matrix.app.name }} (${{ matrix.server-source }}) (push) Has been skipped
CI Agent Skills / agent-skills-publish (push) Has been skipped
CI Create App / ci-create-app-status-check (push) Successful in 2s
CI Agent Skills / agent-skills-remote-source (push) Has been skipped
CI Create App E2E minimal / create-app-e2e-minimal (push) Has been cancelled
CI E2E Main / e2e-test (push) Has been cancelled
CI Front / front-sb-build (push) Has been cancelled
CI Front / front-build (push) Has been cancelled
CI Create App E2E minimal / ci-create-app-e2e-minimal-status-check (push) Has been cancelled
CI E2E Main / ci-e2e-main-status-check (push) Has been cancelled
CI E2E Main / notify-main-ci-failure (push) Has been cancelled
CI E2E Main / qa-scout-comment (push) Has been cancelled
CI Front / front-sb-test (push) Has been cancelled
CI Front / front-sb-screenshots (push) Has been cancelled
CI Front / ci-front-status-check (push) Has been cancelled
DPA Sub-Processor Sync / sync-subprocessors (push) Failing after 3s
AI Catalog Sync / sync-catalog (push) Failing after 3s
227 lines
7.4 KiB
TypeScript
227 lines
7.4 KiB
TypeScript
import { buildBaseManifest } from 'test/integration/metadata/suites/application/utils/build-base-manifest.util';
|
|
import { cleanupApplicationAndAppRegistration } from 'test/integration/metadata/suites/application/utils/cleanup-application-and-app-registration.util';
|
|
import { setupApplicationForSync } from 'test/integration/metadata/suites/application/utils/setup-application-for-sync.util';
|
|
import { syncApplication } from 'test/integration/metadata/suites/application/utils/sync-application.util';
|
|
import { uninstallApplication } from 'test/integration/metadata/suites/application/utils/uninstall-application.util';
|
|
import { type FieldManifest, type Manifest } from 'twenty-shared/application';
|
|
import { STANDARD_OBJECTS } from 'twenty-shared/metadata';
|
|
import {
|
|
FieldMetadataType,
|
|
RowLevelPermissionPredicateOperand,
|
|
} from 'twenty-shared/types';
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
|
|
import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';
|
|
|
|
const TEST_WORKSPACE_ID = SEED_APPLE_WORKSPACE_ID;
|
|
|
|
const TEST_APP_ID = uuidv4();
|
|
const TEST_ROLE_ID = uuidv4();
|
|
const TEST_OBJECT_PERMISSION_ID = uuidv4();
|
|
const TEST_FIELD_ID = uuidv4();
|
|
const TEST_PREDICATE_ID = uuidv4();
|
|
|
|
const PERSON_OBJECT_UNIVERSAL_IDENTIFIER =
|
|
STANDARD_OBJECTS.person.universalIdentifier;
|
|
const WORKSPACE_MEMBER_ID_FIELD_UNIVERSAL_IDENTIFIER =
|
|
STANDARD_OBJECTS.workspaceMember.fields.id.universalIdentifier;
|
|
|
|
const personScopingFieldManifest: FieldManifest = {
|
|
universalIdentifier: TEST_FIELD_ID,
|
|
type: FieldMetadataType.TEXT,
|
|
name: 'integrationRlsScopingColumn',
|
|
label: 'Integration RLS Scoping Column',
|
|
description: 'Custom field a row-level predicate scopes on',
|
|
icon: 'IconLock',
|
|
objectUniversalIdentifier: PERSON_OBJECT_UNIVERSAL_IDENTIFIER,
|
|
};
|
|
|
|
const buildManifestWithPredicates = (
|
|
predicates: NonNullable<
|
|
Manifest['roles'][number]['rowLevelPermissionPredicates']
|
|
>,
|
|
): Manifest =>
|
|
buildBaseManifest({
|
|
appId: TEST_APP_ID,
|
|
roleId: TEST_ROLE_ID,
|
|
overrides: {
|
|
fields: [personScopingFieldManifest],
|
|
roles: [
|
|
{
|
|
universalIdentifier: TEST_ROLE_ID,
|
|
label: 'RLS Test Role',
|
|
description: 'Role exercising declarative row-level predicates',
|
|
objectPermissions: [
|
|
{
|
|
universalIdentifier: TEST_OBJECT_PERMISSION_ID,
|
|
objectUniversalIdentifier: PERSON_OBJECT_UNIVERSAL_IDENTIFIER,
|
|
canReadObjectRecords: true,
|
|
},
|
|
],
|
|
rowLevelPermissionPredicates: predicates,
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
const partnerUserStylePredicate = (
|
|
operand: RowLevelPermissionPredicateOperand,
|
|
) => ({
|
|
universalIdentifier: TEST_PREDICATE_ID,
|
|
objectUniversalIdentifier: PERSON_OBJECT_UNIVERSAL_IDENTIFIER,
|
|
fieldUniversalIdentifier: TEST_FIELD_ID,
|
|
operand,
|
|
workspaceMemberFieldUniversalIdentifier:
|
|
WORKSPACE_MEMBER_ID_FIELD_UNIVERSAL_IDENTIFIER,
|
|
});
|
|
|
|
type PredicateRow = {
|
|
id: string;
|
|
operand: string;
|
|
roleId: string;
|
|
objectMetadataId: string;
|
|
fieldMetadataId: string;
|
|
workspaceMemberFieldMetadataId: string | null;
|
|
applicationId: string;
|
|
};
|
|
|
|
const findActivePredicateRows = async (): Promise<PredicateRow[]> =>
|
|
globalThis.testDataSource.query(
|
|
`SELECT id, operand, "roleId", "objectMetadataId", "fieldMetadataId",
|
|
"workspaceMemberFieldMetadataId", "applicationId"
|
|
FROM core."rowLevelPermissionPredicate"
|
|
WHERE "universalIdentifier" = $1 AND "workspaceId" = $2 AND "deletedAt" IS NULL`,
|
|
[TEST_PREDICATE_ID, TEST_WORKSPACE_ID],
|
|
);
|
|
|
|
const findApplicationId = async (): Promise<string> => {
|
|
const rows = await globalThis.testDataSource.query(
|
|
`SELECT id FROM core."application"
|
|
WHERE "universalIdentifier" = $1 AND "workspaceId" = $2`,
|
|
[TEST_APP_ID, TEST_WORKSPACE_ID],
|
|
);
|
|
|
|
return rows[0]?.id;
|
|
};
|
|
|
|
const findRoleId = async (): Promise<string> => {
|
|
const rows = await globalThis.testDataSource.query(
|
|
`SELECT id FROM core."role"
|
|
WHERE "universalIdentifier" = $1 AND "workspaceId" = $2`,
|
|
[TEST_ROLE_ID, TEST_WORKSPACE_ID],
|
|
);
|
|
|
|
return rows[0]?.id;
|
|
};
|
|
|
|
const findPersonObjectId = async (): Promise<string> => {
|
|
const rows = await globalThis.testDataSource.query(
|
|
`SELECT id FROM core."objectMetadata"
|
|
WHERE "universalIdentifier" = $1 AND "workspaceId" = $2`,
|
|
[PERSON_OBJECT_UNIVERSAL_IDENTIFIER, TEST_WORKSPACE_ID],
|
|
);
|
|
|
|
return rows[0]?.id;
|
|
};
|
|
|
|
describe('Manifest sync - row level permission predicates declared on a role', () => {
|
|
beforeEach(async () => {
|
|
await setupApplicationForSync({
|
|
applicationUniversalIdentifier: TEST_APP_ID,
|
|
name: 'Test RLS Predicate Application',
|
|
description: 'App for testing declarative row-level predicate sync',
|
|
sourcePath: 'test-manifest-rls-predicate',
|
|
});
|
|
}, 60000);
|
|
|
|
afterEach(async () => {
|
|
await cleanupApplicationAndAppRegistration({
|
|
applicationUniversalIdentifier: TEST_APP_ID,
|
|
});
|
|
});
|
|
|
|
it('creates a row-level predicate owned by the app and pointing at the declared role/object/field', async () => {
|
|
const { errors } = await syncApplication({
|
|
manifest: buildManifestWithPredicates([
|
|
partnerUserStylePredicate(RowLevelPermissionPredicateOperand.IS),
|
|
]),
|
|
expectToFail: false,
|
|
});
|
|
|
|
expect(errors).toBeUndefined();
|
|
|
|
const [applicationId, roleId, personObjectId, predicateRows] =
|
|
await Promise.all([
|
|
findApplicationId(),
|
|
findRoleId(),
|
|
findPersonObjectId(),
|
|
findActivePredicateRows(),
|
|
]);
|
|
|
|
expect(predicateRows).toHaveLength(1);
|
|
|
|
const predicate = predicateRows[0];
|
|
|
|
expect(predicate.operand).toBe(RowLevelPermissionPredicateOperand.IS);
|
|
expect(predicate.roleId).toBe(roleId);
|
|
expect(predicate.objectMetadataId).toBe(personObjectId);
|
|
expect(predicate.fieldMetadataId).toBeTruthy();
|
|
expect(predicate.workspaceMemberFieldMetadataId).toBeTruthy();
|
|
expect(predicate.applicationId).toBe(applicationId);
|
|
}, 60000);
|
|
|
|
it('updates the predicate in place on re-sync and removes it when dropped from the manifest', async () => {
|
|
await syncApplication({
|
|
manifest: buildManifestWithPredicates([
|
|
partnerUserStylePredicate(RowLevelPermissionPredicateOperand.IS),
|
|
]),
|
|
expectToFail: false,
|
|
});
|
|
|
|
const createdRows = await findActivePredicateRows();
|
|
|
|
expect(createdRows).toHaveLength(1);
|
|
const predicateId = createdRows[0].id;
|
|
|
|
await syncApplication({
|
|
manifest: buildManifestWithPredicates([
|
|
partnerUserStylePredicate(RowLevelPermissionPredicateOperand.IS_NOT),
|
|
]),
|
|
expectToFail: false,
|
|
});
|
|
|
|
const updatedRows = await findActivePredicateRows();
|
|
|
|
expect(updatedRows).toHaveLength(1);
|
|
expect(updatedRows[0].id).toBe(predicateId);
|
|
expect(updatedRows[0].operand).toBe(
|
|
RowLevelPermissionPredicateOperand.IS_NOT,
|
|
);
|
|
|
|
await syncApplication({
|
|
manifest: buildManifestWithPredicates([]),
|
|
expectToFail: false,
|
|
});
|
|
|
|
expect(await findActivePredicateRows()).toHaveLength(0);
|
|
}, 60000);
|
|
|
|
it('removes the predicate on uninstall', async () => {
|
|
await syncApplication({
|
|
manifest: buildManifestWithPredicates([
|
|
partnerUserStylePredicate(RowLevelPermissionPredicateOperand.IS),
|
|
]),
|
|
expectToFail: false,
|
|
});
|
|
|
|
expect(await findActivePredicateRows()).toHaveLength(1);
|
|
|
|
await uninstallApplication({
|
|
universalIdentifier: TEST_APP_ID,
|
|
expectToFail: false,
|
|
});
|
|
|
|
expect(await findActivePredicateRows()).toHaveLength(0);
|
|
}, 60000);
|
|
});
|