Files
outline/server/queues/processors/OAuthClientUnpublishedProcessor.ts
Tom Moor bf45e97641 chore: Enforce type import consistency (#10968)
* Update types

* fix circular dep

* type imports

* lint type imports and --fix
2025-12-19 23:07:02 -05:00

37 lines
1.1 KiB
TypeScript

import { Op } from "sequelize";
import { OAuthAuthentication, OAuthClient, User } from "@server/models";
import type { OAuthClientEvent, Event as TEvent } from "@server/types";
import BaseProcessor from "./BaseProcessor";
export default class OAuthClientUnpublishedProcessor extends BaseProcessor {
static applicableEvents: TEvent["name"][] = ["oauthClients.update"];
async perform(event: OAuthClientEvent) {
if (
event.changes?.previous.published === true &&
event.changes.attributes.published === false
) {
const oauthClient = await OAuthClient.findByPk(event.modelId, {
rejectOnEmpty: true,
});
const users = await User.findAll({
attributes: ["id"],
where: {
teamId: oauthClient.teamId,
},
});
const userIds = users.map((user) => user.id);
// Revoke access for all users except any that are in the same team
await OAuthAuthentication.destroy({
where: {
oauthClientId: event.modelId,
userId: {
[Op.notIn]: userIds,
},
},
});
}
}
}