diff --git a/app/models/communication/block.rb b/app/models/communication/block.rb index dfc4e60f645305c627bc38a67c2edf2617d9818b..eefa859355215106632fcb614c7c71c49ff2452a 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/extranet.rb b/app/models/communication/extranet.rb index 0dc31636314ab864924471003317609996665e7c..1a4615b3d6c6865f180dd318b43f9c1268235907 100644 --- a/app/models/communication/extranet.rb +++ b/app/models/communication/extranet.rb @@ -2,34 +2,35 @@ # # Table name: communication_extranets # -# id :uuid not null, primary key -# about_type :string indexed => [about_id] -# color :string -# cookies_policy :text -# css :text -# feature_alumni :boolean default(FALSE) -# feature_contacts :boolean default(FALSE) -# feature_jobs :boolean default(FALSE) -# feature_library :boolean default(FALSE) -# feature_posts :boolean default(FALSE) -# has_sso :boolean default(FALSE) -# home_sentence :text -# host :string -# name :string -# privacy_policy :text -# registration_contact :string -# sass :text -# sso_button_label :string -# sso_cert :text -# sso_mapping :jsonb -# sso_name_identifier_format :string -# sso_provider :integer default("saml") -# sso_target_url :string -# terms :text -# created_at :datetime not null -# updated_at :datetime not null -# about_id :uuid indexed => [about_type] -# university_id :uuid not null, indexed +# id :uuid not null, primary key +# about_type :string indexed => [about_id] +# allow_experiences_modification :boolean default(TRUE) +# color :string +# cookies_policy :text +# css :text +# feature_alumni :boolean default(FALSE) +# feature_contacts :boolean default(FALSE) +# feature_jobs :boolean default(FALSE) +# feature_library :boolean default(FALSE) +# feature_posts :boolean default(FALSE) +# has_sso :boolean default(FALSE) +# home_sentence :text +# host :string +# name :string +# privacy_policy :text +# registration_contact :string +# sass :text +# sso_button_label :string +# sso_cert :text +# sso_mapping :jsonb +# sso_name_identifier_format :string +# sso_provider :integer default("saml") +# sso_target_url :string +# terms :text +# created_at :datetime not null +# updated_at :datetime not null +# about_id :uuid indexed => [about_type] +# university_id :uuid not null, indexed # # Indexes # diff --git a/db/schema.rb b/db/schema.rb index 90fb648f002649d4e932e84f13512ca13f023a81..320e151e6fb186a723a9866d48b3d63c7a50ff5c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -78,22 +78,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_05_142031) 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_05_142031) 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 @@ -221,6 +203,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_05_142031) 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 @@ -462,7 +445,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_05_142031) do t.index ["university_id"], name: "index_communication_website_pages_on_university_id" end - create_table "communication_website_permalinks", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_permalinks", id: :uuid, default: -> { "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 @@ -1095,9 +1078,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_05_142031) 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/communication/blocks.yml b/test/fixtures/communication/blocks.yml index 0a0c4a5f730950692e674446a6d394b837c298d5..a60600f67229ea5c6b01309153463389d40205eb 100644 --- a/test/fixtures/communication/blocks.yml +++ b/test/fixtures/communication/blocks.yml @@ -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) # olivia_in_noesya: diff --git a/test/fixtures/communication/extranets.yml b/test/fixtures/communication/extranets.yml index c4a72564511a4905256b44eff1b90d9ad95d76db..5b00f559b78ac19b9a3871e2736923e92e325c4b 100644 --- a/test/fixtures/communication/extranets.yml +++ b/test/fixtures/communication/extranets.yml @@ -2,34 +2,35 @@ # # Table name: communication_extranets # -# id :uuid not null, primary key -# about_type :string indexed => [about_id] -# color :string -# cookies_policy :text -# css :text -# feature_alumni :boolean default(FALSE) -# feature_contacts :boolean default(FALSE) -# feature_jobs :boolean default(FALSE) -# feature_library :boolean default(FALSE) -# feature_posts :boolean default(FALSE) -# has_sso :boolean default(FALSE) -# home_sentence :text -# host :string -# name :string -# privacy_policy :text -# registration_contact :string -# sass :text -# sso_button_label :string -# sso_cert :text -# sso_mapping :jsonb -# sso_name_identifier_format :string -# sso_provider :integer default("saml") -# sso_target_url :string -# terms :text -# created_at :datetime not null -# updated_at :datetime not null -# about_id :uuid indexed => [about_type] -# university_id :uuid not null, indexed +# id :uuid not null, primary key +# about_type :string indexed => [about_id] +# allow_experiences_modification :boolean default(TRUE) +# color :string +# cookies_policy :text +# css :text +# feature_alumni :boolean default(FALSE) +# feature_contacts :boolean default(FALSE) +# feature_jobs :boolean default(FALSE) +# feature_library :boolean default(FALSE) +# feature_posts :boolean default(FALSE) +# has_sso :boolean default(FALSE) +# home_sentence :text +# host :string +# name :string +# privacy_policy :text +# registration_contact :string +# sass :text +# sso_button_label :string +# sso_cert :text +# sso_mapping :jsonb +# sso_name_identifier_format :string +# sso_provider :integer default("saml") +# sso_target_url :string +# terms :text +# created_at :datetime not null +# updated_at :datetime not null +# about_id :uuid indexed => [about_type] +# university_id :uuid not null, indexed # # Indexes # diff --git a/test/models/communication/website/connections_test.rb b/test/models/communication/website/connections_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..b48007b2940576b9a8ea094dbc5ca747f74cf88a --- /dev/null +++ b/test/models/communication/website/connections_test.rb @@ -0,0 +1,56 @@ +require "test_helper" + +# rails test test/models/communication/website/connections_test.rb +class Communication::Website::ConnectionsTest < ActiveSupport::TestCase + test "connect objects to page" do + + # Au début, rien + page = communication_website_pages(:page_with_no_dependency) + assert_no_difference("Communication::Website::Connection.count") do + page.save + end + + # On ajoute un block "Chapitre" : +1 + assert_difference -> { Communication::Website::Connection.count } => 1 do + page.blocks.create(position: 1, published: true, template_kind: :chapter) + end + + # On connecte PA via un block "Personnes" : +2 + assert_difference -> { Communication::Website::Connection.count } => 2 do + block = page.blocks.create(position: 2, published: true, template_kind: :organization_chart) + block.data = "{ \"elements\": [ { \"id\": \"#{pa.id}\" } ] }" + block.save + end + + # On ajoute noesya via un block "Organisations" : +4 parce que noesya a un block "Personnes" avec Olivia + assert_difference -> { Communication::Website::Connection.count } => 4 do + block = page.blocks.create(position: 3, published: true, template_kind: :partners) + block.data = "{ \"elements\": [ { \"id\": \"#{noesya.id}\" } ] }" + block.save + end + + # On ajoute Arnaud à noesya via un block "Personnes" : +2 + assert_difference -> { Communication::Website::Connection.count } => 2 do + block = noesya.blocks.create(position: 2, published: true, template_kind: :organization_chart) + block.data = "{ \"elements\": [ { \"id\": \"#{arnaud.id}\" } ] }" + block.save + end + + # On tente la boucle infine en ajoutant noesya à Olivia : +1 (le block ajouté à Olivia) + assert_difference -> { Communication::Website::Connection.count } => 1 do + block = olivia.blocks.create(position: 1, published: true, template_kind: :partners) + block.data = "{ \"elements\": [ { \"id\": \"#{noesya.id}\" } ] }" + block.save + end + + # On dépublie un bloc : +0 + assert_no_difference("Communication::Website::Connection.count") do + page.blocks.second.update(published: false) + end + + # On supprime le bloc qui contient PA : -2 + assert_difference -> { Communication::Website::Connection.count } => -2 do + page.blocks.find_by(position: 2).destroy + end + end +end