From fc89c0ed8236be11139eb03c9f537001cfff22ca Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Thu, 9 Jun 2022 19:45:59 +0200 Subject: [PATCH] Wip #431 --- app/models/education/program/with_websites.rb | 23 ++++++++++++++----- db/schema.rb | 19 ++++++++++++++- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/models/education/program/with_websites.rb b/app/models/education/program/with_websites.rb index a9b81dbe9..6fe2a4640 100644 --- a/app/models/education/program/with_websites.rb +++ b/app/models/education/program/with_websites.rb @@ -4,18 +4,29 @@ module Education::Program::WithWebsites included do attr_accessor :skip_websites_categories_callback - after_save_commit :set_websites_categories, unless: :skip_websites_categories_callback - - # FIXME incorrect, forgets websites about programs - has_many :websites, -> { distinct }, - through: :schools + after_save_commit :set_websites_categories, + unless: :skip_websites_categories_callback has_many :website_categories, class_name: 'Communication::Website::Category', dependent: :destroy end + def websites + @websites ||= university.websites.reject do |website| + website_concerned = false + # Site de formation + website_concerned = true if website.about == self + # Site d'école + if website.about&.is_a? Education::School + # Formation dispensée dans l'école + website_concerned = true if self.in? website.about.programs + end + !website_concerned + end + end + def set_websites_categories - websites.find_each(&:set_programs_categories!) + websites.each { |website| website.set_programs_categories! } end end diff --git a/db/schema.rb b/db/schema.rb index cfc5d60d1..4b426c3cc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -504,6 +504,23 @@ ActiveRecord::Schema.define(version: 2022_06_09_085535) do t.index ["university_id"], name: "index_education_schools_on_university_id" end + create_table "external_organizations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "title" + t.text "description" + t.string "address" + t.string "zipcode" + t.string "city" + t.string "country" + t.string "website" + t.string "phone" + t.string "mail" + t.boolean "active" + t.string "sirene" + t.integer "kind" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "imports", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.integer "number_of_lines" t.jsonb "processing_errors" @@ -698,8 +715,8 @@ ActiveRecord::Schema.define(version: 2022_06_09_085535) do t.string "linkedin" t.boolean "is_alumnus", default: false t.text "description_short" - t.boolean "is_author" t.string "name" + t.boolean "is_author" t.integer "gender" t.date "birthdate" t.string "phone_professional" -- GitLab