mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
chore: Integration to event backend (#9688)
This commit is contained in:
@@ -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<InferAttributes<AuthenticationProvider>>
|
||||
) => Promise<AuthenticationProvider> = async (options) => {
|
||||
disable: (ctx: APIContext) => Promise<AuthenticationProvider> = 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<InferAttributes<AuthenticationProvider>>
|
||||
) => Promise<AuthenticationProvider> = (options) =>
|
||||
this.update(
|
||||
{
|
||||
enabled: true,
|
||||
},
|
||||
options
|
||||
);
|
||||
enable: (ctx: APIContext) => Promise<AuthenticationProvider> = async (ctx) =>
|
||||
this.updateWithCtx(ctx, {
|
||||
enabled: true,
|
||||
});
|
||||
}
|
||||
|
||||
export default AuthenticationProvider;
|
||||
|
||||
@@ -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]),
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user