Commit 60564aa2 authored by Aishwarya Subramanian's avatar Aishwarya Subramanian

Fix relationship between project and compliance framework

Updates project has_one compliance_management_framework
Was previously a has_many relationship.
Adds deletgation for pipeline_configuration_full_path
in project model required as part of
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52629
parent ad287243
...@@ -46,7 +46,7 @@ module EE ...@@ -46,7 +46,7 @@ module EE
has_one :status_page_setting, inverse_of: :project, class_name: 'StatusPage::ProjectSetting' 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_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 :security_setting, class_name: 'ProjectSecuritySetting'
has_one :vulnerability_statistic, class_name: 'Vulnerabilities::Statistic' has_one :vulnerability_statistic, class_name: 'Vulnerabilities::Statistic'
...@@ -200,6 +200,8 @@ module EE ...@@ -200,6 +200,8 @@ module EE
delegate :jira_vulnerabilities_integration_enabled?, to: :jira_service, allow_nil: true delegate :jira_vulnerabilities_integration_enabled?, to: :jira_service, allow_nil: true
delegate :requirements_access_level, to: :project_feature, 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, validates :repository_size_limit,
numericality: { only_integer: true, greater_than_or_equal_to: 0, allow_nil: true } numericality: { only_integer: true, greater_than_or_equal_to: 0, allow_nil: true }
......
...@@ -218,7 +218,7 @@ RSpec.describe GitlabSchema.types['Project'] do ...@@ -218,7 +218,7 @@ RSpec.describe GitlabSchema.types['Project'] do
end end
frameworks = results.flat_map(&:to_a) 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
end end
......
...@@ -19,12 +19,15 @@ RSpec.describe Project do ...@@ -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(: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 belong_to(:deleting_user) }
it { is_expected.to have_one(:import_state).class_name('ProjectImportState') } 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(: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(: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_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(:security_setting).class_name('ProjectSecuritySetting') }
it { is_expected.to have_one(:vulnerability_statistic).class_name('Vulnerabilities::Statistic') } it { is_expected.to have_one(:vulnerability_statistic).class_name('Vulnerabilities::Statistic') }
......
...@@ -310,18 +310,18 @@ RSpec.describe Projects::UpdateService, '#execute' do ...@@ -310,18 +310,18 @@ RSpec.describe Projects::UpdateService, '#execute' do
expect { update_project(project, user, opts) }.to change { expect { update_project(project, user, opts) }.to change {
project project
.reload .reload
.compliance_management_frameworks .compliance_management_framework
}.from([]).to([framework]) }.from(nil).to(framework)
end end
it 'unassigns a framework from a project' do 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 { expect { update_project(project, user, { compliance_framework_setting_attributes: { framework: nil } }) }.to change {
project project
.reload .reload
.compliance_management_frameworks .compliance_management_framework
}.from([framework]).to([]) }.from(framework).to(nil)
end end
end end
...@@ -331,7 +331,9 @@ RSpec.describe Projects::UpdateService, '#execute' do ...@@ -331,7 +331,9 @@ RSpec.describe Projects::UpdateService, '#execute' do
end end
it 'does not set a framework' do 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 end
end end
......
...@@ -545,7 +545,7 @@ project: ...@@ -545,7 +545,7 @@ project:
- daily_build_group_report_results - daily_build_group_report_results
- jira_imports - jira_imports
- compliance_framework_setting - compliance_framework_setting
- compliance_management_frameworks - compliance_management_framework
- metrics_users_starred_dashboards - metrics_users_starred_dashboards
- alert_management_alerts - alert_management_alerts
- repository_storage_moves - 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