mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 13:06:56 +08:00
FIX: Delegate silenced_till from anonymous user to main user account (#32416)
When a user is silenced they can, given they have the permissions, enter anonymous mode and keep posting, essentially bypassing the silence that way. This change delegates the silenced_till attribute to the main user record if the user is anonymous.
This commit is contained in:
@ -1316,6 +1316,10 @@ class User < ActiveRecord::Base
|
||||
!!(suspended_till && suspended_till > Time.zone.now)
|
||||
end
|
||||
|
||||
def silenced_till
|
||||
main_user_record[:silenced_till]
|
||||
end
|
||||
|
||||
def silenced?
|
||||
!!(silenced_till && silenced_till > Time.zone.now)
|
||||
end
|
||||
@ -2145,6 +2149,10 @@ class User < ActiveRecord::Base
|
||||
|
||||
private
|
||||
|
||||
def main_user_record
|
||||
anonymous? ? master_user : self
|
||||
end
|
||||
|
||||
def set_default_sidebar_section_links(update: false)
|
||||
return if staged? || bot?
|
||||
|
||||
|
@ -2476,6 +2476,22 @@ RSpec.describe User do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#silenced_till" do
|
||||
context "when the user is an anonymous shadow" do
|
||||
let(:main) { Fabricate(:user, silenced_till: 1.day.from_now) }
|
||||
let(:anon) { Fabricate(:anonymous) }
|
||||
|
||||
before do
|
||||
SiteSetting.allow_anonymous_mode = true
|
||||
anon.anonymous_user_master.update(master_user_id: main.id)
|
||||
end
|
||||
|
||||
it "delegates the value from the main user record" do
|
||||
expect(anon.silenced_till).to eq(main.silenced_till)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "silenced?" do
|
||||
it "is not silenced by default" do
|
||||
expect(Fabricate(:user)).not_to be_silenced
|
||||
|
Reference in New Issue
Block a user