mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 22:38:09 +08:00
FIX: Guardian#post_can_act?
shouldn't raise an error if user of post has been deleted.
This commit is contained in:
parent
70155f0923
commit
fae8757cd4
@ -43,7 +43,7 @@ module PostGuardian
|
||||
# post made by staff, but we don't allow staff flags
|
||||
return false if is_flag &&
|
||||
(!SiteSetting.allow_flagging_staff?) &&
|
||||
post.user.staff?
|
||||
post&.user&.staff?
|
||||
|
||||
if [:notify_user, :notify_moderators].include?(action_key) &&
|
||||
(!SiteSetting.enable_personal_messages? ||
|
||||
|
@ -120,16 +120,26 @@ describe Guardian do
|
||||
expect(Guardian.new(user).post_can_act?(staff_post, :spam)).to be_truthy
|
||||
end
|
||||
|
||||
it "doesn't allow flagging of staff posts when allow_flagging_staff is false" do
|
||||
SiteSetting.allow_flagging_staff = false
|
||||
staff_post = Fabricate(:post, user: Fabricate(:moderator))
|
||||
expect(Guardian.new(user).post_can_act?(staff_post, :spam)).to eq(false)
|
||||
end
|
||||
describe 'when allow_flagging_staff is false' do
|
||||
let(:staff_post) { Fabricate(:post, user: Fabricate(:moderator)) }
|
||||
|
||||
it "allows liking of staff when allow_flagging_staff is false" do
|
||||
SiteSetting.allow_flagging_staff = false
|
||||
staff_post = Fabricate(:post, user: Fabricate(:moderator))
|
||||
expect(Guardian.new(user).post_can_act?(staff_post, :like)).to eq(true)
|
||||
before do
|
||||
SiteSetting.allow_flagging_staff = false
|
||||
end
|
||||
|
||||
it "doesn't allow flagging of staff posts" do
|
||||
expect(Guardian.new(user).post_can_act?(staff_post, :spam)).to eq(false)
|
||||
end
|
||||
|
||||
it "allows flagging of staff posts when staff has been deleted" do
|
||||
staff_post.user.destroy!
|
||||
staff_post.reload
|
||||
expect(Guardian.new(user).post_can_act?(staff_post, :spam)).to eq(true)
|
||||
end
|
||||
|
||||
it "allows liking of staff" do
|
||||
expect(Guardian.new(user).post_can_act?(staff_post, :like)).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
it "returns false when liking yourself" do
|
||||
|
Loading…
x
Reference in New Issue
Block a user