🛠️ Fix | Procedure minimal admins presence
This commit is contained in:
parent
857f68c912
commit
5195ebd5c7
1 changed files with 7 additions and 1 deletions
|
@ -119,7 +119,7 @@ class Procedure < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
has_many :administrateurs_procedures, dependent: :delete_all
|
has_many :administrateurs_procedures, dependent: :delete_all
|
||||||
has_many :administrateurs, through: :administrateurs_procedures, after_remove: -> (procedure, _admin) { procedure.validate! }
|
has_many :administrateurs, through: :administrateurs_procedures, before_remove: :check_administrateur_minimal_presence
|
||||||
has_many :groupe_instructeurs, -> { order(:label) }, inverse_of: :procedure, dependent: :destroy
|
has_many :groupe_instructeurs, -> { order(:label) }, inverse_of: :procedure, dependent: :destroy
|
||||||
has_many :instructeurs, through: :groupe_instructeurs
|
has_many :instructeurs, through: :groupe_instructeurs
|
||||||
has_many :export_templates, through: :groupe_instructeurs
|
has_many :export_templates, through: :groupe_instructeurs
|
||||||
|
@ -318,6 +318,12 @@ class Procedure < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_administrateur_minimal_presence(_object)
|
||||||
|
if self.administrateurs.count <= 1
|
||||||
|
raise ActiveRecord::RecordNotDestroyed.new("Cannot remove the last administrateur of procedure #{self.libelle} (#{self.id})")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def dossiers_close_to_expiration
|
def dossiers_close_to_expiration
|
||||||
dossiers.close_to_expiration.count
|
dossiers.close_to_expiration.count
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue