Add updateRole endpoint (#6771)

This commit is contained in:
Tom Moor
2024-04-06 07:32:15 -06:00
committed by GitHub
parent 52643c511c
commit 3f209101e6
14 changed files with 314 additions and 207 deletions

View File

@@ -10,7 +10,7 @@ import { sequelize } from "@server/storage/database";
import { Event as TEvent, UserEvent } from "@server/types";
import BaseProcessor from "./BaseProcessor";
export default class UsersDeletedProcessor extends BaseProcessor {
export default class UserDeletedProcessor extends BaseProcessor {
static applicableEvents: TEvent["name"][] = ["users.delete"];
async perform(event: UserEvent) {

View File

@@ -0,0 +1,11 @@
import { Event as TEvent, UserEvent } from "@server/types";
import CleanupDemotedUserTask from "../tasks/CleanupDemotedUserTask";
import BaseProcessor from "./BaseProcessor";
export default class UserDemotedProcessor extends BaseProcessor {
static applicableEvents: TEvent["name"][] = ["users.demote"];
async perform(event: UserEvent) {
await CleanupDemotedUserTask.schedule({ userId: event.userId });
}
}

View File

@@ -1,5 +1,6 @@
import Logger from "@server/logging/Logger";
import { WebhookSubscription, ApiKey, User } from "@server/models";
import { cannot } from "@server/policies";
import { sequelize } from "@server/storage/database";
import BaseTask, { TaskPriority } from "./BaseTask";
@@ -13,10 +14,12 @@ type Props = {
*/
export default class CleanupDemotedUserTask extends BaseTask<Props> {
public async perform(props: Props) {
await sequelize.transaction(async (transaction) => {
const user = await User.findByPk(props.userId, { rejectOnEmpty: true });
const user = await User.scope("withTeam").findByPk(props.userId, {
rejectOnEmpty: true,
});
if (user.isSuspended || !user.isAdmin) {
await sequelize.transaction(async (transaction) => {
if (cannot(user, "createWebhookSubscription", user.team)) {
const subscriptions = await WebhookSubscription.findAll({
where: {
createdById: props.userId,
@@ -36,7 +39,7 @@ export default class CleanupDemotedUserTask extends BaseTask<Props> {
);
}
if (user.isSuspended || user.isViewer) {
if (cannot(user, "createApiKey", user.team)) {
const apiKeys = await ApiKey.findAll({
where: {
userId: props.userId,