From 1647bb4629384a5f849e53a1bbf65780b86aaae3 Mon Sep 17 00:00:00 2001
From: pabois <pierreandre.boissinot@noesya.coop>
Date: Mon, 30 May 2022 13:34:51 +0200
Subject: [PATCH] close #392

---
 .../admin/university/people_controller.rb     |  5 +-
 app/models/university/person.rb               | 58 +++++++++++--------
 app/models/university/person/administrator.rb | 56 ++++++++++--------
 app/models/university/person/alumnus.rb       | 56 ++++++++++--------
 app/models/university/person/author.rb        | 56 ++++++++++--------
 app/models/university/person/researcher.rb    | 56 ++++++++++--------
 app/models/university/person/teacher.rb       | 56 ++++++++++--------
 .../admin/university/people/_form.html.erb    | 35 ++++++++++-
 .../university/people/_main_infos.html.erb    | 23 +++++++-
 config/locales/en.yml                         |  3 +
 config/locales/fr.yml                         |  3 +
 config/locales/university/en.yml              | 14 ++++-
 config/locales/university/fr.yml              | 14 ++++-
 .../20220530094714_add_infos_to_person.rb     | 13 +++++
 db/schema.rb                                  | 12 +++-
 15 files changed, 307 insertions(+), 153 deletions(-)
 create mode 100644 db/migrate/20220530094714_add_infos_to_person.rb

diff --git a/app/controllers/admin/university/people_controller.rb b/app/controllers/admin/university/people_controller.rb
index bdc9ee2d2..4eda4fadb 100644
--- a/app/controllers/admin/university/people_controller.rb
+++ b/app/controllers/admin/university/people_controller.rb
@@ -65,7 +65,10 @@ class Admin::University::PeopleController < Admin::University::ApplicationContro
 
   def person_params
     params.require(:university_person).permit(
-      :slug, :first_name, :last_name, :email, :phone, :description, :description_short,
+      :slug, :first_name, :last_name, :email, :gender, :birthdate,
+      :phone_mobile, :phone_professional, :phone_personal,
+      :address, :zipcode, :city, :country,
+      :description, :description_short,
       :biography,  :picture, :picture_delete, :picture_infos,
       :habilitation, :tenure, :url, :linkedin, :twitter,
       :is_researcher, :is_teacher, :is_administration, :is_alumnus,
diff --git a/app/models/university/person.rb b/app/models/university/person.rb
index 85e28db5f..873044adc 100644
--- a/app/models/university/person.rb
+++ b/app/models/university/person.rb
@@ -2,30 +2,38 @@
 #
 # Table name: university_people
 #
-#  id                :uuid             not null, primary key
-#  biography         :text
-#  description       :text
-#  description_short :text
-#  email             :string
-#  first_name        :string
-#  habilitation      :boolean          default(FALSE)
-#  is_administration :boolean
-#  is_alumnus        :boolean          default(FALSE)
-#  is_author         :boolean
-#  is_researcher     :boolean
-#  is_teacher        :boolean
-#  last_name         :string
-#  linkedin          :string
-#  name              :string
-#  phone             :string
-#  slug              :string
-#  tenure            :boolean          default(FALSE)
-#  twitter           :string
-#  url               :string
-#  created_at        :datetime         not null
-#  updated_at        :datetime         not null
-#  university_id     :uuid             not null, indexed
-#  user_id           :uuid             indexed
+#  id                 :uuid             not null, primary key
+#  address            :string
+#  biography          :text
+#  birthdate          :date
+#  city               :string
+#  country            :string
+#  description        :text
+#  description_short  :text
+#  email              :string
+#  first_name         :string
+#  gender             :integer
+#  habilitation       :boolean          default(FALSE)
+#  is_administration  :boolean
+#  is_alumnus         :boolean          default(FALSE)
+#  is_author          :boolean
+#  is_researcher      :boolean
+#  is_teacher         :boolean
+#  last_name          :string
+#  linkedin           :string
+#  name               :string
+#  phone_mobile       :string
+#  phone_personal     :string
+#  phone_professional :string
+#  slug               :string
+#  tenure             :boolean          default(FALSE)
+#  twitter            :string
+#  url                :string
+#  zipcode            :string
+#  created_at         :datetime         not null
+#  updated_at         :datetime         not null
+#  university_id      :uuid             not null, indexed
+#  user_id            :uuid             indexed
 #
 # Indexes
 #
@@ -56,6 +64,8 @@ class University::Person < ApplicationRecord
     :author
   ].freeze
 
