Commit 2fa22a07 authored by Jarka Kadlecova's avatar Jarka Kadlecova

Associate Issues tab only with internal issues tracker

parent b92d5135
...@@ -8,7 +8,6 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -8,7 +8,6 @@ class Projects::IssuesController < Projects::ApplicationController
prepend_before_action :authenticate_user!, only: [:new] prepend_before_action :authenticate_user!, only: [:new]
before_action :redirect_to_external_issue_tracker, only: [:index, :new]
before_action :check_issues_available! before_action :check_issues_available!
before_action :issue, except: [:index, :new, :create, :bulk_update] before_action :issue, except: [:index, :new, :create, :bulk_update]
...@@ -243,19 +242,19 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -243,19 +242,19 @@ class Projects::IssuesController < Projects::ApplicationController
end end
def authorize_update_issue! def authorize_update_issue!
return render_404 unless can?(current_user, :update_issue, @issue) render_404 unless can?(current_user, :update_issue, @issue)
end end
def authorize_admin_issues! def authorize_admin_issues!
return render_404 unless can?(current_user, :admin_issue, @project) render_404 unless can?(current_user, :admin_issue, @project)
end end
def authorize_create_merge_request! 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 end
def check_issues_available! 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 end
def redirect_to_external_issue_tracker def redirect_to_external_issue_tracker
...@@ -270,6 +269,10 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -270,6 +269,10 @@ class Projects::IssuesController < Projects::ApplicationController
end end
end end
def module_enabled
render_404 unless @project.feature_available?(:issues, current_user)
end
def issue_params def issue_params
params.require(:issue).permit(*issue_params_attributes) params.require(:issue).permit(*issue_params_attributes)
end end
......
...@@ -287,9 +287,6 @@ class ProjectPolicy < BasePolicy ...@@ -287,9 +287,6 @@ class ProjectPolicy < BasePolicy
prevent :create_issue prevent :create_issue
prevent :update_issue prevent :update_issue
prevent :admin_issue prevent :admin_issue
end
rule { issues_disabled & default_issues_tracker }.policy do
prevent :read_issue prevent :read_issue
end end
......
---
title: Associate Issues tab only with internal issues tracker
merge_request:
author:
...@@ -7,16 +7,30 @@ describe Projects::IssuesController do ...@@ -7,16 +7,30 @@ describe Projects::IssuesController do
describe "GET #index" do describe "GET #index" do
context 'external issue tracker' do context 'external issue tracker' do
let!(:service) do before do
create(:custom_issue_tracker_service, project: project, title: 'Custom Issue Tracker', project_url: 'http://test.com') sign_in(user)
project.add_developer(user)
create(:jira_service, project: project)
end end
it 'redirects to the external issue tracker' do context 'when GitLab issues disabled' do
controller.instance_variable_set(:@project, project) 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
end end
...@@ -42,15 +56,7 @@ describe Projects::IssuesController do ...@@ -42,15 +56,7 @@ describe Projects::IssuesController do
it "returns 404 when issues are disabled" do it "returns 404 when issues are disabled" do
project.issues_enabled = false project.issues_enabled = false
project.save 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)
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) expect(response).to have_http_status(404)
...@@ -148,14 +154,29 @@ describe Projects::IssuesController do ...@@ -148,14 +154,29 @@ describe Projects::IssuesController do
before do before do
sign_in(user) sign_in(user)
project.team << [user, :developer] project.team << [user, :developer]
external = double
allow(project).to receive(:external_issue_tracker).and_return(external)
end end
it 'redirects to the external issue tracker' do context 'when GitLab issues disabled' do
controller.instance_variable_set(:@project, project) 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 end
end end
......
...@@ -39,14 +39,25 @@ describe 'Edit Project Settings', feature: true do ...@@ -39,14 +39,25 @@ describe 'Edit Project Settings', feature: true do
end end
end end
context "When external issue tracker is enabled" do context 'When external issue tracker is enabled and issues enabled on project settings' do
it "does not hide issues tab" do it 'does not hide issues tab' do
project.project_feature.update(issues_access_level: ProjectFeature::DISABLED)
allow_any_instance_of(Project).to receive(:external_issue_tracker).and_return(JiraService.new) allow_any_instance_of(Project).to receive(:external_issue_tracker).and_return(JiraService.new)
visit project_path(project) 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
end end
......
...@@ -103,6 +103,30 @@ describe ProjectPolicy, models: true do ...@@ -103,6 +103,30 @@ describe ProjectPolicy, models: true do
end end
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 context 'abilities for non-public projects' do
let(:project) { create(:empty_project, namespace: owner.namespace) } let(:project) { create(:empty_project, namespace: owner.namespace) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment