mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: add min_trust_level_to_edit_post
add minimum trust level to edit post (default 0)
This commit is contained in:
@@ -1129,6 +1129,8 @@ en:
|
||||
|
||||
min_trust_to_edit_wiki_post: "The minimum trust level required to edit post marked as wiki."
|
||||
|
||||
min_trust_to_edit_post: "The minimum trust level required to edit posts."
|
||||
|
||||
min_trust_to_allow_self_wiki: "The minimum trust level required to make user's own post wiki."
|
||||
|
||||
min_trust_to_send_messages: "The minimum trust level required to create new private messages."
|
||||
|
||||
@@ -762,6 +762,9 @@ trust:
|
||||
min_trust_to_edit_wiki_post:
|
||||
default: 1
|
||||
enum: 'TrustLevelSetting'
|
||||
min_trust_to_edit_post:
|
||||
default: 0
|
||||
enum: 'TrustLevelSetting'
|
||||
min_trust_to_allow_self_wiki:
|
||||
default: 3
|
||||
enum: 'TrustLevelSetting'
|
||||
|
||||
@@ -103,6 +103,10 @@ module PostGuardian
|
||||
return true
|
||||
end
|
||||
|
||||
if @user.trust_level < SiteSetting.min_trust_to_edit_post
|
||||
return false
|
||||
end
|
||||
|
||||
if is_my_own?(post)
|
||||
if post.hidden?
|
||||
return false if post.hidden_at.present? &&
|
||||
|
||||
@@ -972,6 +972,20 @@ describe Guardian do
|
||||
expect(Guardian.new(trust_level_4).can_edit?(post)).to be_truthy
|
||||
end
|
||||
|
||||
it 'returns false when trying to edit a post with no trust' do
|
||||
SiteSetting.min_trust_to_edit_post = 2
|
||||
post.user.trust_level = 1
|
||||
|
||||
expect(Guardian.new(post.user).can_edit?(post)).to be_falsey
|
||||
end
|
||||
|
||||
it 'returns true when trying to edit a post with trust' do
|
||||
SiteSetting.min_trust_to_edit_post = 1
|
||||
post.user.trust_level = 1
|
||||
|
||||
expect(Guardian.new(post.user).can_edit?(post)).to be_truthy
|
||||
end
|
||||
|
||||
it 'returns false when another user has too low trust level to edit wiki post' do
|
||||
SiteSetting.stubs(:min_trust_to_edit_wiki_post).returns(2)
|
||||
post.wiki = true
|
||||
|
||||
Reference in New Issue
Block a user