[#10799] Add error on procedure#show if api entreprise token is expiring

This commit is contained in:
Mathieu Magnin 2024-09-26 16:15:31 +02:00
parent 99a1b68185
commit 64297f9ee8
No known key found for this signature in database
GPG key ID: 8DCAFC82D7BA654E
4 changed files with 11 additions and 0 deletions

View file

@ -47,6 +47,8 @@ class Procedure::ErrorsSummary < ApplicationComponent
when :initiated_mail, :received_mail, :closed_mail, :refused_mail, :without_continuation_mail, :re_instructed_mail when :initiated_mail, :received_mail, :closed_mail, :refused_mail, :without_continuation_mail, :re_instructed_mail
klass = "Mails::#{error.attribute.to_s.classify}".constantize klass = "Mails::#{error.attribute.to_s.classify}".constantize
edit_admin_procedure_mail_template_path(@procedure, klass.const_get(:SLUG)) edit_admin_procedure_mail_template_path(@procedure, klass.const_get(:SLUG))
when :api_entreprise_token
jeton_admin_procedure_path(@procedure)
end end
end end

View file

@ -7,6 +7,7 @@ module APIEntrepriseTokenConcern
included do included do
validates :api_entreprise_token, jwt_token: true, allow_blank: true validates :api_entreprise_token, jwt_token: true, allow_blank: true
validate :api_entreprise_token_expiration_valid?, on: [:publication]
before_save :set_api_entreprise_token_expires_at, if: :will_save_change_to_api_entreprise_token? before_save :set_api_entreprise_token_expires_at, if: :will_save_change_to_api_entreprise_token?
@ -18,6 +19,12 @@ module APIEntrepriseTokenConcern
self[:api_entreprise_token].presence || Rails.application.secrets.api_entreprise[:key] self[:api_entreprise_token].presence || Rails.application.secrets.api_entreprise[:key]
end end
def api_entreprise_token_expiration_valid?
if api_entreprise_token_expired_or_expires_soon?
errors.add(:api_entreprise_token, "expiré ou expirant bientôt")
end
end
def api_entreprise_token_expired? def api_entreprise_token_expired?
APIEntrepriseToken.new(api_entreprise_token).expired? APIEntrepriseToken.new(api_entreprise_token).expired?
end end

View file

@ -48,6 +48,7 @@ en:
personne_morale: 'Legal entity' personne_morale: 'Legal entity'
declarative_with_state/en_instruction: Instruction declarative_with_state/en_instruction: Instruction
declarative_with_state/accepte: Accepted declarative_with_state/accepte: Accepted
api_entreprise_token: Token API Entreprise
api_particulier_token: Token API Particulier api_particulier_token: Token API Particulier
initiated_mail: File sorted for processing notification email initiated_mail: File sorted for processing notification email
received_mail: File submitted notification email received_mail: File submitted notification email

View file

@ -54,6 +54,7 @@ fr:
personne_morale: 'Personne morale' personne_morale: 'Personne morale'
declarative_with_state/en_instruction: En instruction declarative_with_state/en_instruction: En instruction
declarative_with_state/accepte: Accepté declarative_with_state/accepte: Accepté
api_entreprise_token: Jeton API Entreprise
api_particulier_token: Jeton API Particulier api_particulier_token: Jeton API Particulier
initiated_mail: Lemail de notification de passage de dossier en instruction initiated_mail: Lemail de notification de passage de dossier en instruction
received_mail: Lemail de notification de dépôt de dossier received_mail: Lemail de notification de dépôt de dossier