From 204311873e32cc7943130bdae9d1dc710222d6a6 Mon Sep 17 00:00:00 2001
From: Aishwarya Subramanian <asubramanian@gitlab.com>
Date: Thu, 9 Jul 2020 11:06:13 -0500
Subject: [PATCH] Update Project deletion copy based on deletion mode

Display the deletion message based on the project
deletion mode. Mode can either be immediate deletion
or delayed deletion. Follow-up changes for
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/35689
---
 ee/app/controllers/ee/groups_controller.rb    |  2 +-
 ee/app/helpers/ee/groups_helper.rb            |  3 +-
 ee/app/helpers/ee/projects_helper.rb          |  4 +--
 ee/app/models/ee/group.rb                     |  5 ----
 ee/app/models/ee/project.rb                   |  6 ++--
 ee/app/views/projects/_remove.html.haml       |  9 +++++-
 .../copy-update-proj-delete-modal.yml         |  5 ++++
 .../controllers/ee/groups_controller_spec.rb  |  3 +-
 .../controllers/projects_controller_spec.rb   |  8 -----
 ee/spec/helpers/ee/groups_helper_spec.rb      |  9 ++----
 ee/spec/helpers/projects_helper_spec.rb       | 26 +++++++++++++++++
 ee/spec/models/group_spec.rb                  | 20 -------------
 ee/spec/models/project_spec.rb                | 29 ++-----------------
 ee/spec/requests/api/projects_spec.rb         |  8 -----
 locale/gitlab.pot                             |  8 ++++-
 15 files changed, 58 insertions(+), 87 deletions(-)
 create mode 100644 ee/changelogs/unreleased/copy-update-proj-delete-modal.yml

diff --git a/ee/app/controllers/ee/groups_controller.rb b/ee/app/controllers/ee/groups_controller.rb
index ccaf41bbbd4..edc02980b6c 100644
--- a/ee/app/controllers/ee/groups_controller.rb
+++ b/ee/app/controllers/ee/groups_controller.rb
@@ -74,7 +74,7 @@ module EE
         params_ee << :allowed_email_domains_list if current_group&.feature_available?(:group_allowed_email_domains)
         params_ee << :max_pages_size if can?(current_user, :update_max_pages_size)
         params_ee << :max_personal_access_token_lifetime if current_group&.personal_access_token_expiration_policy_available?
-        params_ee << :delayed_project_removal if current_group&.configure_project_deletion_mode_available?
+        params_ee << :delayed_project_removal if current_group&.feature_available?(:adjourned_deletion_for_projects_and_groups)
       end
     end
 
diff --git a/ee/app/helpers/ee/groups_helper.rb b/ee/app/helpers/ee/groups_helper.rb
index b9238f0d290..4003ff4e8fd 100644
--- a/ee/app/helpers/ee/groups_helper.rb
+++ b/ee/app/helpers/ee/groups_helper.rb
@@ -118,8 +118,7 @@ module EE
     end
 
     def show_delayed_project_removal_setting?(group)
-      group.feature_available?(:adjourned_deletion_for_projects_and_groups) &&
-        ::Feature.enabled?(:configure_project_deletion_mode, group)
+      group.feature_available?(:adjourned_deletion_for_projects_and_groups)
     end
 
     private
diff --git a/ee/app/helpers/ee/projects_helper.rb b/ee/app/helpers/ee/projects_helper.rb
index 63e76bded57..2829e1494f2 100644
--- a/ee/app/helpers/ee/projects_helper.rb
+++ b/ee/app/helpers/ee/projects_helper.rb
@@ -104,10 +104,10 @@ module EE
 
     override :remove_project_message
     def remove_project_message(project)
-      return super unless project.feature_available?(:adjourned_deletion_for_projects_and_groups)
+      return super unless project.adjourned_deletion?
 
       date = permanent_deletion_date(Time.now.utc)
