From eacb25c4366bcc8fba20f98f93f004fabc6d5578 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 8 Aug 2018 17:36:10 +0200 Subject: Add reason when banning a user --- server/controllers/api/users.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 8f429d0b5..0e2be7123 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts @@ -302,8 +302,9 @@ async function unblockUser (req: express.Request, res: express.Response, next: e async function blockUser (req: express.Request, res: express.Response, next: express.NextFunction) { const user: UserModel = res.locals.user + const reason = req.body.reason - await changeUserBlock(res, user, true) + await changeUserBlock(res, user, true, reason) return res.status(204).end() } @@ -454,10 +455,11 @@ function success (req: express.Request, res: express.Response, next: express.Nex res.end() } -async function changeUserBlock (res: express.Response, user: UserModel, block: boolean) { +async function changeUserBlock (res: express.Response, user: UserModel, block: boolean, reason?: string) { const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) user.blocked = block + user.blockedReason = reason || null await sequelizeTypescript.transaction(async t => { await OAuthTokenModel.deleteUserToken(user.id, t) @@ -465,6 +467,8 @@ async function changeUserBlock (res: express.Response, user: UserModel, block: b await user.save({ transaction: t }) }) + await Emailer.Instance.addUserBlockJob(user, block, reason) + auditLogger.update( res.locals.oauth.token.User.Account.Actor.getIdentifier(), new UserAuditView(user.toFormattedJSON()), -- cgit v1.2.3