summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-07-24 15:31:15 -0400
committerValery Sizov <vsv2711@gmail.com>2015-07-28 14:39:38 +0300
commit9079f4dd72c146149a0f9faed5d2b0fd16a1176d (patch)
treedeef36f7983093105e1f9d0a7542a634becd32cb
parent1dac44bf8535afdcc91c7a08788035e1ac245000 (diff)
downloadgitlab-ce-9079f4dd72c146149a0f9faed5d2b0fd16a1176d.tar.gz
Add Issuable#to_ability_name
-rw-r--r--app/models/concerns/issuable.rb10
-rw-r--r--app/views/shared/issuable/_context.html.haml4
2 files changed, 12 insertions, 2 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb
index 97846b06d72..c21e7fd0e3b 100644
--- a/app/models/concerns/issuable.rb
+++ b/app/models/concerns/issuable.rb
@@ -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)
diff --git a/app/views/shared/issuable/_context.html.haml b/app/views/shared/issuable/_context.html.haml
index d1bd5ef968d..19e8c31975b 100644
--- a/app/views/shared/issuable/_context.html.haml
+++ b/app/views/shared/issuable/_context.html.haml
@@ -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'