Commit d24ac7d0 authored by Imre Farkas's avatar Imre Farkas

Merge branch 'fix-project-compliance-pipeline-relation' into 'master'

Fix relationship between project and compliance framework

See merge request gitlab-org/gitlab!52813
parents 19344f0e 60564aa2
......@@ -46,7 +46,7 @@ module EE
has_one :status_page_setting, inverse_of: :project, class_name: 'StatusPage::ProjectSetting'
has_one :compliance_framework_setting, class_name: 'ComplianceManagement::ComplianceFramework::ProjectSettings', inverse_of: :project
has_many :compliance_management_frameworks, through: :compliance_framework_setting, source: 'compliance_management_framework'
has_one :compliance_management_framework, through: :compliance_framework_setting, source: 'compliance_management_framework'
has_one :security_setting, class_name: 'ProjectSecuritySetting'
has_one :vulnerability_statistic, class_name: 'Vulnerabilities::Statistic'
......@@ -200,6 +200,8 @@ module EE
delegate :jira_vulnerabilities_integration_enabled?, to: :jira_service, allow_nil: true
delegate :requirements_access_level, to: :project_feature, allow_nil: true
delegate :pipeline_configuration_full_path, to: :compliance_management_framework, allow_nil: true
alias_attribute :compliance_pipeline_configuration_full_path, :pipeline_configuration_full_path
validates :repository_size_limit,
numericality: { only_integer: true, greater_than_or_equal_to: 0, allow_nil: true }
......
......@@ -218,7 +218,7 @@ RSpec.describe GitlabSchema.types['Project'] do
end
frameworks = results.flat_map(&:to_a)
expect(frameworks).to match_array(projects.flat_map(&:compliance_management_frameworks))
expect(frameworks).to match_array(projects.flat_map(&:compliance_management_framework))
end
end
......
......@@ -19,12 +19,15 @@ RSpec.describe Project do
it { is_expected.to delegate_method(:closest_gitlab_subscription).to(:namespace) }
it { is_expected.to delegate_method(:pipeline_configuration_full_path).to(:compliance_management_framework) }
it { is_expected.to belong_to(:deleting_user) }
it { is_expected.to have_one(:import_state).class_name('ProjectImportState') }
it { is_expected.to have_one(:repository_state).class_name('ProjectRepositoryState').inverse_of(:project) }
it { is_expected.to have_one(:status_page_setting).class_name('StatusPage::ProjectSetting') }
it { is_expected.to have_one(:compliance_framework_setting).class_name('ComplianceManagement::ComplianceFramework::ProjectSettings') }
it { is_expected.to have_one(:compliance_management_framework).class_name('ComplianceManagement::Framework') }
it { is_expected.to have_one(:security_setting).class_name('ProjectSecuritySetting') }
it { is_expected.to have_one(:vulnerability_statistic).class_name('Vulnerabilities::Statistic') }
......
......@@ -310,18 +310,18 @@ RSpec.describe Projects::UpdateService, '#execute' do
expect { update_project(project, user, opts) }.to change {
project
.reload
.compliance_management_frameworks
}.from([]).to([framework])
.compliance_management_framework
}.from(nil).to(framework)
end
it 'unassigns a framework from a project' do
project.compliance_management_frameworks = [framework]
project.compliance_management_framework = framework
expect { update_project(project, user, { compliance_framework_setting_attributes: { framework: nil } }) }.to change {
project
.reload
.compliance_management_frameworks
}.from([framework]).to([])
.compliance_management_framework
}.from(framework).to(nil)
end
end
......@@ -331,7 +331,9 @@ RSpec.describe Projects::UpdateService, '#execute' do
end
it 'does not set a framework' do
expect { update_project(project, user, opts) }.not_to change { project.reload.compliance_management_frameworks.count }
update_project(project, user, opts)
expect(project.reload.compliance_management_framework).not_to be_present
end
end
end
......
......@@ -545,7 +545,7 @@ project:
- daily_build_group_report_results
- jira_imports
- compliance_framework_setting
- compliance_management_frameworks
- compliance_management_framework
- metrics_users_starred_dashboards
- alert_management_alerts
- repository_storage_moves
......
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