From 375b6203f7812652a4c9cf1d6c6c81515df9600a Mon Sep 17 00:00:00 2001
From: pabois <pierreandre.boissinot@noesya.coop>
Date: Mon, 17 Oct 2022 16:41:01 +0200
Subject: [PATCH] wip extranet registration

---
 .../communication/extranets_controller.rb     |  2 +-
 app/models/communication/extranet.rb          | 17 +++++++-------
 app/models/user/with_extranet.rb              |  6 ++++-
 .../communication/extranets/_form.html.erb    |  1 +
 config/locales/communication/en.yml           | 23 ++++++++++---------
 config/locales/communication/fr.yml           | 15 ++++++------
 config/locales/extranet/en.yml                |  4 +++-
 config/locales/extranet/fr.yml                |  9 +++++---
 ...tion_contact_to_communication_extranets.rb |  5 ++++
 db/schema.rb                                  |  3 ++-
 test/fixtures/communication/extranets.yml     | 17 +++++++-------
 test/models/communication/extranet_test.rb    | 17 +++++++-------
 12 files changed, 70 insertions(+), 49 deletions(-)
 create mode 100644 db/migrate/20221017142108_add_registration_contact_to_communication_extranets.rb

diff --git a/app/controllers/admin/communication/extranets_controller.rb b/app/controllers/admin/communication/extranets_controller.rb
index 2d11a6318..04eb9d832 100644
--- a/app/controllers/admin/communication/extranets_controller.rb
+++ b/app/controllers/admin/communication/extranets_controller.rb
@@ -64,6 +64,6 @@ class Admin::Communication::ExtranetsController < Admin::Communication::Applicat
 
   def extranet_params
     params.require(:communication_extranet)
-          .permit(:name, :domain, :about_type, :about_id, :logo, :logo_delete)
+          .permit(:name, :domain, :about_type, :about_id, :registration_contact, :logo, :logo_delete)
   end
 end
diff --git a/app/models/communication/extranet.rb b/app/models/communication/extranet.rb
index 75b8c1a0d..eb5cb55bc 100644
--- a/app/models/communication/extranet.rb
+++ b/app/models/communication/extranet.rb
@@ -2,14 +2,15 @@
 #
 # Table name: communication_extranets
 #
-#  id            :uuid             not null, primary key
-#  about_type    :string           indexed => [about_id]
-#  domain        :string
-#  name          :string
-#  created_at    :datetime         not null
-#  updated_at    :datetime         not null
-#  about_id      :uuid             indexed => [about_type]
-#  university_id :uuid             not null, indexed
+#  id                   :uuid             not null, primary key
+#  about_type           :string           indexed => [about_id]
+#  domain               :string
+#  name                 :string
+#  registration_contact :string
+#  created_at           :datetime         not null
+#  updated_at           :datetime         not null
+#  about_id             :uuid             indexed => [about_type]
+#  university_id        :uuid             not null, indexed
 #
 # Indexes
 #
diff --git a/app/models/user/with_extranet.rb b/app/models/user/with_extranet.rb
index 07e27b975..0e647a92d 100644
--- a/app/models/user/with_extranet.rb
+++ b/app/models/user/with_extranet.rb
@@ -11,7 +11,11 @@ module User::WithExtranet
     def extranet_access
       # do extranet_to_validate alumni include current email?
       # TODO
-      # errors.add :email, 'n est pas autorisé'
+      # if extranet_to_validate.registration_contact.present?
+      #   errors.add :email, I18n.t('extranet.errors.email_not_allowed_with_contact', contact: extranet_to_validate.registration_contact)
+      # else
+      #   errors.add :email, I18n.t('extranet.errors.email_not_allowed')
+      # end
     end
 
   end
diff --git a/app/views/admin/communication/extranets/_form.html.erb b/app/views/admin/communication/extranets/_form.html.erb
index 0f75c225c..b6c8ab182 100644
--- a/app/views/admin/communication/extranets/_form.html.erb
+++ b/app/views/admin/communication/extranets/_form.html.erb
@@ -12,6 +12,7 @@
           <%= f.input :name %>
           <%= f.input :domain %>
           <%= render 'admin/communication/abouts', f: f, i18n_key: 'activerecord.attributes.communication/extranet.about_' %>
+          <%= f.input :registration_contact %>
         </div>
       </div>
     </div>
diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml
index a9cf0e144..85bef999d 100644
--- a/config/locales/communication/en.yml
+++ b/config/locales/communication/en.yml
@@ -48,8 +48,9 @@ en:
         about_Research::Journal: Journal extranet
         about_Research::Laboratory: Laboratory extranet
         about_type: About
-        title: Title
         domain: Domain
+        name: Name
+        registration_contact: Contact mail for registrations problems
       communication/website:
         about: About
         about_: Independent website
@@ -216,23 +217,23 @@ en:
                 label: Description
                 placeholder: Enter description here
               element:
-                title: 
+                title:
                   label: Day
                   placeholder: Enter the day or period
                 time_slot_morning:
                   label: Morning (if necessary)
                 time_slot_afternoon:
                   label: Afternoon (or full day)
-              name: 
+              name:
                 label: Name (person, organization...)
                 placeholder: Enter the text
               zipcode:
                 label: Zipcode
                 placeholder: Enter the zipcode
-              mails: 
+              mails:
                 label: Mails
                 placeholder: Enter the mail
-              phones: 
+              phones:
                 label: Telephone numbers
                 placeholder: Enter the number
               slots: Opening times
@@ -357,11 +358,11 @@ en:
                 options:
                   children: Main page and children
                   selection: A specific selection of pages
-              show_main_description: 
+              show_main_description:
                 label: Show main page short description
-              show_description: 
+              show_description:
                 label: Show pages short descriptions
-              show_image: 
+              show_image:
                 label: Show pages images
               main_page:
                 title: Main page
@@ -382,7 +383,7 @@ en:
               add_partner: Add partner
               remove_partner: Remove partner
               element:
-                id: 
+                id:
                   label: Partner
                   placeholder: Choose organization
                   unregistered: Unregistered organization
@@ -465,7 +466,7 @@ en:
                 label: Video url
                 placeholder: Enter video's url
                 hint: >
-                  Ex: 
+                  Ex:
                   https://vimeo.com/732180675,
                   https://www.youtube.com/watch?v=lAYhfCPelO0
               video_title:
@@ -648,6 +649,6 @@ en:
       communication_website_page:
         breadcrumb_title: If the field is empty, page title will be used in breadcrumbs.
         description: If this field is empty, the "lead text" field will be used. If also emty the main text's begining will be used.
-        full_width: On large screens, a full width page uses all available space for the content. This is good for landing pages, or to make them spectacular. If the page is not full width, the content column will be smaller to make reading easier. The unused space might be used for a table of contents. 
+        full_width: On large screens, a full width page uses all available space for the content. This is good for landing pages, or to make them spectacular. If the page is not full width, the content column will be smaller to make reading easier. The unused space might be used for a table of contents.
       communication_website_post:
         description: If this field is empty, the "lead text" field will be used. If also emty the main text's begining will be used.
diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml
index 5897adc44..bf7a104bc 100644
--- a/config/locales/communication/fr.yml
+++ b/config/locales/communication/fr.yml
@@ -48,8 +48,9 @@ fr:
         about_Research::Journal: Extranet d'une revue scientifique
         about_Research::Laboratory: Extranet d'un laboratoire
         about_type: Type d'extranet
-        name: Nom
         domain: Domaine
+        name: Nom
+        registration_contact: Mail de contact pour les problèmes d'inscription
       communication/website:
         about: Sujet du site
         about_: Site indépendant
@@ -217,26 +218,26 @@ fr:
                 label: Description
                 placeholder: Entrer la description
               element:
-                title: 
+                title:
                   label: Jour
                   placeholder: Entrer le jour ou la période
                 time_slot_morning:
                   label: Matin (si nécessaire)
                 time_slot_afternoon:
                   label: Après-midi (ou jour complet)
-              name: 
+              name:
                 label: Nom (personne, établissement...)
                 placeholder: Entrer le texte
               zipcode:
                 label: Code postal
                 placeholder: Entrer le code postal
-              mails: 
+              mails:
                 label: Mails
                 placeholder: Entrer le mail
-              phones: 
+              phones:
                 label: Téléphones
                 placeholder: Entrer le numéro
-              slots: Horaires  
+              slots: Horaires
           datatable:
             description: Un tableau de données, aussi responsive et accessible que possible.
             edit:
@@ -470,7 +471,7 @@ fr:
                 label: Url de la vidéo
                 placeholder: Entrer l'url de la vidéo
                 hint: >
-                  Ex: 
+                  Ex:
                   https://vimeo.com/732180675,
                   https://www.youtube.com/watch?v=lAYhfCPelO0
               video_title:
diff --git a/config/locales/extranet/en.yml b/config/locales/extranet/en.yml
index a71ded4f9..0311a59b0 100644
--- a/config/locales/extranet/en.yml
+++ b/config/locales/extranet/en.yml
@@ -1,7 +1,9 @@
 en:
   extranet:
-    account: 
+    account:
       my: My account
       edit: Edit
       updated: Updated
       logout: Log out
+    experiences:
+      new: Add experience
diff --git a/config/locales/extranet/fr.yml b/config/locales/extranet/fr.yml
index 4c4347226..91e718ba3 100644
--- a/config/locales/extranet/fr.yml
+++ b/config/locales/extranet/fr.yml
@@ -1,9 +1,12 @@
 fr:
   extranet:
-    experiences:
-      new: Ajouter une expérience
-    account: 
+    account:
       my: Mon compte
       edit: Modifier
       updated: Mise à jour effectuée
       logout: Déconnexion
+    errors:
+      email_not_allowed: n'est pas autorisé à accéder à cet extranet.
+      email_not_allowed_with_contact: n'est pas autorisé à accéder à cet extranet. Contactez %{contact} pour en savoir plus.
+    experiences:
+      new: Ajouter une expérience
diff --git a/db/migrate/20221017142108_add_registration_contact_to_communication_extranets.rb b/db/migrate/20221017142108_add_registration_contact_to_communication_extranets.rb
new file mode 100644
index 000000000..da34f0cde
--- /dev/null
+++ b/db/migrate/20221017142108_add_registration_contact_to_communication_extranets.rb
@@ -0,0 +1,5 @@
+class AddRegistrationContactToCommunicationExtranets < ActiveRecord::Migration[6.1]
+  def change
+    add_column :communication_extranets, :registration_contact, :string
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 776268905..5876144fc 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2022_10_11_070402) do
+ActiveRecord::Schema.define(version: 2022_10_17_142108) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "pgcrypto"
@@ -102,6 +102,7 @@ ActiveRecord::Schema.define(version: 2022_10_11_070402) do
     t.datetime "updated_at", precision: 6, null: false
     t.string "about_type"
     t.uuid "about_id"
+    t.string "registration_contact"
     t.index ["about_type", "about_id"], name: "index_communication_extranets_on_about"
     t.index ["university_id"], name: "index_communication_extranets_on_university_id"
   end
diff --git a/test/fixtures/communication/extranets.yml b/test/fixtures/communication/extranets.yml
index 67008e68b..cba2a17ed 100644
--- a/test/fixtures/communication/extranets.yml
+++ b/test/fixtures/communication/extranets.yml
@@ -2,14 +2,15 @@
 #
 # Table name: communication_extranets
 #
-#  id            :uuid             not null, primary key
-#  about_type    :string           indexed => [about_id]
-#  domain        :string
-#  name          :string
-#  created_at    :datetime         not null
-#  updated_at    :datetime         not null
-#  about_id      :uuid             indexed => [about_type]
-#  university_id :uuid             not null, indexed
+#  id                   :uuid             not null, primary key
+#  about_type           :string           indexed => [about_id]
+#  domain               :string
+#  name                 :string
+#  registration_contact :string
+#  created_at           :datetime         not null
+#  updated_at           :datetime         not null
+#  about_id             :uuid             indexed => [about_type]
+#  university_id        :uuid             not null, indexed
 #
 # Indexes
 #
diff --git a/test/models/communication/extranet_test.rb b/test/models/communication/extranet_test.rb
index 54e7cf1a8..c51aec18a 100644
--- a/test/models/communication/extranet_test.rb
+++ b/test/models/communication/extranet_test.rb
@@ -2,14 +2,15 @@
 #
 # Table name: communication_extranets
 #
-#  id            :uuid             not null, primary key
-#  about_type    :string           indexed => [about_id]
-#  domain        :string
-#  name          :string
-#  created_at    :datetime         not null
-#  updated_at    :datetime         not null
-#  about_id      :uuid             indexed => [about_type]
-#  university_id :uuid             not null, indexed
+#  id                   :uuid             not null, primary key
+#  about_type           :string           indexed => [about_id]
+#  domain               :string
+#  name                 :string
+#  registration_contact :string
+#  created_at           :datetime         not null
+#  updated_at           :datetime         not null
+#  about_id             :uuid             indexed => [about_type]
+#  university_id        :uuid             not null, indexed
 #
 # Indexes
 #
-- 
GitLab