mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 23:07:28 +08:00
FEATURE: disable post editing when the post has active flag
This commit is contained in:
@ -356,6 +356,10 @@ class Post < ActiveRecord::Base
|
|||||||
post_actions.where(post_action_type_id: PostActionType.flag_types.values, deleted_at: nil).count != 0
|
post_actions.where(post_action_type_id: PostActionType.flag_types.values, deleted_at: nil).count != 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_active_flag?
|
||||||
|
post_actions.active.where(post_action_type_id: PostActionType.flag_types.values).count != 0
|
||||||
|
end
|
||||||
|
|
||||||
def unhide!
|
def unhide!
|
||||||
self.update_attributes(hidden: false)
|
self.update_attributes(hidden: false)
|
||||||
self.topic.update_attributes(visible: true) if is_first_post?
|
self.topic.update_attributes(visible: true) if is_first_post?
|
||||||
|
@ -90,7 +90,7 @@ module PostGuardian
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if post.topic.archived? || post.user_deleted || post.deleted_at
|
if post.topic.archived? || post.user_deleted || post.deleted_at || post.has_active_flag?
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1008,6 +1008,29 @@ describe Guardian do
|
|||||||
expect(Guardian.new(admin).can_edit?(tos_first_post)).to be_truthy
|
expect(Guardian.new(admin).can_edit?(tos_first_post)).to be_truthy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "flagged post" do
|
||||||
|
let(:user) { Fabricate(:user) }
|
||||||
|
let(:post) { Fabricate(:post) }
|
||||||
|
before { PostAction.act(user, post, PostActionType.types[:off_topic]) }
|
||||||
|
|
||||||
|
it 'returns false when post owner tries to edit active flagged post' do
|
||||||
|
expect(Guardian.new(post.user).can_edit?(post)).to be_falsey
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns true when trust level 4 user tries to edit active flagged post' do
|
||||||
|
expect(Guardian.new(trust_level_4).can_edit?(post)).to be_truthy
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns true when staff tries to edit active flagged post' do
|
||||||
|
expect(Guardian.new(moderator).can_edit?(post)).to be_truthy
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns true when post owner tries to edit post with inactive flag' do
|
||||||
|
PostAction.defer_flags!(post, admin)
|
||||||
|
expect(Guardian.new(post.user).can_edit?(post)).to be_truthy
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'a Topic' do
|
describe 'a Topic' do
|
||||||
|
@ -137,11 +137,12 @@ describe Post do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'flagging helpers' do
|
describe 'flagging helpers' do
|
||||||
it 'isFlagged is accurate' do
|
let(:post) { Fabricate(:post) }
|
||||||
post = Fabricate(:post)
|
let(:user) { Fabricate(:coding_horror) }
|
||||||
user = Fabricate(:coding_horror)
|
let(:admin) { Fabricate(:admin) }
|
||||||
PostAction.act(user, post, PostActionType.types[:off_topic])
|
|
||||||
|
|
||||||
|
it 'isFlagged is accurate' do
|
||||||
|
PostAction.act(user, post, PostActionType.types[:off_topic])
|
||||||
post.reload
|
post.reload
|
||||||
expect(post.is_flagged?).to eq(true)
|
expect(post.is_flagged?).to eq(true)
|
||||||
|
|
||||||
@ -149,6 +150,16 @@ describe Post do
|
|||||||
post.reload
|
post.reload
|
||||||
expect(post.is_flagged?).to eq(false)
|
expect(post.is_flagged?).to eq(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'has_active_flag is accurate' do
|
||||||
|
PostAction.act(user, post, PostActionType.types[:spam])
|
||||||
|
post.reload
|
||||||
|
expect(post.has_active_flag?).to eq(true)
|
||||||
|
|
||||||
|
PostAction.defer_flags!(post, admin)
|
||||||
|
post.reload
|
||||||
|
expect(post.has_active_flag?).to eq(false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "maximum images" do
|
describe "maximum images" do
|
||||||
|
Reference in New Issue
Block a user