Skip to content

Commit

Permalink
Make account deletion remove the email address when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed May 23, 2022
1 parent dd676f2 commit f7a8529
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ def remove_personal_data
self.home_lat = nil
self.home_lon = nil
self.email_valid = false
self.email = "#{id}@example.com" unless must_retain_email?
self.new_email = nil
self.auth_provider = nil
self.auth_uid = nil
Expand Down Expand Up @@ -383,6 +384,10 @@ def max_friends_per_hour
max_friends.clamp(0, Settings.max_friends_per_hour)
end

def must_retain_email?
changesets.exists?
end

private

def encrypt_password
Expand Down
5 changes: 5 additions & 0 deletions app/views/account/deletions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<ul>
<li><%= t ".delete_profile" %></li>
<li><%= t ".delete_display_name" %></li>
<% unless current_user.must_retain_email? -%>
<li><%= t ".delete_email" %></li>
<% end -%>
</ul>

<p><%= t ".retain_caveats" %></p>
Expand All @@ -31,7 +34,9 @@
<li><%= t ".retain_diary_entries" %></li>
<li><%= t ".retain_notes" %></li>
<li><%= t ".retain_changeset_discussions" %></li>
<% if current_user.must_retain_email? -%>
<li><%= t ".retain_email" %></li>
<% end -%>
</ul>

<%= link_to t(".delete_account"), account_path, { :method => :delete, :class => "btn btn-danger", :data => { :confirm => t(".confirm_delete") } } %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ en:
delete_introduction: "You can delete your OpenStreetMap account using the button below. Please note the following details:"
delete_profile: Your profile information, including your avatar, description and home location will be removed.
delete_display_name: Your display name will be removed, and can be reused by other accounts.
delete_email: Your email address will be removed.
retain_caveats: "However, some information about you will be retained on OpenStreetMap, even after your account is deleted:"
retain_edits: Your edits to the map database, if any, will be retained.
retain_traces: Your uploaded traces, if any, will be retained.
Expand Down
2 changes: 1 addition & 1 deletion test/factories/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

trait :deleted do
after(:build) do |user, _evaluator|
user.soft_destroy
user.hide
end
end

Expand Down
18 changes: 18 additions & 0 deletions test/system/account_deletion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ def setup
@user.reload
assert_equal "deleted", @user.status
assert_equal "user_#{@user.id}", @user.display_name
assert_equal "#{@user.id}@example.com", @user.email
end

test "the email is kept if the user has edits" do
create(:changeset, :user => @user)

visit edit_account_path

click_on "Delete Account..."
accept_confirm do
click_on "Delete Account"
end

assert_current_path root_path
@user.reload
assert_equal "deleted", @user.status
assert_equal "user_#{@user.id}", @user.display_name
assert_not_equal "#{@user.id}@example.com", @user.email
end

test "the user is signed out after deletion" do
Expand Down

0 comments on commit f7a8529

Please sign in to comment.