Commit 71e64878 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch...

Merge branch '276893-add-vulnerabilities-support-for-group-and-instance-jira-integration' into 'master'

Add support for enabling Jira for Vulnerabilites for Group/Intance

See merge request gitlab-org/gitlab!48135
parents 473ee64b d2a67afc
......@@ -414,6 +414,10 @@ class Service < ApplicationRecord
!instance? && !group_id
end
def parent
project || group
end
# Returns a hash of the properties that have been assigned a new value since last save,
# indicating their original values (attr => original value).
# ActiveRecord does not provide a mechanism to track changes in serialized keys,
......
......@@ -16,7 +16,7 @@ module EE
if integration.is_a?(JiraService)
form_data.merge!(
show_jira_issues_integration: @project&.feature_available?(:jira_issues_integration).to_s,
show_jira_vulnerabilities_integration: @project&.jira_vulnerabilities_integration_available?.to_s,
show_jira_vulnerabilities_integration: integration.jira_vulnerabilities_integration_available?.to_s,
enable_jira_issues: integration.issues_enabled.to_s,
enable_jira_vulnerabilities: integration.jira_vulnerabilities_integration_enabled?.to_s,
project_key: integration.project_key,
......
......@@ -346,10 +346,6 @@ module EE
feature_available?(:jira_issues_integration)
end
def jira_vulnerabilities_integration_available?
::Feature.enabled?(:jira_for_vulnerabilities, self, default_enabled: false) && feature_available?(:jira_vulnerabilities_integration)
end
def multiple_approval_rules_available?
feature_available?(:multiple_approval_rules)
end
......
......@@ -11,8 +11,15 @@ module EE
validates :vulnerabilities_issuetype, presence: true, if: :vulnerabilities_enabled
end
def jira_vulnerabilities_integration_available?
feature_enabled = ::Feature.enabled?(:jira_for_vulnerabilities, parent, default_enabled: false)
feature_available = parent.present? ? parent&.feature_available?(:jira_vulnerabilities_integration) : License.feature_available?(:jira_vulnerabilities_integration)
feature_enabled && feature_available
end
def jira_vulnerabilities_integration_enabled?
project&.jira_vulnerabilities_integration_available? && vulnerabilities_enabled
jira_vulnerabilities_integration_available? && vulnerabilities_enabled
end
def project_key_required?
......
......@@ -37,7 +37,7 @@ RSpec.describe EE::ServicesHelper do
context 'when there is no license for jira_vulnerabilities_integration' do
before do
stub_feature_flags(jira_for_vulnerabilities: true)
allow(integration).to receive(:jira_vulnerabilities_integration_available?).and_return(false)
end
it 'includes Jira specific fields' do
......
......@@ -48,20 +48,16 @@ RSpec.describe JiraService do
context 'when jira integration is not available for the project' do
before do
allow(jira_service.project).to receive(:jira_vulnerabilities_integration_available?).and_return(false)
stub_feature_flags(jira_for_vulnerabilities: false)
end
context 'when vulnerabilities_enabled is set to false' do
before do
allow(jira_service).to receive(:vulnerabilities_enabled).and_return(false)
end
it { is_expected.to eq(false) }
it { is_expected.to be_falsey }
end
context 'when vulnerabilities_enabled is set to true' do
before do
allow(jira_service).to receive(:vulnerabilities_enabled).and_return(true)
jira_service.vulnerabilities_enabled = true
end
it { is_expected.to eq(false) }
......@@ -70,20 +66,16 @@ RSpec.describe JiraService do
context 'when jira integration is available for the project' do
before do
allow(jira_service.project).to receive(:jira_vulnerabilities_integration_available?).and_return(true)
stub_licensed_features(jira_vulnerabilities_integration: true)
end
context 'when vulnerabilities_enabled is set to false' do
before do
allow(jira_service).to receive(:vulnerabilities_enabled).and_return(false)
end
it { is_expected.to eq(false) }
it { is_expected.to be_falsey }
end
context 'when vulnerabilities_enabled is set to true' do
before do
allow(jira_service).to receive(:vulnerabilities_enabled).and_return(true)
jira_service.vulnerabilities_enabled = true
end
it { is_expected.to eq(true) }
......
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