From 5ced7473bbf692832c48de1d3f72f0ace3b2d82c Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 7 Mar 2022 00:15:23 +0000 Subject: [PATCH] Add latest changes from gitlab-org/gitlab@master --- app/models/project.rb | 8 ++++---- doc/operations/feature_flags.md | 30 ++++++++++++++--------------- doc/user/search/index.md | 2 +- spec/models/project_spec.rb | 34 ++++++++++++++++++++++++++++++++- 4 files changed, 53 insertions(+), 21 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 5009824bba7..14e7bf6d975 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -352,15 +352,15 @@ class Project < ApplicationRecord has_many :pending_builds, class_name: 'Ci::PendingBuild' has_many :builds, class_name: 'Ci::Build', inverse_of: :project has_many :processables, class_name: 'Ci::Processable', inverse_of: :project - has_many :build_trace_chunks, class_name: 'Ci::BuildTraceChunk', through: :builds, source: :trace_chunks + has_many :build_trace_chunks, class_name: 'Ci::BuildTraceChunk', through: :builds, source: :trace_chunks, dependent: :restrict_with_error has_many :build_report_results, class_name: 'Ci::BuildReportResult', inverse_of: :project - has_many :job_artifacts, class_name: 'Ci::JobArtifact' - has_many :pipeline_artifacts, class_name: 'Ci::PipelineArtifact', inverse_of: :project + has_many :job_artifacts, class_name: 'Ci::JobArtifact', dependent: :restrict_with_error + has_many :pipeline_artifacts, class_name: 'Ci::PipelineArtifact', inverse_of: :project, dependent: :restrict_with_error has_many :runner_projects, class_name: 'Ci::RunnerProject', inverse_of: :project has_many :runners, through: :runner_projects, source: :runner, class_name: 'Ci::Runner' has_many :variables, class_name: 'Ci::Variable' has_many :triggers, class_name: 'Ci::Trigger' - has_many :secure_files, class_name: 'Ci::SecureFile' + has_many :secure_files, class_name: 'Ci::SecureFile', dependent: :restrict_with_error has_many :environments has_many :environments_for_dashboard, -> { from(with_rank.unfoldered.available, :environments).where('rank <= 3') }, class_name: 'Environment' has_many :deployments diff --git a/doc/operations/feature_flags.md b/doc/operations/feature_flags.md index 8903e99ab3b..95472f03f7f 100644 --- a/doc/operations/feature_flags.md +++ b/doc/operations/feature_flags.md @@ -163,21 +163,6 @@ WARNING: The Unleash client **must** be given a user ID for the feature to be enabled for target users. See the [Ruby example](#ruby-application-example) below. -## Search for Code References **(PREMIUM)** - -> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/300299) in GitLab 14.4. - -Search your project and find any references of a feature flag in your -code so that you can clean it up when it's time to remove the feature flag. - -To search for code references of a feature flag: - -1. On the top bar, select **Menu > Projects** and find your project. -1. On the left sidebar, select **Deployments > Feature Flags**. -1. Edit the feature flag you want to remove. -1. Select **More actions** (**{ellipsis_v}**). -1. Select **Search code references**. - ### User List > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/35930) in GitLab 13.1. @@ -235,6 +220,21 @@ To remove users from a user list: 1. Select **Edit** (**{pencil}**) next to the list you want to change. 1. Select **Remove** (**{remove}**) next to the ID you want to remove. +## Search for Code References **(PREMIUM)** + +> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/300299) in GitLab 14.4. + +Search your project and find any references of a feature flag in your +code so that you can clean it up when it's time to remove the feature flag. + +To search for code references of a feature flag: + +1. On the top bar, select **Menu > Projects** and find your project. +1. On the left sidebar, select **Deployments > Feature Flags**. +1. Edit the feature flag you want to remove. +1. Select **More actions** (**{ellipsis_v}**). +1. Select **Search code references**. + ## Rollout strategy (legacy) > - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/8240) in GitLab 12.2. diff --git a/doc/user/search/index.md b/doc/user/search/index.md index e57f9260f2c..c3fe021aa97 100644 --- a/doc/user/search/index.md +++ b/doc/user/search/index.md @@ -113,7 +113,7 @@ You can filter the **Issues** list to individual instances by their ID. For exam > Moved to GitLab Premium in 13.9. -To filter merge requests by an individual approver, you can type (or select from +To filter merge requests by an individual eligible approver ([Codeowner](../project/code_owners.md)), you can type (or select from the dropdown list) **Approver** and select the user. ![Filter MRs by an approver](img/filter_approver_merge_requests_v14_6.png) diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 8b2b57949fc..d2d06b64cb3 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -134,7 +134,7 @@ RSpec.describe Project, factory_default: :keep do it { is_expected.to have_many(:packages).class_name('Packages::Package') } it { is_expected.to have_many(:package_files).class_name('Packages::PackageFile') } it { is_expected.to have_many(:debian_distributions).class_name('Packages::Debian::ProjectDistribution').dependent(:destroy) } - it { is_expected.to have_many(:pipeline_artifacts) } + it { is_expected.to have_many(:pipeline_artifacts).dependent(:restrict_with_error) } it { is_expected.to have_many(:terraform_states).class_name('Terraform::State').inverse_of(:project) } it { is_expected.to have_many(:timelogs) } it { is_expected.to have_many(:error_tracking_errors).class_name('ErrorTracking::Error') } @@ -142,6 +142,9 @@ RSpec.describe Project, factory_default: :keep do it { is_expected.to have_many(:pending_builds).class_name('Ci::PendingBuild') } it { is_expected.to have_many(:ci_feature_usages).class_name('Projects::CiFeatureUsage') } it { is_expected.to have_many(:bulk_import_exports).class_name('BulkImports::Export') } + it { is_expected.to have_many(:job_artifacts).dependent(:restrict_with_error) } + it { is_expected.to have_many(:build_trace_chunks).through(:builds).dependent(:restrict_with_error) } + it { is_expected.to have_many(:secure_files).class_name('Ci::SecureFile').dependent(:restrict_with_error) } # GitLab Pages it { is_expected.to have_many(:pages_domains) } @@ -202,6 +205,35 @@ RSpec.describe Project, factory_default: :keep do end end + context 'when project has object storage attached to it' do + let_it_be(:project) { create(:project) } + + before do + create(:ci_job_artifact, project: project) + end + + context 'when associated object storage object is not deleted before the project' do + it 'adds an error to project', :aggregate_failures do + expect { project.destroy! }.to raise_error(ActiveRecord::RecordNotDestroyed) + + expect(project.errors).not_to be_empty + expect(project.errors.first.message).to eq("Cannot delete record because dependent job artifacts exist") + end + end + + context 'when associated object storage object is deleted before the project' do + before do + project.job_artifacts.first.destroy! + end + + it 'deletes the project' do + project.destroy! + + expect { project.reload }.to raise_error(ActiveRecord::RecordNotFound) + end + end + end + context 'when creating a new project' do let_it_be(:project) { create(:project) }