From a46c6ca0a8753dd24351421402695e24f80c1d0c Mon Sep 17 00:00:00 2001 From: Romaric Mourgues Date: Fri, 14 Apr 2023 10:30:07 +0200 Subject: [PATCH] Fix tests --- .../src/services/applications-api/types.ts | 10 +---- .../applications-api/web/controllers/index.ts | 43 ++++++++----------- .../src/services/applications/web/routes.ts | 39 ----------------- 3 files changed, 20 insertions(+), 72 deletions(-) diff --git a/tdrive/backend/node/src/services/applications-api/types.ts b/tdrive/backend/node/src/services/applications-api/types.ts index 9919e15d..b8748241 100644 --- a/tdrive/backend/node/src/services/applications-api/types.ts +++ b/tdrive/backend/node/src/services/applications-api/types.ts @@ -1,13 +1,5 @@ -import { Channel } from "../channels/entities"; -import { Message } from "../messages/entities/messages"; -import { Thread } from "../messages/entities/threads"; - export type HookType = { - type: "message"; + type: string; application_id: string; company_id: string; - - channel?: Channel; - thread: Thread; - message: Message; }; diff --git a/tdrive/backend/node/src/services/applications-api/web/controllers/index.ts b/tdrive/backend/node/src/services/applications-api/web/controllers/index.ts index afbf0f85..709925db 100644 --- a/tdrive/backend/node/src/services/applications-api/web/controllers/index.ts +++ b/tdrive/backend/node/src/services/applications-api/web/controllers/index.ts @@ -1,21 +1,24 @@ import { FastifyInstance, FastifyReply, FastifyRequest, HTTPMethods } from "fastify"; -import { ApplicationObject } from "../../../applications/entities/application"; -import { - ApplicationApiExecutionContext, - ApplicationLoginRequest, - ApplicationLoginResponse, - ConfigureRequest, -} from "../types"; -import { ResourceGetResponse } from "../../../../utils/types"; +import _ from "lodash"; +import { v4 } from "uuid"; import { CrudException } from "../../../../core/platform/framework/api/crud-service"; import { localEventBus } from "../../../../core/platform/framework/event-bus"; import { RealtimeApplicationEvent, RealtimeBaseBusEvent, } from "../../../../core/platform/services/realtime/types"; +import { ResourceGetResponse } from "../../../../utils/types"; +import { + ApplicationObject, + getApplicationObject, +} from "../../../applications/entities/application"; import gr from "../../../global-resolver"; -import _ from "lodash"; -import { v4 } from "uuid"; +import { + ApplicationApiExecutionContext, + ApplicationLoginRequest, + ApplicationLoginResponse, + ConfigureRequest, +} from "../types"; export class ApplicationsApiController { async token( @@ -27,12 +30,7 @@ export class ApplicationsApiController { throw CrudException.forbidden("Application not found"); } - const app = await gr.services.applications.marketplaceApps.get( - { - id: request.body.id, - }, - context, - ); + const app = await gr.services.applications.marketplaceApps.get(request.body.id, context); if (!app) { throw CrudException.forbidden("Application not found"); @@ -60,16 +58,15 @@ export class ApplicationsApiController { const context = getExecutionContext(request); const entity = await gr.services.applications.marketplaceApps.get( - { - id: context.application_id, - }, + context.application_id, + context, ); if (!entity) { throw CrudException.notFound("Application not found"); } - return { resource: entity.getApplicationObject() }; + return { resource: getApplicationObject(entity) }; } async configure( @@ -78,7 +75,7 @@ export class ApplicationsApiController { ): Promise> { const app_id = request.currentUser.application_id; const context = getExecutionContext(request); - const application = await gr.services.applications.marketplaceApps.get({ id: app_id }, context); + const application = await gr.services.applications.marketplaceApps.get(app_id, context); if (!application) { throw CrudException.forbidden("Application not found"); @@ -125,9 +122,7 @@ export class ApplicationsApiController { const context = getExecutionContext(request); const app = await gr.services.applications.marketplaceApps.get( - { - id: request.currentUser.application_id, - }, + request.currentUser.application_id, context, ); diff --git a/tdrive/backend/node/src/services/applications/web/routes.ts b/tdrive/backend/node/src/services/applications/web/routes.ts index da0e0445..3aa62d36 100644 --- a/tdrive/backend/node/src/services/applications/web/routes.ts +++ b/tdrive/backend/node/src/services/applications/web/routes.ts @@ -15,45 +15,6 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next) const applicationController = new ApplicationController(); const companyApplicationController = new CompanyApplicationController(); - const adminCheck = async ( - request: FastifyRequest<{ - Body: { resource: Application }; - Params: { application_id: string }; - }>, - ) => { - try { - let companyId: string = request.body?.resource?.company_id; - - if (request.params.application_id) { - const application = await gr.services.applications.marketplaceApps.get( - request.params.application_id, - undefined, - ); - - if (!application) { - throw fastify.httpErrors.notFound("Application is not defined"); - } - - companyId = application.company_id; - } - - const userId = request.currentUser.id; - - if (!companyId) { - throw fastify.httpErrors.forbidden(`Company ${companyId} not found`); - } - - const companyUser = await checkUserBelongsToCompany(userId, companyId); - - if (!hasCompanyAdminLevel(companyUser.role)) { - throw fastify.httpErrors.forbidden("You must be an admin of this company"); - } - } catch (e) { - log.error(e); - throw e; - } - }; - /** * Applications collection * Marketplace of applications