From 14bd66011451f041553e9e127f6abdd1b52cf9af Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 24 Oct 2023 20:06:06 +0300 Subject: [PATCH] Disable delete account button if there are recent changesets --- app/views/account/deletions/show.html.erb | 10 ++++- config/locales/en.yml | 1 + test/system/account_deletion_test.rb | 55 +++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/app/views/account/deletions/show.html.erb b/app/views/account/deletions/show.html.erb index ddc821677..0ed4d663f 100644 --- a/app/views/account/deletions/show.html.erb +++ b/app/views/account/deletions/show.html.erb @@ -31,5 +31,13 @@
  • <%= t ".retain_email" %>
  • -<%= link_to t(".delete_account"), account_path, { :method => :delete, :class => "btn btn-danger", :data => { :confirm => t(".confirm_delete") } } %> +<% if current_user.deletion_allowed? %> + <%= link_to t(".delete_account"), account_path, { :method => :delete, :class => "btn btn-danger", :data => { :confirm => t(".confirm_delete") } } %> +<% else %> +
    + <%= t ".recent_editing_html", :time => friendly_date(current_user.deletion_allowed_at) %> +
    + +<% end %> + <%= link_to t(".cancel"), edit_account_path, :class => "btn btn-link" %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 1a41dcce8..56d722f43 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -256,6 +256,7 @@ en: retain_notes: Your map notes and note comments, if any, will be retained but hidden from view. retain_changeset_discussions: Your changeset discussions, if any, will be retained. retain_email: Your email address will be retained. + recent_editing_html: "As you have edited recently your account cannot currently be deleted. Deletion will be possible in %{time}." confirm_delete: Are you sure? cancel: Cancel accounts: diff --git a/test/system/account_deletion_test.rb b/test/system/account_deletion_test.rb index 87e981c64..e6517dccc 100644 --- a/test/system/account_deletion_test.rb +++ b/test/system/account_deletion_test.rb @@ -41,4 +41,59 @@ class AccountDeletionTest < ApplicationSystemTestCase assert_content "Account Deleted" end + + test "can delete with any delay setting value if the user has no changesets" do + with_user_account_deletion_delay(10000) do + travel 1.hour do + visit edit_account_path + + click_link "Delete Account..." + + assert_no_content "cannot currently be deleted" + end + end + end + + test "can delete with delay disabled" do + with_user_account_deletion_delay(nil) do + create(:changeset, :user => @user) + + travel 1.hour do + visit edit_account_path + + click_link "Delete Account..." + + assert_no_content "cannot currently be deleted" + end + end + end + + test "can delete when last changeset is old enough" do + with_user_account_deletion_delay(10) do + create(:changeset, :user => @user, :created_at => Time.now.utc, :closed_at => Time.now.utc + 1.hour) + + travel 12.hours do + visit edit_account_path + + click_link "Delete Account..." + + assert_no_content "cannot currently be deleted" + end + end + end + + test "can't delete when last changeset isn't old enough" do + with_user_account_deletion_delay(10) do + create(:changeset, :user => @user, :created_at => Time.now.utc, :closed_at => Time.now.utc + 1.hour) + + travel 10.hours do + visit edit_account_path + + click_link "Delete Account..." + + assert_content "cannot currently be deleted" + assert_content "in about 1 hour" + end + end + end end -- 2.39.5