From d48469ed6a27bdbc60442acd339bd8df901904be Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Fri, 15 Apr 2022 21:42:25 +0200
Subject: [PATCH] roles

---
 app/models/university/person.rb                       | 11 +++++++++++
 app/views/admin/university/people/_list.html.erb      |  8 ++++++++
 .../admin/university/person/alumni/_list.html.erb     |  2 +-
 config/locales/university/fr.yml                      |  5 +++++
 4 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/app/models/university/person.rb b/app/models/university/person.rb
index 247d6682e..acc1f2dd8 100644
--- a/app/models/university/person.rb
+++ b/app/models/university/person.rb
@@ -113,6 +113,17 @@ class University::Person < ApplicationRecord
     "#{first_name} #{last_name}"
   end
 
+  def roles
+    [:administration, :teacher, :researcher, :alumnus, :author].reject do |role|
+      ! send "is_#{role}"
+    end
+  end
+
+  # TODO denormalize
+  def is_author
+    communication_website_posts.any?
+  end
+
   def websites
     university.communication_websites
   end
diff --git a/app/views/admin/university/people/_list.html.erb b/app/views/admin/university/people/_list.html.erb
index 621853564..7ad87044b 100644
--- a/app/views/admin/university/people/_list.html.erb
+++ b/app/views/admin/university/people/_list.html.erb
@@ -3,6 +3,7 @@
     <tr>
       <th><%= University::Person.human_attribute_name('last_name') %></th>
       <th><%= University::Person.human_attribute_name('first_name') %></th>
+      <th><%= University::Person.human_attribute_name('roles') %></th>
       <th></th>
     </tr>
   </thead>
@@ -11,6 +12,13 @@
       <tr>
         <td><%= link_to person.last_name, admin_university_person_path(person) %></td>
         <td><%= link_to person.first_name, admin_university_person_path(person) %></td>
+        <td>
+          <% person.roles.each do |role| %>
+            <span class="badge bg-secondary">
+              <%= t "activerecord.attributes.university/person.#{role}" %>
+            </span>
+          <% end %>
+        </td>
         <td class="text-end">
           <div class="btn-group" role="group">
             <%= link_to t('edit'),
diff --git a/app/views/admin/university/person/alumni/_list.html.erb b/app/views/admin/university/person/alumni/_list.html.erb
index 0d3945bd5..bf9a289c1 100644
--- a/app/views/admin/university/person/alumni/_list.html.erb
+++ b/app/views/admin/university/person/alumni/_list.html.erb
@@ -15,7 +15,7 @@
         <td class="text-end">
           <div class="btn-group" role="group">
             <%= link_to t('edit'),
-                      edit_admin_university_person_alumnus_path(alumnus),
+                      edit_admin_university_person_path(alumnus),
                       class: button_classes if can?(:update, alumnus) %>
             <%= link_to t('delete'),
                       path,
diff --git a/config/locales/university/fr.yml b/config/locales/university/fr.yml
index f016ee4c0..26e9ee1d9 100644
--- a/config/locales/university/fr.yml
+++ b/config/locales/university/fr.yml
@@ -31,6 +31,11 @@ fr:
         is_author: Auteur·rice
         is_researcher: Chercheur·se
         is_teacher: Enseignant·e
+        administration: Personnel administratif
+        alumnus: Alumnus
+        author: Auteur·rice
+        researcher: Chercheur·se
+        teacher: Enseignant·e
         last_name: Nom de famille
         linkedin: LinkedIn (URL)
         name: Nom
-- 
GitLab