diff options
author | Jarka Kadlecova <jarka@gitlab.com> | 2017-06-13 11:25:25 +0300 |
---|---|---|
committer | Jarka Kadlecova <jarka@gitlab.com> | 2017-07-24 09:10:14 +0300 |
commit | 2fa22a07296223c1239bfab94654487cca222097 (patch) | |
tree | cf930855ad24ad2770a832d530e5a5ae36719825 | |
parent | b92d5135d8522e1370636799d74b51f9a37d0b2f (diff) |
Associate Issues tab only with internal issues tracker
-rw-r--r-- | app/controllers/projects/issues_controller.rb | 13 | ||||
-rw-r--r-- | app/policies/project_policy.rb | 3 | ||||
-rw-r--r-- | changelogs/unreleased/33097-issue-tracker.yml | 4 | ||||
-rw-r--r-- | spec/controllers/projects/issues_controller_spec.rb | 59 | ||||
-rw-r--r-- | spec/features/projects/features_visibility_spec.rb | 19 | ||||
-rw-r--r-- | spec/policies/project_policy_spec.rb | 24 |
6 files changed, 91 insertions, 31 deletions
diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb index 0ac9da2ff0f..5b0eeac2477 100644 --- a/app/controllers/projects/issues_controller.rb +++ b/app/controllers/projects/issues_controller.rb @@ -8,7 +8,6 @@ class Projects::IssuesController < Projects::ApplicationController prepend_before_action :authenticate_user!, only: [:new] - before_action :redirect_to_external_issue_tracker, only: [:index, :new] before_action :check_issues_available! before_action :issue, except: [:index, :new, :create, :bulk_update] @@ -243,19 +242,19 @@ class Projects::IssuesController < Projects::ApplicationController end def authorize_update_issue! - return render_404 unless can?(current_user, :update_issue, @issue) + render_404 unless can?(current_user, :update_issue, @issue) end def authorize_admin_issues! - return render_404 unless can?(current_user, :admin_issue, @project) + render_404 unless can?(current_user, :admin_issue, @project) end def authorize_create_merge_request! - return render_404 unless can?(current_user, :push_code, @project) && @issue.can_be_worked_on?(current_user) + render_404 unless can?(current_user, :push_code, @project) && @issue.can_be_worked_on?(current_user) end def check_issues_available! - return render_404 unless @project.feature_available?(:issues, current_user) && @project.default_issues_tracker? + return render_404 unless @project.feature_available?(:issues, current_user) end def redirect_to_external_issue_tracker @@ -270,6 +269,10 @@ class Projects::IssuesController < Projects::ApplicationController end end + def module_enabled + render_404 unless @project.feature_available?(:issues, current_user) + end + def issue_params params.require(:issue).permit(*issue_params_attributes) end diff --git a/app/policies/project_policy.rb b/app/policies/project_policy.rb index 323131c0f7e..d27bbf2948c 100644 --- a/app/policies/project_policy.rb +++ b/app/policies/project_policy.rb @@ -287,9 +287,6 @@ class ProjectPolicy < BasePolicy prevent :create_issue prevent :update_issue prevent :admin_issue - end - - rule { issues_disabled & default_issues_tracker }.policy do prevent :read_issue end diff --git a/changelogs/unreleased/33097-issue-tracker.yml b/changelogs/unreleased/33097-issue-tracker.yml new file mode 100644 index 00000000000..0b13f7165db --- /dev/null +++ b/changelogs/unreleased/33097-issue-tracker.yml @@ -0,0 +1,4 @@ +--- +title: Associate Issues tab only with internal issues tracker +merge_request: +author: diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb index 18d0be3c103..e56f5d11daf 100644 --- a/spec/controllers/projects/issues_controller_spec.rb +++ b/spec/controllers/projects/issues_controller_spec.rb @@ -7,16 +7,30 @@ describe Projects::IssuesController do describe "GET #index" do context 'external issue tracker' do - let!(:service) do - create(:custom_issue_tracker_service, project: project, title: 'Custom Issue Tracker', project_url: 'http://test.com') + before do + sign_in(user) + project.add_developer(user) + create(:jira_service, project: project) end - it 'redirects to the external issue tracker' do - controller.instance_variable_set(:@project, project) + context 'when GitLab issues disabled' do + it 'returns 404 status' do + project.issues_enabled = false + project.save! - get :index, namespace_id: project.namespace, project_id: project + get :index, namespace_id: project.namespace, project_id: project + + expect(response).to have_http_status(404) + end + end + + context 'when GitLab issues enabled' do + it 'renders the "index" template' do + get :index, namespace_id: project.namespace, project_id: project - expect(response).to redirect_to(service.issue_tracker_path) + expect(response).to have_http_status(200) + expect(response).to render_template(:index) + end end end @@ -42,15 +56,7 @@ describe Projects::IssuesController do it "returns 404 when issues are disabled" do project.issues_enabled = false - project.save - - get :index, namespace_id: project.namespace, project_id: project - expect(response).to have_http_status(404) - end - - it "returns 404 when external issue tracker is enabled" do - controller.instance_variable_set(:@project, project) - allow(project).to receive(:default_issues_tracker?).and_return(false) + project.save! get :index, namespace_id: project.namespace, project_id: project expect(response).to have_http_status(404) @@ -148,14 +154,29 @@ describe Projects::IssuesController do before do sign_in(user) project.team << [user, :developer] + + external = double + allow(project).to receive(:external_issue_tracker).and_return(external) end - it 'redirects to the external issue tracker' do - controller.instance_variable_set(:@project, project) + context 'when GitLab issues disabled' do + it 'returns 404 status' do + project.issues_enabled = false + project.save! - get :new, namespace_id: project.namespace, project_id: project + get :new, namespace_id: project.namespace, project_id: project - expect(response).to redirect_to('http://test.com') + expect(response).to have_http_status(404) + end + end + + context 'when GitLab issues enabled' do + it 'renders the "new" template' do + get :new, namespace_id: project.namespace, project_id: project + + expect(response).to have_http_status(200) + expect(response).to render_template(:new) + end end end end diff --git a/spec/features/projects/features_visibility_spec.rb b/spec/features/projects/features_visibility_spec.rb index 827e02a58d0..2091c7b79d3 100644 --- a/spec/features/projects/features_visibility_spec.rb +++ b/spec/features/projects/features_visibility_spec.rb @@ -39,14 +39,25 @@ describe 'Edit Project Settings', feature: true do end end - context "When external issue tracker is enabled" do - it "does not hide issues tab" do - project.project_feature.update(issues_access_level: ProjectFeature::DISABLED) + context 'When external issue tracker is enabled and issues enabled on project settings' do + it 'does not hide issues tab' do allow_any_instance_of(Project).to receive(:external_issue_tracker).and_return(JiraService.new) visit project_path(project) - expect(page).to have_selector(".shortcuts-issues") + expect(page).to have_selector('.shortcuts-issues') + end + end + + context 'When external issue tracker is enabled and issues disabled on project settings' do + it 'hides issues tab' do + project.issues_enabled = false + project.save! + allow_any_instance_of(Project).to receive(:external_issue_tracker).and_return(JiraService.new) + + visit namespace_project_path(project.namespace, project) + + expect(page).not_to have_selector('.shortcuts-issues') end end diff --git a/spec/policies/project_policy_spec.rb b/spec/policies/project_policy_spec.rb index ca435dd0218..4ed788af811 100644 --- a/spec/policies/project_policy_spec.rb +++ b/spec/policies/project_policy_spec.rb @@ -103,6 +103,30 @@ describe ProjectPolicy, models: true do end end + context 'issues feature' do + subject { described_class.new(owner, project) } + + context 'when the feature is disabled' do + it 'does not include the issues permissions' do + project.issues_enabled = false + project.save! + + expect_disallowed :read_issue, :create_issue, :update_issue, :admin_issue + end + end + + context 'when the feature is disabled and external tracker configured' do + it 'does not include the issues permissions' do + create(:jira_service, project: project) + + project.issues_enabled = false + project.save! + + expect_disallowed :read_issue, :create_issue, :update_issue, :admin_issue + end + end + end + context 'abilities for non-public projects' do let(:project) { create(:empty_project, namespace: owner.namespace) } |