Disable delete account button if there are recent changesets

This commit is contained in:
Anton Khorev 2023-10-24 20:06:06 +03:00
parent a8aaf62e62
commit 14bd660114
3 changed files with 65 additions and 1 deletions

View file

@ -31,5 +31,13 @@
<li><%= t ".retain_email" %></li>
</ul>
<%= 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 %>
<div class="alert alert-warning">
<%= t ".recent_editing_html", :time => friendly_date(current_user.deletion_allowed_at) %>
</div>
<button class="btn btn-secondary" disabled><%= t(".delete_account") %></button>
<% end %>
<%= link_to t(".cancel"), edit_account_path, :class => "btn btn-link" %>

View file

@ -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:

View file

@ -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