From 62440d9e4d2429405f21b3d41ffb4f7cadeef905 Mon Sep 17 00:00:00 2001 From: huzaifaiftikhar1 Date: Tue, 16 Aug 2022 19:55:41 +0530 Subject: [PATCH 1/2] Disable support for delayed project deletion for personal projects Disable delayed project deletion feature for personal projects that are in user namespace. Changelog: removed EE: true --- .../visibility_and_access_controls.md | 1 + doc/user/project/settings/index.md | 5 ++-- ee/app/models/ee/project.rb | 15 ++++-------- .../controllers/projects_controller_spec.rb | 18 +------------- .../factories/namespaces/user_namespaces.rb | 24 ------------------- ee/spec/models/project_spec.rb | 8 ++----- 6 files changed, 12 insertions(+), 59 deletions(-) delete mode 100644 ee/spec/factories/namespaces/user_namespaces.rb diff --git a/doc/user/admin_area/settings/visibility_and_access_controls.md b/doc/user/admin_area/settings/visibility_and_access_controls.md index 361a14be75c7a2..01650a95d5610e 100644 --- a/doc/user/admin_area/settings/visibility_and_access_controls.md +++ b/doc/user/admin_area/settings/visibility_and_access_controls.md @@ -53,6 +53,7 @@ By default both administrators and anyone with the **Owner** role can delete a p > - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/255449) in GitLab 14.2 for groups created after August 12, 2021. > - [Renamed](https://gitlab.com/gitlab-org/gitlab/-/issues/352960) from default delayed project deletion in GitLab 15.1. > - [Enabled for projects in personal namespaces](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/89466) in GitLab 15.1. +> - [Disabled for projects in personal namespaces](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/95495) in GitLab 15.4. Instance-level protection against accidental deletion of groups and projects. diff --git a/doc/user/project/settings/index.md b/doc/user/project/settings/index.md index 5a3a7e13205e5f..87df964b5257aa 100644 --- a/doc/user/project/settings/index.md +++ b/doc/user/project/settings/index.md @@ -447,9 +447,10 @@ in GitLab 12.6, and then to [immediate deletion](https://gitlab.com/gitlab-org/g ### Delayed project deletion **(PREMIUM)** -> [Enabled for projects in personal namespaces](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/89466) in GitLab 15.1. +> - [Enabled for projects in personal namespaces](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/89466) in GitLab 15.1. +> - [Disabled for projects in personal namespaces](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/95495) in GitLab 15.4. -Projects can be deleted after a delay period. Multiple settings can affect whether +Projects in a group (not a personal namespace) can be deleted after a delay period. Multiple settings can affect whether delayed project deletion is enabled for a particular project: - Self-managed instance [settings](../../admin_area/settings/visibility_and_access_controls.md#delayed-project-deletion). diff --git a/ee/app/models/ee/project.rb b/ee/app/models/ee/project.rb index 5464757b9c9564..8a2266983ff207 100644 --- a/ee/app/models/ee/project.rb +++ b/ee/app/models/ee/project.rb @@ -137,7 +137,7 @@ def lock_for_confirmation!(id) scope :verification_failed_wikis, -> { joins(:repository_state).merge(ProjectRepositoryState.verification_failed_wikis) } scope :for_plan_name, -> (name) { joins(namespace: { gitlab_subscription: :hosted_plan }).where(plans: { name: name }) } scope :with_feature_available, -> (name) do - projects_with_feature_available_in_plan = ::Project.in_namespace(::Namespace.with_feature_available_in_plan(name)) + projects_with_feature_available_in_plan = ::Project.for_group(::Group.with_feature_available_in_plan(name)) public_projects_in_public_groups = ::Project.public_only.for_group(::Group.public_only) from_union([projects_with_feature_available_in_plan, public_projects_in_public_groups]) end @@ -983,16 +983,11 @@ def requirements_ci_variables end end - # Return the group's setting for delayed deletion + # Return the group's setting for delayed deletion, false for user namespace projects def group_deletion_mode_configured? - if group&.namespace_settings - group.namespace_settings.delayed_project_removal? - elsif namespace&.namespace_settings - # for projects under user namespace - namespace.namespace_settings.delayed_project_removal? - else - false - end + return false unless group&.namespace_settings + + group.namespace_settings.delayed_project_removal? end # If the project is inside a fork network, the mirror URL must diff --git a/ee/spec/controllers/projects_controller_spec.rb b/ee/spec/controllers/projects_controller_spec.rb index 7247c72eb21eaa..e6d0173d592f41 100644 --- a/ee/spec/controllers/projects_controller_spec.rb +++ b/ee/spec/controllers/projects_controller_spec.rb @@ -788,23 +788,7 @@ context 'for projects in user namespace' do let(:project) { create(:project, namespace: user.namespace) } - context 'when feature is enabled at instance level' do - before do - stub_application_setting(deletion_adjourned_period: 7) - stub_application_setting(delayed_project_removal: true) - end - - it_behaves_like 'marks project for deletion' - end - - context 'when feature is not enabled at instance level' do - before do - stub_application_setting(deletion_adjourned_period: 0) - stub_application_setting(delayed_project_removal: false) - end - - it_behaves_like 'deletes project right away' - end + it_behaves_like 'deletes project right away' end end diff --git a/ee/spec/factories/namespaces/user_namespaces.rb b/ee/spec/factories/namespaces/user_namespaces.rb deleted file mode 100644 index a0e4a923407394..00000000000000 --- a/ee/spec/factories/namespaces/user_namespaces.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -FactoryBot.modify do - factory :user_namespace do - trait :user_namespace_with_plan do - transient do - plan { :free_plan } - trial_ends_on { nil } - end - - after(:create) do |user_namespace, evaluator| - if evaluator.plan - create(:namespace_settings, namespace: user_namespace) - - create(:gitlab_subscription, - namespace: user_namespace, - hosted_plan: create(evaluator.plan), - trial: evaluator.trial_ends_on.present?, - trial_ends_on: evaluator.trial_ends_on) - end - end - end - end -end diff --git a/ee/spec/models/project_spec.rb b/ee/spec/models/project_spec.rb index 11a7383fc466c7..025b60315a53d4 100644 --- a/ee/spec/models/project_spec.rb +++ b/ee/spec/models/project_spec.rb @@ -455,13 +455,9 @@ premium_project = create(:project, :archived, creator: user, namespace: premium_group) no_plan_project = create(:project, :archived, creator: user, namespace: no_plan_group) no_plan_public_project = create(:project, :archived, creator: user, visibility: ::Gitlab::VisibilityLevel::PUBLIC, namespace: no_plan_group) - free_user_namespace = create(:user_namespace, :user_namespace_with_plan, plan: :free_plan) - ultimate_user_namespace = create(:user_namespace, :user_namespace_with_plan, plan: :ultimate_plan) - free_personal_project = create(:project, :archived, creator: user, namespace: free_user_namespace) - ultimate_personal_project = create(:project, :archived, creator: user, namespace: ultimate_user_namespace) - expect(described_class.with_feature_available(:adjourned_deletion_for_projects_and_groups)).to contain_exactly(premium_project, ultimate_project, no_plan_public_project, ultimate_personal_project) - expect(described_class.with_feature_available(:adjourned_deletion_for_projects_and_groups)).not_to include(no_plan_project, free_personal_project) + expect(described_class.with_feature_available(:adjourned_deletion_for_projects_and_groups)).to contain_exactly(premium_project, ultimate_project, no_plan_public_project) + expect(described_class.with_feature_available(:adjourned_deletion_for_projects_and_groups)).not_to include(no_plan_project) end end end -- GitLab From 704d4ad0fe6b285aafdd771307cde667d57afe19 Mon Sep 17 00:00:00 2001 From: Huzaifa Iftikhar Date: Wed, 17 Aug 2022 13:34:36 +0000 Subject: [PATCH 2/2] Update documentation regarding release --- doc/user/admin_area/settings/visibility_and_access_controls.md | 2 +- doc/user/project/settings/index.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/user/admin_area/settings/visibility_and_access_controls.md b/doc/user/admin_area/settings/visibility_and_access_controls.md index 01650a95d5610e..118d375da010d9 100644 --- a/doc/user/admin_area/settings/visibility_and_access_controls.md +++ b/doc/user/admin_area/settings/visibility_and_access_controls.md @@ -53,7 +53,7 @@ By default both administrators and anyone with the **Owner** role can delete a p > - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/255449) in GitLab 14.2 for groups created after August 12, 2021. > - [Renamed](https://gitlab.com/gitlab-org/gitlab/-/issues/352960) from default delayed project deletion in GitLab 15.1. > - [Enabled for projects in personal namespaces](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/89466) in GitLab 15.1. -> - [Disabled for projects in personal namespaces](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/95495) in GitLab 15.4. +> - [Disabled for projects in personal namespaces](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/95495) in GitLab 15.3. Instance-level protection against accidental deletion of groups and projects. diff --git a/doc/user/project/settings/index.md b/doc/user/project/settings/index.md index 87df964b5257aa..b973a0f56d1823 100644 --- a/doc/user/project/settings/index.md +++ b/doc/user/project/settings/index.md @@ -448,7 +448,7 @@ in GitLab 12.6, and then to [immediate deletion](https://gitlab.com/gitlab-org/g ### Delayed project deletion **(PREMIUM)** > - [Enabled for projects in personal namespaces](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/89466) in GitLab 15.1. -> - [Disabled for projects in personal namespaces](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/95495) in GitLab 15.4. +> - [Disabled for projects in personal namespaces](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/95495) in GitLab 15.3. Projects in a group (not a personal namespace) can be deleted after a delay period. Multiple settings can affect whether delayed project deletion is enabled for a particular project: -- GitLab