bring back find_or_create_instructeurs
This commit is contained in:
parent
d0c432d939
commit
fcd0f7c609
5 changed files with 22 additions and 19 deletions
|
@ -51,6 +51,25 @@ class GroupeInstructeur < ApplicationRecord
|
|||
.update_all(unfollowed_at: Time.zone.now)
|
||||
end
|
||||
|
||||
def add_instructeurs(ids: [], emails: [])
|
||||
instructeurs_to_add, valid_emails, invalid_emails = Instructeur.find_all_by_identifier_with_emails(ids:, emails:)
|
||||
not_found_emails = valid_emails - instructeurs_to_add.map(&:email)
|
||||
|
||||
# Send invitations to users without account
|
||||
if not_found_emails.present?
|
||||
instructeurs_to_add += not_found_emails.map do |email|
|
||||
user = User.create_or_promote_to_instructeur(email, SecureRandom.hex, administrateurs: procedure.administrateurs)
|
||||
user.invite!
|
||||
user.instructeur
|
||||
end
|
||||
end
|
||||
|
||||
# We dont't want to assign a user to a groupe_instructeur if they are already assigned to it
|
||||
instructeurs_to_add -= instructeurs
|
||||
|
||||
[instructeurs_to_add, invalid_emails]
|
||||
end
|
||||
|
||||
def can_delete?
|
||||
dossiers.empty? && (procedure.groupe_instructeurs.active.many? || (procedure.groupe_instructeurs.active.one? && closed))
|
||||
end
|
||||
|
|
|
@ -52,22 +52,6 @@ class Instructeur < ApplicationRecord
|
|||
find_by(users: { email: email })
|
||||
end
|
||||
|
||||
def self.find_or_create_instructeurs(ids: [], emails: [], administrateurs:)
|
||||
instructeurs_to_add, valid_emails, invalid_emails = Instructeur.find_all_by_identifier_with_emails(ids:, emails:)
|
||||
not_found_emails = valid_emails - instructeurs_to_add.map(&:email)
|
||||
|
||||
# Send invitations to users without account
|
||||
if not_found_emails.present?
|
||||
instructeurs_to_add += not_found_emails.map do |email|
|
||||
user = User.create_or_promote_to_instructeur(email, SecureRandom.hex, administrateurs: administrateurs)
|
||||
user.invite!
|
||||
user.instructeur
|
||||
end
|
||||
end
|
||||
|
||||
[instructeurs_to_add, invalid_emails]
|
||||
end
|
||||
|
||||
def self.find_all_by_identifier(ids: [], emails: [])
|
||||
find_all_by_identifier_with_emails(ids:, emails:).first
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue