Skip to content

Commit

Permalink
[bug 2555] - Admin tool: allow un-shadowbanning #2555
Browse files Browse the repository at this point in the history
    -added role add & remove for all roles
    -on suspend removal 'newsletter: true, public: true'
    -for suspend and shadowbanned : set color is red unset is green
    -for other buttons : set color is green unset is red
  • Loading branch information
vssdeo authored and hlibbabii committed Jul 23, 2023
1 parent bdc4571 commit fe05083
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 47 deletions.
66 changes: 24 additions & 42 deletions modules/admin/client/components/AdminUser.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class AdminUser extends Component {
const id = get(this, ['state', 'user', 'profile', '_id']);
if (id) {
const username = get(this, ['state', 'user', 'profile', 'username']);
if (role === 'shadowban' && this.hasRole(role)) {
if (this.hasRole(role)) {
if (window.confirm(`Remove ${username} from role: ${role}?`)) {
this.setState({ isSettingUserRole: true }, async () => {
await unsetUserRole(id, role);
Expand Down Expand Up @@ -90,29 +90,28 @@ export default class AdminUser extends Component {
return get(this.state.user, ['profile', 'roles'], []).includes(role);
}

getUndoState(role) {
if (this.hasRole(role)) {
getUndoState(curRole, label) {
const butLabel = !label ? curRole : label;
let setColor = 'success';
if (curRole === 'suspended' || curRole === 'shadowban') {
setColor = 'danger';
}

if (this.hasRole(curRole)) {
return {
role: 'shadowban',
color: 'success',
label: 'Undo Shadow Ban',
role: curRole,
color: 'danger',
label: 'Undo ' + butLabel,
};
} else {
return {
role: 'shadowban',
color: 'danger',
label: 'Shadow Ban',
role: curRole,
color: setColor,
label: butLabel,
};
}
}

actButtonDisabled(user, role, isSettingUserRole) {
if (role !== 'shadowban') {
return user.profile.roles.includes(role) || isSettingUserRole;
}
return isSettingUserRole;
}

render() {
const { user, isSettingUserRole } = this.state;
const isProfile = user && user.profile;
Expand Down Expand Up @@ -158,36 +157,19 @@ export default class AdminUser extends Component {

<div className="btn-group">
{[
{
role: 'suspended',
color: 'danger',
label: 'Suspend',
},
this.getUndoState('shadowban'),
{
role: 'moderator',
color: 'success',
label: 'Make moderator',
},
{
role: 'volunteer',
color: 'success',
label: 'Make volunteer',
},
{
role: 'volunteer-alumni',
color: 'success',
label: 'Make volunteer alumni',
},
this.getUndoState('suspended', 'Suspend'),
this.getUndoState('shadowban', 'Shadowban'),
this.getUndoState('moderator', 'Make moderator'),
this.getUndoState('volunteer', 'Make volunteer'),
this.getUndoState(
'volunteer-alumni',
'Make volunteer alumni',
),
].map(({ role, color, label }) => (
<button
key={role}
className={`btn btn-${color}`}
disabled={this.actButtonDisabled(
user,
role,
isSettingUserRole,
)}
disabled={isSettingUserRole}
onClick={() => this.handleUserRoleChange(role)}
>
{label}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,9 @@ exports.getUser = async (req, res) => {

exports.updateRoleDeps = async (role, userId, unset, status) => {
if (unset === true) {
// should suspend be handled by setting fields as true
// or left as shadow ban removes suspend status below ?
// const additionalChangesForSuspended =
// role === 'suspended' ? { $set: { newsletter: true, public: true } } : {};
// await User.updateOne({ _id: userId }, { ...additionalChangesForSuspended });
const additionalChangesForSuspended =
role === 'suspended' ? { $set: { newsletter: true, public: true } } : {};
await User.updateOne({ _id: userId }, { ...additionalChangesForSuspended });

status.roleChangeMessage = 'User removed from role:' + role + '.';
return;
Expand Down

0 comments on commit fe05083

Please sign in to comment.