Add updateRole endpoint (#6771)
This commit is contained in:
@@ -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) {
|
||||
|
||||
11
server/queues/processors/UserDemotedProcessor.ts
Normal file
11
server/queues/processors/UserDemotedProcessor.ts
Normal 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 });
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user