-      _("Removing a project places it into a read-only state until %{date}, at which point the project will be permanantly removed. Are you ABSOLUTELY sure?") %
+      _("Removing a project places it into a read-only state until %{date}, at which point the project will be permanently removed. Are you ABSOLUTELY sure?") %
         { date: date }
     end
 
diff --git a/ee/app/models/ee/group.rb b/ee/app/models/ee/group.rb
index 24de0aaf38f..e636123a6a6 100644
--- a/ee/app/models/ee/group.rb
+++ b/ee/app/models/ee/group.rb
@@ -390,11 +390,6 @@ module EE
       owners.pluck(:email)
     end
 
-    def configure_project_deletion_mode_available?
-      feature_available?(:adjourned_deletion_for_projects_and_groups) &&
-        ::Feature.enabled?(:configure_project_deletion_mode, self)
-    end
-
     private
 
     def custom_project_templates_group_allowed
diff --git a/ee/app/models/ee/project.rb b/ee/app/models/ee/project.rb
index 4d6a3f69e73..c91b52a69cd 100644
--- a/ee/app/models/ee/project.rb
+++ b/ee/app/models/ee/project.rb
@@ -752,11 +752,9 @@ module EE
       end
     end
 
-    # If the feature to configure project deletion mode is NOT enabled, we default to delayed deletion
+    # Return the group's setting for delayed deletion, false for user namespace projects
     def group_deletion_mode_configured?
-      return true unless ::Feature.enabled?(:configure_project_deletion_mode, self)
-
-      group && group.delayed_project_removal? # Return the group's setting for delayed deletion, false for user namespace projects
+      group && group.delayed_project_removal?
     end
   end
 end
diff --git a/ee/app/views/projects/_remove.html.haml b/ee/app/views/projects/_remove.html.haml
index 0ae485d37dc..8cf7ace5fd5 100644
--- a/ee/app/views/projects/_remove.html.haml
+++ b/ee/app/views/projects/_remove.html.haml
@@ -1,9 +1,16 @@
 - return unless can?(current_user, :remove_project, project)
+- adjourned_deletion = project.adjourned_deletion?
 
 - unless project.marked_for_deletion?
   .sub-section
     %h4.danger-title= _('Remove project')
-    = render 'projects/settings/marked_for_removal'
+    %p
+      %strong= s_('Delayed Project Deletion (%{adjourned_deletion})') % { adjourned_deletion: adjourned_deletion ? 'Enabled' : 'Disabled' }
+    - if adjourned_deletion
+      = render 'projects/settings/marked_for_removal'
+    - else
+      %p
+        = _("Removing a project deletes it immediately, there will be no delay before the project is permanently removed.")
     %p
       %strong= _('Removing the project will delete its repository and all related resources including issues, merge requests etc.')
     = form_tag(project_path(project), method: :delete) do
diff --git a/ee/changelogs/unreleased/copy-update-proj-delete-modal.yml b/ee/changelogs/unreleased/copy-update-proj-delete-modal.yml
new file mode 100644
index 00000000000..e13433556c3
--- /dev/null
+++ b/ee/changelogs/unreleased/copy-update-proj-delete-modal.yml
@@ -0,0 +1,5 @@
+---
+title: Update Project deletion text based on deletion mode
+merge_request: 36461
+author:
+type: changed
diff --git a/ee/spec/controllers/ee/groups_controller_spec.rb b/ee/spec/controllers/ee/groups_controller_spec.rb
index 444b9508483..3638575dda2 100644
--- a/ee/spec/controllers/ee/groups_controller_spec.rb
+++ b/ee/spec/controllers/ee/groups_controller_spec.rb
@@ -512,8 +512,7 @@ RSpec.describe GroupsController do
       before do
         group.add_owner(user)
         sign_in(user)
-        stub_licensed_features(adjourned_deletion_for_projects_and_groups: true)
-        stub_feature_flags(configure_project_deletion_mode: available)
+        stub_licensed_features(adjourned_deletion_for_projects_and_groups: available)
       end
 
       context 'when feature is available' do