+  enum gender: { male: 0, female: 1, non_binary: 2 }
+
   has_summernote :biography
 
   belongs_to :user, optional: true
diff --git a/app/models/university/person/administrator.rb b/app/models/university/person/administrator.rb
index e2287f0fa..cc72eecb8 100644
--- a/app/models/university/person/administrator.rb
+++ b/app/models/university/person/administrator.rb
@@ -2,30 +2,38 @@
 #
 # Table name: university_people
 #
-#  id                :uuid             not null, primary key
-#  biography         :text
-#  description       :text
-#  description_short :text
-#  email             :string
-#  first_name        :string
-#  habilitation      :boolean          default(FALSE)
-#  is_administration :boolean
-#  is_alumnus        :boolean          default(FALSE)
-#  is_author         :boolean
-#  is_researcher     :boolean
-#  is_teacher        :boolean
-#  last_name         :string
-#  linkedin          :string
-#  name              :string
-#  phone             :string
-#  slug              :string
-#  tenure            :boolean          default(FALSE)
-#  twitter           :string
-#  url               :string
-#  created_at        :datetime         not null
-#  updated_at        :datetime         not null
-#  university_id     :uuid             not null, indexed
-#  user_id           :uuid             indexed
+#  id                 :uuid             not null, primary key
+#  address            :string
+#  biography          :text
+#  birthdate          :date
+#  city               :string
+#  country            :string
+#  description        :text
+#  description_short  :text
+#  email              :string
+#  first_name         :string
+#  gender             :integer
+#  habilitation       :boolean          default(FALSE)
+#  is_administration  :boolean
+#  is_alumnus         :boolean          default(FALSE)
+#  is_author          :boolean
+#  is_researcher      :boolean
+#  is_teacher         :boolean
+#  last_name          :string
+#  linkedin           :string
+#  name               :string
+#  phone_mobile       :string
+#  phone_personal     :string
+#  phone_professional :string
+#  slug               :string
+#  tenure             :boolean          default(FALSE)
+#  twitter            :string
+#  url                :string
+#  zipcode            :string
+#  created_at         :datetime         not null
+#  updated_at         :datetime         not null
+#  university_id      :uuid             not null, indexed
+#  user_id            :uuid             indexed
 #
 # Indexes
 #
diff --git a/app/models/university/person/alumnus.rb b/app/models/university/person/alumnus.rb
index 6340ea714..028735cba 100644
--- a/app/models/university/person/alumnus.rb
+++ b/app/models/university/person/alumnus.rb
@@ -2,30 +2,38 @@
 #
 # Table name: university_people
 #
-#  id                :uuid             not null, primary key
-#  biography         :text
-#  description       :text
-#  description_short :text
-#  email             :string
-#  first_name        :string
-#  habilitation      :boolean          default(FALSE)
-#  is_administration :boolean
-#  is_alumnus        :boolean          default(FALSE)
-#  is_author         :boolean
-#  is_researcher     :boolean
-#  is_teacher        :boolean
-#  last_name         :string
-#  linkedin          :string
-#  name              :string
-#  phone             :string
-#  slug              :string
-#  tenure            :boolean          default(FALSE)
-#  twitter           :string
-#  url               :string
-#  created_at        :datetime         not null
-#  updated_at        :datetime         not null
-#  university_id     :uuid             not null, indexed
-#  user_id           :uuid             indexed
+#  id                 :uuid             not null, primary key
+#  address            :string
+#  biography          :text
+#  birthdate          :date
+#  city               :string
+#  country            :string
+#  description        :text
+#  description_short  :text
+#  email              :string
+#  first_name         :string
+#  gender             :integer
+#  habilitation       :boolean          default(FALSE)
+#  is_administration  :boolean
+#  is_alumnus         :boolean          default(FALSE)
+#  is_author          :boolean
+#  is_researcher      :boolean
+#  is_teacher         :boolean
+#  last_name          :string
+#  linkedin           :string
+#  name               :string
+#  phone_mobile       :string
+#  phone_personal     :string
+#  phone_professional :string
+#  slug               :string
+#  tenure             :boolean          default(FALSE)
+#  twitter            :string
+#  url                :string
+#  zipcode            :string
+#  created_at         :datetime         not null
+#  updated_at         :datetime         not null
+#  university_id      :uuid             not null, indexed
+#  user_id            :uuid             indexed
 #
 # Indexes
 #
