From f06ccbc29eecb8da01cd394aaa1d5cf34e4b2fa2 Mon Sep 17 00:00:00 2001
From: pabois <pierreandre.boissinot@noesya.coop>
Date: Thu, 6 Jan 2022 18:44:47 +0100
Subject: [PATCH] wip #108

---
 app/models/university/person.rb                 | 17 ++++++++++-------
 .../admin/university/people/static.html.erb     |  8 ++++----
 test/fixtures/education/program/role/people.yml |  1 -
 3 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/app/models/university/person.rb b/app/models/university/person.rb
index 8cd7b16e9..0a8223ff4 100644
--- a/app/models/university/person.rb
+++ b/app/models/university/person.rb
@@ -101,27 +101,30 @@ class University::Person < ApplicationRecord
 
   def identifiers(website: nil)
     list = []
-    # TODO :administrator
-    [:author, :researcher, :teacher].each do |role|
-      list << role if public_send("#{role.to_s}_for_website", website)
+    [:author, :researcher, :teacher, :administrator].each do |role|
+      list << role if public_send("is_#{role.to_s}_for_website", website)
     end
     list << :static unless list.empty?
     list
   end
 
-  def author_for_website(website)
+  def is_author_for_website(website)
     is_author && communication_website_posts.published.where(communication_website_id: website&.id).any?
   end
 
-  def researcher_for_website(website)
+  def is_researcher_for_website(website)
     is_researcher
   end
 
-  def teacher_for_website(website)
-    # a des formations publiées pour ce website
+  def is_teacher_for_website(website)
     is_teacher && website.programs.published.joins(:teachers).where(education_program_teachers: { person_id: id }).any?
   end
 
+  def is_administrator_for_website(website)
+    # TODO
+    is_administrative
+  end
+
   def git_path_static
     "content/persons/#{slug}.html"
   end
diff --git a/app/views/admin/university/people/static.html.erb b/app/views/admin/university/people/static.html.erb
index 0bbfffa7d..c6e4a9835 100644
--- a/app/views/admin/university/people/static.html.erb
+++ b/app/views/admin/university/people/static.html.erb
@@ -7,16 +7,16 @@ last_name: "<%= @person.last_name %>"
 phone: "<%= @person.phone %>"
 email: "<%= @person.email %>"
 roles:
-<% if @person.is_author %>
+<% if @person.is_author_for_website(@website) %>
   - author
 <% end %>
-<% if @person.is_teacher %>
+<% if @person.is_teacher_for_website(@website) %>
   - teacher
 <% end %>
-<% if @person.is_researcher %>
+<% if @person.is_researcher_for_website(@website) %>
   - researcher
 <% end %>
-<% if @person.is_administrative %>
+<% if @person.is_administrator_for_website(@website) %>
   - administrator
 <% end %>
 ---
diff --git a/test/fixtures/education/program/role/people.yml b/test/fixtures/education/program/role/people.yml
index dd8da3363..50a25e47a 100644
--- a/test/fixtures/education/program/role/people.yml
+++ b/test/fixtures/education/program/role/people.yml
@@ -19,7 +19,6 @@
 #  fk_rails_...  (person_id => university_people.id)
 #  fk_rails_...  (role_id => education_program_roles.id)
 #
-# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
 
 one:
   position: 1
-- 
GitLab