mirror of
https://github.com/discourse/discourse.git
synced 2025-09-05 08:59:27 +08:00
Can clear flags on deleted posts if you're a moderator
This commit is contained in:
parent
ea631e75c9
commit
03a798b202
6 changed files with 90 additions and 11 deletions
|
@ -68,6 +68,29 @@ describe Guardian do
|
|||
end
|
||||
|
||||
|
||||
describe "can_clear_flags" do
|
||||
let(:post) { Fabricate(:post) }
|
||||
let(:user) { post.user }
|
||||
let(:moderator) { Fabricate(:moderator) }
|
||||
|
||||
it "returns false when the user is nil" do
|
||||
Guardian.new(nil).can_clear_flags?(post).should be_false
|
||||
end
|
||||
|
||||
it "returns false when the post is nil" do
|
||||
Guardian.new(moderator).can_clear_flags?(nil).should be_false
|
||||
end
|
||||
|
||||
it "returns false when the user is not a moderator" do
|
||||
Guardian.new(user).can_clear_flags?(post).should be_false
|
||||
end
|
||||
|
||||
it "returns true when the user is a moderator" do
|
||||
Guardian.new(moderator).can_clear_flags?(post).should be_true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'can_send_private_message' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:another_user) { Fabricate(:user) }
|
||||
|
|
|
@ -85,6 +85,55 @@ describe PostActionsController do
|
|||
|
||||
end
|
||||
|
||||
context 'clear_flags' do
|
||||
|
||||
let(:flagged_post) { Fabricate(:post, user: Fabricate(:coding_horror)) }
|
||||
|
||||
context "not logged in" do
|
||||
it "should not allow them to clear flags" do
|
||||
lambda { xhr :post, :clear_flags }.should raise_error(Discourse::NotLoggedIn)
|
||||
end
|
||||
end
|
||||
|
||||
context 'logged in' do
|
||||
let!(:user) { log_in(:moderator) }
|
||||
|
||||
it "raises an error without a post_action_type_id" do
|
||||
-> { xhr :post, :clear_flags, id: flagged_post.id }.should raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
it "raises an error when the user doesn't have access" do
|
||||
Guardian.any_instance.expects(:can_clear_flags?).returns(false)
|
||||
xhr :post, :clear_flags, id: flagged_post.id, post_action_type_id: PostActionType.Types[:spam]
|
||||
response.should be_forbidden
|
||||
end
|
||||
|
||||
context "success" do
|
||||
before do
|
||||
Guardian.any_instance.expects(:can_clear_flags?).returns(true)
|
||||
PostAction.expects(:clear_flags!).with(flagged_post, user.id, PostActionType.Types[:spam])
|
||||
end
|
||||
|
||||
it "delegates to clear_flags" do
|
||||
xhr :post, :clear_flags, id: flagged_post.id, post_action_type_id: PostActionType.Types[:spam]
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it "works with a deleted post" do
|
||||
flagged_post.destroy
|
||||
xhr :post, :clear_flags, id: flagged_post.id, post_action_type_id: PostActionType.Types[:spam]
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
describe 'users' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue