FIX: unsuspend a moderator (#35452)

If, for some reasons, you were to try to "unsuspend" a moderator, you
wouldn't be able to because the "can_suspend" was checking for
"user.regular?".

Added a "can_unsuspend?" to support this use-case.

Ref - https://meta.discourse.org/t/-/385786
This commit is contained in:
Régis Hanol
2025-10-16 21:05:47 +02:00
committed by GitHub
parent bf4d07a89c
commit 1fe35c74e1
3 changed files with 25 additions and 2 deletions
+3 -1
View File
@@ -146,10 +146,12 @@ class Admin::UsersController < Admin::StaffController
end
def unsuspend
guardian.ensure_can_suspend!(@user)
guardian.ensure_can_unsuspend!(@user)
@user.suspended_till = nil
@user.suspended_at = nil
@user.save!
StaffActionLogger.new(current_user).log_user_unsuspend(@user)
DiscourseEvent.trigger(:user_unsuspended, user: @user)
+5 -1
View File
@@ -342,10 +342,14 @@ class Guardian
end
def can_suspend?(user)
user && is_staff? && user.regular?
can_unsuspend?(user) && user.regular?
end
alias can_deactivate? can_suspend?
def can_unsuspend?(user)
user && is_staff?
end
def can_revoke_admin?(admin)
can_administer_user?(admin) && admin.admin?
end
@@ -648,6 +648,23 @@ RSpec.describe Admin::UsersController do
expect(job_args["payload"]).to eq(WebHook.generate_payload(:user, user))
end
end
it "can unsuspend a user who was granted moderation while suspended" do
user.update!(suspended_at: DateTime.now, suspended_till: 2.years.from_now)
user.grant_moderation!
expect(user.reload).to be_suspended
expect(user).to be_moderator
put "/admin/users/#{user.id}/unsuspend.json"
expect(response.status).to eq(200)
user.reload
expect(user.suspended_till).to eq(nil)
expect(user.suspended_at).to eq(nil)
expect(user).not_to be_suspended
expect(user).to be_moderator
end
end
end