Skip to content

Commit

Permalink
customise error message when account is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
madhums committed Mar 5, 2024
1 parent 9cf3cc9 commit 88edc01
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
15 changes: 11 additions & 4 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ def permissions
@permissions ||= roles.flat_map(&:permissions).map(&:name).uniq
end

def active_for_authentication?
super && !discarded?
end

def after_confirmation
create_default_preference
end
Expand All @@ -66,6 +62,17 @@ def unread_notifications?
notifications.unread.count > 0
end

# Devise soft delete methods
# https://github.com/heartcombo/devise/wiki/How-to:-Soft-delete-a-user-when-user-deletes-account#4--update-the-user-model-with-soft_delete-method--check-if-user-is-active-when-authenticating
#
def active_for_authentication?
super && !discarded?
end

def inactive_message
(!discarded?) ? super : :deleted_account
end

private

def create_default_preference
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ en:
default: "You cannot perform this action."
user_policy:
update?: "You are not authorised to perform this action."
devise:
failure:
user:
deleted_account: It looks like you've deleted your account. Contact us if you need any support.
activerecord:
attributes:
user:
Expand Down
4 changes: 4 additions & 0 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ nl:
default: "U kunt deze actie niet uitvoeren."
user_policy:
update?: "U bent niet bevoegd om deze actie uit te voeren."
devise:
failure:
user:
deleted_account: Het lijkt erop dat je je account hebt verwijderd. Neem contact met ons op als je ondersteuning nodig hebt.
activerecord:
attributes:
user:
Expand Down

0 comments on commit 88edc01

Please sign in to comment.