diff --git a/app/models/communication/block.rb b/app/models/communication/block.rb index 4046234af35cb1101b3ca58094f47c8d8e4c0dbc..bc8294d0edb98d08fc5e7ce0c77ff44a1a3365f2 100644 --- a/app/models/communication/block.rb +++ b/app/models/communication/block.rb @@ -12,19 +12,16 @@ # created_at :datetime not null # updated_at :datetime not null # about_id :uuid indexed => [about_type] -# heading_id :uuid indexed # university_id :uuid not null, indexed # # Indexes # -# index_communication_blocks_on_heading_id (heading_id) # index_communication_blocks_on_university_id (university_id) # index_communication_website_blocks_on_about (about_type,about_id) # # Foreign Keys # # fk_rails_18291ef65f (university_id => universities.id) -# fk_rails_90ac986fab (heading_id => communication_block_headings.id) # class Communication::Block < ApplicationRecord include Accessible diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 17b93564d14497972531071efb56cd04187879d1..2af72ac558e2fb3fd4485f6df82c4cdee0dee422 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -91,12 +91,16 @@ class Communication::Website < ApplicationRecord def dependencies pages + - posts + + posts + categories + menus + [about] end + def references + [] + end + def best_language_for(iso_code) # We look for the language by the ISO code in the websites languages. # If not found, we fallback to the default language. diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index c14427eeed27b4bfd1f28723b3b610a1ba001306..612276685f122391352a1a04d20c57c8209b29fe 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -98,9 +98,11 @@ class Communication::Website::Category < ApplicationRecord def dependencies active_storage_blobs + blocks + - children + - posts + - [parent] + children + end + + def references + posts + [parent] end def update_children_paths diff --git a/app/models/communication/website/menu.rb b/app/models/communication/website/menu.rb index 51b9aedab15fe3be27d0e2f45dcc880c629b1bc6..87041f6d6966715259467fd5eca2969b75de5c24 100644 --- a/app/models/communication/website/menu.rb +++ b/app/models/communication/website/menu.rb @@ -57,6 +57,10 @@ class Communication::Website::Menu < ApplicationRecord items end + def references + [] + end + def translate_additional_data!(translation) items.root.ordered.each { |item| translate_menu_item!(item, translation) } end diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 85ad0a6e0b6defb967e02e46a8284b0be5fbe5f2..2c3478afb10608c214df60cb1c15a113e2328288 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -84,7 +84,7 @@ class Communication::Website::Page < ApplicationRecord has_many :translations, class_name: 'Communication::Website::Page', foreign_key: :original_id - + validates :title, presence: true scope :recent, -> { order(updated_at: :desc).limit(5) } @@ -93,7 +93,7 @@ class Communication::Website::Page < ApplicationRecord def template_static "admin/communication/websites/pages/static" end - + def menu_items Communication::Website::Menu::Item.where(website: website, kind: :page, about: self) end @@ -101,10 +101,13 @@ class Communication::Website::Page < ApplicationRecord def dependencies active_storage_blobs + blocks + - menu_items + children end + def references + menu_items + end + def to_s "#{title}" end diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index c833e666d2133b2c83712b28f07d856df36988f7..fe8fabdbd7ad26165e094516530ab24e4a692f22 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -119,7 +119,7 @@ class Communication::Website::Post < ApplicationRecord def template_static "admin/communication/websites/posts/static" end - + def menu_items Communication::Website::Menu::Item.where(website: website, kind: :post, about: self) end @@ -127,10 +127,13 @@ class Communication::Website::Post < ApplicationRecord def dependencies active_storage_blobs + blocks + - menu_items + categories end + def references + menu_items + end + def url return unless published return if website.url.blank? diff --git a/app/models/concerns/with_connections.rb b/app/models/concerns/with_connections.rb index d4dd9030d74159a1a1a85ddae0519f7d2d04c1d3..6a6dbd4f5448e86d903ab412c3de09022f58b4dd 100644 --- a/app/models/concerns/with_connections.rb +++ b/app/models/concerns/with_connections.rb @@ -4,6 +4,7 @@ module WithConnections included do include WithDependencies + include WithGitFiles include WithReferences has_many :connections, as: :indirect_object, class_name: 'Communication::Website::Connection' @@ -15,6 +16,10 @@ module WithConnections after_touch :sync_connections end + def for_website?(website) + Communication::Website::Connection.in_website(website).for_object(self).exists? + end + def direct_sources connections.collect &:direct_source end diff --git a/app/models/concerns/with_git.rb b/app/models/concerns/with_git.rb index 426e3692503c968c16d5f88573885a6ecf60f95f..01e36762e9552a6d91be36b69d3abebb797ffe84 100644 --- a/app/models/concerns/with_git.rb +++ b/app/models/concerns/with_git.rb @@ -1,28 +1,11 @@ module WithGit extend ActiveSupport::Concern - + included do - # WithGit a besoin de WithDependencies et WithReferences + # WithGit a besoin de ces 3 concerns include WithDependencies + include WithGitFiles include WithReferences - - has_many :git_files, - class_name: "Communication::Website::GitFile", - as: :about, - dependent: :destroy - end - - def git_path(website) - raise NotImplementedError - end - - def git_path_content_prefix(website) - # Handle language-less objects - # TODO I18n: Right now, we use the language of the object, fallbacking on the language of the website. In the end, we'll only use the language of the object - path = "content/" - path_language = respond_to?(:language_id) && language_id.present? ? language : website.default_language - path += "#{path_language.iso_code}/" - path end def save_and_sync @@ -75,7 +58,15 @@ module WithGit website.git_repository.sync! end end - + + def for_website?(website) + if is_a? Communication::Website + website.id == id + else + website.id == website_id + end + end + protected def websites_for_self diff --git a/app/models/concerns/with_git_files.rb b/app/models/concerns/with_git_files.rb new file mode 100644 index 0000000000000000000000000000000000000000..1e5ad126821214d5604af4b56e97e195bb688706 --- /dev/null +++ b/app/models/concerns/with_git_files.rb @@ -0,0 +1,23 @@ +module WithGitFiles + extend ActiveSupport::Concern + + included do + has_many :git_files, + class_name: "Communication::Website::GitFile", + as: :about, + dependent: :destroy + end + + def git_path(website) + raise NotImplementedError + end + + def git_path_content_prefix(website) + # Handle language-less objects + # TODO I18n: Right now, we use the language of the object, fallbacking on the language of the website. In the end, we'll only use the language of the object + path = "content/" + path_language = respond_to?(:language_id) && language_id.present? ? language : website.default_language + path += "#{path_language.iso_code}/" + path + end +end diff --git a/app/models/education/diploma.rb b/app/models/education/diploma.rb index f73e09b992d1810d12a45ffc85fd9873fd10682a..81151c816e4647d58b347893bd966c7b69e75cda 100644 --- a/app/models/education/diploma.rb +++ b/app/models/education/diploma.rb @@ -51,6 +51,10 @@ class Education::Diploma < ApplicationRecord "#{git_path_content_prefix(website)}diplomas/#{slug}/_index.html" if for_website?(website) end + def references + [] + end + def to_s "#{name}" end diff --git a/app/models/education/program.rb b/app/models/education/program.rb index 557571d15bdfaebe7c5d25224a1266a3daa8ec7a..3f50ce62bd43319fdac79f90608ecd0fd249a340 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -149,6 +149,10 @@ class Education::Program < ApplicationRecord [diploma] end + def references + [] + end + def references siblings + descendants diff --git a/app/models/education/school.rb b/app/models/education/school.rb index 93d7561d1f28ab100948a356c47e0a88aabcd155..114d925efc9c547f72ea85cb351347bd0aafefc6 100644 --- a/app/models/education/school.rb +++ b/app/models/education/school.rb @@ -10,7 +10,6 @@ # longitude :float # name :string # phone :string -# url :string # zipcode :string # created_at :datetime not null # updated_at :datetime not null @@ -77,6 +76,10 @@ class Education::School < ApplicationRecord administrators.map(&:administrator) end + def references + [] + end + ##################### # Aboutable methods # ##################### diff --git a/app/models/research/journal.rb b/app/models/research/journal.rb index c997d59baf2ae5f1365179e92f66ffdae12e2b60..dcc0352abfba665884d9fe9ec841f5f876c3d085 100644 --- a/app/models/research/journal.rb +++ b/app/models/research/journal.rb @@ -62,6 +62,10 @@ class Research::Journal < ApplicationRecord researchers.map(&:researcher) end + def references + [] + end + ##################### # Aboutable methods # ##################### diff --git a/app/models/research/journal/paper/kind.rb b/app/models/research/journal/paper/kind.rb index a30acaf334e23554b78fa91e53c52348caa9ad7c..ff7783d35b1687156fb8dc949aec192decfe7bdc 100644 --- a/app/models/research/journal/paper/kind.rb +++ b/app/models/research/journal/paper/kind.rb @@ -31,6 +31,10 @@ class Research::Journal::Paper::Kind < ApplicationRecord scope :ordered, -> { order(:title) } + def references + [] + end + def to_s "#{title}" end diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb index bdba30633ed42663df44d7e4acfdfab237048af9..532965c2a6ccd1fa45d2bfe5ae13a179e536dd82 100644 --- a/app/models/research/journal/volume.rb +++ b/app/models/research/journal/volume.rb @@ -62,6 +62,10 @@ class Research::Journal::Volume < ApplicationRecord active_storage_blobs end + def references + [] + end + def path "/#{published_at&.year}-#{slug}" if published_at end diff --git a/app/models/university/organization.rb b/app/models/university/organization.rb index 4f99e796a1af10a1c72ffdd640d50a3795a255b2..46341be2a136eb045696c2a3fd00453b3e646d4f 100644 --- a/app/models/university/organization.rb +++ b/app/models/university/organization.rb @@ -110,6 +110,10 @@ class University::Organization < ApplicationRecord blocks end + def references + [] + end + def git_path(website) "#{git_path_content_prefix(website)}organizations/#{slug}.html" if for_website?(website) end diff --git a/app/models/university/person.rb b/app/models/university/person.rb index d70ae5e340e4d85bc8322acd2bba61d61cbb526a..cce0b109b5887f088efde4b566a189df9a1a1a2a 100644 --- a/app/models/university/person.rb +++ b/app/models/university/person.rb @@ -204,6 +204,10 @@ class University::Person < ApplicationRecord # person.author.active_storage_blobs => [] end + def references + [] + end + def administrator @administrator ||= University::Person::Administrator.find(id) end diff --git a/db/schema.rb b/db/schema.rb index cb37a3739032839f58036531e833cf07195d3fbd..520d7840648bedb7cbda6627fa2967c1a09ab057 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -78,22 +78,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_03_101306) do t.index ["criterion_id"], name: "index_administration_qualiopi_indicators_on_criterion_id" end - create_table "communication_block_headings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.uuid "university_id", null: false - t.string "about_type", null: false - t.uuid "about_id", null: false - t.string "title" - t.integer "level", default: 2 - t.uuid "parent_id" - t.integer "position" - t.string "slug" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["about_type", "about_id"], name: "index_communication_block_headings_on_about" - t.index ["parent_id"], name: "index_communication_block_headings_on_parent_id" - t.index ["university_id"], name: "index_communication_block_headings_on_university_id" - end - create_table "communication_blocks", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "about_type" @@ -105,9 +89,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_03_101306) do t.datetime "updated_at", null: false t.string "title" t.boolean "published", default: true - t.uuid "heading_id" t.index ["about_type", "about_id"], name: "index_communication_website_blocks_on_about" - t.index ["heading_id"], name: "index_communication_blocks_on_heading_id" t.index ["university_id"], name: "index_communication_blocks_on_university_id" end @@ -676,7 +658,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_03_101306) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "phone" - t.string "url" t.index ["university_id"], name: "index_education_schools_on_university_id" end @@ -1094,9 +1075,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_03_101306) do add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "administration_qualiopi_indicators", "administration_qualiopi_criterions", column: "criterion_id" - add_foreign_key "communication_block_headings", "communication_block_headings", column: "parent_id" - add_foreign_key "communication_block_headings", "universities" - add_foreign_key "communication_blocks", "communication_block_headings", column: "heading_id" add_foreign_key "communication_blocks", "universities" add_foreign_key "communication_extranet_connections", "communication_extranets", column: "extranet_id" add_foreign_key "communication_extranet_connections", "universities" diff --git a/test/fixtures/education/schools.yml b/test/fixtures/education/schools.yml index fce634f27a350704a40420834e959f0cf72af1e5..50828e0153ed9b13d774b46b01801aae3485141d 100644 --- a/test/fixtures/education/schools.yml +++ b/test/fixtures/education/schools.yml @@ -10,7 +10,6 @@ # longitude :float # name :string # phone :string -# url :string # zipcode :string # created_at :datetime not null # updated_at :datetime not null