diff --git a/app/models/university/person/author.rb b/app/models/university/person/author.rb
index ae695b0b9..08ad2f90c 100644
--- a/app/models/university/person/author.rb
+++ b/app/models/university/person/author.rb
@@ -2,30 +2,38 @@
 #
 # Table name: university_people
 #
-#  id                :uuid             not null, primary key
-#  biography         :text
-#  description       :text
-#  description_short :text
-#  email             :string
-#  first_name        :string
-#  habilitation      :boolean          default(FALSE)
-#  is_administration :boolean
-#  is_alumnus        :boolean          default(FALSE)
-#  is_author         :boolean
-#  is_researcher     :boolean
-#  is_teacher        :boolean
-#  last_name         :string
-#  linkedin          :string
-#  name              :string
-#  phone             :string
-#  slug              :string
-#  tenure            :boolean          default(FALSE)
-#  twitter           :string
-#  url               :string
-#  created_at        :datetime         not null
-#  updated_at        :datetime         not null
-#  university_id     :uuid             not null, indexed
-#  user_id           :uuid             indexed
+#  id                 :uuid             not null, primary key
+#  address            :string
+#  biography          :text
+#  birthdate          :date
+#  city               :string
+#  country            :string
+#  description        :text
+#  description_short  :text
+#  email              :string
+#  first_name         :string
+#  gender             :integer
+#  habilitation       :boolean          default(FALSE)
+#  is_administration  :boolean
+#  is_alumnus         :boolean          default(FALSE)
+#  is_author          :boolean
+#  is_researcher      :boolean
+#  is_teacher         :boolean
+#  last_name          :string
+#  linkedin           :string
+#  name               :string
+#  phone_mobile       :string
+#  phone_personal     :string
+#  phone_professional :string
+#  slug               :string
+#  tenure             :boolean          default(FALSE)
+#  twitter            :string
+#  url                :string
+#  zipcode            :string
+#  created_at         :datetime         not null
+#  updated_at         :datetime         not null
+#  university_id      :uuid             not null, indexed
+#  user_id            :uuid             indexed
 #
 # Indexes
 #
diff --git a/app/models/university/person/researcher.rb b/app/models/university/person/researcher.rb
index c00c664d8..254d0ce1f 100644
--- a/app/models/university/person/researcher.rb
+++ b/app/models/university/person/researcher.rb
@@ -2,30 +2,38 @@
 #
 # Table name: university_people
 #
-#  id                :uuid             not null, primary key
-#  biography         :text
-#  description       :text
-#  description_short :text
-#  email             :string
-#  first_name        :string
-#  habilitation      :boolean          default(FALSE)
-#  is_administration :boolean
-#  is_alumnus        :boolean          default(FALSE)
-#  is_author         :boolean
-#  is_researcher     :boolean
-#  is_teacher        :boolean
-#  last_name         :string
-#  linkedin          :string
-#  name              :string
-#  phone             :string
-#  slug              :string
-#  tenure            :boolean          default(FALSE)
-#  twitter           :string
-#  url               :string
-#  created_at        :datetime         not null
-#  updated_at        :datetime         not null
-#  university_id     :uuid             not null, indexed
-#  user_id           :uuid             indexed
+#  id                 :uuid             not null, primary key
+#  address            :string
+#  biography          :text
+#  birthdate          :date
+#  city               :string
+#  country            :string
+#  description        :text
+#  description_short  :text
+#  email              :string
+#  first_name         :string
+#  gender             :integer
+#  habilitation       :boolean          default(FALSE)
+#  is_administration  :boolean
+#  is_alumnus         :boolean          default(FALSE)
+#  is_author          :boolean
+#  is_researcher      :boolean
+#  is_teacher         :boolean
+#  last_name          :string
+#  linkedin           :string
+#  name               :string
+#  phone_mobile       :string
+#  phone_personal     :string
+#  phone_professional :string
+#  slug               :string
+#  tenure             :boolean          default(FALSE)
+#  twitter            :string
+#  url                :string
+#  zipcode            :string
+#  created_at         :datetime         not null
+#  updated_at         :datetime         not null
+#  university_id      :uuid             not null, indexed
+#  user_id            :uuid             indexed
 #
 # Indexes
 #
