Skip to content

The open alternative to Salesforce, designed for AI.

Relabel the app permissions as Workspace Apps and User Apps and enforce User Apps on the server (#28083)

nitin2ee84b05655d
diff --git a/packages/twenty-agent-skills/references/develop-app/layout.md b/packages/twenty-agent-skills/references/develop-app/layout.md
index b247a1c35b9..db6f6f50dcf 100644
--- a/packages/twenty-agent-skills/references/develop-app/layout.md
+++ b/packages/twenty-agent-skills/references/develop-app/layout.md
@@ -60,7 +60,7 @@ To add an entry to an app's settings menu, declare it with `defineSettingsMenuIt
The menu item points at the component, not the reverse, so one component can back several items. Declare as many as the app needs. Each renders as a tab on the app's page under Settings > Apps, after the built-in General tab, in `position` order.
-`scope` is `WORKSPACE` (configured once for the whole workspace, the default) or `USER` (configured by each member for themselves). A `USER` item renders as a tab on the app's page under the member's Settings > App preferences, but that page is not enabled in every workspace yet — where it is not, the item is persisted and synced but nothing displays it, so say so rather than relying on a `USER` item for a settings entry every workspace needs visible now. To store something per person, a `USER` item should use an application variable declared with `scope: 'USER'`, which `getApplicationVariable` returns with the viewing member's value unless it is secret; the component saves it with `updateMyUserApplicationVariable`, which writes the viewing member's value only and refuses a token with nobody behind it, and since a `USER` item replaces the generated Variables form like a `WORKSPACE` item does, it should let the member set every user variable the app needs; a variable without that scope holds one value shared by the whole workspace.
+`scope` is `WORKSPACE` (configured once for the whole workspace, the default) or `USER` (configured by each member for themselves). A `USER` item renders as a tab on the app's page under the member's Settings > App preferences, but that page is not enabled in every workspace yet — where it is not, the item is persisted and synced but nothing displays it, so say so rather than relying on a `USER` item for a settings entry every workspace needs visible now. To store something per person, a `USER` item should use an application variable declared with `scope: 'USER'`, which `getApplicationVariable` returns with the viewing member's value unless it is secret; the component saves it with `updateMyUserApplicationVariable`, which writes the viewing member's value only, refuses a token with nobody behind it, and needs `SystemPermissionFlag.CONNECTED_ACCOUNTS` in the app's default role, if it declares one (and in the member's role, since the component's token is the intersection of both), and since a `USER` item replaces the generated Variables form like a `WORKSPACE` item does, it should let the member set every user variable the app needs; a variable without that scope holds one value shared by the whole workspace.
Items sort by ascending `position`, which is a decimal so an item can be slotted between two existing ones. Two items of one app cannot share a position in the same scope, and `General` is reserved for the built-in item.
diff --git a/packages/twenty-cli/src/commands/metadata/object/list/run-metadata-object-list-command.ts b/packages/twenty-cli/src/commands/metadata/object/list/run-metadata-object-list-command.ts
index 11723e7f103..1128c321464 100644
--- a/packages/twenty-cli/src/commands/metadata/object/list/run-metadata-object-list-command.ts
+++ b/packages/twenty-cli/src/commands/metadata/object/list/run-metadata-object-list-command.ts
@@ -49,7 +49,7 @@ export const runMetadataObjectListCommand: CommandRun<
output.warn({
code: 'OWNERS_UNAVAILABLE',
message:
- 'Owners other than Custom show as unknown: listing apps needs the Applications permission.',
+ 'Owners other than Custom show as unknown: listing apps needs the Workspace Apps permission.',
});
}
diff --git a/packages/twenty-cli/src/metadata/fetch-metadata-inspection.ts b/packages/twenty-cli/src/metadata/fetch-metadata-inspection.ts
index 68ab17b927e..d790f3b1a4d 100644
--- a/packages/twenty-cli/src/metadata/fetch-metadata-inspection.ts
+++ b/packages/twenty-cli/src/metadata/fetch-metadata-inspection.ts
@@ -74,7 +74,7 @@ export const fetchMetadataInspection = async ({
output.warn({
code: 'OWNERS_UNAVAILABLE',
message:
- 'Owners other than Custom show as unknown: listing apps needs the Applications permission.',
+ 'Owners other than Custom show as unknown: listing apps needs the Workspace Apps permission.',
});
}
diff --git a/packages/twenty-docs/developers/extend/apps/config/application.mdx b/packages/twenty-docs/developers/extend/apps/config/application.mdx
index 0b5845f587e..50fc3387811 100644
--- a/packages/twenty-docs/developers/extend/apps/config/application.mdx
+++ b/packages/twenty-docs/developers/extend/apps/config/application.mdx
@@ -185,7 +185,9 @@ const { myUserApplicationVariables } = await client.query({
Values are strings, in the same format as `process.env` (see [Variable types](#variable-types)).
-`updateMyUserApplicationVariable` saves a member's own value. It takes your app's `applicationUniversalIdentifier` and needs no `APPLICATIONS` permission, and it writes the value of the person behind the token: the member's own session, or your app's token when a member is behind it, such as in a front component or a logic function run for a member. Your app's token can only name your own app, and a token with nobody behind it, such as in a cron job or an install hook, is refused.
+`updateMyUserApplicationVariable` saves a member's own value. It takes your app's `applicationUniversalIdentifier` and writes the value of the person behind the token: the member's own session, or your app's token when a member is behind it, such as in a front component or a logic function run for a member. Your app's token can only name your own app, and a token with nobody behind it, such as in a cron job or an install hook, is refused.
+
+It needs no `APPLICATIONS` permission, but it needs `CONNECTED_ACCOUNTS`: on the member's role, and, when your app's token makes the call, on your app's default role too, if it declares one. If your app saves user variables, add `SystemPermissionFlag.CONNECTED_ACCOUNTS` to `permissionFlagUniversalIdentifiers` in its [role](/developers/extend/apps/config/roles).
## Default function role
diff --git a/packages/twenty-docs/developers/extend/apps/layout/front-components.mdx b/packages/twenty-docs/developers/extend/apps/layout/front-components.mdx
index d780c5fef99..e9ee9cb538f 100644
--- a/packages/twenty-docs/developers/extend/apps/layout/front-components.mdx
+++ b/packages/twenty-docs/developers/extend/apps/layout/front-components.mdx
@@ -166,12 +166,13 @@ Declare as many as you need. Twenty's own **General** item — auto-upgrade, App
<Note>
A `USER` item renders as a tab on the app's page under **Settings > App
- preferences**, where only the signed-in member sees it. That page is not
- enabled in every workspace yet: where it is not, a `USER` item is persisted
- and synced but nothing renders it.
+ preferences**, where only the signed-in member sees it, and only when their
+ role grants the `CONNECTED_ACCOUNTS` permission. That page is not enabled in
+ every workspace yet: where it is not, a `USER` item is persisted and synced
+ but nothing renders it.
</Note>
-A `USER` item runs as the member viewing it. To store something per person, declare the variable with `scope: 'USER'`: `getApplicationVariable` returns the viewing member's value, and your component saves it with `updateMyUserApplicationVariable`, which writes that member's value only (see [Reading and updating variables at runtime](#reading-and-updating-variables-at-runtime)). Like a `WORKSPACE` item, a `USER` item replaces the generated **Variables** form, so it should let the member set every user variable your app needs. A workspace variable holds one value shared by everyone, so one member's save would overwrite another's.
+A `USER` item runs as the member viewing it. To store something per person, declare the variable with `scope: 'USER'`: `getApplicationVariable` returns the viewing member's value, and your component saves it with `updateMyUserApplicationVariable`, which writes that member's value only and needs `SystemPermissionFlag.CONNECTED_ACCOUNTS` in your app's role, if it declares one (see [Reading and updating variables at runtime](#reading-and-updating-variables-at-runtime)). Like a `WORKSPACE` item, a `USER` item replaces the generated **Variables** form, so it should let the member set every user variable your app needs. A workspace variable holds one value shared by everyone, so one member's save would overwrite another's.
<Note>
`defineSettingsFrontComponent()` is deprecated in favor of
@@ -612,7 +613,7 @@ Notes:
- The key must be one your app declares in [`defineApplication()`](/developers/extend/apps/config/application). Writing a key that is not declared is a not found.
- Secret variables read back masked, never as the stored value. Writing them works normally.
- Reading a variable's `value`, and writing it, need the `APPLICATIONS` settings permission on both your app's role and the signed-in person's role, since the component's token is the intersection of the two. Add `SystemPermissionFlag.APPLICATIONS` to `permissionFlagUniversalIdentifiers` in your [application role](/developers/extend/apps/config/roles).
-- A user variable (`scope: 'USER'`) is injected with the viewing member's value, unless it is secret. `updateOneApplicationVariable` refuses it: save it with `updateMyUserApplicationVariable`, as `saveMyLanguage` does above. It writes the viewing member's value only, needs no permission on either role, and refuses naming another application. See [Workspace and user variables](/developers/extend/apps/config/application#workspace-and-user-variables).
+- A user variable (`scope: 'USER'`) is injected with the viewing member's value, unless it is secret. `updateOneApplicationVariable` refuses it: save it with `updateMyUserApplicationVariable`, as `saveMyLanguage` does above. It writes the viewing member's value only and refuses naming another application. It needs no `APPLICATIONS` permission, but it needs the `CONNECTED_ACCOUNTS` permission on the viewing member's role and on your app's role, if it declares one: add `SystemPermissionFlag.CONNECTED_ACCOUNTS` to `permissionFlagUniversalIdentifiers` in your [application role](/developers/extend/apps/config/roles). See [Workspace and user variables](/developers/extend/apps/config/application#workspace-and-user-variables).
### System variables
diff --git a/packages/twenty-docs/developers/extend/apps/operations/publishing.mdx b/packages/twenty-docs/developers/extend/apps/operations/publishing.mdx
index efb4fd94eee..c1188eaa9fb 100644
--- a/packages/twenty-docs/developers/extend/apps/operations/publishing.mdx
+++ b/packages/twenty-docs/developers/extend/apps/operations/publishing.mdx
@@ -296,7 +296,7 @@ After the package has synced into the catalog, continue with [Claiming your app]
## Claiming your app
-Claiming assigns your app's registration to the Twenty workspace that will manage it. App claiming is available to all workspaces. Your role needs the **Applications** and **Developers** permissions to claim through the **Apps** tab of **Settings > Developers**.
+Claiming assigns your app's registration to the Twenty workspace that will manage it. App claiming is available to all workspaces. Your role needs the **Workspace Apps** and **Developers** permissions to claim through the **Apps** tab of **Settings > Developers**.
Ownership is per Twenty instance: claiming on Twenty Cloud does not claim the app on a separate self-hosted server. Other workspaces on the same instance install your app without claiming it themselves.
diff --git a/packages/twenty-front/src/modules/activities/calendar/components/CalendarEventComposerFields.tsx b/packages/twenty-front/src/modules/activities/calendar/components/CalendarEventComposerFields.tsx
index ec53515270b..0040f96b776 100644
--- a/packages/twenty-front/src/modules/activities/calendar/components/CalendarEventComposerFields.tsx
+++ b/packages/twenty-front/src/modules/activities/calendar/components/CalendarEventComposerFields.tsx
@@ -271,7 +271,7 @@ export const CalendarEventComposerFields = ({
description={
isDefined(onAddAccount)
? t`Connect Google, Microsoft or CalDAV and enable calendar sync before creating an event.`
- : t`Ask a workspace admin for the Sync Account permission to connect a calendar account.`
+ : t`Ask a workspace admin for the User Apps permission to connect a calendar account.`
}
action={
isDefined(onAddAccount) ? (
@@ -290,7 +290,7 @@ export const CalendarEventComposerFields = ({
description={
isDefined(onReauthorize)
? t`Reconnect this account to grant permission to create calendar events.`
- : t`Ask a workspace admin for the Sync Account permission to reconnect this account.`
+ : t`Ask a workspace admin for the User Apps permission to reconnect this account.`
}
action={
isDefined(onReauthorize) ? (
diff --git a/packages/twenty-front/src/modules/marketplace/constants/PermissionFlagSummaryConfigs.ts b/packages/twenty-front/src/modules/marketplace/constants/PermissionFlagSummaryConfigs.ts
index c886f8200c7..9065c9f110f 100644
--- a/packages/twenty-front/src/modules/marketplace/constants/PermissionFlagSummaryConfigs.ts
+++ b/packages/twenty-front/src/modules/marketplace/constants/PermissionFlagSummaryConfigs.ts
@@ -4,7 +4,6 @@ import {
IconApi,
IconApps,
IconAppWindow,
- IconAt,
IconCalendarEvent,
IconCode,
type IconComponent,
@@ -76,7 +75,7 @@ export const PERMISSION_FLAG_SUMMARY_CONFIGS: Record<
},
[PermissionFlagType.APPLICATIONS]: {
Icon: IconApps,
- getLabel: () => t`Install and manage applications`,
+ getLabel: () => t`Install and manage workspace apps`,
},
[PermissionFlagType.MARKETPLACE_APPS]: {
Icon: IconShoppingBag,
@@ -135,8 +134,8 @@ export const PERMISSION_FLAG_SUMMARY_CONFIGS: Record<
getLabel: () => t`Export CSV files`,
},
[PermissionFlagType.CONNECTED_ACCOUNTS]: {
- Icon: IconAt,
- getLabel: () => t`Sync email and calendar accounts`,
+ Icon: IconApps,
+ getLabel: () => t`Manage own app preferences and accounts`,
},
[PermissionFlagType.PROFILE_INFORMATION]: {
Icon: IconUser,
diff --git a/packages/twenty-front/src/modules/marketplace/utils/__tests__/buildPermissionSummaryFromRoleManifest.test.ts b/packages/twenty-front/src/modules/marketplace/utils/__tests__/buildPermissionSummaryFromRoleManifest.test.ts
index 259d6ca0c2d..9ab35431ad7 100644
--- a/packages/twenty-front/src/modules/marketplace/utils/__tests__/buildPermissionSummaryFromRoleManifest.test.ts
+++ b/packages/twenty-front/src/modules/marketplace/utils/__tests__/buildPermissionSummaryFromRoleManifest.test.ts
@@ -376,7 +376,8 @@ describe('buildPermissionSummaryFromRoleManifest', () => {
expect(labels).toEqual(
expect.arrayContaining([
'Upload files',
- 'Install and manage applications',
+ 'Install and manage workspace apps',
+ 'Manage own app preferences and accounts',
'Run AI agents',
'Manage billing',
'Manage MCP, API keys, and webhooks',
diff --git a/packages/twenty-front/src/modules/settings/applications/components/__tests__/SettingsApplicationActionButton.test.tsx b/packages/twenty-front/src/modules/settings/applications/components/__tests__/SettingsApplicationActionButton.test.tsx
index 16832749007..cd8c60507d8 100644
--- a/packages/twenty-front/src/modules/settings/applications/components/__tests__/SettingsApplicationActionButton.test.tsx
+++ b/packages/twenty-front/src/modules/settings/applications/components/__tests__/SettingsApplicationActionButton.test.tsx
@@ -38,7 +38,7 @@ const renderActionButton = ({
);
describe('SettingsApplicationActionButton', () => {
- it('renders nothing without the applications permission', () => {
+ it('renders nothing without the Workspace Apps permission', () => {
const { container } = renderActionButton({
canInstallMarketplaceApps: false,
});
@@ -101,7 +101,7 @@ describe('SettingsApplicationActionButton', () => {
);
});
- it('offers the settings link even without the applications permission', () => {
+ it('offers the settings link even without the Workspace Apps permission', () => {
renderActionButton({
installedApplicationId: INSTALLED_APPLICATION_ID,
canInstallMarketplaceApps: false,
diff --git a/packages/twenty-front/src/modules/settings/roles/role-permissions/permission-flags/components/__stories__/SettingsRolePermissionsFlagSections.stories.tsx b/packages/twenty-front/src/modules/settings/roles/role-permissions/permission-flags/components/__stories__/SettingsRolePermissionsFlagSections.stories.tsx
index 7fda4f1c413..befad2414a2 100644
--- a/packages/twenty-front/src/modules/settings/roles/role-permissions/permission-flags/components/__stories__/SettingsRolePermissionsFlagSections.stories.tsx
+++ b/packages/twenty-front/src/modules/settings/roles/role-permissions/permission-flags/components/__stories__/SettingsRolePermissionsFlagSections.stories.tsx
@@ -141,7 +141,7 @@ export const ForUsers: Story = {
await expect(
logic.queryByText('Configure notifications'),
).not.toBeInTheDocument();
- await expect(layout.getAllByText('Applications')).toHaveLength(1);
+ await expect(layout.getAllByText('Workspace Apps')).toHaveLength(1);
await expect(layout.getByText('Notifications')).toBeVisible();
await expect(logic.getByText('Notifications')).toBeVisible();
await expect(layout.getByText('Standard')).toBeVisible();
@@ -199,7 +199,7 @@ export const ToggleAllLayoutFlags: Story = {
await userEvent.click(toggleAll);
await expect(appFlag).toBeChecked();
await expect(
- layout.getByRole('checkbox', { name: 'Applications' }),
+ layout.getByRole('checkbox', { name: 'Workspace Apps' }),
).toBeChecked();
await expect(logicFlag).toBeChecked();
await userEvent.click(toggleAll);
diff --git a/packages/twenty-front/src/modules/settings/roles/role-permissions/permission-flags/hooks/useActionRolePermissionFlagConfig.ts b/packages/twenty-front/src/modules/settings/roles/role-permissions/permission-flags/hooks/useActionRolePermissionFlagConfig.ts
index 938f5ec8292..bd65d18a38e 100644
--- a/packages/twenty-front/src/modules/settings/roles/role-permissions/permission-flags/hooks/useActionRolePermissionFlagConfig.ts
+++ b/packages/twenty-front/src/modules/settings/roles/role-permissions/permission-flags/hooks/useActionRolePermissionFlagConfig.ts
@@ -3,7 +3,7 @@ import { t } from '@lingui/core/macro';
import { useMemo } from 'react';
import {
IconApi,
- IconAt,
+ IconApps,
IconCalendarEvent,
IconCode,
IconDownload,
@@ -130,9 +130,9 @@ export const useActionRolePermissionFlagConfig = ({
},
{
key: PermissionFlagType.CONNECTED_ACCOUNTS,
- name: t`Sync Account`,
- description: t`Sync email and calendar accounts`,
- Icon: IconAt,
+ name: t`User Apps`,
+ description: t`Manage own app preferences and accounts`,
+ Icon: IconApps,
isToolPermission: true,
isRelevantForAgents: false,
isRelevantForApiKeys: false,
diff --git a/packages/twenty-front/src/modules/settings/roles/role-permissions/permission-flags/hooks/useSettingsRolePermissionFlagConfig.ts b/packages/twenty-front/src/modules/settings/roles/role-permissions/permission-flags/hooks/useSettingsRolePermissionFlagConfig.ts
index 87953e198cd..8d6fa41e50b 100644
--- a/packages/twenty-front/src/modules/settings/roles/role-permissions/permission-flags/hooks/useSettingsRolePermissionFlagConfig.ts
+++ b/packages/twenty-front/src/modules/settings/roles/role-permissions/permission-flags/hooks/useSettingsRolePermissionFlagConfig.ts
@@ -122,8 +122,8 @@ export const useSettingsRolePermissionFlagConfig = ({
},
{
key: PermissionFlagType.APPLICATIONS,
- name: t`Applications`,
- description: t`Install and manage applications`,
+ name: t`Workspace Apps`,
+ description: t`Install and manage workspace apps`,
Icon: IconApps,
isRelevantForAgents: true,
isRelevantForApiKeys: true,
diff --git a/packages/twenty-front/src/modules/side-panel/pages/__stories__/SidePanelComposerPages.stories.tsx b/packages/twenty-front/src/modules/side-panel/pages/__stories__/SidePanelComposerPages.stories.tsx
index 21d88bb49b1..06a1a7de32f 100644
--- a/packages/twenty-front/src/modules/side-panel/pages/__stories__/SidePanelComposerPages.stories.tsx
+++ b/packages/twenty-front/src/modules/side-panel/pages/__stories__/SidePanelComposerPages.stories.tsx
@@ -325,7 +325,7 @@ export const CalendarEventWithoutAccountPermission: Story = {
expect(
await canvas.findByText(
- 'Ask a workspace admin for the Sync Account permission to connect a calendar account.',
+ 'Ask a workspace admin for the User Apps permission to connect a calendar account.',
),
).toBeVisible();
expect(
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionCreateCalendarEvent.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionCreateCalendarEvent.tsx
index 8b7e4e2eae9..866e6d40724 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionCreateCalendarEvent.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionCreateCalendarEvent.tsx
@@ -136,7 +136,7 @@ export const WorkflowEditActionCreateCalendarEvent = ({
description={
hasConnectedAccountsPermission
? t`This account is connected, but we don't have permission to create calendar events on your behalf yet. You'll be redirected to approve this access.`
- : t`Ask a workspace admin for the Sync Account permission to reconnect this account.`
+ : t`Ask a workspace admin for the User Apps permission to reconnect this account.`
}
action={
hasConnectedAccountsPermission ? (
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionEmailBase.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionEmailBase.tsx
index abf54598578..ec555a4ec7a 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionEmailBase.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionEmailBase.tsx
@@ -261,7 +261,7 @@ export const WorkflowEditActionEmailBase = ({
description={
hasConnectedAccountsPermission
? t`This account is connected, but we don't have permission to draft emails on your behalf yet. You'll be redirected to approve this access.`
- : t`Ask a workspace admin for the Sync Account permission to reconnect this account.`
+ : t`Ask a workspace admin for the User Apps permission to reconnect this account.`
}
action={
hasConnectedAccountsPermission ? (
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/__stories__/WorkflowEditActionEmailBase.stories.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/__stories__/WorkflowEditActionEmailBase.stories.tsx
index e8cae064e53..07f98d09657 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/__stories__/WorkflowEditActionEmailBase.stories.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/__stories__/WorkflowEditActionEmailBase.stories.tsx
@@ -399,7 +399,7 @@ export const DraftEmailMissingScopesWithoutPermission: Story = {
expect(
await canvas.findByText(
- 'Ask a workspace admin for the Sync Account permission to reconnect this account.',
+ 'Ask a workspace admin for the User Apps permission to reconnect this account.',
),
).toBeVisible();
expect(
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/2-50-upgrade-version-command.module.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/2-50-upgrade-version-command.module.ts
index c1d16eab7e5..9d2f5e22b62 100644
--- a/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/2-50-upgrade-version-command.module.ts
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/2-50-upgrade-version-command.module.ts
@@ -4,6 +4,7 @@ import { WorkspaceIteratorModule } from 'src/database/commands/command-runners/w
import { BackfillMemberRoleUniversalIdentifierCommand } from 'src/database/commands/upgrade-version-command/2-50/2-50-workspace-command-1792413669590-backfill-member-role-universal-identifier.command';
import { AddTimelineActivityLinkedRecordIdIndexCommand } from 'src/database/commands/upgrade-version-command/2-50/2-50-workspace-command-1792423420000-add-timeline-activity-linked-record-id-index.command';
import { WrapBareSelectFilterValuesCommand } from 'src/database/commands/upgrade-version-command/2-50/2-50-workspace-command-1792423785749-wrap-bare-select-filter-values.command';
+import { RelabelAppPermissionFlagsCommand } from 'src/database/commands/upgrade-version-command/2-50/2-50-workspace-command-1792429840509-relabel-app-permission-flags.command';
import { ApplicationModule } from 'src/engine/core-modules/application/application.module';
import { RoleModule } from 'src/engine/metadata-modules/role/role.module';
import { WorkspaceSchemaManagerModule } from 'src/engine/twenty-orm/workspace-schema-manager/workspace-schema-manager.module';
@@ -23,6 +24,7 @@ import { WorkspaceMigrationModule } from 'src/engine/workspace-manager/workspace
BackfillMemberRoleUniversalIdentifierCommand,
AddTimelineActivityLinkedRecordIdIndexCommand,
WrapBareSelectFilterValuesCommand,
+ RelabelAppPermissionFlagsCommand,
],
})
export class V2_50_UpgradeVersionCommandModule {}
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/2-50-workspace-command-1792429840509-relabel-app-permission-flags.command.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/2-50-workspace-command-1792429840509-relabel-app-permission-flags.command.ts
new file mode 100644
index 00000000000..4c8c66dc060
--- /dev/null
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/2-50-workspace-command-1792429840509-relabel-app-permission-flags.command.ts
@@ -0,0 +1,94 @@
+import { Command } from 'nest-commander';
+import { TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER } from 'twenty-shared/application';
+import { isNonEmptyArray } from 'twenty-shared/utils';
+
+import { ProvisionedWorkspaceCommandRunner } from 'src/database/commands/command-runners/provisioned-workspace.command-runner';
+import { WorkspaceIteratorService } from 'src/database/commands/command-runners/workspace-iterator.service';
+import { type RunOnWorkspaceArgs } from 'src/database/commands/command-runners/workspace.command-runner';
+import { buildPermissionFlagRelabelUpdates } from 'src/database/commands/upgrade-version-command/2-50/utils/build-permission-flag-relabel-updates.util';
+import { RegisteredWorkspaceCommand } from 'src/engine/core-modules/upgrade/decorators/registered-workspace-command.decorator';
+import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';
+import { WorkspaceMigrationBuilderException } from 'src/engine/workspace-manager/workspace-migration/exceptions/workspace-migration-builder-exception';
+import { WorkspaceMigrationValidateBuildAndRunService } from 'src/engine/workspace-manager/workspace-migration/services/workspace-migration-validate-build-and-run-service';
+
+@RegisteredWorkspaceCommand('2.50.0', 1792429840509)
+@Command({
+ name: 'upgrade:2-50:relabel-app-permission-flags',
+ description:
+ 'Rename the Applications permission flag to Workspace Apps and the Sync Account permission flag to User Apps in existing workspaces',
+})
+export class RelabelAppPermissionFlagsCommand extends ProvisionedWorkspaceCommandRunner {
+ constructor(
+ protected readonly workspaceIteratorService: WorkspaceIteratorService,
+ private readonly workspaceCacheService: WorkspaceCacheService,
+ private readonly workspaceMigrationValidateBuildAndRunService: WorkspaceMigrationValidateBuildAndRunService,
+ ) {
+ super(workspaceIteratorService);
+ }
+
+ override async runOnWorkspace(args: RunOnWorkspaceArgs): Promise<void> {
+ await this.up(args);
+ }
+
+ async up(args: RunOnWorkspaceArgs): Promise<void> {
+ await this.relabel({ ...args, direction: 'up' });
+ }
+
+ async down(args: RunOnWorkspaceArgs): Promise<void> {
+ await this.relabel({ ...args, direction: 'down' });
+ }
+
+ private async relabel({
+ workspaceId,
+ options,
+ direction,
+ }: RunOnWorkspaceArgs & { direction: 'up' | 'down' }): Promise<void> {
+ const { flatPermissionFlagMaps } =
+ await this.workspaceCacheService.getOrRecompute(workspaceId, [
+ 'flatPermissionFlagMaps',
+ ]);
+
+ const permissionFlagsToUpdate = buildPermissionFlagRelabelUpdates({
+ flatPermissionFlagsByUniversalIdentifier:
+ flatPermissionFlagMaps.byUniversalIdentifier,
+ now: new Date().toISOString(),
+ direction,
+ });
+
+ if (!isNonEmptyArray(permissionFlagsToUpdate)) {
+ return;
+ }
+
+ this.logger.log(
+ `${options.dryRun ? '[DRY RUN] ' : ''}Workspace ${workspaceId}: relabeling ${permissionFlagsToUpdate.length} permission flag(s)`,
+ );
+
+ if (options.dryRun) {
+ return;
+ }
+
+ const result =
+ await this.workspaceMigrationValidateBuildAndRunService.validateBuildAndRunLegacyWorkspaceMigration(
+ {
+ workspaceId,
+ isSystemBuild: true,
+ applicationUniversalIdentifier:
+ TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER,
+ allFlatEntityOperationByMetadataName: {
+ permissionFlag: {
+ flatEntityToCreate: [],
+ flatEntityToDelete: [],
+ flatEntityToUpdate: permissionFlagsToUpdate,
+ },
+ },
+ },
+ );
+
+ if (result.status === 'fail') {
+ throw new WorkspaceMigrationBuilderException(
+ result,
+ `Failed to relabel the app permission flags for workspace ${workspaceId}`,
+ );
+ }
+ }
+}
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/utils/__tests__/build-permission-flag-relabel-updates.util.spec.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/utils/__tests__/build-permission-flag-relabel-updates.util.spec.ts
new file mode 100644
index 00000000000..5cd75d384a0
--- /dev/null
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/utils/__tests__/build-permission-flag-relabel-updates.util.spec.ts
@@ -0,0 +1,188 @@
+import { SystemPermissionFlag } from 'twenty-shared/constants';
+import { isDefined } from 'twenty-shared/utils';
+
+import { buildPermissionFlagRelabelUpdates } from 'src/database/commands/upgrade-version-command/2-50/utils/build-permission-flag-relabel-updates.util';
+import { type FlatPermissionFlag } from 'src/engine/metadata-modules/flat-permission-flag/types/flat-permission-flag.type';
+import { computeTwentyStandardApplicationAllFlatEntityMaps } from 'src/engine/workspace-manager/twenty-standard-application/utils/twenty-standard-application-all-flat-entity-maps.constant';
+
+const NOW = '2026-10-14T12:00:00.000Z';
+
+const PREVIOUS_PRESENTATIONS = {
+ [SystemPermissionFlag.APPLICATIONS]: {
+ label: 'Applications',
+ description: 'Install and manage applications',
+ icon: 'IconApps',
+ },
+ [SystemPermissionFlag.CONNECTED_ACCOUNTS]: {
+ label: 'Sync Account',
+ description: 'Sync email and calendar accounts',
+ icon: 'IconAt',
+ },
+};
+
+const NEXT_PRESENTATIONS = {
+ [SystemPermissionFlag.APPLICATIONS]: {
+ label: 'Workspace Apps',
+ description: 'Install and manage workspace apps',
+ icon: 'IconApps',
+ },
+ [SystemPermissionFlag.CONNECTED_ACCOUNTS]: {
+ label: 'User Apps',
+ description: 'Manage own app preferences and accounts',
+ icon: 'IconApps',
+ },
+};
+
+const { allFlatEntityMaps } = computeTwentyStandardApplicationAllFlatEntityMaps(
+ {
+ now: '2026-10-13T12:00:00.000Z',
+ workspaceId: '20202020-1111-4111-8111-111111111111',
+ twentyStandardApplicationId: '20202020-2222-4222-8222-222222222222',
+ },
+);
+
+const getStandardPermissionFlag = (
+ universalIdentifier: string,
+): FlatPermissionFlag => {
+ const permissionFlag =
+ allFlatEntityMaps.flatPermissionFlagMaps.byUniversalIdentifier[
+ universalIdentifier
+ ];
+
+ if (!isDefined(permissionFlag)) {
+ throw new Error(`Standard permission flag ${universalIdentifier} missing`);
+ }
+
+ return permissionFlag;
+};
+
+const buildPermissionFlagsByUniversalIdentifier = (
+ presentations: typeof PREVIOUS_PRESENTATIONS,
+) =>
+ Object.fromEntries(
+ Object.entries(presentations).map(([universalIdentifier, presentation]) => [
+ universalIdentifier,
+ {
+ ...getStandardPermissionFlag(universalIdentifier),
+ ...presentation,
+ },
+ ]),
+ );
+
+describe('buildPermissionFlagRelabelUpdates', () => {
+ it('matches the standard application permission flags', () => {
+ for (const [universalIdentifier, presentation] of Object.entries(
+ NEXT_PRESENTATIONS,
+ )) {
+ const { label, description, icon } =
+ getStandardPermissionFlag(universalIdentifier);
+
+ expect({ label, description, icon }).toEqual(presentation);
+ }
+ });
+
+ it('relabels Applications and Sync Account on up', () => {
+ const updates = buildPermissionFlagRelabelUpdates({
+ flatPermissionFlagsByUniversalIdentifier:
+ buildPermissionFlagsByUniversalIdentifier(PREVIOUS_PRESENTATIONS),
+ now: NOW,
+ direction: 'up',
+ });
+
+ expect(
+ updates.map(({ universalIdentifier, label, description, icon }) => ({
+ universalIdentifier,
+ label,
+ description,
+ icon,
+ })),
+ ).toEqual([
+ {
+ universalIdentifier: SystemPermissionFlag.APPLICATIONS,
+ label: 'Workspace Apps',
+ description: 'Install and manage workspace apps',
+ icon: 'IconApps',
+ },
+ {
+ universalIdentifier: SystemPermissionFlag.CONNECTED_ACCOUNTS,
+ label: 'User Apps',
+ description: 'Manage own app preferences and accounts',
+ icon: 'IconApps',
+ },
+ ]);
+ expect(updates.every(({ updatedAt }) => updatedAt === NOW)).toBe(true);
+ });
+
+ it('restores the previous labels on down', () => {
+ const updates = buildPermissionFlagRelabelUpdates({
+ flatPermissionFlagsByUniversalIdentifier:
+ buildPermissionFlagsByUniversalIdentifier(NEXT_PRESENTATIONS),
+ now: NOW,
+ direction: 'down',
+ });
+
+ expect(
+ updates.map(({ label, description, icon }) => ({
+ label,
+ description,
+ icon,
+ })),
+ ).toEqual([
+ {
+ label: 'Applications',
+ description: 'Install and manage applications',
+ icon: 'IconApps',
+ },
+ {
+ label: 'Sync Account',
+ description: 'Sync email and calendar accounts',
+ icon: 'IconAt',
+ },
+ ]);
+ });
+
+ it('skips permission flags already relabeled', () => {
+ expect(
+ buildPermissionFlagRelabelUpdates({
+ flatPermissionFlagsByUniversalIdentifier:
+ buildPermissionFlagsByUniversalIdentifier(NEXT_PRESENTATIONS),
+ now: NOW,
+ direction: 'up',
+ }),
+ ).toEqual([]);
+ });
+
+ it('skips permission flags owned by another application', () => {
+ const permissionFlagsByUniversalIdentifier =
+ buildPermissionFlagsByUniversalIdentifier(PREVIOUS_PRESENTATIONS);
+
+ expect(
+ buildPermissionFlagRelabelUpdates({
+ flatPermissionFlagsByUniversalIdentifier: Object.fromEntries(
+ Object.entries(permissionFlagsByUniversalIdentifier).map(
+ ([universalIdentifier, permissionFlag]) => [
+ universalIdentifier,
+ {
+ ...permissionFlag,
+ applicationUniversalIdentifier:
+ '20202020-3333-4333-8333-333333333333',
+ },
+ ],
+ ),
+ ),
+ now: NOW,
+ direction: 'up',
+ }),
+ ).toEqual([]);
+ });
+
+ it('skips workspaces without the permission flags', () => {
+ expect(
+ buildPermissionFlagRelabelUpdates({
+ flatPermissionFlagsByUniversalIdentifier: {},
+ now: NOW,
+ direction: 'up',
+ }),
+ ).toEqual([]);
+ });
+});
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/utils/build-permission-flag-relabel-updates.util.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/utils/build-permission-flag-relabel-updates.util.ts
new file mode 100644
index 00000000000..5aa7437e38b
--- /dev/null
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/utils/build-permission-flag-relabel-updates.util.ts
@@ -0,0 +1,82 @@
+import { TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER } from 'twenty-shared/application';
+import { SystemPermissionFlag } from 'twenty-shared/constants';
+import { isDefined } from 'twenty-shared/utils';
+
+import { type FlatPermissionFlag } from 'src/engine/metadata-modules/flat-permission-flag/types/flat-permission-flag.type';
+
+type PermissionFlagPresentation = Pick<
+ FlatPermissionFlag,
+ 'label' | 'description' | 'icon'
+>;
+
+type PermissionFlagRelabel = {
+ universalIdentifier: string;
+ previous: PermissionFlagPresentation;
+ next: PermissionFlagPresentation;
+};
+
+const PERMISSION_FLAG_RELABELS: PermissionFlagRelabel[] = [
+ {
+ universalIdentifier: SystemPermissionFlag.APPLICATIONS,
+ previous: {
+ label: 'Applications',
+ description: 'Install and manage applications',
+ icon: 'IconApps',
+ },
+ next: {
+ label: 'Workspace Apps',
+ description: 'Install and manage workspace apps',
+ icon: 'IconApps',
+ },
+ },
+ {
+ universalIdentifier: SystemPermissionFlag.CONNECTED_ACCOUNTS,
+ previous: {
+ label: 'Sync Account',
+ description: 'Sync email and calendar accounts',
+ icon: 'IconAt',
+ },
+ next: {
+ label: 'User Apps',
+ description: 'Manage own app preferences and accounts',
+ icon: 'IconApps',
+ },
+ },
+];
+
+export const buildPermissionFlagRelabelUpdates = ({
+ flatPermissionFlagsByUniversalIdentifier,
+ now,
+ direction,
+}: {
+ flatPermissionFlagsByUniversalIdentifier: Record<
+ string,
+ FlatPermissionFlag | undefined
+ >;
+ now: string;
+ direction: 'up' | 'down';
+}): FlatPermissionFlag[] =>
+ PERMISSION_FLAG_RELABELS.flatMap(({ universalIdentifier, previous, next }) => {
+ const permissionFlag =
+ flatPermissionFlagsByUniversalIdentifier[universalIdentifier];
+
+ if (
+ !isDefined(permissionFlag) ||
+ permissionFlag.applicationUniversalIdentifier !==
+ TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER
+ ) {
+ return [];
+ }
+
+ const target = direction === 'up' ? next : previous;
+
+ if (
+ permissionFlag.label === target.label &&
+ permissionFlag.description === target.description &&
+ permissionFlag.icon === target.icon
+ ) {
+ return [];
+ }
+
+ return [{ ...permissionFlag, ...target, updatedAt: now }];
+ });
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-preferences/application-preferences.module.ts b/packages/twenty-server/src/engine/core-modules/application/application-preferences/application-preferences.module.ts
index 69af43d7f10..f3d64f32247 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-preferences/application-preferences.module.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-preferences/application-preferences.module.ts
@@ -4,12 +4,14 @@ import { ApplicationPreferencesResolver } from 'src/engine/core-modules/applicat
import { ApplicationPreferencesService } from 'src/engine/core-modules/application/application-preferences/application-preferences.service';
import { ApplicationVariableEntityModule } from 'src/engine/core-modules/application/application-variable/application-variable.module';
import { ApplicationModule } from 'src/engine/core-modules/application/application.module';
+import { PermissionsModule } from 'src/engine/metadata-modules/permissions/permissions.module';
import { WorkspaceCacheModule } from 'src/engine/workspace-cache/workspace-cache.module';
@Module({
imports: [
ApplicationModule,
ApplicationVariableEntityModule,
+ PermissionsModule,
WorkspaceCacheModule,
],
providers: [ApplicationPreferencesService, ApplicationPreferencesResolver],
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-preferences/application-preferences.resolver.ts b/packages/twenty-server/src/engine/core-modules/application/application-preferences/application-preferences.resolver.ts
index 428208b4845..e62bf3736e4 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-preferences/application-preferences.resolver.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-preferences/application-preferences.resolver.ts
@@ -1,6 +1,8 @@
import { UseFilters, UseGuards } from '@nestjs/common';
import { Query } from '@nestjs/graphql';
+import { PermissionFlagType } from 'twenty-shared/constants';
+
import { MetadataResolver } from 'src/engine/api/graphql/graphql-config/decorators/metadata-resolver.decorator';
import { ApplicationPreferencesService } from 'src/engine/core-modules/application/application-preferences/application-preferences.service';
import { ApplicationPreferencesDTO } from 'src/engine/core-modules/application/application-preferences/dtos/application-preferences.dto';
@@ -9,7 +11,7 @@ import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.ent
import { AuthUserWorkspaceId } from 'src/engine/decorators/auth/auth-user-workspace-id.decorator';
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
import { AuthPrincipalGuard } from 'src/engine/guards/auth-principal.guard';
-import { NoPermissionGuard } from 'src/engine/guards/no-permission.guard';
+import { SettingsPermissionGuard } from 'src/engine/guards/settings-permission.guard';
@UseGuards(
AuthPrincipalGuard({
@@ -23,7 +25,7 @@ import { NoPermissionGuard } from 'src/engine/guards/no-permission.guard';
oauthClient: false,
application: false,
}),
- NoPermissionGuard,
+ SettingsPermissionGuard(PermissionFlagType.CONNECTED_ACCOUNTS),
)
@MetadataResolver()
@UseFilters(AuthGraphqlApiExceptionFilter)
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-variable/user-application-variable-value.resolver.ts b/packages/twenty-server/src/engine/core-modules/application/application-variable/user-application-variable-value.resolver.ts
index c61d64b4d9e..7d437859f59 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-variable/user-application-variable-value.resolver.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-variable/user-application-variable-value.resolver.ts
@@ -1,6 +1,8 @@
import { UseFilters, UseGuards } from '@nestjs/common';
import { Mutation, Query } from '@nestjs/graphql';
+import { PermissionFlagType } from 'twenty-shared/constants';
+
import { MetadataResolver } from 'src/engine/api/graphql/graphql-config/decorators/metadata-resolver.decorator';
import { ApplicationExceptionFilter } from 'src/engine/core-modules/application/application-exception-filter';
import { ApplicationVariableEntityExceptionFilter } from 'src/engine/core-modules/application/application-variable/application-variable-exception-filter';
@@ -17,6 +19,7 @@ import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorat
import { NoPermissionGuard } from 'src/engine/guards/no-permission.guard';
import { AuthPrincipalGuard } from 'src/engine/guards/auth-principal.guard';
import { ApplicationTargetGuard } from 'src/engine/guards/application-target.guard';
+import { SettingsPermissionGuard } from 'src/engine/guards/settings-permission.guard';
@UseGuards(
AuthPrincipalGuard({
@@ -56,6 +59,7 @@ export class UserApplicationVariableValueResolver {
oauthClient: false,
application: { withUser: true, withoutUser: false },
}),
+ SettingsPermissionGuard(PermissionFlagType.CONNECTED_ACCOUNTS),
ApplicationTargetGuard,
)
async updateMyUserApplicationVariable(
diff --git a/packages/twenty-server/src/engine/metadata-modules/connected-account/utils/__tests__/get-connected-account-administration-permission-flag.util.spec.ts b/packages/twenty-server/src/engine/metadata-modules/connected-account/utils/__tests__/get-connected-account-administration-permission-flag.util.spec.ts
index 04766261582..a785ea771b2 100644
--- a/packages/twenty-server/src/engine/metadata-modules/connected-account/utils/__tests__/get-connected-account-administration-permission-flag.util.spec.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/connected-account/utils/__tests__/get-connected-account-administration-permission-flag.util.spec.ts
@@ -4,7 +4,7 @@ import { ConnectedAccountProvider } from 'twenty-shared/types';
import { getConnectedAccountAdministrationPermissionFlag } from 'src/engine/metadata-modules/connected-account/utils/get-connected-account-administration-permission-flag.util';
describe('getConnectedAccountAdministrationPermissionFlag', () => {
- it('requires the Applications permission for an app connection', () => {
+ it('requires the Workspace Apps permission for an app connection', () => {
expect(
getConnectedAccountAdministrationPermissionFlag(
ConnectedAccountProvider.APP,
diff --git a/packages/twenty-server/src/engine/metadata-modules/permission-flag/constants/standard-permission-flag-definitions.constant.ts b/packages/twenty-server/src/engine/metadata-modules/permission-flag/constants/standard-permission-flag-definitions.constant.ts
index 7302629ddf2..dcdad1dc094 100644
--- a/packages/twenty-server/src/engine/metadata-modules/permission-flag/constants/standard-permission-flag-definitions.constant.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/permission-flag/constants/standard-permission-flag-definitions.constant.ts
@@ -70,8 +70,8 @@ const STANDARD_PERMISSION_FLAG_METADATA: Record<
icon: 'IconShield',
},
[PermissionFlagType.APPLICATIONS]: {
- label: 'Applications',
- description: 'Install and manage applications',
+ label: 'Workspace Apps',
+ description: 'Install and manage workspace apps',
icon: 'IconApps',
},
[PermissionFlagType.MARKETPLACE_APPS]: {
@@ -145,9 +145,9 @@ const STANDARD_PERMISSION_FLAG_METADATA: Record<
icon: 'IconFileExport',
},
[PermissionFlagType.CONNECTED_ACCOUNTS]: {
- label: 'Sync Account',
- description: 'Sync email and calendar accounts',
- icon: 'IconAt',
+ label: 'User Apps',
+ description: 'Manage own app preferences and accounts',
+ icon: 'IconApps',
},
[PermissionFlagType.PROFILE_INFORMATION]: {
label: 'Edit Profile',
diff --git a/packages/twenty-server/test/integration/metadata/suites/application/failing-application-preferences.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/application/failing-application-preferences.integration-spec.ts
index c98210e19d0..f6424f4716a 100644
--- a/packages/twenty-server/test/integration/metadata/suites/application/failing-application-preferences.integration-spec.ts
+++ b/packages/twenty-server/test/integration/metadata/suites/application/failing-application-preferences.integration-spec.ts
@@ -1,11 +1,21 @@
+import { randomUUID } from 'crypto';
+
import { expectOneNotInternalServerErrorSnapshot } from 'test/integration/graphql/utils/expect-one-not-internal-server-error-snapshot.util';
+import { expectPermissionDenied } from 'test/integration/metadata/suites/application/utils/expect-permission-denied.util';
import { cleanupApplicationAndAppRegistration } from 'test/integration/metadata/suites/application/utils/cleanup-application-and-app-registration.util';
import { myApplicationPreferences } from 'test/integration/metadata/suites/application/utils/my-application-preferences.util';
import {
type ApplicationWithVariable,
setupApplicationWithVariable,
} from 'test/integration/metadata/suites/application/utils/setup-application-with-variable.util';
+import { createOneRole } from 'test/integration/metadata/suites/role/utils/create-one-role.util';
+import { deleteOneRole } from 'test/integration/metadata/suites/role/utils/delete-one-role.util';
+import { findOneRoleByLabel } from 'test/integration/metadata/suites/role/utils/find-one-role-by-label.util';
+import { updateWorkspaceMemberRole } from 'test/integration/metadata/suites/role/utils/update-workspace-member-role.util';
import { generateAppleAdminApplicationTokenPair } from 'test/integration/utils/generate-apple-admin-application-token-pair.util';
+import { jestExpectToBeDefined } from 'test/utils/jest-expect-to-be-defined.util.test';
+
+import { WORKSPACE_MEMBER_DATA_SEED_IDS } from 'src/engine/workspace-manager/dev-seeder/data/constants/workspace-member-data-seeds.constant';
describe('My application preferences should fail', () => {
let application: ApplicationWithVariable;
@@ -52,4 +62,82 @@ describe('My application preferences should fail', () => {
expectOneNotInternalServerErrorSnapshot({ errors });
});
+
+ it('should refuse a guest whose role lacks the User Apps permission', async () => {
+ const { data, errors } = await myApplicationPreferences({
+ input: {},
+ token: APPLE_PHIL_GUEST_ACCESS_TOKEN,
+ expectToFail: true,
+ });
+
+ expect(data).toBeNull();
+ expectPermissionDenied(errors);
+ });
+
+ describe('for a member whose role lacks the User Apps permission', () => {
+ let memberRoleId: string;
+ let customRoleId: string;
+
+ beforeAll(async () => {
+ const memberRole = await findOneRoleByLabel({ label: 'Member' });
+
+ memberRoleId = memberRole.id;
+
+ const { data } = await createOneRole({
+ expectToFail: false,
+ input: {
+ label: `Application preferences denied role ${randomUUID()}`,
+ description: 'Member role without the User Apps permission',
+ icon: 'IconUser',
+ canUpdateAllSettings: false,
+ canAccessAllTools: false,
+ canReadAllObjectRecords: true,
+ canUpdateAllObjectRecords: true,
+ canSoftDeleteAllObjectRecords: false,
+ canDestroyAllObjectRecords: false,
+ canBeAssignedToUsers: true,
+ canBeAssignedToAgents: false,
+ canBeAssignedToApiKeys: false,
+ },
+ });
+
+ const createdRoleId = data?.createOneRole?.id;
+
+ jestExpectToBeDefined(createdRoleId);
+ customRoleId = createdRoleId;
+
+ await updateWorkspaceMemberRole({
+ input: {
+ workspaceMemberId: WORKSPACE_MEMBER_DATA_SEED_IDS.JONY,
+ roleId: customRoleId,
+ },
+ expectToFail: false,
+ });
+ });
+
+ afterAll(async () => {
+ await updateWorkspaceMemberRole({
+ input: {
+ workspaceMemberId: WORKSPACE_MEMBER_DATA_SEED_IDS.JONY,
+ roleId: memberRoleId,
+ },
+ expectToFail: false,
+ });
+ await deleteOneRole({
+ expectToFail: false,
+ input: { idToDelete: customRoleId },
+ });
+ });
+
+ it('should refuse the member', async () => {
+ const { data, errors } = await myApplicationPreferences({
+ input: {},
+ token: APPLE_JONY_MEMBER_ACCESS_TOKEN,
+ expectToFail: true,
+ });
+
+ expect(data).toBeNull();
+ expectPermissionDenied(errors);
+ });
+ });
});
diff --git a/packages/twenty-server/test/integration/metadata/suites/application/failing-user-application-variable-values.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/application/failing-user-application-variable-values.integration-spec.ts
index 0fbba0ddf2f..b3922fcd166 100644
--- a/packages/twenty-server/test/integration/metadata/suites/application/failing-user-application-variable-values.integration-spec.ts
+++ b/packages/twenty-server/test/integration/metadata/suites/application/failing-user-application-variable-values.integration-spec.ts
@@ -1,4 +1,5 @@
import { expectOneNotInternalServerErrorSnapshot } from 'test/integration/graphql/utils/expect-one-not-internal-server-error-snapshot.util';
+import { expectPermissionDenied } from 'test/integration/metadata/suites/application/utils/expect-permission-denied.util';
import { myUserApplicationVariables } from 'test/integration/metadata/suites/application/utils/my-user-application-variables.util';
import { cleanupApplicationAndAppRegistration } from 'test/integration/metadata/suites/application/utils/cleanup-application-and-app-registration.util';
import {
@@ -8,9 +9,11 @@ import {
import { updateMyUserApplicationVariable } from 'test/integration/metadata/suites/application/utils/update-my-user-application-variable.util';
import { generateAppleAdminApplicationTokenPair } from 'test/integration/utils/generate-apple-admin-application-token-pair.util';
import { generateApplicationTokenPair } from 'test/integration/utils/generate-application-token-pair.util';
+import { SystemPermissionFlag } from 'twenty-shared/constants';
import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';
import { USER_WORKSPACE_DATA_SEED_IDS } from 'src/engine/workspace-manager/dev-seeder/core/utils/seed-user-workspaces.util';
+import { USER_DATA_SEED_IDS } from 'src/engine/workspace-manager/dev-seeder/core/utils/seed-users.util';
const NOT_INSTALLED_APPLICATION_UNIVERSAL_IDENTIFIER =
'8f7c1e0a-4b2d-4c3e-9a1f-0d2e3c4b5a69';
@@ -19,8 +22,10 @@ describe('User application variable values should fail', () => {
let userVariableApplication: ApplicationWithVariable;
let otherUserVariableApplication: ApplicationWithVariable;
let workspaceVariableApplication: ApplicationWithVariable;
+ let withoutConnectedAccountsApplication: ApplicationWithVariable;
let janeApplicationToken: string;
let applicationToken: string;
+ let jonyWithoutConnectedAccountsApplicationToken: string;
beforeAll(async () => {
userVariableApplication = await setupApplicationWithVariable({
@@ -37,8 +42,18 @@ describe('User application variable values should fail', () => {
name: 'Workspace Variable Application',
variableKey: 'RECORD_ALL_MEETINGS',
});
+ withoutConnectedAccountsApplication = await setupApplicationWithVariable({
+ name: 'User Variable Application Without Connected Accounts',
+ variableKey: 'RECORD_MY_CALLS',
+ variableScope: 'USER',
+ permissionFlagUniversalIdentifiers: [SystemPermissionFlag.APPLICATIONS],
+ });
- const [janeApplicationTokenPair, applicationTokenPair] = await Promise.all([
+ const [
+ janeApplicationTokenPair,
+ applicationTokenPair,
+ jonyWithoutConnectedAccountsApplicationTokenPair,
+ ] = await Promise.all([
generateAppleAdminApplicationTokenPair({
applicationId: userVariableApplication.id,
}),
@@ -46,11 +61,20 @@ describe('User application variable values should fail', () => {
workspaceId: SEED_APPLE_WORKSPACE_ID,
applicationId: userVariableApplication.id,
}),
+ generateApplicationTokenPair({
+ workspaceId: SEED_APPLE_WORKSPACE_ID,
+ applicationId: withoutConnectedAccountsApplication.id,
+ userId: USER_DATA_SEED_IDS.JONY,
+ userWorkspaceId: USER_WORKSPACE_DATA_SEED_IDS.JONY,
+ }),
]);
janeApplicationToken =
janeApplicationTokenPair.applicationAccessToken.token;
applicationToken = applicationTokenPair.applicationAccessToken.token;
+ jonyWithoutConnectedAccountsApplicationToken =
+ jonyWithoutConnectedAccountsApplicationTokenPair.applicationAccessToken
+ .token;
}, 120000);
afterAll(async () => {
@@ -66,6 +90,10 @@ describe('User application variable values should fail', () => {
applicationUniversalIdentifier:
workspaceVariableApplication.universalIdentifier,
});
+ await cleanupApplicationAndAppRegistration({
+ applicationUniversalIdentifier:
+ withoutConnectedAccountsApplication.universalIdentifier,
+ });
});
it('should refuse to set a member value on a workspace variable', async () => {
@@ -140,6 +168,38 @@ describe('User application variable values should fail', () => {
expectOneNotInternalServerErrorSnapshot({ errors });
});
+ it('should refuse a guest whose role lacks the User Apps permission', async () => {
+ const { data, errors } = await updateMyUserApplicationVariable({
+ input: {
+ applicationUniversalIdentifier:
+ userVariableApplication.universalIdentifier,
+ key: userVariableApplication.variableKey,
+ value: 'phil',
+ },
+ token: APPLE_PHIL_GUEST_ACCESS_TOKEN,
+ expectToFail: true,
+ });
+
+ expect(data).toBeNull();
+ expectPermissionDenied(errors);
+ });
+
+ it('should refuse an application token acting for a member when the application role lacks the User Apps permission', async () => {
+ const { data, errors } = await updateMyUserApplicationVariable({
+ input: {
+ applicationUniversalIdentifier:
+ withoutConnectedAccountsApplication.universalIdentifier,
+ key: withoutConnectedAccountsApplication.variableKey,
+ value: 'jony-from-app',
+ },
+ token: jonyWithoutConnectedAccountsApplicationToken,
+ expectToFail: true,
+ });
+
+ expect(data).toBeNull();
+ expectPermissionDenied(errors);
+ });
+
it('should refuse to list every member value from a session', async () => {
const { errors } = await myUserApplicationVariables({
input: {},
diff --git a/packages/twenty-server/test/integration/metadata/suites/application/successful-application-preferences.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/application/successful-application-preferences.integration-spec.ts
index 35232584f32..c8139b93a09 100644
--- a/packages/twenty-server/test/integration/metadata/suites/application/successful-application-preferences.integration-spec.ts
+++ b/packages/twenty-server/test/integration/metadata/suites/application/successful-application-preferences.integration-spec.ts
@@ -162,7 +162,7 @@ describe('My application preferences should succeed', () => {
});
});
- it('should give a member without the applications permission the user settings and defaults of every application that has some', async () => {
+ it('should give a member without the Workspace Apps permission the user settings and defaults of every application that has some', async () => {
const { data } = await myApplicationPreferences({
input: {},
token: APPLE_JONY_MEMBER_ACCESS_TOKEN,
diff --git a/packages/twenty-server/test/integration/metadata/suites/application/successful-user-application-variable-values.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/application/successful-user-application-variable-values.integration-spec.ts
index 5ff1829ce2b..a17af80ecff 100644
--- a/packages/twenty-server/test/integration/metadata/suites/application/successful-user-application-variable-values.integration-spec.ts
+++ b/packages/twenty-server/test/integration/metadata/suites/application/successful-user-application-variable-values.integration-spec.ts
@@ -10,6 +10,7 @@ import { generateApplicationTokenPair } from 'test/integration/utils/generate-ap
import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';
import { USER_WORKSPACE_DATA_SEED_IDS } from 'src/engine/workspace-manager/dev-seeder/core/utils/seed-user-workspaces.util';
+import { USER_DATA_SEED_IDS } from 'src/engine/workspace-manager/dev-seeder/core/utils/seed-users.util';
import { WORKSPACE_MEMBER_DATA_SEED_IDS } from 'src/engine/workspace-manager/dev-seeder/data/constants/workspace-member-data-seeds.constant';
describe('User application variable values should succeed', () => {
@@ -19,6 +20,7 @@ describe('User application variable values should succeed', () => {
let applicationToken: string;
let defaultApplicationToken: string;
let janeApplicationToken: string;
+ let jonyApplicationToken: string;
beforeAll(async () => {
application = await setupApplicationWithVariable({
@@ -42,6 +44,7 @@ describe('User application variable values should succeed', () => {
applicationTokenPair,
janeApplicationTokenPair,
defaultApplicationTokenPair,
+ jonyApplicationTokenPair,
] = await Promise.all([
generateApplicationTokenPair({
workspaceId: SEED_APPLE_WORKSPACE_ID,
@@ -54,6 +57,12 @@ describe('User application variable values should succeed', () => {
workspaceId: SEED_APPLE_WORKSPACE_ID,
applicationId: defaultApplication.id,
}),
+ generateApplicationTokenPair({
+ workspaceId: SEED_APPLE_WORKSPACE_ID,
+ applicationId: application.id,
+ userId: USER_DATA_SEED_IDS.JONY,
+ userWorkspaceId: USER_WORKSPACE_DATA_SEED_IDS.JONY,
+ }),
]);
applicationToken = applicationTokenPair.applicationAccessToken.token;
@@ -61,6 +70,8 @@ describe('User application variable values should succeed', () => {
defaultApplicationTokenPair.applicationAccessToken.token;
janeApplicationToken =
janeApplicationTokenPair.applicationAccessToken.token;
+ jonyApplicationToken =
+ jonyApplicationTokenPair.applicationAccessToken.token;
}, 120000);
afterAll(async () => {
@@ -118,7 +129,7 @@ describe('User application variable values should succeed', () => {
);
});
- it('should let a member without the applications permission set their own value', async () => {
+ it('should let a member without the Workspace Apps permission set their own value', async () => {
const { data: updateData } = await updateMyUserApplicationVariable({
input: {
applicationUniversalIdentifier: application.universalIdentifier,
@@ -325,4 +336,33 @@ describe('User application variable values should succeed', () => {
]),
);
});
+
+ it('should let an application token act for a member when both their roles grant the User Apps permission', async () => {
+ const { data: updateData } = await updateMyUserApplicationVariable({
+ input: {
+ applicationUniversalIdentifier: application.universalIdentifier,
+ key: application.variableKey,
+ value: 'jony-from-app',
+ },
+ token: jonyApplicationToken,
+ expectToFail: false,
+ });
+
+ expect(updateData.updateMyUserApplicationVariable).toBe(true);
+
+ const { data } = await myUserApplicationVariables({
+ input: {},
+ token: applicationToken,
+ expectToFail: false,
+ });
+
+ const jonyValues = data.myUserApplicationVariables.find(
+ ({ userWorkspaceId }) =>
+ userWorkspaceId === USER_WORKSPACE_DATA_SEED_IDS.JONY,
+ );
+
+ expect(jonyValues?.variables).toEqual([
+ { key: application.variableKey, value: 'jony-from-app' },
+ ]);
+ });
});
diff --git a/packages/twenty-server/test/integration/metadata/suites/application/utils/expect-permission-denied.util.ts b/packages/twenty-server/test/integration/metadata/suites/application/utils/expect-permission-denied.util.ts
new file mode 100644
index 00000000000..d72a19c008a
--- /dev/null
+++ b/packages/twenty-server/test/integration/metadata/suites/application/utils/expect-permission-denied.util.ts
@@ -0,0 +1,11 @@
+import {
+ type BaseGraphQLError,
+ ErrorCode,
+} from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
+import { PermissionsExceptionMessage } from 'src/engine/metadata-modules/permissions/permissions.exception';
+
+export const expectPermissionDenied = (errors: BaseGraphQLError[]) => {
+ expect(errors).toHaveLength(1);
+ expect(errors[0].message).toBe(PermissionsExceptionMessage.PERMISSION_DENIED);
+ expect(errors[0].extensions.code).toBe(ErrorCode.FORBIDDEN);
+};
diff --git a/packages/twenty-server/test/integration/metadata/suites/application/utils/setup-application-with-variable.util.ts b/packages/twenty-server/test/integration/metadata/suites/application/utils/setup-application-with-variable.util.ts
index 03711352fde..a5d3ae96099 100644
--- a/packages/twenty-server/test/integration/metadata/suites/application/utils/setup-application-with-variable.util.ts
+++ b/packages/twenty-server/test/integration/metadata/suites/application/utils/setup-application-with-variable.util.ts
@@ -17,15 +17,18 @@ export type ApplicationWithVariable = {
variableKey: string;
};
-// Application settings components need APPLICATIONS by default; tests can
-// override the permissions to exercise narrower access.
export const setupApplicationWithVariable = async ({
name,
variableKey,
variableScope,
isSecret = false,
value = variableScope === 'USER' ? undefined : 'initial',
- permissionFlagUniversalIdentifiers = [SystemPermissionFlag.APPLICATIONS],
+ permissionFlagUniversalIdentifiers = variableScope === 'USER'
+ ? [
+ SystemPermissionFlag.APPLICATIONS,
+ SystemPermissionFlag.CONNECTED_ACCOUNTS,
+ ]
+ : [SystemPermissionFlag.APPLICATIONS],
objectPermissions = [],
}: {
name: string;
diff --git a/packages/twenty-server/test/integration/metadata/suites/connection-provider/app-connection-management-guards.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/connection-provider/app-connection-management-guards.integration-spec.ts
index 9484a853dad..ad22189f650 100644
--- a/packages/twenty-server/test/integration/metadata/suites/connection-provider/app-connection-management-guards.integration-spec.ts
+++ b/packages/twenty-server/test/integration/metadata/suites/connection-provider/app-connection-management-guards.integration-spec.ts
@@ -248,7 +248,7 @@ describe('app connection management guards (e2e)', () => {
);
});
- it('lets a member with the Applications permission reconnect a workspace-shared connection', async () => {
+ it('lets a member with the Workspace Apps permission reconnect a workspace-shared connection', async () => {
const errorMessage = await startAuthorizeAndGetErrorMessage({
reconnectingConnectedAccountId: SHARED_BY_TIM_ID,
});
@@ -257,7 +257,7 @@ describe('app connection management guards (e2e)', () => {
expect(errorMessage).not.toContain('does not have permission');
});
- it('refuses a member without the Applications permission to reconnect a workspace-shared connection', async () => {
+ it('refuses a member without the Workspace Apps permission to reconnect a workspace-shared connection', async () => {
const errorMessage = await startAuthorizeAndGetErrorMessage({
reconnectingConnectedAccountId: SHARED_BY_TIM_ID,
as: 'member',
@@ -266,7 +266,7 @@ describe('app connection management guards (e2e)', () => {
expect(errorMessage).toContain('does not have permission');
});
- it('refuses a member without the Applications permission to create a workspace-shared connection', async () => {
+ it('refuses a member without the Workspace Apps permission to create a workspace-shared connection', async () => {
const errorMessage = await startAuthorizeAndGetErrorMessage({
scope: 'WORKSPACE',
as: 'member',
@@ -275,7 +275,7 @@ describe('app connection management guards (e2e)', () => {
expect(errorMessage).toContain('does not have permission');
});
- it('refuses a member without the Applications permission to share their own private connection', async () => {
+ it('refuses a member without the Workspace Apps permission to share their own private connection', async () => {
const errorMessage = await startAuthorizeAndGetErrorMessage({
reconnectingConnectedAccountId: PRIVATE_OF_JONY_ID,
scope: 'WORKSPACE',
@@ -285,7 +285,7 @@ describe('app connection management guards (e2e)', () => {
expect(errorMessage).toContain('does not have permission');
});
- it('lets a member without the Applications permission reconnect their own private connection', async () => {
+ it('lets a member without the Workspace Apps permission reconnect their own private connection', async () => {
const errorMessage = await startAuthorizeAndGetErrorMessage({
reconnectingConnectedAccountId: PRIVATE_OF_JONY_ID,
as: 'member',