From a7d8a7bd3d4b6f7b388d8976201cbdf3b36ab7aa Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 22 May 2015 06:17:37 -0400 Subject: Disable "New Issue" and "New Merge Request" buttons when features are disabled in project settings Closes #1676 --- CHANGELOG | 1 + app/models/ability.rb | 27 ++++++++++++++++++++ app/views/projects/_dropdown.html.haml | 37 ---------------------------- app/views/projects/milestones/show.html.haml | 2 +- features/project/project.feature | 6 +++++ features/steps/project/project.rb | 8 ++++++ features/steps/shared/project.rb | 6 +++++ 7 files changed, 49 insertions(+), 38 deletions(-) delete mode 100644 app/views/projects/_dropdown.html.haml diff --git a/CHANGELOG b/CHANGELOG index d1ecfb40350..c78e7f9b621 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) + - 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) - Disabled expansion of top/bottom blobs for new file diffs - Update Asciidoctor gem to version 1.5.2. (Jakub Jirutka) diff --git a/app/models/ability.rb b/app/models/ability.rb index 85a15596f8d..04d9dccf916 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -101,6 +101,22 @@ class Ability rules -= project_archived_rules end + unless project.issues_enabled + rules -= named_abilities('issue') + end + + unless project.merge_requests_enabled + rules -= named_abilities('merge_request') + end + + unless project.snippets_enabled + rules -= named_abilities('snippet') + end + + unless project.wiki_enabled + rules -= named_abilities('wiki') + end + rules end end @@ -272,5 +288,16 @@ class Ability abilities end end + + private + + def named_abilities(name) + [ + :"read_#{name}", + :"write_#{name}", + :"modify_#{name}", + :"admin_#{name}" + ] + end end end diff --git a/app/views/projects/_dropdown.html.haml b/app/views/projects/_dropdown.html.haml deleted file mode 100644 index d623a3716ed..00000000000 --- a/app/views/projects/_dropdown.html.haml +++ /dev/null @@ -1,37 +0,0 @@ -- if current_user - .dropdown.pull-right - %a.dropdown-toggle.btn.btn-sm{href: '#', "data-toggle" => "dropdown"} - %i.fa.fa-bars - %ul.dropdown-menu - - if @project.issues_enabled && can?(current_user, :write_issue, @project) - %li - = link_to url_for_new_issue(@project, only_path: true), title: "New Issue" do - %i.fa.fa-fw.fa-exclamation-circle - New issue - - if @project.merge_requests_enabled && can?(current_user, :write_merge_request, @project) - %li - = link_to new_namespace_project_merge_request_path(@project.namespace, @project), title: "New Merge Request" do - %i.fa.fa-fw.fa-tasks - New merge request - - if @project.snippets_enabled && can?(current_user, :write_snippet, @project) - %li - = link_to new_namespace_project_snippet_path(@project.namespace, @project), title: "New Snippet" do - %i.fa.fa-fw.fa-file-text-o - New snippet - - if can?(current_user, :admin_project_member, @project) - %li - = link_to namespace_project_project_members_path(@project.namespace, @project), title: "New project member" do - %i.fa.fa-fw.fa-users - New project member - - if can? current_user, :push_code, @project - %li.divider - %li - = link_to new_namespace_project_branch_path(@project.namespace, @project) do - %i.fa.fa-fw.fa-code-fork - New branch - %li - = link_to new_namespace_project_tag_path(@project.namespace, @project) do - %i.fa.fa-fw.fa-tag - New tag - - diff --git a/app/views/projects/milestones/show.html.haml b/app/views/projects/milestones/show.html.haml index bba2b8764ac..22172a31289 100644 --- a/app/views/projects/milestones/show.html.haml +++ b/app/views/projects/milestones/show.html.haml @@ -61,7 +61,7 @@ Participants %span.badge= @users.count - - if @project.issues_enabled + - if can?(current_user, :write_issue, @project) .pull-right = 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 diff --git a/features/project/project.feature b/features/project/project.feature index ae28312a69a..ef11bceed11 100644 --- a/features/project/project.feature +++ b/features/project/project.feature @@ -62,3 +62,9 @@ Feature: Project And I add project tags And I save project Then I should see project tags + + Scenario: I should not see "New Issue" or "New Merge Request" buttons + Given I disable issues and merge requests in project + When I visit project "Shop" page + Then I should not see "New Issue" button + And I should not see "New Merge Request" button diff --git a/features/steps/project/project.rb b/features/steps/project/project.rb index 00706ab30e9..93fea693f89 100644 --- a/features/steps/project/project.rb +++ b/features/steps/project/project.rb @@ -102,4 +102,12 @@ class Spinach::Features::Project < Spinach::FeatureSteps step 'I should see project tags' do expect(find_field('Tags').value).to eq 'tag1, tag2' end + + step 'I should not see "New Issue" button' do + page.should_not have_link 'New Issue' + end + + step 'I should not see "New Merge Request" button' do + page.should_not have_link 'New Merge Request' + end end diff --git a/features/steps/shared/project.rb b/features/steps/shared/project.rb index b60ac5e3423..24136fe421c 100644 --- a/features/steps/shared/project.rb +++ b/features/steps/shared/project.rb @@ -14,6 +14,12 @@ module SharedProject @project.team << [@user, :master] end + step 'I disable issues and merge requests in project' do + @project.issues_enabled = false + @project.merge_requests_enabled = false + @project.save + end + # Add another user to project "Shop" step 'I add a user to project "Shop"' do @project = Project.find_by(name: "Shop") -- cgit v1.2.1