2023-09-04 12:07:04 +02:00
|
|
|
class Gestionnaire < ApplicationRecord
|
2023-10-06 17:12:00 +02:00
|
|
|
include UserFindByConcern
|
2023-09-04 12:07:04 +02:00
|
|
|
has_and_belongs_to_many :groupe_gestionnaires
|
2023-08-25 22:53:30 +02:00
|
|
|
|
|
|
|
belongs_to :user
|
|
|
|
|
|
|
|
delegate :email, to: :user
|
|
|
|
|
|
|
|
default_scope { eager_load(:user) }
|
|
|
|
|
2023-09-28 17:45:39 +02:00
|
|
|
def email
|
|
|
|
user&.email
|
|
|
|
end
|
|
|
|
|
|
|
|
def active?
|
|
|
|
user&.active?
|
|
|
|
end
|
|
|
|
|
2023-08-25 22:53:30 +02:00
|
|
|
def can_be_deleted?
|
2023-10-01 12:52:05 +02:00
|
|
|
groupe_gestionnaires.roots.each do |rt|
|
|
|
|
return false unless rt.gestionnaires.size > 1
|
|
|
|
end
|
|
|
|
true
|
2023-08-25 22:53:30 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def registration_state
|
|
|
|
if user.active?
|
|
|
|
'Actif'
|
|
|
|
elsif user.reset_password_period_valid?
|
|
|
|
'En attente'
|
|
|
|
else
|
|
|
|
'Expiré'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|