diff --git a/app/models/university/person/teacher.rb b/app/models/university/person/teacher.rb
index e26b9e332..83303c45c 100644
--- a/app/models/university/person/teacher.rb
+++ b/app/models/university/person/teacher.rb
@@ -2,30 +2,38 @@
 #
 # Table name: university_people
 #
-#  id                :uuid             not null, primary key
-#  biography         :text
-#  description       :text
-#  description_short :text
-#  email             :string
-#  first_name        :string
-#  habilitation      :boolean          default(FALSE)
-#  is_administration :boolean
-#  is_alumnus        :boolean          default(FALSE)
-#  is_author         :boolean
-#  is_researcher     :boolean
-#  is_teacher        :boolean
-#  last_name         :string
-#  linkedin          :string
-#  name              :string
-#  phone             :string
-#  slug              :string
-#  tenure            :boolean          default(FALSE)
-#  twitter           :string
-#  url               :string
-#  created_at        :datetime         not null
-#  updated_at        :datetime         not null
-#  university_id     :uuid             not null, indexed
-#  user_id           :uuid             indexed
+#  id                 :uuid             not null, primary key
+#  address            :string
+#  biography          :text
+#  birthdate          :date
+#  city               :string
+#  country            :string
+#  description        :text
+#  description_short  :text
+#  email              :string
+#  first_name         :string
+#  gender             :integer
+#  habilitation       :boolean          default(FALSE)
+#  is_administration  :boolean
+#  is_alumnus         :boolean          default(FALSE)
+#  is_author          :boolean
+#  is_researcher      :boolean
+#  is_teacher         :boolean
+#  last_name          :string
+#  linkedin           :string
+#  name               :string
+#  phone_mobile       :string
+#  phone_personal     :string
+#  phone_professional :string
+#  slug               :string
+#  tenure             :boolean          default(FALSE)
+#  twitter            :string
+#  url                :string
+#  zipcode            :string
+#  created_at         :datetime         not null
+#  updated_at         :datetime         not null
+#  university_id      :uuid             not null, indexed
+#  user_id            :uuid             indexed
 #
 # Indexes
 #
diff --git a/app/views/admin/university/people/_form.html.erb b/app/views/admin/university/people/_form.html.erb
index 6ba4c1232..d3571ddee 100644
--- a/app/views/admin/university/people/_form.html.erb
+++ b/app/views/admin/university/people/_form.html.erb
@@ -9,6 +9,14 @@
           <h5 class="card-title mb-0"><%= t('content') %></h5>
         </div>
         <div class="card-body">
+          <div class="row">
+            <div class="col-md-6">
+              <%= f.input :gender, label_method: lambda { |g| t("activerecord.attributes.university/person.genders.#{g[1]}") } %>
+            </div>
+            <div class="col-md-6">
+              <%= f.input :birthdate, discard_year: true, include_blank: true %>
+            </div>
+          </div>
           <div class="row">
             <div class="col-md-6">
               <%= f.input :first_name %>
@@ -22,9 +30,34 @@
               <%= f.input :email %>
             </div>
             <div class="col-md-6">
-              <%= f.input :phone %>
+              <%= f.input :phone_mobile %>
             </div>
           </div>
