diff options
author | Stan Hu <stanhu@gmail.com> | 2015-05-25 17:42:41 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2015-05-26 02:51:04 +0300 |
commit | 9bcd36396b9b71467f66dd4ed79ab709bb5d027a (patch) | |
tree | 39d444294c96393beaccdd8dc0acebb4c62a6541 | |
parent | bdf7b44ac36809383431d439c343b313fc7b1d90 (diff) |
Refactor permission checks to use `can?` instead of `issues_enabled` and `merge_requests_enabled`
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/helpers/projects_helper.rb | 16 | ||||
-rw-r--r-- | app/models/ability.rb | 5 | ||||
-rw-r--r-- | app/views/projects/milestones/show.html.haml | 5 |
4 files changed, 21 insertions, 6 deletions
diff --git a/CHANGELOG b/CHANGELOG index ed9ffefb67f..d1ba75a0dc5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 7.12.0 (unreleased) + - Refactor permission checks with issues and merge requests project settings (Stan Hu) - Add web hook support for note events (Stan Hu) - Disable "New Issue" and "New Merge Request" buttons when features are disabled in project settings (Stan Hu) - Allow to configure location of the `.gitlab_shell_secret` file. (Jakub Jirutka) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 96d2606f1a1..f8df39d236a 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -148,7 +148,7 @@ module ProjectsHelper nav_tabs << [:files, :commits, :network, :graphs] end - if project.repo_exists? && project.merge_requests_enabled + if project.repo_exists? && can?(current_user, :read_merge_request, project) nav_tabs << :merge_requests end @@ -156,11 +156,19 @@ module ProjectsHelper nav_tabs << :settings end - [:issues, :wiki, :snippets].each do |feature| - nav_tabs << feature if project.send :"#{feature}_enabled" + if can?(current_user, :read_issue, project) + nav_tabs << :issues end - if project.issues_enabled || project.merge_requests_enabled + if can?(current_user, :read_wiki, project) + nav_tabs << :wiki + end + + if can?(current_user, :read_project_snippet, project) + nav_tabs << :snippets + end + + if can?(current_user, :read_milestone, project) nav_tabs << [:milestones, :labels] end diff --git a/app/models/ability.rb b/app/models/ability.rb index 04d9dccf916..e166b4197fd 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -109,6 +109,11 @@ class Ability rules -= named_abilities('merge_request') end + unless project.issues_enabled or project.merge_requests_enabled + rules -= named_abilities('label') + rules -= named_abilities('milestone') + end + unless project.snippets_enabled rules -= named_abilities('snippet') end diff --git a/app/views/projects/milestones/show.html.haml b/app/views/projects/milestones/show.html.haml index 22172a31289..5845fd744f4 100644 --- a/app/views/projects/milestones/show.html.haml +++ b/app/views/projects/milestones/show.html.haml @@ -61,11 +61,12 @@ Participants %span.badge= @users.count - - if can?(current_user, :write_issue, @project) - .pull-right + .pull-right + - if can?(current_user, :write_issue, @project) = link_to new_namespace_project_issue_path(@project.namespace, @project, issue: { milestone_id: @milestone.id }), class: "btn btn-grouped", title: "New Issue" do %i.fa.fa-plus New Issue + - if can?(current_user, :read_issue, @project) = link_to 'Browse Issues', namespace_project_issues_path(@milestone.project.namespace, @milestone.project, milestone_id: @milestone.id), class: "btn edit-milestone-link btn-grouped" .tab-content |