-
-
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 all 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# encoding: utf-8 | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
|
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. | ||
*/ | ||
$(() => { | ||
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,47 @@ | ||
# 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? | ||
|
||
Decidim::User.transaction do | ||
destroy_user_account! | ||
destroy_user_identities | ||
destroy_user_group_memberships | ||
end | ||
|
||
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.name = "" | ||
@user.email = "" | ||
@user.delete_reason = @form.delete_reason | ||
@user.deleted_at = Time.current | ||
@user.skip_reconfirmation! | ||
@user.remove_avatar! | ||
@user.save! | ||
end | ||
|
||
def destroy_user_identities | ||
@user.identities.destroy_all | ||
end | ||
|
||
def destroy_user_group_memberships | ||
Decidim::UserGroupMembership.where(user: @user).destroy_all | ||
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 %> | ||
</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> |
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.
What the hell? Is this a normal thing to do?
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.
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.