diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index a8a6d12ca3236edf0385159f53ce8a3f4767145c..75c044ef5a65375f1e6eee8db7ce6733f81877b5 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -41,12 +41,13 @@ class Communication::Website < ApplicationRecord "#{name}" end - def git_path_static + def git_path(website) "data/website.yml" end - def git_dependencies_static + def git_dependencies(website) dependencies = ( + [self] + pages + pages.map(&:active_storage_blobs).flatten + posts + posts.map(&:active_storage_blobs).flatten + [home] + home.explicit_active_storage_blobs + diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index c933b35269bf8380342f5e5b7f0a902fb5a136d8..a669a35ede0567fb53421f45d53efe38a95da081 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -71,16 +71,16 @@ class Communication::Website::Category < ApplicationRecord "#{name}" end - def git_path_static + def git_path(website) "content/categories/#{path}/_index.html" end - def git_dependencies_static - descendents + posts + def git_dependencies(website) + [self] + descendents + posts end - def git_destroy_dependencies_static - descendents + def git_destroy_dependencies(website) + [self] + descendents end def update_children_paths diff --git a/app/models/communication/website/git_file.rb b/app/models/communication/website/git_file.rb index 0f414e31fab00a776f9593ba2cde9deb34f369da..2cf993bcdec963023792f47ff0fa0aa23932aaa8 100644 --- a/app/models/communication/website/git_file.rb +++ b/app/models/communication/website/git_file.rb @@ -27,8 +27,8 @@ class Communication::Website::GitFile < ApplicationRecord attr_accessor :will_be_destroyed - def self.sync(website, object, identifier, destroy: false) - git_file = where(website: website, about: object, identifier: identifier).first_or_create + def self.sync(website, object, destroy: false) + git_file = where(website: website, about: object).first_or_create git_file.will_be_destroyed = destroy website.git_repository.add_git_file git_file end @@ -59,7 +59,7 @@ class Communication::Website::GitFile < ApplicationRecord end def path - @path ||= about.send "git_path_#{identifier}" + @path ||= about.git_path(website) end def sha diff --git a/app/models/communication/website/home.rb b/app/models/communication/website/home.rb index 25805e59fb121d2da2eeda22ae93011b40767972..2a8408d4526253bcc7fc2b57debb290c31e243c1 100644 --- a/app/models/communication/website/home.rb +++ b/app/models/communication/website/home.rb @@ -34,15 +34,15 @@ class Communication::Website::Home < ApplicationRecord website.to_s end - def git_path_static + def git_path(website) 'content/_index.html' end - def git_dependencies_static - active_storage_blobs + def git_dependencies(website) + [self] + active_storage_blobs end - def git_destroy_dependencies_static - active_storage_blobs + def git_destroy_dependencies(website) + [self] + active_storage_blobs end end diff --git a/app/models/communication/website/menu.rb b/app/models/communication/website/menu.rb index 7396c580d3f64b3abead4188658c3a02ea54daed..050c52fdaa0fdbdff38b42b7d240cf88b51d2af4 100644 --- a/app/models/communication/website/menu.rb +++ b/app/models/communication/website/menu.rb @@ -37,7 +37,7 @@ class Communication::Website::Menu < ApplicationRecord "#{title}" end - def git_path_static + def git_path(website) "data/menus/#{identifier}.yml" end end diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 6bb784199b9454011891c0868c81e84496d36abe..11b61e8889121aac2a06493eb0166268568ebb5d 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -71,16 +71,16 @@ class Communication::Website::Page < ApplicationRecord scope :recent, -> { order(updated_at: :desc).limit(5) } - def git_path_static + def git_path(website) "content/pages/#{path}/_index.html" if published end - def git_dependencies_static - descendents + active_storage_blobs + siblings + def git_dependencies(website) + [self] + descendents + active_storage_blobs + siblings end - def git_destroy_dependencies_static - descendents + active_storage_blobs + def git_destroy_dependencies(website) + [self] + descendents + active_storage_blobs end def to_s diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index fe3fb85225e9da1d2bdbc5f3fd3ab86eda26e39b..bcb93c6e6572fcf7ac3d994a03953407f4444efa 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -68,15 +68,15 @@ class Communication::Website::Post < ApplicationRecord "/#{website.posts_github_directory}/#{published_at.strftime "%Y/%m/%d"}/#{slug}/" end - def git_path_static + def git_path(website) "content/posts/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" if published_at end - def git_dependencies_static - [author] + categories + active_storage_blobs + def git_dependencies(website) + [self] + [author] + categories + active_storage_blobs end - def git_destroy_dependencies_static + def git_destroy_dependencies explicit_active_storage_blobs end diff --git a/app/models/concerns/with_git.rb b/app/models/concerns/with_git.rb index 2bbe7cc57f37599c2ce0a3818a1c2058fb7b1183..b58d7922910497627a761caf031cf4c95f0c0915 100644 --- a/app/models/concerns/with_git.rb +++ b/app/models/concerns/with_git.rb @@ -8,7 +8,7 @@ module WithGit dependent: :destroy end - def git_path_static + def git_path(website) raise NotImplementedError end @@ -37,12 +37,9 @@ module WithGit def sync_with_git websites_for_self.each do |website| - identifiers(website: website).each do |identifier| - Communication::Website::GitFile.sync website, self, identifier - dependencies = send("git_dependencies_#{identifier}").flatten.uniq.compact - dependencies.each do |object| - Communication::Website::GitFile.sync website, object, identifier - end + dependencies = git_dependencies(website).flatten.uniq.compact + dependencies.each do |object| + Communication::Website::GitFile.sync website, object end website.git_repository.sync! end @@ -51,12 +48,9 @@ module WithGit def destroy_from_git websites_for_self.each do |website| - identifiers(website: website).each do |identifier| - Communication::Website::GitFile.sync website, self, identifier, destroy: true - dependencies = send("git_destroy_dependencies_#{identifier}").flatten.uniq.compact - dependencies.each do |object| - Communication::Website::GitFile.sync website, object, identifier, destroy: true - end + dependencies = git_destroy_dependencies(website).flatten.uniq.compact + dependencies.each do |object| + Communication::Website::GitFile.sync website, object, destroy: true end website.git_repository.sync! end @@ -76,16 +70,11 @@ module WithGit end end - # Overridden for multiple files generation - def identifiers(website: nil) - [:static] + def git_dependencies(website = nil) + [self] end - def git_dependencies_static - [] - end - - def git_destroy_dependencies_static - [] + def git_destroy_dependencies(website = nil) + [self] end end diff --git a/app/models/education/program.rb b/app/models/education/program.rb index ebf7b7d8bd138de1814d4e528018ff9a664c4a06..b1a9803a78a1fdeaf7ea7d9819bb89ee333e0bf0 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -116,11 +116,11 @@ class Education::Program < ApplicationRecord best_image end - def git_path_static + def git_path "content/programs/#{path}/_index.html" end - def git_dependencies_static + def git_dependencies ( active_storage_blobs + university_people_through_teachers + @@ -128,7 +128,7 @@ class Education::Program < ApplicationRecord ) end - def git_destroy_dependencies_static + def git_destroy_dependencies explicit_active_storage_blobs end diff --git a/app/models/education/school.rb b/app/models/education/school.rb index ad5acb370e3e51f897ecfe4e301dd18eae3d0003..0db82ad793232140b953bcbcb9f1b5a08017e2a0 100644 --- a/app/models/education/school.rb +++ b/app/models/education/school.rb @@ -44,7 +44,7 @@ class Education::School < ApplicationRecord "#{name}" end - def git_path_static + def git_path "data/school.yml" end end diff --git a/app/models/research/journal.rb b/app/models/research/journal.rb index 3b815b5ade15b803e6af74fa335c866c36458f33..01ff89d6190b80ad71390ddd0e6aee610f50ded7 100644 --- a/app/models/research/journal.rb +++ b/app/models/research/journal.rb @@ -35,15 +35,15 @@ class Research::Journal < ApplicationRecord "#{title}" end - def git_path_static + def git_path "data/journal.yml" end - def git_dependencies_static + def git_dependencies articles + volumes + researchers end - def git_destroy_dependencies_static + def git_destroy_dependencies articles + volumes end end diff --git a/app/models/research/journal/article.rb b/app/models/research/journal/article.rb index bf51e9631fa363feaf911f7b100b392175f854e8..6dcc524c6c1bbe339b96c585bc4ffc52ca56b515 100644 --- a/app/models/research/journal/article.rb +++ b/app/models/research/journal/article.rb @@ -55,11 +55,11 @@ class Research::Journal::Article < ApplicationRecord "/assets/articles/#{id}/#{pdf.filename}" end - def git_path_static + def git_path "content/articles/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" if published_at end - def git_dependencies_static + def git_dependencies researchers end diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb index 8f66ce3e62bb448cd45433695d3ddaff584522d5..310403fd4c1c6e3029b60bc2ed28bd212e6448ed 100644 --- a/app/models/research/journal/volume.rb +++ b/app/models/research/journal/volume.rb @@ -43,15 +43,15 @@ class Research::Journal::Volume < ApplicationRecord journal.website end - def git_path_static + def git_path "content/volumes/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" if published_at end - def git_dependencies_static + def git_dependencies articles + researchers + active_storage_blobs end - def git_destroy_dependencies_static + def git_destroy_dependencies active_storage_blobs end diff --git a/app/models/university/person.rb b/app/models/university/person.rb index 558d22a9325e992297d866c43b35fca131e308be..ae11eb93d91de2b13b270c3e5beb582cdbc8b141 100644 --- a/app/models/university/person.rb +++ b/app/models/university/person.rb @@ -96,77 +96,44 @@ class University::Person < ApplicationRecord end def websites - Communication::Website.where(id: [ - author_website_ids, - researcher_website_ids, - teacher_website_ids - ].flatten.uniq) + university.communication_websites end - def identifiers(website: nil) - list = [] - [: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 + def git_path(website) + "content/persons/#{slug}.html" if for_website?(website) end - def is_author_for_website(website) - is_author && communication_website_posts.published.where(communication_website_id: website&.id).any? + def git_dependencies(website) + dependencies = [] + dependencies << self if for_website?(website) + dependencies << administrator if administrator.for_website?(website) + dependencies << author if author.for_website?(website) + dependencies << researcher if researcher.for_website?(website) + dependencies << teacher if teacher.for_website?(website) + dependencies end - def is_researcher_for_website(website) - is_researcher + def administrator + @administrator ||= University::Person::Administrator.find(id) end - def is_teacher_for_website(website) - is_teacher && website.programs.published.joins(:teachers).where(education_program_teachers: { person_id: id }).any? + def author + @author ||= University::Person::Author.find(id) end - def is_administrator_for_website(website) - # TODO - is_administrative + def researcher + @researcher ||= University::Person::Researcher.find(id) end - def git_path_static - "content/persons/#{slug}.html" + def teacher + @teacher ||= University::Person::Teacher.find(id) end - def git_path_author - "content/authors/#{slug}/_index.html" - end - - def git_path_researcher - "content/researchers/#{slug}/_index.html" - end - - def git_path_teacher - "content/teachers/#{slug}/_index.html" - end - - def git_path_administrator - "content/administrators/#{slug}/_index.html" - end - - def git_dependencies_static - [] - end - - def git_dependencies_author - [] - end - - def git_dependencies_researcher - [] - end - - def git_dependencies_teacher - [] - end - - def git_dependencies_administrator - [] + def for_website?(website) + administrator.for_website?(website) || + author.for_website?(website) || + researcher.for_website?(website) || + teacher.for_website?(website) end protected diff --git a/app/models/university/person/administrator.rb b/app/models/university/person/administrator.rb new file mode 100644 index 0000000000000000000000000000000000000000..7af44209c09508865bae81a39dc35ff01d3670d3 --- /dev/null +++ b/app/models/university/person/administrator.rb @@ -0,0 +1,14 @@ +class University::Person::Administrator < University::Person + def self.polymorphic_name + 'University::Person::Administrator' + end + + def git_path(website) + "content/administrators/#{slug}/_index.html" if for_website?(website) + end + + def for_website?(website) + # TODO + is_administrative + end +end diff --git a/app/models/university/person/author.rb b/app/models/university/person/author.rb new file mode 100644 index 0000000000000000000000000000000000000000..347b502c12d4fd14f78bfd2a3af4dbdd70559f01 --- /dev/null +++ b/app/models/university/person/author.rb @@ -0,0 +1,15 @@ +class University::Person::Author < University::Person + def self.polymorphic_name + 'University::Person::Author' + end + + def git_path(website) + "content/authors/#{slug}/_index.html" if for_website?(website) + end + + def for_website?(website) + is_author && communication_website_posts.published + .where(communication_website_id: website&.id) + .any? + end +end diff --git a/app/models/university/person/researcher.rb b/app/models/university/person/researcher.rb new file mode 100644 index 0000000000000000000000000000000000000000..2d9a23df6ef774ddb1d59a86a07ee1734ac670a4 --- /dev/null +++ b/app/models/university/person/researcher.rb @@ -0,0 +1,14 @@ +class University::Person::Researcher < University::Person + def self.polymorphic_name + 'University::Person::Researcher' + end + + def git_path(website) + "content/researchers/#{slug}/_index.html" if for_website?(website) + end + + def for_website?(website) + # TODO + is_researcher + end +end diff --git a/app/models/university/person/teacher.rb b/app/models/university/person/teacher.rb index a104bbdb5722f5768fbfb8f75c11a0efba66282c..879ebd3303b8e544fd543b176c0a430037f93e06 100644 --- a/app/models/university/person/teacher.rb +++ b/app/models/university/person/teacher.rb @@ -1,4 +1,17 @@ -class University::Person::Author - include WithGit +class University::Person::Teacher < University::Person + def self.polymorphic_name + 'University::Person::Teacher' + end + def git_path(website) + "content/teachers/#{slug}/_index.html" if for_website?(website) + end + + def for_website?(website) + is_teacher && website.programs + .published + .joins(:teachers) + .where(education_program_teachers: { person_id: id }) + .any? + end end diff --git a/app/views/admin/university/people/administrator.html.erb b/app/views/admin/university/people/administrator.html.erb deleted file mode 100644 index 7338333cf928e914c6a08fa1c81172978590c4a5..0000000000000000000000000000000000000000 --- a/app/views/admin/university/people/administrator.html.erb +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: > - Responsabilités de <%= @person.to_s %> -person: > - <%= @person.to_s %> -slug: "<%= @person.slug %>" ---- diff --git a/app/views/admin/university/people/author.html.erb b/app/views/admin/university/people/author.html.erb deleted file mode 100644 index e9875a83372183cc27da66d44692a356ad501252..0000000000000000000000000000000000000000 --- a/app/views/admin/university/people/author.html.erb +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: > - Actualités de <%= @person.to_s %> -person: > - <%= @person.to_s %> -slug: "<%= @person.slug %>" ---- diff --git a/app/views/admin/university/people/researcher.html.erb b/app/views/admin/university/people/researcher.html.erb deleted file mode 100644 index aac484f676d5d91517e0d317cfcd5b87c5beca96..0000000000000000000000000000000000000000 --- a/app/views/admin/university/people/researcher.html.erb +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: > - Publications de <%= @person.to_s %> -person: > - <%= @person.to_s %> -slug: "<%= @person.slug %>" ---- diff --git a/app/views/admin/university/people/static.html.erb b/app/views/admin/university/people/static.html.erb index c6e4a98351f7edf255c7b498f423a1fcc26358fa..53dc13c4d1faa0110a248c149d139b87791ee0da 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_for_website(@website) %> +<% if @person.author.for_website?(@website) %> - author <% end %> -<% if @person.is_teacher_for_website(@website) %> +<% if @person.teacher.for_website?(@website) %> - teacher <% end %> -<% if @person.is_researcher_for_website(@website) %> +<% if @person.researcher.for_website?(@website) %> - researcher <% end %> -<% if @person.is_administrator_for_website(@website) %> +<% if @person.administrator.for_website?(@website) %> - administrator <% end %> --- diff --git a/app/views/admin/university/people/teacher.html.erb b/app/views/admin/university/people/teacher.html.erb deleted file mode 100644 index c7ab2cf33d622c055b7bb4b096922f592e153ea8..0000000000000000000000000000000000000000 --- a/app/views/admin/university/people/teacher.html.erb +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: > - Enseignements de <%= @person.to_s %> -person: > - <%= @person.to_s %> -slug: "<%= @person.slug %>" ---- diff --git a/app/views/admin/university/person/administrators/static.html.erb b/app/views/admin/university/person/administrators/static.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..0424fd9996b4f088369a72d1eed11dc5f47e9fde --- /dev/null +++ b/app/views/admin/university/person/administrators/static.html.erb @@ -0,0 +1,7 @@ +--- +title: > + Responsabilités de <%= @administrator.to_s %> +person: > + <%= @administrator.to_s %> +slug: "<%= @administrator.slug %>" +--- diff --git a/app/views/admin/university/person/authors/static.html.erb b/app/views/admin/university/person/authors/static.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..caef355c905532c463041ff091a9251a8672f467 --- /dev/null +++ b/app/views/admin/university/person/authors/static.html.erb @@ -0,0 +1,7 @@ +--- +title: > + Actualités de <%= @author.to_s %> +person: > + <%= @author.to_s %> +slug: "<%= @author.slug %>" +--- diff --git a/app/views/admin/university/person/researchers/static.html.erb b/app/views/admin/university/person/researchers/static.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..7286358c1e21d95dc59fd84943446a7bb74459ef --- /dev/null +++ b/app/views/admin/university/person/researchers/static.html.erb @@ -0,0 +1,7 @@ +--- +title: > + Publications de <%= @researcher.to_s %> +person: > + <%= @researcher.to_s %> +slug: "<%= @researcher.slug %>" +--- diff --git a/app/views/admin/university/person/teachers/static.html.erb b/app/views/admin/university/person/teachers/static.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..be19ccd3ebc44ac1bb3ced94ef71271e38acb48d --- /dev/null +++ b/app/views/admin/university/person/teachers/static.html.erb @@ -0,0 +1,7 @@ +--- +title: > + Enseignements de <%= @teacher.to_s %> +person: > + <%= @teacher.to_s %> +slug: "<%= @teacher.slug %>" +---