diff --git a/app/dashboards/procedure_dashboard.rb b/app/dashboards/procedure_dashboard.rb index 79f77b233..8d9444e94 100644 --- a/app/dashboards/procedure_dashboard.rb +++ b/app/dashboards/procedure_dashboard.rb @@ -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, diff --git a/app/fields/jwt_field.rb b/app/fields/jwt_field.rb new file mode 100644 index 000000000..e2c944066 --- /dev/null +++ b/app/fields/jwt_field.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require "administrate/field/base" + +class JwtField < Administrate::Field::Base + def to_s + if data.present? + begin + decoded_token = JWT.decode(data, nil, false) + + return "Token présent, sans expiration" unless decoded_token[0].key?('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 diff --git a/app/views/fields/jwt_field/_show.html.erb b/app/views/fields/jwt_field/_show.html.erb new file mode 100644 index 000000000..6d9dbc907 --- /dev/null +++ b/app/views/fields/jwt_field/_show.html.erb @@ -0,0 +1 @@ +<%= field.to_s %>