diff --git a/ee/spec/controllers/projects_controller_spec.rb b/ee/spec/controllers/projects_controller_spec.rb
index 47a00ffe41b..e8aaffed8c2 100644
--- a/ee/spec/controllers/projects_controller_spec.rb
+++ b/ee/spec/controllers/projects_controller_spec.rb
@@ -582,14 +582,6 @@ RSpec.describe ProjectsController do
 
         it_behaves_like 'deletes project right away'
       end
-
-      context 'when configure_project_deletion_mode feature is disabled' do
-        before do
-          stub_feature_flags(configure_project_deletion_mode: false)
-        end
-
-        it_behaves_like 'marks project for deletion'
-      end
     end
 
     context 'feature is not available' do
diff --git a/ee/spec/helpers/ee/groups_helper_spec.rb b/ee/spec/helpers/ee/groups_helper_spec.rb
index d9f2b512e77..e182b90f26c 100644
--- a/ee/spec/helpers/ee/groups_helper_spec.rb
+++ b/ee/spec/helpers/ee/groups_helper_spec.rb
@@ -313,14 +313,11 @@ RSpec.describe GroupsHelper do
   describe '#show_delayed_project_removal_setting?' do
     before do
       stub_licensed_features(adjourned_deletion_for_projects_and_groups: licensed?)
-      stub_feature_flags(configure_project_deletion_mode: flag_enabled?)
     end
 
-    where(:licensed?, :flag_enabled?, :result) do
-      true  | true  | true
-      true  | false | false
-      false | true  | false
-      false | false | false
+    where(:licensed?, :result) do
+      true  | true
+      false | false
     end
 
     with_them do
diff --git a/ee/spec/helpers/projects_helper_spec.rb b/ee/spec/helpers/projects_helper_spec.rb
index c4e83c156a2..70dd9aab409 100644
--- a/ee/spec/helpers/projects_helper_spec.rb
+++ b/ee/spec/helpers/projects_helper_spec.rb
@@ -234,4 +234,30 @@ RSpec.describe ProjectsHelper do
       end
     end
   end
+
+  describe '#remove_project_message' do
+    subject { helper.remove_project_message(project) }
+
+    before do
+      allow(project).to receive(:adjourned_deletion?).and_return(enabled)
+    end
+
+    context 'when project has adjourned deletion enabled' do
+      let(:enabled) { true }
+
+      it do
+        deletion_date = helper.permanent_deletion_date(Time.now.utc)
+
+        expect(subject).to eq "Removing a project places it into a read-only state until #{deletion_date}, at which point the project will be permanently removed. Are you ABSOLUTELY sure?"
+      end
+    end
+
+    context 'when project has adjourned deletion disabled' do
+      let(:enabled) { false }
+
+      it do
+        expect(subject).to eq "You are going to remove #{project.full_name}. Removed project CANNOT be restored! Are you ABSOLUTELY sure?"
+      end
+    end
+  end
 end
diff --git a/ee/spec/models/group_spec.rb b/ee/spec/models/group_spec.rb
index 614bd0d8cde..0f0584b739a 100644
--- a/ee/spec/models/group_spec.rb
+++ b/ee/spec/models/group_spec.rb
@@ -1029,24 +1029,4 @@ RSpec.describe Group do
 
     it { is_expected.to match([user.email]) }
   end
-
-  describe '#configure_project_deletion_mode_available?' do
-    using RSpec::Parameterized::TableSyntax
-
-    before do
-      stub_licensed_features(adjourned_deletion_for_projects_and_groups: licensed?)
-      stub_feature_flags(configure_project_deletion_mode: flag_enabled?)
-    end
-
-    where(:licensed?, :flag_enabled?, :result) do
-      true  | true  | true
-      true  | false | false
-      false | true  | false
-      false | false | false
-    end
-
-    with_them do
-      it { expect(group.configure_project_deletion_mode_available?).to be result }
-    end
-  end
 end
