From d037cdc6fd5890c6b8b1c09bfcda65b52e2c6213 Mon Sep 17 00:00:00 2001 From: montaghanmy Date: Mon, 10 Apr 2023 13:10:07 +0100 Subject: [PATCH] ref: applications/channels --- .../applications/services/applications.ts | 3 - .../services/internal-event-to-hooks.ts | 64 ------------------- .../channels/services/member/service.ts | 3 +- .../node/src/services/channels/types.ts | 4 -- .../node/src/services/global-resolver.ts | 13 ++++ 5 files changed, 14 insertions(+), 73 deletions(-) delete mode 100644 twake/backend/node/src/services/applications/services/internal-event-to-hooks.ts diff --git a/twake/backend/node/src/services/applications/services/applications.ts b/twake/backend/node/src/services/applications/services/applications.ts index 4eecdd8f..b2891be3 100644 --- a/twake/backend/node/src/services/applications/services/applications.ts +++ b/twake/backend/node/src/services/applications/services/applications.ts @@ -18,7 +18,6 @@ import SearchRepository from "../../../core/platform/services/search/repository" import assert from "assert"; import gr from "../../global-resolver"; -import { InternalToHooksProcessor } from "./internal-event-to-hooks"; export class ApplicationServiceImpl implements TwakeServiceProvider, Initializable { version: "1"; @@ -37,8 +36,6 @@ export class ApplicationServiceImpl implements TwakeServiceProvider, Initializab logger.error("Error while initializing applications service"); } - gr.platformServices.messageQueue.processor.addHandler(new InternalToHooksProcessor()); - return this; } diff --git a/twake/backend/node/src/services/applications/services/internal-event-to-hooks.ts b/twake/backend/node/src/services/applications/services/internal-event-to-hooks.ts deleted file mode 100644 index 77fe8d74..00000000 --- a/twake/backend/node/src/services/applications/services/internal-event-to-hooks.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { logger } from "../../../core/platform/framework"; -import { HookType } from "../../applications-api/types"; -import { MessageQueueHandler } from "../../../core/platform/services/message-queue/api"; -import { MessageHook } from "../../messages/types"; -import gr from "../../global-resolver"; -import { ExecutionContext } from "../../../core/platform/framework/api/crud-service"; - -export class InternalToHooksProcessor implements MessageQueueHandler { - readonly topics = { - in: "application:hook:message", - }; - - readonly options = { - unique: true, - ack: true, - queue: "application:hook:message:consumer1", - }; - - readonly name = "Application::InternalToHooksProcessor"; - - validate(_: HookType): boolean { - return true; - } - - async process(message: HookType, context?: ExecutionContext): Promise { - logger.debug(`${this.name} - Receive hook of type ${message.type}`); - - const application = await gr.services.applications.marketplaceApps.get( - { - id: message.application_id, - }, - context, - ); - - //TODO Check application access rights (hooks) - const _access = application.access; - - // Check application still exists in the company - if ( - !(await gr.services.applications.companyApps.get({ - company_id: message.company_id, - application_id: message.application_id, - id: undefined, - })) - ) { - logger.error( - `${this.name} - Application ${message.application_id} not found in company ${message.company_id}`, - ); - return; - } - - await gr.services.applications.hooks.notifyApp( - message.application_id, - null, - null, - "hook", - null, - { message }, - null, - null, - context, - ); - } -} diff --git a/twake/backend/node/src/services/channels/services/member/service.ts b/twake/backend/node/src/services/channels/services/member/service.ts index 014f19ce..f16aadbd 100644 --- a/twake/backend/node/src/services/channels/services/member/service.ts +++ b/twake/backend/node/src/services/channels/services/member/service.ts @@ -26,7 +26,6 @@ import { ChannelMemberType, ChannelVisibility, WorkspaceExecutionContext, - CompanyExecutionContext, } from "../../types"; import { Channel, ResourceEventsPayload, User } from "../../../../utils/types"; import { cloneDeep, isNil, omitBy } from "lodash"; @@ -53,7 +52,7 @@ import { WorkspacePrimaryKey } from "../../../workspaces/entities/workspace"; import gr from "../../../global-resolver"; import uuidTime from "uuid-time"; import { ChannelObject } from "../channel/types"; - +import { CompanyExecutionContext } from "../../../applications/web/types"; const USER_CHANNEL_KEYS = [ "id", "company_id", diff --git a/twake/backend/node/src/services/channels/types.ts b/twake/backend/node/src/services/channels/types.ts index 0b9e4a28..20894579 100644 --- a/twake/backend/node/src/services/channels/types.ts +++ b/twake/backend/node/src/services/channels/types.ts @@ -52,7 +52,3 @@ export type ChannelActivityNotification = { sender_name: string; body: string; }; - -export interface CompanyExecutionContext extends ExecutionContext { - company: { id: string }; -} diff --git a/twake/backend/node/src/services/global-resolver.ts b/twake/backend/node/src/services/global-resolver.ts index a7f111ed..dd04c0af 100644 --- a/twake/backend/node/src/services/global-resolver.ts +++ b/twake/backend/node/src/services/global-resolver.ts @@ -25,6 +25,8 @@ import { UserExternalLinksServiceImpl } from "./user/services/external_links"; import { UserNotificationBadgeService } from "./notifications/services/bages"; import { NotificationPreferencesService } from "./notifications/services/preferences"; import { UserServiceImpl } from "./user/services/users/service"; +import { CompanyApplicationServiceImpl } from "./applications/services/company-applications"; +import { ApplicationServiceImpl } from "./applications/services/applications"; import { FileServiceImpl } from "./files/services"; import { ChannelServiceImpl } from "./channels/services/channel/service"; import { MemberServiceImpl } from "./channels/services/member/service"; @@ -36,6 +38,7 @@ import { NotificationEngine } from "./notifications/services/engine"; import { MobilePushService } from "./notifications/services/mobile-push"; import { ChannelMemberPreferencesServiceImpl } from "./notifications/services/channel-preferences"; import { ChannelThreadUsersServiceImpl } from "./notifications/services/channel-thread-users"; +import { ApplicationHooksService } from "./applications/services/hooks"; import OnlineServiceImpl from "./online/service"; import { ChannelsMessageQueueListener } from "./channels/services/pubsub"; import { UserNotificationDigestService } from "./notifications/services/digest"; @@ -75,6 +78,11 @@ type TwakeServices = { mobilePush: MobilePushService; digest: UserNotificationDigestService; }; + applications: { + marketplaceApps: ApplicationServiceImpl; + companyApps: CompanyApplicationServiceImpl; + hooks: ApplicationHooksService; + }; files: FileServiceImpl; channels: { channels: ChannelServiceImpl; @@ -145,6 +153,11 @@ class GlobalResolver { mobilePush: await new MobilePushService().init(), digest: await new UserNotificationDigestService().init(), }, + applications: { + marketplaceApps: await new ApplicationServiceImpl().init(), + companyApps: await new CompanyApplicationServiceImpl().init(), + hooks: await new ApplicationHooksService().init(), + }, files: await new FileServiceImpl().init(), channels: { channels: await new ChannelServiceImpl().init(),