FIX: Apply 'hide email account' for invites

This commit is contained in:
Loïc Guitaut
2022-05-10 17:45:43 +02:00
committed by Loïc Guitaut
parent f31301b6de
commit 73de203843
6 changed files with 126 additions and 62 deletions

View File

@@ -49,20 +49,20 @@ class Invite < ActiveRecord::Base
self.email = Email.downcase(email) unless email.nil?
end
attr_accessor :email_already_exists
attribute :email_already_exists
def self.emailed_status_types
@emailed_status_types ||= Enum.new(not_required: 0, pending: 1, bulk_pending: 2, sending: 3, sent: 4)
end
def user_doesnt_already_exist
@email_already_exists = false
self.email_already_exists = false
return if email.blank?
user = Invite.find_user_by_email(email)
if user && user.id != self.invited_users&.first&.user_id
@email_already_exists = true
errors.add(:base, user_exists_error_msg(email, user.username))
self.email_already_exists = true
errors.add(:base, user_exists_error_msg(email))
end
end
@@ -100,9 +100,7 @@ class Invite < ActiveRecord::Base
email = Email.downcase(opts[:email]) if opts[:email].present?
if user = find_user_by_email(email)
raise UserExists.new(new.user_exists_error_msg(email, user.username))
end
raise UserExists.new(new.user_exists_error_msg(email)) if find_user_by_email(email)
if email.present?
invite = Invite
@@ -270,14 +268,8 @@ class Invite < ActiveRecord::Base
end
end
def user_exists_error_msg(email, username)
sanitized_email = CGI.escapeHTML(email)
sanitized_username = CGI.escapeHTML(username)
I18n.t(
"invite.user_exists",
email: sanitized_email, username: sanitized_username, base_path: Discourse.base_path
)
def user_exists_error_msg(email)
I18n.t("invite.user_exists", email: CGI.escapeHTML(email))
end
end