From f23559d1b89c0b810b3ab5bf2020fc302d7ce1cf Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 20 Jul 2025 13:13:27 -0400 Subject: [PATCH] chore: Integration to event backend (#9688) --- server/models/AuthenticationProvider.ts | 38 +++++++------------ .../authenticationProviders.ts | 12 +----- .../routes/api/integrations/integrations.ts | 12 ++---- 3 files changed, 18 insertions(+), 44 deletions(-) diff --git a/server/models/AuthenticationProvider.ts b/server/models/AuthenticationProvider.ts index 58de38201e..64b0a66563 100644 --- a/server/models/AuthenticationProvider.ts +++ b/server/models/AuthenticationProvider.ts @@ -1,9 +1,4 @@ -import { - InferAttributes, - InferCreationAttributes, - InstanceUpdateOptions, - Op, -} from "sequelize"; +import { InferAttributes, InferCreationAttributes, Op } from "sequelize"; import { BelongsTo, Column, @@ -28,6 +23,7 @@ import Length from "./validators/Length"; import AzureClient from "plugins/azure/server/azure"; import GoogleClient from "plugins/google/server/google"; import OIDCClient from "plugins/oidc/server/oidc"; +import { APIContext } from "@server/types"; @Scopes(() => ({ withUserAuthentication: (userId: string) => ({ @@ -112,13 +108,13 @@ class AuthenticationProvider extends Model< } } - disable: ( - options?: InstanceUpdateOptions> - ) => Promise = async (options) => { + disable: (ctx: APIContext) => Promise = async ( + ctx + ) => { const res = await ( this.constructor as typeof AuthenticationProvider ).findAndCountAll({ - ...options, + transaction: ctx.transaction, where: { teamId: this.teamId, enabled: true, @@ -130,26 +126,18 @@ class AuthenticationProvider extends Model< }); if (res.count >= 1) { - return this.update( - { - enabled: false, - }, - options - ); + return this.updateWithCtx(ctx, { + enabled: false, + }); } else { throw ValidationError("At least one authentication provider is required"); } }; - enable: ( - options?: InstanceUpdateOptions> - ) => Promise = (options) => - this.update( - { - enabled: true, - }, - options - ); + enable: (ctx: APIContext) => Promise = async (ctx) => + this.updateWithCtx(ctx, { + enabled: true, + }); } export default AuthenticationProvider; diff --git a/server/routes/api/authenticationProviders/authenticationProviders.ts b/server/routes/api/authenticationProviders/authenticationProviders.ts index f40afaec44..98da29b54d 100644 --- a/server/routes/api/authenticationProviders/authenticationProviders.ts +++ b/server/routes/api/authenticationProviders/authenticationProviders.ts @@ -52,19 +52,11 @@ router.post( const enabled = !!isEnabled; if (enabled) { - await authenticationProvider.enable({ transaction }); + await authenticationProvider.enable(ctx); } else { - await authenticationProvider.disable({ transaction }); + await authenticationProvider.disable(ctx); } - await Event.createFromContext(ctx, { - name: "authenticationProviders.update", - data: { - enabled, - }, - modelId: id, - }); - ctx.body = { data: presentAuthenticationProvider(authenticationProvider), policies: presentPolicies(user, [authenticationProvider]), diff --git a/server/routes/api/integrations/integrations.ts b/server/routes/api/integrations/integrations.ts index 8e51099963..c88791e606 100644 --- a/server/routes/api/integrations/integrations.ts +++ b/server/routes/api/integrations/integrations.ts @@ -4,7 +4,6 @@ import { IntegrationType, UserRole } from "@shared/types"; import auth from "@server/middlewares/authentication"; import { transaction } from "@server/middlewares/transaction"; import validate from "@server/middlewares/validate"; -import { Event } from "@server/models"; import Integration from "@server/models/Integration"; import { authorize } from "@server/policies"; import { presentIntegration, presentPolicies } from "@server/presenters"; @@ -76,7 +75,7 @@ router.post( authorize(user, "createIntegration", user.team); - const integration = await Integration.create({ + const integration = await Integration.createWithCtx(ctx, { userId: user.id, teamId: user.teamId, service, @@ -135,7 +134,7 @@ router.post( integration.settings = settings; - await integration.save({ transaction }); + await integration.saveWithCtx(ctx); ctx.body = { data: presentIntegration(integration), @@ -161,12 +160,7 @@ router.post( }); authorize(user, "delete", integration); - await integration.destroy({ transaction }); - - await Event.createFromContext(ctx, { - name: "integrations.delete", - modelId: integration.id, - }); + await integration.destroyWithCtx(ctx); ctx.body = { success: true,