Commit 2f5cddea authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'check-jira-integrationn-license' into 'master'

Add license tier feature check

See merge request gitlab-org/gitlab!36540
parents 5a12723b 7e79d9c0
...@@ -2469,6 +2469,7 @@ class Project < ApplicationRecord ...@@ -2469,6 +2469,7 @@ class Project < ApplicationRecord
def service_desk_enabled def service_desk_enabled
Gitlab::ServiceDesk.enabled?(project: self) Gitlab::ServiceDesk.enabled?(project: self)
end end
alias_method :service_desk_enabled?, :service_desk_enabled alias_method :service_desk_enabled?, :service_desk_enabled
def service_desk_address def service_desk_address
......
...@@ -69,7 +69,7 @@ module Projects ...@@ -69,7 +69,7 @@ module Projects
protected protected
def check_feature_enabled! def check_feature_enabled!
return render_404 unless Feature.enabled?(:jira_integration, project) && project.external_issue_tracker return render_404 unless project.jira_issues_integration_available? && project.external_issue_tracker
end end
def render_bad_request(error) def render_bad_request(error)
......
...@@ -25,7 +25,7 @@ module Projects ...@@ -25,7 +25,7 @@ module Projects
end end
def execute def execute
return [] unless Feature.enabled?(:jira_integration, project) return [] unless project.jira_issues_integration_available?
raise IntegrationError, _('Jira service not configured.') unless jira_service&.active? raise IntegrationError, _('Jira service not configured.') unless jira_service&.active?
......
...@@ -6,7 +6,7 @@ module EE ...@@ -6,7 +6,7 @@ module EE
override :project_jira_issues_integration? override :project_jira_issues_integration?
def project_jira_issues_integration? def project_jira_issues_integration?
::Feature.enabled?(:jira_integration, @project) && @project.jira_service.issues_enabled @project.jira_issues_integration_available? && @project.jira_service.issues_enabled
end end
override :integration_form_data override :integration_form_data
......
...@@ -313,6 +313,10 @@ module EE ...@@ -313,6 +313,10 @@ module EE
end end
end end
def jira_issues_integration_available?
feature_available?(:jira_issues_integration)
end
def multiple_approval_rules_available? def multiple_approval_rules_available?
feature_available?(:multiple_approval_rules) feature_available?(:multiple_approval_rules)
end end
......
...@@ -82,6 +82,7 @@ class License < ApplicationRecord ...@@ -82,6 +82,7 @@ class License < ApplicationRecord
group_saml group_saml
issues_analytics issues_analytics
jira_dev_panel_integration jira_dev_panel_integration
jira_issues_integration
ldap_group_sync_filter ldap_group_sync_filter
merge_pipelines merge_pipelines
merge_request_performance_metrics merge_request_performance_metrics
......
...@@ -8,6 +8,10 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do ...@@ -8,6 +8,10 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:user) { create(:user) } let(:user) { create(:user) }
before do
stub_licensed_features(jira_issues_integration: true)
end
describe 'GET #index' do describe 'GET #index' do
before do before do
sign_in(user) sign_in(user)
...@@ -15,9 +19,9 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do ...@@ -15,9 +19,9 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do
create(:jira_service, project: project) create(:jira_service, project: project)
end end
context 'when jira_integration feature disabled' do context 'when jira_issues_integration licensed feature is not available' do
it 'returns 404 status' do it 'returns 404 status' do
stub_feature_flags(jira_integration: false) stub_licensed_features(jira_issues_integration: false)
get :index, params: { namespace_id: project.namespace, project_id: project } get :index, params: { namespace_id: project.namespace, project_id: project }
......
...@@ -3,15 +3,29 @@ ...@@ -3,15 +3,29 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Jira issues list' do RSpec.describe 'Jira issues list' do
let_it_be(:project) { create(:project) } let_it_be(:project, refind: true) { create(:project) }
let_it_be(:jira_integration) { create(:jira_service, project: project, issues_enabled: true) } let_it_be(:jira_integration) { create(:jira_service, project: project, issues_enabled: true) }
let(:user) { create(:user) } let(:user) { create(:user) }
before do before do
stub_licensed_features(jira_issues_integration: true)
project.add_user(user, :developer) project.add_user(user, :developer)
sign_in(user) sign_in(user)
end end
context 'when jira_issues_integration licensed feature is not available' do
before do
stub_licensed_features(jira_issues_integration: false)
end
it 'renders "Create new issue" button' do
visit project_integrations_jira_issues_path(project)
expect(page).to have_gitlab_http_status(:not_found)
expect(page).not_to have_link('Create new issue in Jira')
end
end
it 'renders "Create new issue" button' do it 'renders "Create new issue" button' do
visit project_integrations_jira_issues_path(project) visit project_integrations_jira_issues_path(project)
......
...@@ -9,6 +9,7 @@ RSpec.describe 'User activates Jira', :js do ...@@ -9,6 +9,7 @@ RSpec.describe 'User activates Jira', :js do
describe 'user sets and activates Jira Service' do describe 'user sets and activates Jira Service' do
context 'when Jira connection test succeeds' do context 'when Jira connection test succeeds' do
before do before do
stub_licensed_features(jira_issues_integration: true)
allow_any_instance_of(JiraService).to receive(:issues_enabled) { true } allow_any_instance_of(JiraService).to receive(:issues_enabled) { true }
server_info = { key: 'value' }.to_json server_info = { key: 'value' }.to_json
stub_request(:get, test_url).with(basic_auth: %w(username password)).to_return(body: server_info) stub_request(:get, test_url).with(basic_auth: %w(username password)).to_return(body: server_info)
...@@ -26,6 +27,21 @@ RSpec.describe 'User activates Jira', :js do ...@@ -26,6 +27,21 @@ RSpec.describe 'User activates Jira', :js do
expect(page).not_to have_link('Jira', href: url) expect(page).not_to have_link('Jira', href: url)
end end
end end
context 'when jira_issues_integration feature is not available' do
before do
stub_licensed_features(jira_issues_integration: false)
end
it 'does not show Jira links to sidebar menu' do
page.within('.nav-sidebar') do
expect(page).not_to have_link('Jira Issues', href: project_integrations_jira_issues_path(project))
expect(page).not_to have_link('Issue List', href: project_integrations_jira_issues_path(project), visible: false)
expect(page).not_to have_link('Open Jira', href: url, visible: false)
expect(page).to have_link('Jira', href: url)
end
end
end
end end
end end
end end
...@@ -3,24 +3,17 @@ ...@@ -3,24 +3,17 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Projects::Integrations::Jira::IssuesFinder do RSpec.describe Projects::Integrations::Jira::IssuesFinder do
let_it_be(:project, reload: true) { create(:project) } let_it_be(:project, refind: true) { create(:project) }
let_it_be(:jira_service, reload: true) { create(:jira_service, project: project) } let_it_be(:jira_service, reload: true) { create(:jira_service, project: project) }
let(:params) { {} } let(:params) { {} }
let(:service) { described_class.new(project, params) } let(:service) { described_class.new(project, params) }
describe '#execute' do
subject(:issues) { service.execute }
context 'when jira_integration feature flag is not enabled' do
before do before do
stub_feature_flags(jira_integration: false) stub_licensed_features(jira_issues_integration: true)
end end
it 'exits early and returns no issues' do describe '#execute' do
expect(issues.size).to eq 0 subject(:issues) { service.execute }
expect(service.total_count).to be_nil
end
end
context 'when jira service integration does not have project_key' do context 'when jira service integration does not have project_key' do
it 'raises error' do it 'raises error' do
...@@ -131,5 +124,14 @@ RSpec.describe Projects::Integrations::Jira::IssuesFinder do ...@@ -131,5 +124,14 @@ RSpec.describe Projects::Integrations::Jira::IssuesFinder do
end end
end end
end end
context 'when jira_issues_integration licensed feature is not available' do
it 'exits early and returns no issues' do
stub_licensed_features(jira_issues_integration: false)
expect(issues.size).to eq 0
expect(service.total_count).to be_nil
end
end
end end
end end
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