diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 36099f9fed95cad1cfb9c360a425e38a7bebd062..fe3fb85225e9da1d2bdbc5f3fd3ab86eda26e39b 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -59,6 +59,7 @@ class Communication::Website::Post < ApplicationRecord before_validation :set_published_at, if: :published_changed? + scope :published, -> { where(published: true) } scope :ordered, -> { order(published_at: :desc, created_at: :desc) } scope :recent, -> { order(published_at: :desc).limit(5) } diff --git a/app/models/university/person.rb b/app/models/university/person.rb index 68299e2fa74a136970c24d63b7be6eef2e7ef09c..8cd7b16e989dc14f708cbf5c8e5114e55d8fb06d 100644 --- a/app/models/university/person.rb +++ b/app/models/university/person.rb @@ -100,16 +100,28 @@ class University::Person < ApplicationRecord end def identifiers(website: nil) - website_id = website&.id list = [] # TODO :administrator [:author, :researcher, :teacher].each do |role| - list << role if send("#{role.to_s}_websites").pluck(:id).include?(website_id) + list << role if public_send("#{role.to_s}_for_website", website) end list << :static unless list.empty? list end + def author_for_website(website) + is_author && communication_website_posts.published.where(communication_website_id: website&.id).any? + end + + def researcher_for_website(website) + is_researcher + end + + def teacher_for_website(website) + # a des formations publiées pour ce website + is_teacher && website.programs.published.joins(:teachers).where(education_program_teachers: { person_id: id }).any? + end + def git_path_static "content/persons/#{slug}.html" end