fix: Group membership count off after suspending users in groups (#1670)

* fix: Clear group memberships when suspending a user
Refactor to command

* test

* test
This commit is contained in:
Tom Moor
2020-11-22 11:21:47 -08:00
committed by GitHub
parent 273d9c4680
commit 56d5f048f9
4 changed files with 104 additions and 19 deletions

View File

@ -1,6 +1,7 @@
// @flow
import Router from "koa-router";
import userInviter from "../commands/userInviter";
import userSuspender from "../commands/userSuspender";
import auth from "../middlewares/authentication";
import { Event, User, Team } from "../models";
import policy from "../policies";
@ -135,23 +136,15 @@ router.post("users.demote", auth(), async (ctx) => {
});
router.post("users.suspend", auth(), async (ctx) => {
const admin = ctx.state.user;
const userId = ctx.body.id;
const teamId = ctx.state.user.teamId;
ctx.assertPresent(userId, "id is required");
const user = await User.findByPk(userId);
authorize(ctx.state.user, "suspend", user);
const team = await Team.findByPk(teamId);
await team.suspendUser(user, admin);
await Event.create({
name: "users.suspend",
await userSuspender({
user,
actorId: ctx.state.user.id,
userId,
teamId,
data: { name: user.name },
ip: ctx.request.ip,
});