Skip to content

Commit

Permalink
remove other statuses when banning a user
Browse files Browse the repository at this point in the history
  • Loading branch information
tessalt committed Nov 20, 2020
1 parent 31e144b commit 6dc2289
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 10 deletions.
29 changes: 20 additions & 9 deletions src/core/client/admin/components/UserStatus/BanUserMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,20 @@ const BanUserMutation = createMutation(
id
status {
current
suspension {
active
}
warning {
active
}
premod {
active
}
ban {
active
history {
active
createdAt
createdBy {
id
username
}
}
premod {
active
}
}
}
clientMutationId
}
Expand Down Expand Up @@ -71,6 +73,15 @@ const BanUserMutation = createMutation(
},
],
},
suspension: {
active: false,
},
warning: {
active: false,
},
premod: {
active: false,
},
},
},
clientMutationId: (clientMutationId++).toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ const BanUserMutation = createMutation(
ban {
active
}
suspension {
active
}
warning {
active
}
premod {
active
}
}
}
clientMutationId
Expand All @@ -59,6 +68,15 @@ const BanUserMutation = createMutation(
ban: {
active: true,
},
suspension: {
active: false,
},
warning: {
active: false,
},
premod: {
active: false,
},
},
},
clientMutationId: (clientMutationId++).toString(),
Expand Down
31 changes: 30 additions & 1 deletion src/core/server/services/users/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,36 @@ export async function ban(
}

// Ban the user.
const user = await banUser(mongo, tenant.id, userID, banner.id, message, now);
let user = await banUser(mongo, tenant.id, userID, banner.id, message, now);

const supsensionStatus = consolidateUserSuspensionStatus(
targetUser.status.suspension
);

// remove suspension if present
if (supsensionStatus.active) {
user = await removeActiveUserSuspensions(
mongo,
tenant.id,
userID,
banner.id,
now
);
}

const premodStatus = consolidateUserPremodStatus(targetUser.status.premod);

// remove premod if present
if (premodStatus.active) {
user = await removeUserPremod(mongo, tenant.id, userID, banner.id, now);
}

// remove warning if present
const warningStatus = consolidateUserWarningStatus(targetUser.status.warning);

if (warningStatus.active) {
user = await removeUserWarning(mongo, tenant.id, userID, banner.id, now);
}

if (rejectExistingComments) {
await rejector.add({
Expand Down

0 comments on commit 6dc2289

Please sign in to comment.