Skip to content

The open alternative to Salesforce, designed for AI.

Allow twenty standard app to access messaging items (#17659)

Mariecdaa8f1d9dae
diff --git a/packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-event/calendar-event-find-many.post-query.hook.ts b/packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-event/calendar-event-find-many.post-query.hook.ts
index be8c5e8f289..b1418753df5 100644
--- a/packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-event/calendar-event-find-many.post-query.hook.ts
+++ b/packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-event/calendar-event-find-many.post-query.hook.ts
@@ -6,6 +6,7 @@ import { WorkspaceQueryHook } from 'src/engine/api/graphql/workspace-query-runne
import { WorkspaceQueryHookType } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/types/workspace-query-hook.type';
import { type AuthContext } from 'src/engine/core-modules/auth/types/auth-context.type';
import { ForbiddenError } from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
+import { TWENTY_STANDARD_APPLICATION } from 'src/engine/workspace-manager/twenty-standard-application/constants/twenty-standard-applications';
import { ApplyCalendarEventsVisibilityRestrictionsService } from 'src/modules/calendar/common/query-hooks/calendar-event/services/apply-calendar-events-visibility-restrictions.service';
import { type CalendarEventWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event.workspace-entity';
@@ -25,10 +26,19 @@ export class CalendarEventFindManyPostQueryHook
_objectName: string,
payload: CalendarEventWorkspaceEntity[],
): Promise<void> {
- const { user, apiKey } = authContext;
-
- if (!isDefined(user) && !isDefined(apiKey)) {
- throw new ForbiddenError('User is required');
+ const { user, apiKey, application } = authContext;
+
+ const isTwentyStandardApplication =
+ isDefined(application) &&
+ application.universalIdentifier ===
+ TWENTY_STANDARD_APPLICATION.universalIdentifier;
+
+ if (
+ !isDefined(user) &&
+ !isDefined(apiKey) &&
+ !isTwentyStandardApplication
+ ) {
+ throw new ForbiddenError('Authentication is required');
}
const workspace = authContext.workspace;
diff --git a/packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-event/calendar-event-find-one.post-query.hook.ts b/packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-event/calendar-event-find-one.post-query.hook.ts
index d6bc8e16cb0..5dfcac0a9fe 100644
--- a/packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-event/calendar-event-find-one.post-query.hook.ts
+++ b/packages/twenty-server/src/modules/calendar/common/query-hooks/calendar-event/calendar-event-find-one.post-query.hook.ts
@@ -6,6 +6,7 @@ import { WorkspaceQueryHook } from 'src/engine/api/graphql/workspace-query-runne
import { WorkspaceQueryHookType } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/types/workspace-query-hook.type';
import { type AuthContext } from 'src/engine/core-modules/auth/types/auth-context.type';
import { ForbiddenError } from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
+import { TWENTY_STANDARD_APPLICATION } from 'src/engine/workspace-manager/twenty-standard-application/constants/twenty-standard-applications';
import { ApplyCalendarEventsVisibilityRestrictionsService } from 'src/modules/calendar/common/query-hooks/calendar-event/services/apply-calendar-events-visibility-restrictions.service';
import { type CalendarEventWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event.workspace-entity';
@@ -25,10 +26,19 @@ export class CalendarEventFindOnePostQueryHook
_objectName: string,
payload: CalendarEventWorkspaceEntity[],
): Promise<void> {
- const { user, apiKey } = authContext;
-
- if (!isDefined(user) && !isDefined(apiKey)) {
- throw new ForbiddenError('User is required');
+ const { user, apiKey, application } = authContext;
+
+ const isTwentyStandardApplication =
+ isDefined(application) &&
+ application.universalIdentifier ===
+ TWENTY_STANDARD_APPLICATION.universalIdentifier;
+
+ if (
+ !isDefined(user) &&
+ !isDefined(apiKey) &&
+ !isTwentyStandardApplication
+ ) {
+ throw new ForbiddenError('Authentication is required');
}
const workspace = authContext.workspace;
diff --git a/packages/twenty-server/src/modules/messaging/common/query-hooks/message/message-find-many.post-query.hook.ts b/packages/twenty-server/src/modules/messaging/common/query-hooks/message/message-find-many.post-query.hook.ts
index 294a4ba02f2..14f4ec7cc8e 100644
--- a/packages/twenty-server/src/modules/messaging/common/query-hooks/message/message-find-many.post-query.hook.ts
+++ b/packages/twenty-server/src/modules/messaging/common/query-hooks/message/message-find-many.post-query.hook.ts
@@ -6,6 +6,7 @@ import { WorkspaceQueryHook } from 'src/engine/api/graphql/workspace-query-runne
import { WorkspaceQueryHookType } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/types/workspace-query-hook.type';
import { type AuthContext } from 'src/engine/core-modules/auth/types/auth-context.type';
import { ForbiddenError } from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
+import { TWENTY_STANDARD_APPLICATION } from 'src/engine/workspace-manager/twenty-standard-application/constants/twenty-standard-applications';
import { ApplyMessagesVisibilityRestrictionsService } from 'src/modules/messaging/common/query-hooks/message/apply-messages-visibility-restrictions.service';
import { type MessageWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message.workspace-entity';
@@ -25,10 +26,19 @@ export class MessageFindManyPostQueryHook
_objectName: string,
payload: MessageWorkspaceEntity[],
): Promise<void> {
- const { user, apiKey } = authContext;
-
- if (!isDefined(user) && !isDefined(apiKey)) {
- throw new ForbiddenError('User is required');
+ const { user, apiKey, application } = authContext;
+
+ const isTwentyStandardApplication =
+ isDefined(application) &&
+ application.universalIdentifier ===
+ TWENTY_STANDARD_APPLICATION.universalIdentifier;
+
+ if (
+ !isDefined(user) &&
+ !isDefined(apiKey) &&
+ !isTwentyStandardApplication
+ ) {
+ throw new ForbiddenError('Authentication is required');
}
const workspace = authContext.workspace;
diff --git a/packages/twenty-server/src/modules/messaging/common/query-hooks/message/message-find-one.post-query.hook.ts b/packages/twenty-server/src/modules/messaging/common/query-hooks/message/message-find-one.post-query.hook.ts
index e6cf8fe4018..bdf976965b7 100644
--- a/packages/twenty-server/src/modules/messaging/common/query-hooks/message/message-find-one.post-query.hook.ts
+++ b/packages/twenty-server/src/modules/messaging/common/query-hooks/message/message-find-one.post-query.hook.ts
@@ -6,6 +6,7 @@ import { WorkspaceQueryHook } from 'src/engine/api/graphql/workspace-query-runne
import { WorkspaceQueryHookType } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/types/workspace-query-hook.type';
import { type AuthContext } from 'src/engine/core-modules/auth/types/auth-context.type';
import { ForbiddenError } from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
+import { TWENTY_STANDARD_APPLICATION } from 'src/engine/workspace-manager/twenty-standard-application/constants/twenty-standard-applications';
import { ApplyMessagesVisibilityRestrictionsService } from 'src/modules/messaging/common/query-hooks/message/apply-messages-visibility-restrictions.service';
import { type MessageWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message.workspace-entity';
@@ -25,10 +26,19 @@ export class MessageFindOnePostQueryHook
_objectName: string,
payload: MessageWorkspaceEntity[],
): Promise<void> {
- const { user, apiKey } = authContext;
-
- if (!isDefined(user) && !isDefined(apiKey)) {
- throw new ForbiddenError('User is required');
+ const { user, apiKey, application } = authContext;
+
+ const isTwentyStandardApplication =
+ isDefined(application) &&
+ application.universalIdentifier ===
+ TWENTY_STANDARD_APPLICATION.universalIdentifier;
+
+ if (
+ !isDefined(user) &&
+ !isDefined(apiKey) &&
+ !isTwentyStandardApplication
+ ) {
+ throw new ForbiddenError('Authentication is required');
}
const workspace = authContext.workspace;