Add Issuable#to_ability_name

This commit is contained in:
Robert Speicher 2015-07-24 15:31:15 -04:00
parent b5e6ffa616
commit 37bc7bac19
2 changed files with 12 additions and 2 deletions

View File

@ -159,6 +159,16 @@ module Issuable
end
end
# Convert this Issuable class name to a format usable by Ability definitions
#
# Examples:
#
# issuable.class # => MergeRequest
# issuable.to_ability_name # => "merge_request"
def to_ability_name
self.class.to_s.underscore
end
private
def filter_superceded_votes(votes, notes)

View File

@ -8,7 +8,7 @@
- else
none
.issuable-context-selectbox
- if can?(current_user, :"admin_#{issuable.class.to_s.underscore}", @project)
- if can?(current_user, :"admin_#{issuable.to_ability_name}", @project)
= users_select_tag("#{issuable.class.table_name.singularize}[assignee_id]", placeholder: 'Select assignee', class: 'custom-form-control js-select2 js-assignee', selected: issuable.assignee_id, project: @target_project, null_user: true)
%div.prepend-top-20.clearfix
@ -24,7 +24,7 @@
- else
none
.issuable-context-selectbox
- if can?(current_user, :"admin_#{issuable.class.to_s.underscore}", @project)
- if can?(current_user, :"admin_#{issuable.to_ability_name}", @project)
= f.select(:milestone_id, milestone_options(issuable), { include_blank: 'Select milestone' }, {class: 'select2 select2-compact js-select2 js-milestone'})
= hidden_field_tag :issuable_context
= f.submit class: 'btn hide'