Skip to content

Commit

Permalink
add destroy user account button
Browse files Browse the repository at this point in the history
  • Loading branch information
hesslau committed Feb 10, 2020
1 parent 8e25de0 commit 475480e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ def contact
render layout: false
end

def destroy
authorize @user
@user.update!(banned: true)
reset_session if @user == current_user
redirect_to root_path, notice: t('common.actions.destroy_profile.confirmation_notice')
end

private

def user_deleted
Expand Down
6 changes: 6 additions & 0 deletions app/policies/user_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ def create?
true unless banned?
end

def destroy?
return false if banned?
return true if User.is_admin?(user)
user == resource
end

private

def banned?
Expand Down
3 changes: 3 additions & 0 deletions app/views/users/_header.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@
a.Button href="#{ contact_user_path(user_resource) }" class='ungrouped_colorbox'
span= fa_icon 'envelope-o', class: 'fa-lg fa-fw'
=< t 'users.profile.contact.heading'
= link_to(user_path(user_resource), method: :delete, data: {confirm: t('common.actions.destroy_profile.confirmation_dialog')}, class: "Button Button--red") do
span= fa_icon 'trash', class: 'fa-lg fa-fw'
= t 'common.actions.destroy_profile.button'
.user-extra
= render '/shared/take_part'
4 changes: 4 additions & 0 deletions config/locales/old/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ de:
send: 'Absenden'
more: "mehr"
send: 'Absenden'
destroy_profile:
button: "Account löschen"
confirmation_dialog: "<b>Willst du deinen Account wirklich löschen?</b><br><br>Ja, ich möchte meinen Account wirklich löschen. Ich bin einverstanden, dass Fairmondo meine Account-Daten für 12 Monate für eine mögliche Nachvollziehung von Transaktionen bei Konfliktfällen speichert. In diesem Zeitraum ist eine Reaktivierung des Accounts per Email an kundenservice@fairmondo.de möglich."
confirmation_notice: "Der Account wurde erfolgreich gelöscht. Hoffentlich bis bald!"
title:
man: "Herr"
woman: "Frau"
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@

# the user routes

resources :users, only: [:show] do
resources :users, only: [:show, :destroy] do
resources :addresses, except: [:index, :show]
resources :libraries, except: [:new, :edit]
resources :library_elements, only: [:create, :destroy]
Expand Down

0 comments on commit 475480e

Please sign in to comment.