Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Users can delete their account #1447

Merged
merged 9 commits into from
Jun 6, 2017
Merged

Users can delete their account #1447

merged 9 commits into from
Jun 6, 2017

Conversation

beagleknight
Copy link
Contributor

@beagleknight beagleknight commented Jun 6, 2017

🎩 What? Why?

This adds the deleting accounts feature. A user will be able to delete his account filling in an optional reason. The account will become inaccessible and anonymizes his data.

📌 Related Issues

📋 Subtasks

  • Delete account form
  • Fix menu highlight
  • Anonymize data for proposals
  • Anonymize data for comments

📷 Screenshots (optional)

image

image

image

👻 GIF

@codecov
Copy link

codecov bot commented Jun 6, 2017

Codecov Report

Merging #1447 into master will increase coverage by <.01%.
The diff coverage is 98.21%.

@@            Coverage Diff            @@
##           master   #1447      +/-   ##
=========================================
+ Coverage   95.49%   95.5%   +<.01%     
=========================================
  Files         439     441       +2     
  Lines        7574    7627      +53     
=========================================
+ Hits         7233    7284      +51     
- Misses        341     343       +2

oriolgual
oriolgual previously approved these changes Jun 6, 2017
Copy link
Contributor

@josepjaume josepjaume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

private

def destroy_user_account!
@user.email = "deleted-user-#{SecureRandom.uuid}@example.org"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

email can be empty when the user is deleted. There's a special index for that (not sure about the model's validation) but I think is way better to deal it this way.

Copy link
Contributor Author

@beagleknight beagleknight Jun 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And erase their name


private

def destroy_user_account!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should delete all the user's identities as well, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And authorizations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrcasals Authorizations are anonymous and doesn't container user data so we are fine.

@@ -106,6 +114,8 @@ export interface CommentDataFragment extends UpVoteButtonFragment, DownVoteButto
name: string,
// The author's avatar url
avatarUrl: string,
// Wheter the author's account has been deleted or not
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Wheter/Whether

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is auto-generated so I made the change but didn't regenerate the schema 😄

@@ -0,0 +1,27 @@
/**
* Since the delete account has a modal to confirm it we need to copy the content of the
* reason field to the hidden field in the form inside the modal.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the hell? Is this a normal thing to do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it isn't. The problem is the foundation reveal is rendered outside the real form and it is also a copy of the template marked as a popup. I know it's not a perfect solution but I needed this to solve the problem.

$deleteAccountModalForm.find('input#delete_account_delete_reason').val(reasonValue);
$modal.foundation('open');
} catch (error) {
console.error(error); // eslint-disable-line no-console
Copy link
Contributor

@mrcasals mrcasals Jun 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we report this to Sentry instead of logging to the console

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have sentry configured for js errors but I think it's a good idea. I will do it in a separate PR

@@ -13,6 +15,9 @@ en:
user_group_document_number: Organization document number
user_group_name: Organization name
user_group_phone: Organization phone
placeholders:
account:
delete_reason: Reason
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need a placeholder here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied the template but I think you are right.

@@ -2,6 +2,8 @@
en:
activemodel:
attributes:
account:
delete_reason: Reason
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change this to: "Reason to delete your account"

field :avatarUrl, !types.String, "The author's avatar url"

field :deleted, !types.Boolean, "Wheter the author's account has been deleted or not"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Wheter/Whether/

@@ -13,11 +13,15 @@ module Decidim
field :name, !types.String, "The user's name"

field :avatarUrl, !types.String, "The user's avatar url" do
resolve ->(obj, _args, _ctx) { obj.avatar.url }
resolve ->(obj, _args, _ctx) { obj.deleted? ? ActionController::Base.helpers.asset_path("decidim/default-avatar.svg") : obj.avatar.url }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This smells. Shouldn't we change the avatar to this when deleting the user? This way you don't need to check this value in the API level, you just change it when deleting the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, since we don't need to preserve the old ones I think it is fine.

end

field :organizationName, !types.String, "The user's organization name" do
resolve ->(obj, _args, _ctx) { obj.organization.name }
end

field :deleted, !types.Boolean, "Whether the user's account has been deleted or not" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

field :deleted, type, "description", property: :deleted? should work just fine, and you avoid having to use the block

@@ -11,11 +11,21 @@
<div class="author-data__main">
<div class="author author--inline">
<span class="author__avatar">
<%= image_tag @proposal.author_avatar_url %>
<% if @proposal.author&.deleted? %>
<%= image_tag ActionController::Base.helpers.asset_path("decidim/default-avatar.svg") %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, changing the avatar when deleting the user will make you skip this logic in the views

</span>
<%= l @proposal.created_at, format: :long %>
<span class="author__name">
<%= @proposal.author_name %>
<% if @proposal.author&.deleted? %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we use this in the admin section too? We should update it there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not displaying users in the admin section so I think it is not needed.

oriolgual
oriolgual previously approved these changes Jun 6, 2017
josepjaume
josepjaume previously approved these changes Jun 6, 2017
@beagleknight beagleknight dismissed stale reviews from josepjaume and oriolgual via 3a44d08 June 6, 2017 13:55
@beagleknight beagleknight dismissed mrcasals’s stale review June 6, 2017 14:04

I made all the changes requested :D

@beagleknight beagleknight merged commit ead7613 into master Jun 6, 2017
@beagleknight beagleknight deleted the feature/delete-account branch June 6, 2017 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants