From 87205fe408581155ed33807015649c9f13de1203 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Wed, 18 Oct 2023 21:06:34 +0200 Subject: [PATCH] pages --- app/models/communication/website/page.rb | 1 + .../website/page/accessibility.rb | 1 + .../website/page/administrator.rb | 1 + .../communication/website/page/author.rb | 1 + .../website/page/communication_agenda.rb | 1 + .../page/communication_agenda_archive.rb | 1 + .../website/page/communication_post.rb | 1 + .../website/page/education_diploma.rb | 1 + .../website/page/education_program.rb | 1 + app/models/communication/website/page/home.rb | 1 + .../communication/website/page/legal_term.rb | 1 + .../website/page/organization.rb | 1 + .../communication/website/page/person.rb | 1 + .../website/page/privacy_policy.rb | 1 + .../website/page/research_hal_publication.rb | 1 + .../website/page/research_paper.rb | 1 + .../website/page/research_volume.rb | 1 + .../communication/website/page/researcher.rb | 1 + .../communication/website/page/sitemap.rb | 1 + .../communication/website/page/teacher.rb | 1 + .../api/osuny/communication/website/page.rb | 34 +++++++++++++- ...entifier_to_communication_website_pages.rb | 5 ++ db/schema.rb | 46 +++++++++---------- test/fixtures/communication/website/pages.yml | 1 + 24 files changed, 82 insertions(+), 24 deletions(-) create mode 100644 db/migrate/20231018182341_add_migration_identifier_to_communication_website_pages.rb diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index d10eb3941..d7f7baeed 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/accessibility.rb b/app/models/communication/website/page/accessibility.rb index 9905f2880..6c0928dd5 100644 --- a/app/models/communication/website/page/accessibility.rb +++ b/app/models/communication/website/page/accessibility.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/administrator.rb b/app/models/communication/website/page/administrator.rb index ca6144ead..df5454934 100644 --- a/app/models/communication/website/page/administrator.rb +++ b/app/models/communication/website/page/administrator.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/author.rb b/app/models/communication/website/page/author.rb index dd81fa6db..d8fff0dfa 100644 --- a/app/models/communication/website/page/author.rb +++ b/app/models/communication/website/page/author.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/communication_agenda.rb b/app/models/communication/website/page/communication_agenda.rb index 4e17c15e0..48c0fc640 100644 --- a/app/models/communication/website/page/communication_agenda.rb +++ b/app/models/communication/website/page/communication_agenda.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/communication_agenda_archive.rb b/app/models/communication/website/page/communication_agenda_archive.rb index 822731a13..018f0b0e8 100644 --- a/app/models/communication/website/page/communication_agenda_archive.rb +++ b/app/models/communication/website/page/communication_agenda_archive.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/communication_post.rb b/app/models/communication/website/page/communication_post.rb index 7d08bc227..1ab6d6b24 100644 --- a/app/models/communication/website/page/communication_post.rb +++ b/app/models/communication/website/page/communication_post.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/education_diploma.rb b/app/models/communication/website/page/education_diploma.rb index 416c168f7..a3205229d 100644 --- a/app/models/communication/website/page/education_diploma.rb +++ b/app/models/communication/website/page/education_diploma.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/education_program.rb b/app/models/communication/website/page/education_program.rb index 6a1e28270..6712e72d8 100644 --- a/app/models/communication/website/page/education_program.rb +++ b/app/models/communication/website/page/education_program.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/home.rb b/app/models/communication/website/page/home.rb index 8c944b124..c75c3aca6 100644 --- a/app/models/communication/website/page/home.rb +++ b/app/models/communication/website/page/home.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/legal_term.rb b/app/models/communication/website/page/legal_term.rb index 91deae075..8f187975e 100644 --- a/app/models/communication/website/page/legal_term.rb +++ b/app/models/communication/website/page/legal_term.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/organization.rb b/app/models/communication/website/page/organization.rb index f160ede8c..b17a2c96d 100644 --- a/app/models/communication/website/page/organization.rb +++ b/app/models/communication/website/page/organization.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/person.rb b/app/models/communication/website/page/person.rb index 175d5ec7a..4c11cd187 100644 --- a/app/models/communication/website/page/person.rb +++ b/app/models/communication/website/page/person.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/privacy_policy.rb b/app/models/communication/website/page/privacy_policy.rb index f1508624d..a5ae32ade 100644 --- a/app/models/communication/website/page/privacy_policy.rb +++ b/app/models/communication/website/page/privacy_policy.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/research_hal_publication.rb b/app/models/communication/website/page/research_hal_publication.rb index c6d3c4dee..0e4a31a61 100644 --- a/app/models/communication/website/page/research_hal_publication.rb +++ b/app/models/communication/website/page/research_hal_publication.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/research_paper.rb b/app/models/communication/website/page/research_paper.rb index 4312f9faf..d8e103365 100644 --- a/app/models/communication/website/page/research_paper.rb +++ b/app/models/communication/website/page/research_paper.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/research_volume.rb b/app/models/communication/website/page/research_volume.rb index a4f383ee9..e732c2b7d 100644 --- a/app/models/communication/website/page/research_volume.rb +++ b/app/models/communication/website/page/research_volume.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/researcher.rb b/app/models/communication/website/page/researcher.rb index c5ac173da..a82afe69a 100644 --- a/app/models/communication/website/page/researcher.rb +++ b/app/models/communication/website/page/researcher.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/sitemap.rb b/app/models/communication/website/page/sitemap.rb index fe79d1768..cf8ce880f 100644 --- a/app/models/communication/website/page/sitemap.rb +++ b/app/models/communication/website/page/sitemap.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/models/communication/website/page/teacher.rb b/app/models/communication/website/page/teacher.rb index 3b55bacc2..ad29eedad 100644 --- a/app/models/communication/website/page/teacher.rb +++ b/app/models/communication/website/page/teacher.rb @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed diff --git a/app/services/importers/api/osuny/communication/website/page.rb b/app/services/importers/api/osuny/communication/website/page.rb index cf2d66d17..38f6b8286 100644 --- a/app/services/importers/api/osuny/communication/website/page.rb +++ b/app/services/importers/api/osuny/communication/website/page.rb @@ -3,7 +3,39 @@ class Importers::Api::Osuny::Communication::Website::Page < Importers::Api::Osun protected def import - # TODO + object.parent = parent + object.update page_params + object.save + import_blocks end + def home_page + website.special_page(Communication::Website::Page::Home, language: language) + end + + def parent + parent_migration_identifier = params.dig(:parent, :migration_identifier) + @parent = page_with parent_migration_identifier if parent_migration_identifier + @parent = home_page if @parent.nil? + @parent + end + + def object + @object ||= page_with migration_identifier + end + + def page_with(migration_identifier) + website.pages.where( + university: university, + website: website, + migration_identifier: migration_identifier, + language: language + ).first_or_initialize + end + + def page_params + ActionController::Parameters.new({ page: params }) + .require(:page) + .permit(:title, :language, :meta_description, :summary) + end end \ No newline at end of file diff --git a/db/migrate/20231018182341_add_migration_identifier_to_communication_website_pages.rb b/db/migrate/20231018182341_add_migration_identifier_to_communication_website_pages.rb new file mode 100644 index 000000000..ca4c63d9d --- /dev/null +++ b/db/migrate/20231018182341_add_migration_identifier_to_communication_website_pages.rb @@ -0,0 +1,5 @@ +class AddMigrationIdentifierToCommunicationWebsitePages < ActiveRecord::Migration[7.0] + def change + add_column :communication_website_pages, :migration_identifier, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 58b3335aa..ab23e0452 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do +ActiveRecord::Schema[7.0].define(version: 2023_10_18_182341) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -78,7 +78,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.index ["criterion_id"], name: "index_administration_qualiopi_indicators_on_criterion_id" end - create_table "communication_block_headings", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + 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 @@ -106,8 +106,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.datetime "updated_at", null: false t.string "title" t.boolean "published", default: true - t.uuid "communication_website_id" t.uuid "heading_id" + t.uuid "communication_website_id" t.string "migration_identifier" t.index ["about_type", "about_id"], name: "index_communication_website_blocks_on_about" t.index ["communication_website_id"], name: "index_communication_blocks_on_communication_website_id" @@ -115,7 +115,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.index ["university_id"], name: "index_communication_blocks_on_university_id" end - create_table "communication_extranet_connections", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_connections", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "extranet_id", null: false t.string "object_type" @@ -127,7 +127,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.index ["university_id"], name: "index_communication_extranet_connections_on_university_id" end - create_table "communication_extranet_document_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_document_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "extranet_id", null: false t.uuid "university_id", null: false t.string "name" @@ -139,7 +139,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.index ["university_id"], name: "extranet_document_categories_universities" end - create_table "communication_extranet_document_kinds", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_document_kinds", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "extranet_id", null: false t.uuid "university_id", null: false t.string "name" @@ -151,7 +151,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.index ["university_id"], name: "extranet_document_kinds_universities" end - create_table "communication_extranet_documents", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_documents", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.uuid "extranet_id", null: false @@ -167,7 +167,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.index ["university_id"], name: "index_communication_extranet_documents_on_university_id" end - create_table "communication_extranet_post_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_post_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "slug" t.uuid "extranet_id", null: false @@ -179,7 +179,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.index ["university_id"], name: "index_communication_extranet_post_categories_on_university_id" end - create_table "communication_extranet_posts", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_posts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "title" t.boolean "published", default: false t.datetime "published_at" @@ -229,12 +229,11 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.text "home_sentence" t.text "sass" t.text "css" - t.boolean "allow_experiences_modification", default: true t.index ["about_type", "about_id"], name: "index_communication_extranets_on_about" t.index ["university_id"], name: "index_communication_extranets_on_university_id" end - create_table "communication_website_agenda_events", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_agenda_events", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "title" t.text "summary" t.uuid "university_id", null: false @@ -295,7 +294,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.index ["communication_website_post_id", "communication_website_category_id"], name: "post_category" end - create_table "communication_website_connections", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_connections", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false t.string "indirect_object_type", null: false @@ -382,6 +381,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.boolean "full_width", default: false t.string "type" t.uuid "original_id" + t.string "migration_identifier" t.index ["communication_website_id"], name: "index_communication_website_pages_on_communication_website_id" t.index ["language_id"], name: "index_communication_website_pages_on_language_id" t.index ["original_id"], name: "index_communication_website_pages_on_original_id" @@ -390,7 +390,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.index ["university_id"], name: "index_communication_website_pages_on_university_id" end - create_table "communication_website_permalinks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_permalinks", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false t.string "about_type", null: false @@ -630,7 +630,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.index ["university_id"], name: "index_education_schools_on_university_id" end - create_table "emergency_messages", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "emergency_messages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id" t.string "name" t.string "role" @@ -666,7 +666,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.string "summernote_locale" end - create_table "research_hal_authors", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_hal_authors", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "docid" t.string "form_identifier" t.string "person_identifier" @@ -692,7 +692,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.index ["university_person_id", "research_hal_author_id"], name: "hal_person_author" end - create_table "research_hal_publications", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_hal_publications", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "docid" t.jsonb "data" t.string "title" @@ -722,7 +722,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.index ["university_person_id", "research_hal_publication_id"], name: "index_person_publication" end - create_table "research_journal_paper_kinds", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_journal_paper_kinds", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "journal_id", null: false t.string "title" @@ -883,7 +883,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.index ["default_language_id"], name: "index_universities_on_default_language_id" end - create_table "university_apps", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_apps", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.string "token" @@ -894,7 +894,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.index ["university_id"], name: "index_university_apps_on_university_id" end - create_table "university_organization_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_organization_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.datetime "created_at", null: false @@ -938,7 +938,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.index ["university_id"], name: "index_university_organizations_on_university_id" end - create_table "university_organizations_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_organizations_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "organization_id", null: false t.uuid "category_id", null: false t.index ["category_id"], name: "index_university_organizations_categories_on_category_id" @@ -987,14 +987,14 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.index ["user_id"], name: "index_university_people_on_user_id" end - create_table "university_people_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_people_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "person_id", null: false t.uuid "category_id", null: false t.index ["category_id"], name: "index_university_people_categories_on_category_id" t.index ["person_id"], name: "index_university_people_categories_on_person_id" end - create_table "university_person_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_person_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.datetime "created_at", null: false @@ -1043,7 +1043,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_13_090313) do t.index ["university_id"], name: "index_university_roles_on_university_id" end - create_table "user_favorites", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "user_favorites", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "user_id", null: false t.string "about_type", null: false t.uuid "about_id", null: false diff --git a/test/fixtures/communication/website/pages.yml b/test/fixtures/communication/website/pages.yml index 7acaaf1b2..f56dc72fa 100644 --- a/test/fixtures/communication/website/pages.yml +++ b/test/fixtures/communication/website/pages.yml @@ -11,6 +11,7 @@ # header_text :text # kind :integer # meta_description :text +# migration_identifier :string # position :integer default(0), not null # published :boolean default(FALSE) # slug :string indexed -- GitLab