Skip to content

Commit

Permalink
Fix unknown user variable after deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Dec 1, 2024
1 parent 2dc4bd6 commit 102dd19
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"factorybot",
"helpdesk",
"katex",
"turbolinks"
"turbolinks",
"Unsets"
]
}
14 changes: 6 additions & 8 deletions app/mailers/user_cleaner_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@ class UserCleanerMailer < ApplicationMailer
#
# @param [Integer] num_days_until_deletion:
# The number of days until the account will be deleted.
def pending_deletion_email(num_days_until_deletion)
user = params[:user]
def pending_deletion_email(user_email, user_locale, num_days_until_deletion)
sender = "#{t("mailer.warning")} <#{DefaultSetting::PROJECT_EMAIL}>"
I18n.locale = user.locale
I18n.locale = user_locale

@num_days_until_deletion = num_days_until_deletion
subject = t("mailer.pending_deletion_subject",
num_days_until_deletion: @num_days_until_deletion)
mail(from: sender, to: user.email, subject: subject, priority: "high")
mail(from: sender, to: user_email, subject: subject, priority: "high")
end

# Creates an email to inform a user that their account has been deleted.
def deletion_email
user = params[:user]
def deletion_email(user_email, user_locale)
sender = "#{t("mailer.warning")} <#{DefaultSetting::PROJECT_EMAIL}>"
I18n.locale = user.locale
I18n.locale = user_locale

subject = t("mailer.deletion_subject")
mail(from: sender, to: user.email, subject: subject, priority: "high")
mail(from: sender, to: user_email, subject: subject, priority: "high")
end
end
7 changes: 4 additions & 3 deletions app/models/user_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ def set_deletion_date_for_inactive_users
.find_each do |user|
user.update(deletion_date: Date.current + 40.days)

if user.generic? # rubocop:disable Style/IfUnlessModifier
UserCleanerMailer.with(user: user).pending_deletion_email(40).deliver_later
if user.generic?
UserCleanerMailer.pending_deletion_email(user.email, user.locale, 40)
.deliver_later
end
end
end
Expand Down Expand Up @@ -114,7 +115,7 @@ def delete_users_according_to_deletion_date!
User.where(deletion_date: ..Date.current).find_each do |user|
next unless user.generic?

UserCleanerMailer.with(user: user).deletion_email.deliver_later
UserCleanerMailer.deletion_email(user.email, user.locale).deliver_later
user.destroy
num_deleted_users += 1
end
Expand Down

0 comments on commit 102dd19

Please sign in to comment.