From faadce5b113a057d5fff9aba8df3f8942b45457e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Mon, 25 Sep 2023 17:00:44 +0200
Subject: [PATCH] display once

---
 app/controllers/admin/university/apps_controller.rb | 1 +
 app/models/university/app.rb                        | 6 ++++++
 app/views/admin/university/apps/show.html.erb       | 6 +++++-
 config/locales/university/en.yml                    | 4 +++-
 config/locales/university/fr.yml                    | 4 +++-
 5 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/app/controllers/admin/university/apps_controller.rb b/app/controllers/admin/university/apps_controller.rb
index 7f1bf3d0d..e138c615c 100644
--- a/app/controllers/admin/university/apps_controller.rb
+++ b/app/controllers/admin/university/apps_controller.rb
@@ -9,6 +9,7 @@ class Admin::University::AppsController < Admin::University::ApplicationControll
   end
 
   def show
+    @should_display_token = @app.display_token!
     breadcrumb
   end
 
diff --git a/app/models/university/app.rb b/app/models/university/app.rb
index 3ecc92834..24e357386 100644
--- a/app/models/university/app.rb
+++ b/app/models/university/app.rb
@@ -30,6 +30,12 @@ class University::App < ApplicationRecord
 
   scope :ordered, -> { order(:name) }
 
+  def display_token!
+    return false if token_was_displayed?
+    update(token_was_displayed: true)
+    true
+  end
+
   def regenerate_token!
     update(token: nil, token_was_displayed: false)
   end
diff --git a/app/views/admin/university/apps/show.html.erb b/app/views/admin/university/apps/show.html.erb
index 456a644a3..e368793a3 100644
--- a/app/views/admin/university/apps/show.html.erb
+++ b/app/views/admin/university/apps/show.html.erb
@@ -1,9 +1,13 @@
 <% content_for :title, @app %>
 
+<% if @should_display_token %>
+  <p class="text-danger"><%= t('university.apps.token_display_notice') %></p>
+<% end %>
+
 <div class="row">
   <div class="col-lg-6">
     <%= osuny_label University::App.human_attribute_name('token') %>
-    <input type="string" value="<%= @app.token %>" class="form-control" disabled>
+    <input type="string" value="<%= @should_display_token ? @app.token : masked_string(@app.token) %>" class="form-control" disabled>
   </div>
 </div>
 
diff --git a/config/locales/university/en.yml b/config/locales/university/en.yml
index 3eb6096b1..35cdf08c2 100644
--- a/config/locales/university/en.yml
+++ b/config/locales/university/en.yml
@@ -208,7 +208,9 @@ en:
         import_btn: Import cohorts
         import_hint_html: "Possible values for <i>gender</i> are: m (male), f (female) and n (non binary).<br><i>Phone_professional</i>, <i>phone_personal</i>, <i>mobile</i> and <i>zipcode</i> fields must have a text format, not numbers.<br><i>Country</i> field must contain the ISO 3166 code of the country, so 2 upcase characters (<a href=\"https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes\" target=\_blank\">list</a>).<br><i>Social_twitter</i> field should have no @.<br><i>School</i> field should contain the internal school id.<br><i>Program</i> field should contain the internal program id."
         title: Cohorts imports
-    contributing: 
+    apps:
+      token_display_notice: Make sure to store your token somewhere safe. You won’t be able to see it again!
+    contributing:
       one: contributing university
       other: contributing universities
     contributions_total: Contributions (total)
diff --git a/config/locales/university/fr.yml b/config/locales/university/fr.yml
index b255321a9..da2f149e8 100644
--- a/config/locales/university/fr.yml
+++ b/config/locales/university/fr.yml
@@ -208,7 +208,9 @@ fr:
         import_btn: Importer des promotions
         import_hint_html: "Les valeurs pour <i>gender</i> peuvent être m (masculin), f (féminin) et n (non binaire).<br>Les champs <i>phone_professional</i>, <i>phone_personal</i>, <i>mobile</i> et <i>zipcode</i> doivent être au format texte, pas nombre.<br>Le champ <i>country</i> doit contenir le code ISO 3166 du pays, sur 2 caratères en majuscule (<a href=\"https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes\" target=\_blank\">liste</a>)<br>Le champ <i>social_twitter</i> ne doit pas contenir d'@.<br>Le champ <i>school</i> doit contenir l'id interne de l'école.<br>Le champ <i>program</i> doit contenir l'id interne de la formation."
         title: Imports de promotions
-    contributing: 
+    apps:
+      token_display_notice: Assurez-vous de stocker votre jeton secret de manière sécurisée. Vous ne pourrez pas le revoir !
+    contributing:
       one: université contributrice
       other: universités contributrices
     contributions_total: Contributions (total)
-- 
GitLab