The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Block system and relation fields on workspace member settings update (#26026)
Charles Bochet1ac815b13e44
diff --git a/packages/twenty-server/src/engine/core-modules/user/utils/__tests__/assert-workspace-member-update-non-custom-fields.util.spec.ts b/packages/twenty-server/src/engine/core-modules/user/utils/__tests__/assert-workspace-member-update-non-custom-fields.util.spec.tsindex e89f78dc07d..223ce915567 100644--- a/packages/twenty-server/src/engine/core-modules/user/utils/__tests__/assert-workspace-member-update-non-custom-fields.util.spec.ts+++ b/packages/twenty-server/src/engine/core-modules/user/utils/__tests__/assert-workspace-member-update-non-custom-fields.util.spec.ts@@ -46,6 +46,60 @@ describe('assertWorkspaceMemberUpdateUsesNonCustomFieldsOnly', () => {},);+ it.each([+ 'deletedAt',+ 'createdAt',+ 'updatedAt',+ 'createdBy',+ 'updatedBy',+ 'position',+ 'searchVector',+ 'userEmail',+ 'assignedTasks',+ 'accountOwnerForCompanies',+ 'authoredAttachments',+ 'messageParticipants',+ 'blocklist',+ 'calendarEventParticipants',+ 'timelineActivities',+ 'ownedOpportunities',+ ] as const)(+ 'should throw when the update includes the system or relation field %s',+ (fieldName) => {+ expect(() =>+ assertWorkspaceMemberUpdateUsesNonCustomFieldsOnly({+ update: {+ [fieldName]: 'value',+ },+ }),+ ).toThrow(UserInputError);+ },+ );++ it('should throw when a system field is mixed with allowed settings fields', () => {+ expect(() =>+ assertWorkspaceMemberUpdateUsesNonCustomFieldsOnly({+ update: {+ timeZone: 'Europe/Paris',+ deletedAt: new Date().toISOString(),+ },+ }),+ ).toThrow(UserInputError);+ });++ it('should not throw for editable settings fields', () => {+ expect(() =>+ assertWorkspaceMemberUpdateUsesNonCustomFieldsOnly({+ update: {+ colorScheme: 'Dark',+ locale: 'en',+ dateFormat: 'MONTH_FIRST',+ avatarUrl: 'https://example.com/a.png',+ },+ }),+ ).not.toThrow();+ });+it('should throw when a top-level key is not in the standard field allowlist', () => {const unknownKey = 'notAWorkspaceMemberField';diff --git a/packages/twenty-server/src/engine/core-modules/user/utils/assert-workspace-member-update-non-custom-fields.util.ts b/packages/twenty-server/src/engine/core-modules/user/utils/assert-workspace-member-update-non-custom-fields.util.tsindex e8ae7986b7b..927f2b1957b 100644--- a/packages/twenty-server/src/engine/core-modules/user/utils/assert-workspace-member-update-non-custom-fields.util.ts+++ b/packages/twenty-server/src/engine/core-modules/user/utils/assert-workspace-member-update-non-custom-fields.util.ts@@ -1,21 +1,23 @@import { msg } from '@lingui/core/macro';-import { STANDARD_OBJECTS } from 'twenty-shared/metadata';-import { UserInputError } from 'src/engine/core-modules/graphql/utils/graphql-errors.util';-const WORKSPACE_MEMBER_UPDATE_DISALLOWED_FIELD_NAMES = new Set([- 'id',- 'userId',+// Deny-by-default allowlist of self-service settings: lifecycle, audit and email columns (notably deletedAt) and relations must go through their own flow.+const WORKSPACE_MEMBER_SETTINGS_UPDATE_ALLOWED_FIELD_NAMES = new Set<string>([+ 'name',+ 'colorScheme',+ 'uiScale',+ 'openRecordIn',+ 'locale',+ 'avatarUrl',+ 'jobTitle',+ 'calendarStartDay',+ 'timeZone',+ 'dateFormat',+ 'timeFormat',+ 'numberFormat',]);-const WORKSPACE_MEMBER_NON_CUSTOM_UPDATE_FIELD_ALLOWLIST = new Set<string>(- Object.keys(STANDARD_OBJECTS.workspaceMember.fields).filter(- (fieldName) =>- !WORKSPACE_MEMBER_UPDATE_DISALLOWED_FIELD_NAMES.has(fieldName),- ),-);-export const assertWorkspaceMemberUpdateUsesNonCustomFieldsOnly = ({update,}: {@@ -30,7 +32,7 @@ export const assertWorkspaceMemberUpdateUsesNonCustomFieldsOnly = ({}for (const payloadKey of updateKeys) {- if (!WORKSPACE_MEMBER_NON_CUSTOM_UPDATE_FIELD_ALLOWLIST.has(payloadKey)) {+ if (!WORKSPACE_MEMBER_SETTINGS_UPDATE_ALLOWED_FIELD_NAMES.has(payloadKey)) {throw new UserInputError(`Cannot update custom workspaceMember field via this endpoint: ${payloadKey}`,{