[#10798] Indicate in manager if api_entreprise_token is present / valid / expired

This commit is contained in:
Mathieu Magnin 2024-09-13 16:47:31 +02:00
parent 7286fb9ef2
commit ce22adf811
No known key found for this signature in database
GPG key ID: 8DCAFC82D7BA654E
3 changed files with 25 additions and 0 deletions

View file

@ -29,6 +29,7 @@ class ProcedureDashboard < Administrate::BaseDashboard
updated_at: Field::DateTime,
for_individual: Field::Boolean,
auto_archive_on: Field::DateTime,
api_entreprise_token: JwtField,
published_at: Field::DateTime,
unpublished_at: Field::DateTime,
hidden_at: Field::DateTime,
@ -100,6 +101,7 @@ class ProcedureDashboard < Administrate::BaseDashboard
:published_types_de_champ_public,
:published_types_de_champ_private,
:for_individual,
:api_entreprise_token,
:auto_archive_on,
:passer_en_construction_email_template,
:passer_en_instruction_email_template,

22
app/fields/jwt_field.rb Normal file
View file

@ -0,0 +1,22 @@
require "administrate/field/base"
class JwtField < Administrate::Field::Base
def to_s
if data.present?
begin
decoded_token = JWT.decode(data, nil, false)
expiration = Time.zone.at(decoded_token[0]['exp'])
if expiration < Time.zone.now
"Token présent, expiré le #{expiration.strftime('%d/%m/%Y à %H:%M')}"
else
"Token présent, expirera le #{expiration.strftime('%d/%m/%Y à %H:%M')}"
end
rescue JWT::DecodeError => e
"Token invalide : #{e.message}"
end
else
"Pas de token"
end
end
end

View file

@ -0,0 +1 @@
<%= field.to_s %>