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 2s
518 lines
14 KiB
TypeScript
518 lines
14 KiB
TypeScript
import gql from 'graphql-tag';
|
|
import { TEST_COMPANY_1_ID } from 'test/integration/constants/test-company-ids.constants';
|
|
import { TEST_PERSON_1_ID } from 'test/integration/constants/test-person-ids.constants';
|
|
import { TEST_PRIMARY_LINK_URL } from 'test/integration/constants/test-primary-link-url.constant';
|
|
import { upsertFieldPermissions } from 'test/integration/graphql/utils/upsert-field-permissions.util';
|
|
import { upsertRowLevelPermissionPredicates } from 'test/integration/metadata/suites/row-level-permission-predicate/utils/upsert-row-level-permission-predicates.util';
|
|
import { makeMetadataAPIRequest } from 'test/integration/metadata/suites/utils/make-metadata-api-request.util';
|
|
import { makeRestAPIRequest } from 'test/integration/rest/utils/make-rest-api-request.util';
|
|
import { generateRecordName } from 'test/integration/utils/generate-record-name';
|
|
import { RowLevelPermissionPredicateOperand } from 'twenty-shared/types';
|
|
|
|
describe('Restricted fields', () => {
|
|
let personJobTitle: string;
|
|
let memberRoleId: string;
|
|
let personObjectId: string;
|
|
let emailsFieldId: string;
|
|
let phonesFieldId: string;
|
|
|
|
beforeAll(async () => {
|
|
personJobTitle = generateRecordName(TEST_PERSON_1_ID);
|
|
|
|
await makeRestAPIRequest({
|
|
method: 'post',
|
|
path: '/companies',
|
|
body: {
|
|
id: TEST_COMPANY_1_ID,
|
|
domainName: {
|
|
primaryLinkUrl: TEST_PRIMARY_LINK_URL,
|
|
},
|
|
},
|
|
});
|
|
|
|
await makeRestAPIRequest({
|
|
method: 'post',
|
|
path: '/people',
|
|
body: {
|
|
id: TEST_PERSON_1_ID,
|
|
jobTitle: personJobTitle,
|
|
emails: {
|
|
primaryEmail: 'test@test.com',
|
|
},
|
|
phones: {
|
|
primaryPhoneNumber: '123456789',
|
|
primaryPhoneCountryCode: 'US',
|
|
primaryPhoneCallingCode: '+1',
|
|
},
|
|
},
|
|
});
|
|
|
|
const getObjectMetadataOperation = {
|
|
query: gql`
|
|
query {
|
|
objects(paging: { first: 1000 }) {
|
|
edges {
|
|
node {
|
|
id
|
|
nameSingular
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`,
|
|
};
|
|
|
|
const objectMetadataResponse = await makeMetadataAPIRequest(
|
|
getObjectMetadataOperation,
|
|
);
|
|
const objects = objectMetadataResponse.body.data.objects.edges;
|
|
|
|
personObjectId = objects.find(
|
|
(obj: any) => obj.node.nameSingular === 'person',
|
|
)?.node.id;
|
|
|
|
const getFieldMetadataOperation = {
|
|
query: gql`
|
|
query {
|
|
fields(paging: { first: 1000 }) {
|
|
edges {
|
|
node {
|
|
id
|
|
name
|
|
object {
|
|
nameSingular
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`,
|
|
};
|
|
|
|
const fieldMetadataResponse = await makeMetadataAPIRequest(
|
|
getFieldMetadataOperation,
|
|
);
|
|
const fields = fieldMetadataResponse.body.data.fields.edges;
|
|
|
|
emailsFieldId = fields.find(
|
|
(field: any) =>
|
|
field.node.name === 'emails' &&
|
|
field.node.object.nameSingular === 'person',
|
|
).node.id;
|
|
|
|
phonesFieldId = fields.find(
|
|
(field: any) =>
|
|
field.node.name === 'phones' &&
|
|
field.node.object.nameSingular === 'person',
|
|
).node.id;
|
|
|
|
const getRolesOperation = {
|
|
query: gql`
|
|
query {
|
|
getRoles {
|
|
id
|
|
label
|
|
}
|
|
}
|
|
`,
|
|
};
|
|
|
|
const rolesResponse = await makeMetadataAPIRequest(getRolesOperation);
|
|
|
|
memberRoleId = rolesResponse.body.data.getRoles.find(
|
|
(role: any) => role.label === 'Member',
|
|
)?.id;
|
|
|
|
await upsertFieldPermissions({
|
|
roleId: memberRoleId,
|
|
fieldPermissions: [
|
|
{
|
|
objectMetadataId: personObjectId,
|
|
fieldMetadataId: emailsFieldId,
|
|
canReadFieldValue: false,
|
|
canUpdateFieldValue: null,
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
it('should hide fields when user has restricted read permissions - findOne', async () => {
|
|
await makeRestAPIRequest({
|
|
method: 'get',
|
|
path: `/people/${TEST_PERSON_1_ID}`,
|
|
bearer: APPLE_JONY_MEMBER_ACCESS_TOKEN,
|
|
})
|
|
.expect(200)
|
|
.expect((res) => {
|
|
const person = res.body.data.person;
|
|
|
|
expect(person).toBeDefined();
|
|
expect(person.id).toBeDefined();
|
|
expect(person.emails).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe('updateOne', () => {
|
|
it('should hide fields in the response when user has restricted read permissions', async () => {
|
|
await upsertFieldPermissions({
|
|
roleId: memberRoleId,
|
|
fieldPermissions: [
|
|
{
|
|
objectMetadataId: personObjectId,
|
|
fieldMetadataId: phonesFieldId,
|
|
canReadFieldValue: false,
|
|
canUpdateFieldValue: null,
|
|
},
|
|
],
|
|
});
|
|
|
|
await makeRestAPIRequest({
|
|
method: 'patch',
|
|
path: `/people/${TEST_PERSON_1_ID}`,
|
|
bearer: APPLE_JONY_MEMBER_ACCESS_TOKEN,
|
|
body: {
|
|
name: {
|
|
firstName: 'John',
|
|
},
|
|
},
|
|
})
|
|
.expect(200)
|
|
.expect((res) => {
|
|
const updatedPerson = res.body.data.updatePerson;
|
|
|
|
expect(updatedPerson.name.firstName).toBe('John');
|
|
expect(updatedPerson.phones).toBeUndefined();
|
|
});
|
|
});
|
|
it('should block update when user tries to update non-updatable field', async () => {
|
|
await upsertFieldPermissions({
|
|
roleId: memberRoleId,
|
|
fieldPermissions: [
|
|
{
|
|
objectMetadataId: personObjectId,
|
|
fieldMetadataId: phonesFieldId,
|
|
canReadFieldValue: null,
|
|
canUpdateFieldValue: false,
|
|
},
|
|
],
|
|
});
|
|
|
|
await makeRestAPIRequest({
|
|
method: 'patch',
|
|
path: `/people/${TEST_PERSON_1_ID}`,
|
|
bearer: APPLE_JONY_MEMBER_ACCESS_TOKEN,
|
|
body: {
|
|
phones: {
|
|
primaryPhoneNumber: '987654321',
|
|
primaryPhoneCountryCode: 'FR',
|
|
primaryPhoneCallingCode: '+33',
|
|
},
|
|
},
|
|
})
|
|
.expect(400)
|
|
.expect((res) => {
|
|
expect(res.body.messages[0]).toContain(
|
|
'Entity performing the request does not have permission',
|
|
);
|
|
});
|
|
});
|
|
|
|
it('should allow update when user has no restricted update permissions', async () => {
|
|
await upsertFieldPermissions({
|
|
roleId: memberRoleId,
|
|
fieldPermissions: [
|
|
{
|
|
objectMetadataId: personObjectId,
|
|
fieldMetadataId: phonesFieldId,
|
|
canReadFieldValue: null,
|
|
canUpdateFieldValue: null,
|
|
},
|
|
],
|
|
});
|
|
|
|
await makeRestAPIRequest({
|
|
method: 'patch',
|
|
path: `/people/${TEST_PERSON_1_ID}`,
|
|
bearer: APPLE_JONY_MEMBER_ACCESS_TOKEN,
|
|
body: {
|
|
jobTitle: 'Updated City',
|
|
},
|
|
})
|
|
.expect(200)
|
|
.expect((res) => {
|
|
const updatedPerson = res.body.data.updatePerson;
|
|
|
|
expect(updatedPerson.jobTitle).toBe('Updated City');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('createOne', () => {
|
|
it('should block create when restricted field is not in any RLS predicate', async () => {
|
|
await upsertFieldPermissions({
|
|
roleId: memberRoleId,
|
|
fieldPermissions: [
|
|
{
|
|
objectMetadataId: personObjectId,
|
|
fieldMetadataId: phonesFieldId,
|
|
canReadFieldValue: null,
|
|
canUpdateFieldValue: false,
|
|
},
|
|
],
|
|
});
|
|
|
|
await makeRestAPIRequest({
|
|
method: 'post',
|
|
path: `/people`,
|
|
bearer: APPLE_JONY_MEMBER_ACCESS_TOKEN,
|
|
body: {
|
|
phones: {
|
|
primaryPhoneNumber: '555123456',
|
|
primaryPhoneCountryCode: 'US',
|
|
primaryPhoneCallingCode: '+1',
|
|
},
|
|
},
|
|
})
|
|
.expect(400)
|
|
.expect((res) => {
|
|
expect(res.body.messages[0]).toContain(
|
|
'Entity performing the request does not have permission',
|
|
);
|
|
});
|
|
});
|
|
|
|
it('should allow create when restricted field is referenced in an RLS predicate', async () => {
|
|
await upsertFieldPermissions({
|
|
roleId: memberRoleId,
|
|
fieldPermissions: [
|
|
{
|
|
objectMetadataId: personObjectId,
|
|
fieldMetadataId: phonesFieldId,
|
|
canReadFieldValue: null,
|
|
canUpdateFieldValue: false,
|
|
},
|
|
],
|
|
});
|
|
|
|
await upsertRowLevelPermissionPredicates({
|
|
input: {
|
|
roleId: memberRoleId,
|
|
objectMetadataId: personObjectId,
|
|
predicates: [
|
|
{
|
|
fieldMetadataId: phonesFieldId,
|
|
operand: RowLevelPermissionPredicateOperand.IS_NOT_EMPTY,
|
|
},
|
|
],
|
|
predicateGroups: [],
|
|
},
|
|
});
|
|
|
|
await makeRestAPIRequest({
|
|
method: 'post',
|
|
path: `/people`,
|
|
bearer: APPLE_JONY_MEMBER_ACCESS_TOKEN,
|
|
body: {
|
|
phones: {
|
|
primaryPhoneNumber: '555123456',
|
|
primaryPhoneCountryCode: 'US',
|
|
primaryPhoneCallingCode: '+1',
|
|
},
|
|
},
|
|
})
|
|
.expect(201)
|
|
.expect((res) => {
|
|
const createdPerson = res.body.data.createPerson;
|
|
|
|
expect(createdPerson).toBeDefined();
|
|
expect(createdPerson.phones.primaryPhoneNumber).toBe('555123456');
|
|
});
|
|
|
|
await upsertRowLevelPermissionPredicates({
|
|
input: {
|
|
roleId: memberRoleId,
|
|
objectMetadataId: personObjectId,
|
|
predicates: [],
|
|
predicateGroups: [],
|
|
},
|
|
});
|
|
});
|
|
|
|
it('should allow create when user has no restricted update permissions', async () => {
|
|
await upsertFieldPermissions({
|
|
roleId: memberRoleId,
|
|
fieldPermissions: [
|
|
{
|
|
objectMetadataId: personObjectId,
|
|
fieldMetadataId: phonesFieldId,
|
|
canReadFieldValue: null,
|
|
canUpdateFieldValue: null,
|
|
},
|
|
{
|
|
objectMetadataId: personObjectId,
|
|
fieldMetadataId: emailsFieldId,
|
|
canReadFieldValue: false,
|
|
canUpdateFieldValue: null,
|
|
},
|
|
],
|
|
});
|
|
|
|
await makeRestAPIRequest({
|
|
method: 'post',
|
|
path: `/people`,
|
|
bearer: APPLE_JONY_MEMBER_ACCESS_TOKEN,
|
|
body: {
|
|
jobTitle: 'New City',
|
|
},
|
|
})
|
|
.expect(201)
|
|
.expect((res) => {
|
|
const createdPerson = res.body.data.createPerson;
|
|
|
|
expect(createdPerson.jobTitle).toBe('New City');
|
|
expect(createdPerson.emails).toBeUndefined();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('createMany', () => {
|
|
it('should block createMany when restricted field is not in any RLS predicate', async () => {
|
|
await upsertFieldPermissions({
|
|
roleId: memberRoleId,
|
|
fieldPermissions: [
|
|
{
|
|
objectMetadataId: personObjectId,
|
|
fieldMetadataId: phonesFieldId,
|
|
canReadFieldValue: null,
|
|
canUpdateFieldValue: false,
|
|
},
|
|
],
|
|
});
|
|
|
|
await makeRestAPIRequest({
|
|
method: 'post',
|
|
path: `/batch/people`,
|
|
bearer: APPLE_JONY_MEMBER_ACCESS_TOKEN,
|
|
body: [
|
|
{
|
|
phones: {
|
|
primaryPhoneNumber: '555123456',
|
|
primaryPhoneCountryCode: 'US',
|
|
primaryPhoneCallingCode: '+1',
|
|
},
|
|
},
|
|
],
|
|
})
|
|
.expect(400)
|
|
.expect((res) => {
|
|
expect(res.body.messages[0]).toContain(
|
|
'Entity performing the request does not have permission',
|
|
);
|
|
});
|
|
});
|
|
|
|
it('should allow createMany when restricted field is referenced in an RLS predicate', async () => {
|
|
await upsertFieldPermissions({
|
|
roleId: memberRoleId,
|
|
fieldPermissions: [
|
|
{
|
|
objectMetadataId: personObjectId,
|
|
fieldMetadataId: phonesFieldId,
|
|
canReadFieldValue: null,
|
|
canUpdateFieldValue: false,
|
|
},
|
|
],
|
|
});
|
|
|
|
await upsertRowLevelPermissionPredicates({
|
|
input: {
|
|
roleId: memberRoleId,
|
|
objectMetadataId: personObjectId,
|
|
predicates: [
|
|
{
|
|
fieldMetadataId: phonesFieldId,
|
|
operand: RowLevelPermissionPredicateOperand.IS_NOT_EMPTY,
|
|
},
|
|
],
|
|
predicateGroups: [],
|
|
},
|
|
});
|
|
|
|
await makeRestAPIRequest({
|
|
method: 'post',
|
|
path: `/batch/people`,
|
|
bearer: APPLE_JONY_MEMBER_ACCESS_TOKEN,
|
|
body: [
|
|
{
|
|
phones: {
|
|
primaryPhoneNumber: '555123456',
|
|
primaryPhoneCountryCode: 'US',
|
|
primaryPhoneCallingCode: '+1',
|
|
},
|
|
},
|
|
],
|
|
})
|
|
.expect(201)
|
|
.expect((res) => {
|
|
const createdPeople = res.body.data.createPeople;
|
|
|
|
expect(createdPeople).toHaveLength(1);
|
|
expect(createdPeople[0].phones.primaryPhoneNumber).toBe('555123456');
|
|
});
|
|
|
|
await upsertRowLevelPermissionPredicates({
|
|
input: {
|
|
roleId: memberRoleId,
|
|
objectMetadataId: personObjectId,
|
|
predicates: [],
|
|
predicateGroups: [],
|
|
},
|
|
});
|
|
});
|
|
|
|
it('should allow createMany when user has no restricted update permissions', async () => {
|
|
await upsertFieldPermissions({
|
|
roleId: memberRoleId,
|
|
fieldPermissions: [
|
|
{
|
|
objectMetadataId: personObjectId,
|
|
fieldMetadataId: phonesFieldId,
|
|
canReadFieldValue: null,
|
|
canUpdateFieldValue: null,
|
|
},
|
|
{
|
|
objectMetadataId: personObjectId,
|
|
fieldMetadataId: emailsFieldId,
|
|
canReadFieldValue: false,
|
|
canUpdateFieldValue: null,
|
|
},
|
|
],
|
|
});
|
|
|
|
await makeRestAPIRequest({
|
|
method: 'post',
|
|
path: `/batch/people`,
|
|
bearer: APPLE_JONY_MEMBER_ACCESS_TOKEN,
|
|
body: [
|
|
{
|
|
jobTitle: 'Batch City 1',
|
|
},
|
|
{
|
|
jobTitle: 'Batch City 2',
|
|
},
|
|
],
|
|
})
|
|
.expect(201)
|
|
.expect((res) => {
|
|
const createdPeople = res.body.data.createPeople;
|
|
|
|
expect(createdPeople).toHaveLength(2);
|
|
expect(createdPeople[0].jobTitle).toBe('Batch City 1');
|
|
expect(createdPeople[0].emails).toBeUndefined();
|
|
expect(createdPeople[1].jobTitle).toBe('Batch City 2');
|
|
expect(createdPeople[1].emails).toBeUndefined();
|
|
});
|
|
});
|
|
});
|
|
});
|