-
-
Notifications
You must be signed in to change notification settings - Fork 408
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
Changes from 5 commits
57182cc
1a0e129
2e66212
c3bec35
a9fb4c3
5fcdad0
1cb16f9
03b2298
3a44d08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ fragment CommentData on Comment { | |
author { | ||
name | ||
avatarUrl | ||
deleted | ||
} | ||
hasComments | ||
acceptsNewComments | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What the hell? Is this a normal thing to do? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
*/ | ||
$(() => { | ||
const $deleteAccountForm = $('.delete-account'); | ||
const $deleteAccountModalForm = $('.delete-account-modal'); | ||
|
||
if ($deleteAccountForm.length > 0) { | ||
const $openModalButton = $('.open-modal-button'); | ||
const $modal = $('#deleteConfirm'); | ||
|
||
$openModalButton.on('click', (event) => { | ||
try { | ||
const reasonValue = $deleteAccountForm.find('textarea#delete_account_delete_reason').val(); | ||
$deleteAccountModalForm.find('input#delete_account_delete_reason').val(reasonValue); | ||
$modal.foundation('open'); | ||
} catch (error) { | ||
console.error(error); // eslint-disable-line no-console | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
|
||
event.preventDefault(); | ||
event.stopPropagation(); | ||
return false; | ||
}); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
# This command destroys the user's account. | ||
class DestroyAccount < Rectify::Command | ||
# Destroy a user's account. | ||
# | ||
# user - The user to be updated. | ||
# form - The form with the data. | ||
def initialize(user, form) | ||
@user = user | ||
@form = form | ||
end | ||
|
||
def call | ||
return broadcast(:invalid) unless @form.valid? | ||
|
||
destroy_user_account! | ||
broadcast(:ok) | ||
end | ||
|
||
private | ||
|
||
def destroy_user_account! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should delete all the user's identities as well, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And authorizations? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
@user.email = "deleted-user-#{SecureRandom.uuid}@example.org" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And erase their |
||
@user.delete_reason = @form.delete_reason | ||
@user.deleted_at = Time.current | ||
@user.skip_reconfirmation! | ||
@user.save! | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
# The form object that handles the data behind deleting users account. | ||
class DeleteAccountForm < Form | ||
attribute :delete_reason, String | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<div class="row"> | ||
<div class="columns large-8 end"> | ||
<div class="callout alert"> | ||
<p><%= t('.alert') %></p> | ||
</div> | ||
<p><%= t('.explanation') %></p> | ||
<%= decidim_form_for(@form, url: account_path, method: :delete, html: { class: "user-form delete-account" }) do |f| %> | ||
<div> | ||
<label> | ||
<span class="user-form__label"><%= t('activemodel.attributes.account.delete_reason') %></span> | ||
<%= f.text_area :delete_reason, rows: 2, placeholder: t('activemodel.placeholders.account.delete_reason') %> | ||
</label> | ||
</div> | ||
<input type="submit" class="button open-modal-button" value="<%= t('.confirm.title') %>" /> | ||
<% end %> | ||
<div class="tiny reveal" id="deleteConfirm" data-reveal> | ||
<%= decidim_form_for(@form, url: account_path, method: :delete, html: { class: "user-form delete-account-modal" }) do |f| %> | ||
<%= f.hidden_field :delete_reason %> | ||
|
||
<p><%= t('.confirm.question') %></p> | ||
|
||
<input type="submit" class="button expanded" value="<%= t('.confirm.ok') %>" /> | ||
|
||
<button class="close-button" data-close aria-label="<%= t('.confirm.close') %>" type="button"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
en: | ||
activemodel: | ||
attributes: | ||
account: | ||
delete_reason: Reason | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would change this to: "Reason to delete your account" |
||
report: | ||
details: Additional comments | ||
user: | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you really need a placeholder here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just copied the template but I think you are right. |
||
activerecord: | ||
attributes: | ||
decidim/user: | ||
|
@@ -33,6 +38,17 @@ en: | |
image_too_big: The image is too big | ||
decidim: | ||
account: | ||
delete: | ||
alert: This action cannot be undone. If you delete your account you won't be able to log in. | ||
confirm: | ||
close: Close window | ||
ok: Yes, I want to delete my account | ||
question: Are you sure you want to delete your account? | ||
title: Delete my account | ||
explanation: Please, fill in the reason you want to delete your account (optional). | ||
destroy: | ||
error: There's been an error deleting your account. | ||
success: Your account was deleted successfully. | ||
show: | ||
change_password: Change password | ||
update_account: Update account | ||
|
@@ -322,6 +338,7 @@ en: | |
user_profile: | ||
account: Account | ||
authorizations: Authorizations | ||
delete_my_account: Delete my account | ||
notifications_settings: Notifications settings | ||
title: User settings | ||
user_groups: Organizations | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddDeletedFieldsToUsers < ActiveRecord::Migration[5.0] | ||
def change | ||
add_column :decidim_users, :delete_reason, :text | ||
add_column :decidim_users, :deleted_at, :datetime | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ module Decidim | |
description "An author" | ||
|
||
field :name, !types.String, "The author's name" | ||
|
||
field :avatarUrl, !types.String, "The author's avatar url" | ||
|
||
field :deleted, !types.Boolean, "Wheter the author's account has been deleted or not" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Wheter/Whether
There was a problem hiding this comment.
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 😄