FEATURE: Trust level 4 abilities: pin/unpin, close, archive, make invisible, split/merge topic

This commit is contained in:
Neil Lalonde 2014-03-17 14:50:28 -04:00
parent 5b0d8d5ffd
commit 2c725e2779
6 changed files with 36 additions and 23 deletions

View File

@ -123,6 +123,9 @@ Discourse.User = Discourse.Model.extend({
return Discourse.Site.currentProp('trustLevels').findProperty('id', parseInt(this.get('trust_level'), 10)); return Discourse.Site.currentProp('trustLevels').findProperty('id', parseInt(this.get('trust_level'), 10));
}.property('trust_level'), }.property('trust_level'),
isElder: Em.computed.equal('trust_level', 4),
canManageTopic: Em.computed.or('staff', 'isElder'),
isSuspended: Em.computed.equal('suspended', true), isSuspended: Em.computed.equal('suspended', true),
suspended: function() { suspended: function() {

View File

@ -150,7 +150,7 @@
{{render quoteButton}} {{render quoteButton}}
{{/if}} {{/if}}
{{#if currentUser.staff}} {{#if currentUser.canManageTopic}}
{{render topicAdminMenu content}} {{render topicAdminMenu content}}
{{/if}} {{/if}}

View File

@ -58,9 +58,11 @@
</li> </li>
{{/if}} {{/if}}
{{#if currentUser.staff}}
<li> <li>
<button class='btn btn-admin' {{action resetRead}}><i class='fa fa-times'></i> {{i18n topic.actions.reset_read}}</button> <button class='btn btn-admin' {{action resetRead}}><i class='fa fa-times'></i> {{i18n topic.actions.reset_read}}</button>
</li> </li>
{{/if}}
</ul> </ul>
</div> </div>
{{else}} {{else}}

View File

@ -71,6 +71,26 @@ class Guardian
end end
end end
def can_create?(klass, parent=nil)
return false unless authenticated? && klass
# If no parent is provided, we look for a can_create_klass?
# custom method.
#
# If a parent is provided, we look for a method called
# can_create_klass_on_parent?
target = klass.name.underscore
if parent.present?
return false unless can_see?(parent)
target << "_on_#{parent.class.name.underscore}"
end
create_method = :"can_create_#{target}?"
return send(create_method, parent) if respond_to?(create_method)
true
end
# Can the user edit the obj # Can the user edit the obj
def can_edit?(obj) def can_edit?(obj)
can_do?(:edit, obj) can_do?(:edit, obj)
@ -82,7 +102,7 @@ class Guardian
end end
def can_moderate?(obj) def can_moderate?(obj)
obj && is_staff? obj && authenticated? && (is_staff? || (obj.is_a?(Topic) && @user.has_trust_level?(:elder)))
end end
alias :can_move_posts? :can_moderate? alias :can_move_posts? :can_moderate?
alias :can_see_flags? :can_moderate? alias :can_see_flags? :can_moderate?

View File

@ -1,25 +1,5 @@
#mixin for all guardian methods dealing with topic permisions #mixin for all guardian methods dealing with topic permisions
module TopicGuardian module TopicGuardian
# Can the user create a topic in the forum
def can_create?(klass, parent=nil)
return false unless authenticated? && klass
# If no parent is provided, we look for a can_i_create_klass?
# custom method.
#
# If a parent is provided, we look for a method called
# can_i_create_klass_on_parent?
target = klass.name.underscore
if parent.present?
return false unless can_see?(parent)
target << "_on_#{parent.class.name.underscore}"
end
create_method = :"can_create_#{target}?"
return send(create_method, parent) if respond_to?(create_method)
true
end
def can_remove_allowed_users?(topic) def can_remove_allowed_users?(topic)
is_staff? is_staff?
@ -41,7 +21,7 @@ module TopicGuardian
# No users can create posts on deleted topics # No users can create posts on deleted topics
return false if topic.trashed? return false if topic.trashed?
is_staff? || (not(topic.closed? || topic.archived? || topic.trashed?) && can_create_post?(topic)) is_staff? || (authenticated? && user.has_trust_level?(:elder)) || (not(topic.closed? || topic.archived? || topic.trashed?) && can_create_post?(topic))
end end
# Editing Method # Editing Method

View File

@ -409,6 +409,10 @@ describe Guardian do
it "allows new posts from admins" do it "allows new posts from admins" do
Guardian.new(admin).can_create?(Post, topic).should be_true Guardian.new(admin).can_create?(Post, topic).should be_true
end end
it "allows new posts from elders" do
Guardian.new(elder).can_create?(Post, topic).should be_true
end
end end
context 'archived topic' do context 'archived topic' do
@ -728,6 +732,10 @@ describe Guardian do
Guardian.new(admin).can_moderate?(topic).should be_true Guardian.new(admin).can_moderate?(topic).should be_true
end end
it 'returns true when trust level 4' do
Guardian.new(elder).can_moderate?(topic).should be_true
end
end end
end end