+          <div class="row">
+            <div class="col-md-6">
+              <%= f.input :phone_professional %>
+            </div>
+            <div class="col-md-6">
+              <%= f.input :phone_personal %>
+            </div>
+          </div>
+          <div class="row">
+            <div class="col-md-6">
+              <%= f.input :address %>
+            </div>
+            <div class="col-md-6">
+              <%= f.input :zipcode %>
+            </div>
+          </div>
+          <div class="row">
+            <div class="col-md-6">
+              <%= f.input :city %>
+            </div>
+            <div class="col-md-6">
+              <%= f.input :country, input_html: { class: 'form-select' } %>
+            </div>
+          </div>
+
           <%= f.input :description_short %>
           <%= f.input :biography, as: :summernote %>
         </div>
diff --git a/app/views/admin/university/people/_main_infos.html.erb b/app/views/admin/university/people/_main_infos.html.erb
index 12dd8800b..fafbbbb01 100644
--- a/app/views/admin/university/people/_main_infos.html.erb
+++ b/app/views/admin/university/people/_main_infos.html.erb
@@ -5,14 +5,31 @@
         <h2 class="card-title mb-0 h5"><%= t('content') %></h2>
       </div>
       <div class="card-body">
+        <% unless person.gender.blank? %>
+          <h3 class="h5"><%= University::Person.human_attribute_name('gender') %></h3>
+          <p><%= t("activerecord.attributes.university/person.genders.#{person.gender}") %></p>
+        <% end %>
         <% unless person.email.blank? %>
           <h3 class="h5"><%= University::Person.human_attribute_name('email') %></h3>
           <p><%= link_to person.email, "mailto:#{person.email}", target: '_blank' %></p>
         <% end %>
-        <% unless person.phone.blank? %>
-          <h3 class="h5"><%= University::Person.human_attribute_name('phone') %></h3>
-          <p><%= link_to person.phone, "tel:#{person.phone}", target: '_blank' %></p>
+        <% ['phone_mobile', 'phone_personal', 'phone_professional'].each do |phone| %>
+          <% unless person[phone].blank? %>
+            <h3 class="h5"><%= University::Person.human_attribute_name(phone) %></h3>
+            <p><%= link_to person[phone], "tel:#{person[phone]}", target: '_blank' %></p>
+          <% end %>
+        <% end %>
+        <% unless person.birthdate.blank? %>
+          <h3 class="h5"><%= University::Person.human_attribute_name('birthdate') %></h3>
+          <p><%= l(person.birthdate, format: :birthday) %></p>
+        <% end %>
+        <% [:address, :zipcode, :city, :country].each do |property| %>
+          <% value = person.send property %>
+          <% next if value.blank? %>
+          <h3 class="h5"><%= University::Person.human_attribute_name(property) %></h3>
+          <p><%= value %></p>
         <% end %>
+
         <% unless person.description_short.blank? %>
           <h3 class="h5"><%= University::Person.human_attribute_name('description_short') %></h3>
           <%= simple_format person.description_short %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 89f02117d..c2bba1bca 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -80,6 +80,9 @@ en:
   cookies_policy: Cookies policy
   cookies_policy_url: https://osuny.org/politique-de-cookies
   create: Create
+  date:
+    formats:
+      birthday: "%B %d"
   delete: Delete
   devise:
     failure:
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index b4894dbc4..824f1bfb5 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -80,6 +80,9 @@ fr:
   cookies_policy: Politique de cookies
   cookies_policy_url: https://osuny.org/politique-de-cookies
   create: Créer
+  date:
+    formats:
+      birthday: "%d %B"
   delete: Supprimer
   devise:
     failure:
diff --git a/config/locales/university/en.yml b/config/locales/university/en.yml
index 32a353dbc..f85407646 100644
--- a/config/locales/university/en.yml
+++ b/config/locales/university/en.yml
@@ -23,16 +23,25 @@ en:
         zipcode: Zipcode
       university/person:
         abilities: Abilities
+        address: Address
         administration: Administrative staff
         alumnus: Alumnus
         author: Author
         biography: Biography
+        birthdate: Birthdate
+        city: City
+        country: Country
         communication_website_posts: Posts
         description: Meta Description
         description_short: Short description
         education_programs: Programs
         email: Email
         first_name: First name
+        gender: Gender
+        genders:
+          female: Female
+          male: Male
+          non_binary: Non binary
         habilitation: Can direct research?
         is_administration: Administrative staff
         is_alumnus: Alumnus