diff --git a/ee/spec/models/project_spec.rb b/ee/spec/models/project_spec.rb
index f209133179e..f9239cfeb64 100644
--- a/ee/spec/models/project_spec.rb
+++ b/ee/spec/models/project_spec.rb
@@ -2461,18 +2461,6 @@ RSpec.describe Project do
       it { is_expected.to be result }
     end
 
-    context 'when configure_project_deletion_mode feature is disabled' do
-      before do
-        stub_licensed_features(adjourned_deletion_for_projects_and_groups: true)
-        stub_application_setting(deletion_adjourned_period: 7)
-        stub_feature_flags(configure_project_deletion_mode: false)
-      end
-
-      it 'adjourns deletion' do
-        is_expected.to be true
-      end
-    end
-
     context 'when project belongs to user namespace' do
       let_it_be(:user) { create(:user) }
       let_it_be(:user_project) { create(:project, namespace: user.namespace) }
@@ -2480,23 +2468,10 @@ RSpec.describe Project do
       before do
         stub_licensed_features(adjourned_deletion_for_projects_and_groups: true)
         stub_application_setting(deletion_adjourned_period: 7)
-        stub_feature_flags(configure_project_deletion_mode: feature_enabled?)
       end
 
-      context 'configure_project_deletion_mode is enabled' do
-        let(:feature_enabled?) { true }
-
-        it 'deletes immediately' do
-          expect(user_project.adjourned_deletion?).to be nil
-        end
-      end
-
-      context 'configure_project_deletion_mode is disabled' do
-        let(:feature_enabled?) { false }
-
-        it 'adjourns deletion' do
-          expect(user_project.adjourned_deletion?).to be true
-        end
+      it 'deletes immediately' do
+        expect(user_project.adjourned_deletion?).to be nil
       end
     end
   end
diff --git a/ee/spec/requests/api/projects_spec.rb b/ee/spec/requests/api/projects_spec.rb
index 1be95c8c213..d1dc1436d5a 100644
--- a/ee/spec/requests/api/projects_spec.rb
+++ b/ee/spec/requests/api/projects_spec.rb
@@ -985,14 +985,6 @@ RSpec.describe API::Projects do
 
         it_behaves_like 'deletes project immediately'
       end
-
-      context 'when configure_project_deletion_mode feature is disabled' do
-        before do
-          stub_feature_flags(configure_project_deletion_mode: false)
-        end
-
-        it_behaves_like 'marks project for deletion'
-      end
     end
 
     context 'when feature is not available' do
diff --git a/locale/gitlab.pot b/locale/gitlab.pot
index 8f93603904b..025b2bcd994 100644
--- a/locale/gitlab.pot
+++ b/locale/gitlab.pot
@@ -7500,6 +7500,9 @@ msgstr ""
 msgid "Define environments in the deploy stage(s) in <code>.gitlab-ci.yml</code> to track deployments here."
 msgstr ""
 
+msgid "Delayed Project Deletion (%{adjourned_deletion})"
+msgstr ""
+
 msgid "DelayedJobs|Are you sure you want to run %{jobName} immediately? Otherwise this job will run automatically after it's timer finishes."
 msgstr ""
 
@@ -19510,12 +19513,15 @@ msgstr ""
 msgid "Removes time estimate."
 msgstr ""
 
-msgid "Removing a project places it into a read-only state until %{date}, at which point the project will be permanantly removed. Are you ABSOLUTELY sure?"
+msgid "Removing a project deletes it immediately, there will be no delay before the project is permanently removed."
 msgstr ""
 
 msgid "Removing a project places it into a read-only state until %{date}, at which point the project will be permanently removed."
 msgstr ""
 
+msgid "Removing a project places it into a read-only state until %{date}, at which point the project will be permanently removed. Are you ABSOLUTELY sure?"
+msgstr ""
+
 msgid "Removing license鈥�"
 msgstr ""
 
-- 
2.30.9