The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(last-contact): scope app record permissions (#24823)
Félix Malfait8ca238dcab7d
diff --git a/packages/twenty-apps/public/last-contact/CHANGELOG.md b/packages/twenty-apps/public/last-contact/CHANGELOG.mdindex 90c2c6a2712..3aaef495774 100644--- a/packages/twenty-apps/public/last-contact/CHANGELOG.md+++ b/packages/twenty-apps/public/last-contact/CHANGELOG.md@@ -1,5 +1,9 @@# Changelog+## 1.2.4++- Limit the app role to reading synced messages, calendar events, and their participants, and to reading and updating people, companies, and opportunities. The app no longer requests read and edit access to every record type.+## 1.2.3- Rework the last-contact backfill into a single fan-out instead of a logic function that called its own HTTP route in a loop with blocking sleeps. On install it counts people, opportunities and companies and enqueues one job per record batch via `enqueueJob`. Each job receives its batch id and processes the matching record window (offset pagination). Jobs are staggered with `delayMs` to stay under the hosted API rate limiting.diff --git a/packages/twenty-apps/public/last-contact/package.json b/packages/twenty-apps/public/last-contact/package.jsonindex 84acdaee106..7638aef220d 100644--- a/packages/twenty-apps/public/last-contact/package.json+++ b/packages/twenty-apps/public/last-contact/package.json@@ -1,6 +1,6 @@{"name": "@twentyhq/last-contact",- "version": "1.2.3",+ "version": "1.2.4","license": "MIT","engines": {"node": "^24.5.0",diff --git a/packages/twenty-apps/public/last-contact/src/__tests__/default-role.test.ts b/packages/twenty-apps/public/last-contact/src/__tests__/default-role.test.tsnew file mode 100644index 00000000000..18b76f4ba96--- /dev/null+++ b/packages/twenty-apps/public/last-contact/src/__tests__/default-role.test.ts@@ -0,0 +1,55 @@+import { STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS } from 'twenty-sdk/define';+import { describe, expect, it } from 'vitest';++import defaultRole from 'src/default-role';++const permissionFor = (objectUniversalIdentifier: string) =>+ defaultRole.config?.objectPermissions?.find(+ (permission) =>+ permission.objectUniversalIdentifier === objectUniversalIdentifier,+ );++describe('default role', () => {+ it('only grants write access to the CRM records with last-contact fields', () => {+ expect(defaultRole.success).toBe(true);+ expect(defaultRole.config).toMatchObject({+ canReadAllObjectRecords: false,+ canUpdateAllObjectRecords: false,+ canSoftDeleteAllObjectRecords: false,+ canDestroyAllObjectRecords: false,+ });++ for (const objectUniversalIdentifier of [+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.person.universalIdentifier,+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.company.universalIdentifier,+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.opportunity.universalIdentifier,+ ]) {+ expect(permissionFor(objectUniversalIdentifier)).toMatchObject({+ canReadObjectRecords: true,+ canUpdateObjectRecords: true,+ canSoftDeleteObjectRecords: false,+ canDestroyObjectRecords: false,+ });+ }+ });++ it('keeps interaction source records read-only', () => {+ for (const objectUniversalIdentifier of [+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.message.universalIdentifier,+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.messageParticipant+ .universalIdentifier,+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.calendarEvent.universalIdentifier,+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.calendarEventParticipant+ .universalIdentifier,+ ]) {+ expect(permissionFor(objectUniversalIdentifier)).toMatchObject({+ canReadObjectRecords: true,+ canUpdateObjectRecords: false,+ canSoftDeleteObjectRecords: false,+ canDestroyObjectRecords: false,+ });+ }++ expect(defaultRole.config?.objectPermissions).toHaveLength(7);+ });+});diff --git a/packages/twenty-apps/public/last-contact/src/default-role.ts b/packages/twenty-apps/public/last-contact/src/default-role.tsindex b1bd057299b..f3faf0f119c 100644--- a/packages/twenty-apps/public/last-contact/src/default-role.ts+++ b/packages/twenty-apps/public/last-contact/src/default-role.ts@@ -1,4 +1,7 @@-import { defineApplicationRole } from 'twenty-sdk/define';+import {+ defineApplicationRole,+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS,+} from 'twenty-sdk/define';import {APP_DISPLAY_NAME,@@ -7,10 +10,44 @@ import {export default defineApplicationRole({universalIdentifier: DEFAULT_ROLE_UNIVERSAL_IDENTIFIER,- label: `${APP_DISPLAY_NAME} default function role`,- description: `${APP_DISPLAY_NAME} default function role`,- canReadAllObjectRecords: true,- canUpdateAllObjectRecords: true,+ label: `${APP_DISPLAY_NAME} function role`,+ description:+ 'Reads synced email and calendar interactions, then updates last-contact fields on people, companies, and opportunities.',+ canReadAllObjectRecords: false,+ canUpdateAllObjectRecords: false,canSoftDeleteAllObjectRecords: false,canDestroyAllObjectRecords: false,+ canUpdateAllSettings: false,+ canBeAssignedToAgents: false,+ canBeAssignedToUsers: false,+ canBeAssignedToApiKeys: false,+ objectPermissions: [+ ...[+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.person.universalIdentifier,+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.company.universalIdentifier,+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.opportunity.universalIdentifier,+ ].map((objectUniversalIdentifier) => ({+ objectUniversalIdentifier,+ canReadObjectRecords: true,+ canUpdateObjectRecords: true,+ canSoftDeleteObjectRecords: false,+ canDestroyObjectRecords: false,+ })),+ ...[+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.message.universalIdentifier,+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.messageParticipant+ .universalIdentifier,+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.calendarEvent.universalIdentifier,+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.calendarEventParticipant+ .universalIdentifier,+ ].map((objectUniversalIdentifier) => ({+ objectUniversalIdentifier,+ canReadObjectRecords: true,+ canUpdateObjectRecords: false,+ canSoftDeleteObjectRecords: false,+ canDestroyObjectRecords: false,+ })),+ ],+ fieldPermissions: [],+ permissionFlagUniversalIdentifiers: [],});