Skip to content

A platform for community discussion. Free, open, simple.

FIX: Moderators being able to clear suspensions and silences from other staff accounts (#38563)

Gabriel Grubba541ef5ac4e85
diff --git a/lib/guardian.rb b/lib/guardian.rb
index 99b4a127420..6ffa1828d93 100644
--- a/lib/guardian.rb
+++ b/lib/guardian.rb
@@ -344,7 +344,7 @@ class Guardian
alias can_deactivate? can_suspend?
def can_unsuspend?(user)
- user && is_staff?
+ user && is_staff? && (!user.staff? || is_admin?)
end
def can_revoke_admin?(admin)
diff --git a/lib/guardian/user_guardian.rb b/lib/guardian/user_guardian.rb
index 7406742ebbe..785e1b845b7 100644
--- a/lib/guardian/user_guardian.rb
+++ b/lib/guardian/user_guardian.rb
@@ -57,7 +57,7 @@ module UserGuardian
end
def can_unsilence_user?(user)
- user && is_staff?
+ user && is_staff? && (!user.staff? || is_admin?)
end
def can_delete_user?(user)
diff --git a/spec/requests/admin/users_controller_spec.rb b/spec/requests/admin/users_controller_spec.rb
index 9b18128cf16..308ff7a3944 100644
--- a/spec/requests/admin/users_controller_spec.rb
+++ b/spec/requests/admin/users_controller_spec.rb
@@ -666,6 +666,32 @@ RSpec.describe Admin::UsersController do
expect(user).to be_moderator
end
end
+
+ context "when logged in as a moderator" do
+ before { sign_in(moderator) }
+
+ it "prevents unsuspending a staff user" do
+ another_admin.update!(suspended_at: DateTime.now, suspended_till: 2.years.from_now)
+ other_moderator =
+ Fabricate(:moderator, suspended_at: DateTime.now, suspended_till: 2.years.from_now)
+
+ put "/admin/users/#{another_admin.id}/unsuspend.json"
+ expect(response.status).to eq(403)
+ expect(another_admin.reload).to be_suspended
+
+ put "/admin/users/#{other_moderator.id}/unsuspend.json"
+ expect(response.status).to eq(403)
+ expect(other_moderator.reload).to be_suspended
+ end
+
+ it "can unsuspend a regular user" do
+ user.update!(suspended_at: DateTime.now, suspended_till: 2.years.from_now)
+
+ put "/admin/users/#{user.id}/unsuspend.json"
+ expect(response.status).to eq(200)
+ expect(user.reload).not_to be_suspended
+ end
+ end
end
describe "#revoke_admin" do
@@ -2046,6 +2072,19 @@ RSpec.describe Admin::UsersController do
before { sign_in(moderator) }
include_examples "unsilencing user possible"
+
+ it "prevents unsilencing a staff user" do
+ silenced_admin = Fabricate(:admin, silenced_till: 10.years.from_now)
+ silenced_mod = Fabricate(:moderator, silenced_till: 10.years.from_now)
+
+ put "/admin/users/#{silenced_admin.id}/unsilence.json"
+ expect(response.status).to eq(403)
+ expect(silenced_admin.reload).to be_silenced
+
+ put "/admin/users/#{silenced_mod.id}/unsilence.json"
+ expect(response.status).to eq(403)
+ expect(silenced_mod.reload).to be_silenced
+ end
end
context "when logged in as a non-staff user" do