A platform for community discussion. Free, open, simple.
Enforce disabling flagging hidden posts server-side
Penar Musaraj7b3432f71151
diff --git a/lib/guardian/post_guardian.rb b/lib/guardian/post_guardian.rbindex dd7504fa70d..d30db1972d6 100644--- a/lib/guardian/post_guardian.rb+++ b/lib/guardian/post_guardian.rb@@ -40,6 +40,9 @@ module PostGuardian# Silenced users can't flagreturn false if is_flag && @user.silenced?+ # Hidden posts can't be flagged+ return false if is_flag && post.hidden?+# post made by staff, but we don't allow staff flagsreturn false if is_flag &&(!SiteSetting.allow_flagging_staff?) &&diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rbindex 5a05341928c..9f9da726038 100644--- a/spec/components/guardian_spec.rb+++ b/spec/components/guardian_spec.rb@@ -116,6 +116,11 @@ describe Guardian doexpect(Guardian.new(user).post_can_act?(post, :spam)).to be_truthyend+ it "does not allow flagging of hidden posts" do+ post.hidden = true+ expect(Guardian.new(user).post_can_act?(post, :spam)).to be_falsey+ end+it "allows flagging of staff posts when allow_flagging_staff is true" doSiteSetting.allow_flagging_staff = truestaff_post = Fabricate(:post, user: Fabricate(:moderator))