send invite notifications using a hook

This commit is contained in:
clemkeirua 2020-09-25 11:10:12 +02:00 committed by Keirua (Rebase PR Action)
parent dd7840cdc4
commit d23b1136ad
2 changed files with 11 additions and 6 deletions

View file

@ -19,6 +19,8 @@ class Invite < ApplicationRecord
before_validation -> { sanitize_email(:email) }
after_save_commit :send_notification
validates :email, presence: true
validates :email, uniqueness: { scope: :dossier_id }
@ -32,4 +34,12 @@ class Invite < ApplicationRecord
scope :kept, -> { joins(:dossier).merge(Dossier.kept) }
default_scope { kept }
def send_notification
if self.user.present?
InviteMailer.invite_user(self).deliver_later
else
InviteMailer.invite_guest(self).deliver_later
end
end
end