@@ -42,7 +51,9 @@ en:
         last_name: Last name
         linkedin: LinkedIn URL
         name: Name
-        phone: Phone
+        phone_mobile: Mobile phone
+        phone_personal: Personal phone
+        phone_professional: Professional phone
         picture: Profile picture
         research_journal_articles: Articles
         researcher: Researcher
@@ -54,6 +65,7 @@ en:
         twitter: Twitter username
         url: Website
         user: User
+        zipcode: Zipcode
       university/person/experience:
         from_year: Start year
         to_year: End year
diff --git a/config/locales/university/fr.yml b/config/locales/university/fr.yml
index 17bda962d..3ecfc5d4c 100644
--- a/config/locales/university/fr.yml
+++ b/config/locales/university/fr.yml
@@ -23,16 +23,25 @@ fr:
         zipcode: Code postal
       university/person:
         abilities: Responsabilités
+        address: Adresse
         administration: Personnel administratif
         alumnus: Alumnus
         author: Auteur·rice
         biography: Biographie
+        birthdate: Anniversaire
+        city: Ville
         communication_website_posts: Actualités
+        country: Pays
         description: Meta Description
         description_short: Description courte
         education_programs: Formations
         email: Email
         first_name: Prénom
+        gender: Genre
+        genders:
+          female: Féminin
+          male: Masculin
+          non_binary: Non binaire
         habilitation: Peut diriger des recherches ?
         is_administration: Personnel administratif
         is_alumnus: Alumnus
@@ -42,7 +51,9 @@ fr:
         last_name: Nom de famille
         linkedin: LinkedIn (URL)
         name: Nom
-        phone: Téléphone
+        phone_mobile: Téléphone mobile
+        phone_personal: Téléphone personnel
+        phone_professional: Téléphone professionnel
         picture: Photo de profil
         research_journal_articles: Articles
         researcher: Chercheur·se
@@ -54,6 +65,7 @@ fr:
         twitter: Twitter (nom d'utilisateur)
         url: Site web
         user: Utilisateur
+        zipcode: Code postal
       university/person/experience:
         from_year: Année de début
         to_year: Année de fin
diff --git a/db/migrate/20220530094714_add_infos_to_person.rb b/db/migrate/20220530094714_add_infos_to_person.rb
new file mode 100644
index 000000000..935a64e70
--- /dev/null
+++ b/db/migrate/20220530094714_add_infos_to_person.rb
@@ -0,0 +1,13 @@
+class AddInfosToPerson < ActiveRecord::Migration[6.1]
+  def change
+    add_column :university_people, :gender, :integer
+    add_column :university_people, :birthdate, :date
+    rename_column :university_people, :phone, :phone_mobile
+    add_column :university_people, :phone_professional, :string
+    add_column :university_people, :phone_personal, :string
+    add_column :university_people, :address, :string
+    add_column :university_people, :zipcode, :string
+    add_column :university_people, :city, :string
+    add_column :university_people, :country, :string
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 5d00fa8ee..45ca2a503 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_05_23_172753) do
+ActiveRecord::Schema.define(version: 2022_05_30_094714) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "pgcrypto"
@@ -685,7 +685,7 @@ ActiveRecord::Schema.define(version: 2022_05_23_172753) do
     t.boolean "is_administration"
     t.datetime "created_at", precision: 6, null: false
     t.datetime "updated_at", precision: 6, null: false
-    t.string "phone"
+    t.string "phone_mobile"
     t.string "email"
     t.text "description"
     t.boolean "habilitation", default: false
@@ -698,6 +698,14 @@ ActiveRecord::Schema.define(version: 2022_05_23_172753) do
     t.text "description_short"
     t.boolean "is_author"
     t.string "name"
+    t.integer "gender"
+    t.date "birthdate"
+    t.string "phone_professional"
+    t.string "phone_personal"
+    t.string "address"
+    t.string "zipcode"
+    t.string "city"
+    t.string "country"
     t.index ["university_id"], name: "index_university_people_on_university_id"
     t.index ["user_id"], name: "index_university_people_on_user_id"
   end
-- 
GitLab