diff --git a/app/models/communication/block.rb b/app/models/communication/block.rb index d9a1936eb18f707afb9ab13fa11ad59bbb3aebff..a29994da51dd85c73de3bd5fff9c273820e288a5 100644 --- a/app/models/communication/block.rb +++ b/app/models/communication/block.rb @@ -23,9 +23,9 @@ # fk_rails_18291ef65f (university_id => universities.id) # class Communication::Block < ApplicationRecord + include WithUniversity include WithPosition - belongs_to :university belongs_to :about, polymorphic: true enum template: { diff --git a/app/models/communication/extranet.rb b/app/models/communication/extranet.rb index 3ab3df33121f64dedf46635849f7c8c5d05501d9..4d22aba55404c4e436f3ce97998dadb1c8fda678 100644 --- a/app/models/communication/extranet.rb +++ b/app/models/communication/extranet.rb @@ -18,7 +18,7 @@ # fk_rails_c2268c7ebd (university_id => universities.id) # class Communication::Extranet < ApplicationRecord - belongs_to :university + include WithUniversity validates_presence_of :name, :domain diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 34d1eb1cfc8e8919fe33bde6bf232ffb6adbce3c..f235303488e854edb39273990f23fab9251a1208 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -25,6 +25,7 @@ # fk_rails_bb6a496c08 (university_id => universities.id) # class Communication::Website < ApplicationRecord + include WithUniversity include WithAbouts include WithConfigs include WithGit @@ -33,8 +34,6 @@ class Communication::Website < ApplicationRecord include WithIndexPages include WithMenuItems - belongs_to :university - scope :ordered, -> { order(:name) } enum git_provider: { diff --git a/app/models/communication/website/imported/author.rb b/app/models/communication/website/imported/author.rb index ad3f3b708130c9446783c3c1126eaa4f996ee060..98469ecdf16660e072eb7885f1c3ca3ab0473fb5 100644 --- a/app/models/communication/website/imported/author.rb +++ b/app/models/communication/website/imported/author.rb @@ -27,8 +27,8 @@ # fk_rails_e37b63f880 (author_id => university_people.id) # class Communication::Website::Imported::Author < ApplicationRecord + include WithUniversity - belongs_to :university belongs_to :website, class_name: 'Communication::Website::Imported::Website' belongs_to :author, diff --git a/app/models/communication/website/imported/category.rb b/app/models/communication/website/imported/category.rb index 4eb668cf6dd673223e0c2d20f4b9a18cc6b39438..b3f5841f8857526ae587fb6891185c3b2e12840a 100644 --- a/app/models/communication/website/imported/category.rb +++ b/app/models/communication/website/imported/category.rb @@ -29,8 +29,8 @@ # fk_rails_f6070ca53d (university_id => universities.id) # class Communication::Website::Imported::Category < ApplicationRecord + include WithUniversity - belongs_to :university belongs_to :website, class_name: 'Communication::Website::Imported::Website' belongs_to :category, diff --git a/app/models/communication/website/imported/medium.rb b/app/models/communication/website/imported/medium.rb index f4388e679674cb935e401ef1753daacc0f8dd6e3..0f3ab3b074d0a0644af758e0dd88e05bea0ca5ea 100644 --- a/app/models/communication/website/imported/medium.rb +++ b/app/models/communication/website/imported/medium.rb @@ -25,7 +25,8 @@ # fk_rails_c54ac5a28b (website_id => communication_website_imported_websites.id) # class Communication::Website::Imported::Medium < ApplicationRecord - belongs_to :university + include WithUniversity + belongs_to :website, class_name: 'Communication::Website::Imported::Website' has_many :pages, diff --git a/app/models/communication/website/imported/page.rb b/app/models/communication/website/imported/page.rb index b98885582337fe802e421153a0167ce6a74655bd..f4dbdce8b81fd6e8eaea69c81cbe758c6badc6f7 100644 --- a/app/models/communication/website/imported/page.rb +++ b/app/models/communication/website/imported/page.rb @@ -36,9 +36,9 @@ # fk_rails_e582fbdc5c (featured_medium_id => communication_website_imported_media.id) # class Communication::Website::Imported::Page < ApplicationRecord + include WithUniversity include Communication::Website::Imported::WithRichText - belongs_to :university belongs_to :website, class_name: 'Communication::Website::Imported::Website' belongs_to :page, diff --git a/app/models/communication/website/imported/post.rb b/app/models/communication/website/imported/post.rb index 44f5f36dea1ddc112322fb9d104930f302f4912d..8e2bcaec9fdd9d675bc39f557c55f873ce59a9c2 100644 --- a/app/models/communication/website/imported/post.rb +++ b/app/models/communication/website/imported/post.rb @@ -37,9 +37,9 @@ # fk_rails_f9a08c7c77 (post_id => communication_website_posts.id) # class Communication::Website::Imported::Post < ApplicationRecord + include WithUniversity include Communication::Website::Imported::WithRichText - belongs_to :university belongs_to :website, class_name: 'Communication::Website::Imported::Website' belongs_to :post, diff --git a/app/models/communication/website/imported/website.rb b/app/models/communication/website/imported/website.rb index 024462b80a51beb86ffcdbe3667bf8a6ed20681f..0e6426109becb482228823a05df9be03e10fe64b 100644 --- a/app/models/communication/website/imported/website.rb +++ b/app/models/communication/website/imported/website.rb @@ -20,7 +20,8 @@ # fk_rails_3dbdb9cb2d (website_id => communication_websites.id) # class Communication::Website::Imported::Website < ApplicationRecord - belongs_to :university + include WithUniversity + belongs_to :website, class_name: 'Communication::Website' has_many :authors, diff --git a/app/models/communication/website/index_page.rb b/app/models/communication/website/index_page.rb index aa62f6213fdf980d31f1a80779a281ede7eb922c..fc8f8e428e219ad60969a3790a9f40202609d565 100644 --- a/app/models/communication/website/index_page.rb +++ b/app/models/communication/website/index_page.rb @@ -27,6 +27,7 @@ # fk_rails_7eb45227ae (university_id => universities.id) # class Communication::Website::IndexPage < ApplicationRecord + include WithUniversity include Sanitizable include WithGit include WithFeaturedImage @@ -45,7 +46,6 @@ class Communication::Website::IndexPage < ApplicationRecord teachers: 140 } - belongs_to :university belongs_to :website, foreign_key: :communication_website_id has_summernote :header_text diff --git a/app/models/communication/website/menu.rb b/app/models/communication/website/menu.rb index 2e21098b71da60df7718b6c4cafc3b213cdf2f5c..24f8df696b480e62085385e77032640ac7d278a0 100644 --- a/app/models/communication/website/menu.rb +++ b/app/models/communication/website/menu.rb @@ -22,10 +22,10 @@ # fk_rails_dcc7198fc5 (communication_website_id => communication_websites.id) # class Communication::Website::Menu < ApplicationRecord + include WithUniversity include Sanitizable include WithGit - belongs_to :university belongs_to :website, foreign_key: :communication_website_id has_many :items, class_name: 'Communication::Website::Menu::Item', dependent: :destroy diff --git a/app/models/communication/website/menu/item.rb b/app/models/communication/website/menu/item.rb index f4980a4655b27ce1fb73ebbb489a05fe4c9f5f4b..4f84f3ebddf63b8241b907e2b7ff9f5028ae8bd2 100644 --- a/app/models/communication/website/menu/item.rb +++ b/app/models/communication/website/menu/item.rb @@ -32,6 +32,7 @@ # fk_rails_fa4f4585e4 (website_id => communication_websites.id) # class Communication::Website::Menu::Item < ApplicationRecord + include WithUniversity include Sanitizable include WithTree include WithPosition @@ -39,7 +40,6 @@ class Communication::Website::Menu::Item < ApplicationRecord attr_accessor :skip_publication_callback - belongs_to :university belongs_to :website, class_name: 'Communication::Website' belongs_to :menu, class_name: 'Communication::Website::Menu' belongs_to :parent, class_name: 'Communication::Website::Menu::Item', optional: true diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 74521470c08d82a39f76f5e567b885ee5e874faa..207d51207c01cac6a0e43a9bf038fa6bf0f1148b 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -40,6 +40,7 @@ class Communication::Website::Page < ApplicationRecord include Sanitizable + include WithUniversity include WithGit include WithFeaturedImage include WithBlobs @@ -51,7 +52,6 @@ class Communication::Website::Page < ApplicationRecord has_summernote :text - belongs_to :university belongs_to :website, foreign_key: :communication_website_id belongs_to :related_category, diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 9acbeb444e941802e6b258fc8c41eefe72b50aad..0a2250b06d975d66a7e28c2707aa6cb048ed4e48 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -33,6 +33,7 @@ # class Communication::Website::Post < ApplicationRecord include Sanitizable + include WithUniversity include WithGit include WithFeaturedImage include WithBlobs @@ -44,7 +45,6 @@ class Communication::Website::Post < ApplicationRecord has_one :imported_post, class_name: 'Communication::Website::Imported::Post', dependent: :destroy - belongs_to :university belongs_to :website, class_name: 'Communication::Website', foreign_key: :communication_website_id diff --git a/app/models/concerns/with_university.rb b/app/models/concerns/with_university.rb new file mode 100644 index 0000000000000000000000000000000000000000..d0433b792e1c729e9ff536588c720bd4b22f3a16 --- /dev/null +++ b/app/models/concerns/with_university.rb @@ -0,0 +1,8 @@ +module WithUniversity + extend ActiveSupport::Concern + + included do + belongs_to :university + validates_presence_of :university + end +end diff --git a/app/models/education/program.rb b/app/models/education/program.rb index 449c1d170691d18078b711e2faee6cab714d1ef4..360d5ba5f7ddf67fe2e8f92e2b5115037db5dd4e 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -44,6 +44,7 @@ # class Education::Program < ApplicationRecord include Sanitizable + include WithUniversity include WithGit include WithFeaturedImage include WithBlobs @@ -70,7 +71,6 @@ class Education::Program < ApplicationRecord attr_accessor :skip_websites_categories_callback - belongs_to :university belongs_to :parent, class_name: 'Education::Program', optional: true diff --git a/app/models/research/journal.rb b/app/models/research/journal.rb index e34fdbcd3bd3d7f67cabcfe6bf70e5351114ef6b..62c75abdd15fd6a9a73965ec6492230ecd32334d 100644 --- a/app/models/research/journal.rb +++ b/app/models/research/journal.rb @@ -21,9 +21,9 @@ # fk_rails_96097d5f10 (university_id => universities.id) # class Research::Journal < ApplicationRecord + include WithUniversity include WithGit - belongs_to :university has_many :websites, class_name: 'Communication::Website', as: :about, dependent: :nullify has_many :volumes, foreign_key: :research_journal_id, dependent: :destroy has_many :articles, foreign_key: :research_journal_id, dependent: :destroy diff --git a/app/models/research/journal/article.rb b/app/models/research/journal/article.rb index 984835af06ded8aaeaed80882e56cd4fc6e5480b..4b2dbf5d18c4bf160fe7a74237b76eb3069073cb 100644 --- a/app/models/research/journal/article.rb +++ b/app/models/research/journal/article.rb @@ -35,6 +35,7 @@ # class Research::Journal::Article < ApplicationRecord include Sanitizable + include WithUniversity include WithGit include WithBlobs include WithPosition @@ -43,7 +44,6 @@ class Research::Journal::Article < ApplicationRecord has_summernote :text has_one_attached :pdf - belongs_to :university belongs_to :journal, foreign_key: :research_journal_id belongs_to :volume, foreign_key: :research_journal_volume_id, optional: true belongs_to :updated_by, class_name: 'User' diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb index 844cb9b931a943f5a738b3665660df5e387032a5..669024489df736771e47d66d5f29ced058304df4 100644 --- a/app/models/research/journal/volume.rb +++ b/app/models/research/journal/volume.rb @@ -28,12 +28,12 @@ # class Research::Journal::Volume < ApplicationRecord include Sanitizable + include WithUniversity include WithGit include WithBlobs include WithFeaturedImage include WithSlug - belongs_to :university belongs_to :journal, foreign_key: :research_journal_id has_many :articles, foreign_key: :research_journal_volume_id, dependent: :nullify has_many :websites, -> { distinct }, through: :journal diff --git a/app/models/research/laboratory/axis.rb b/app/models/research/laboratory/axis.rb index 40cae3951f593bcdbdf768e46945d393921becca..9601058ec7bb7bb9ae7a29b6a7df0e2e1d06f020 100644 --- a/app/models/research/laboratory/axis.rb +++ b/app/models/research/laboratory/axis.rb @@ -25,11 +25,11 @@ # class Research::Laboratory::Axis < ApplicationRecord include Sanitizable + include WithUniversity include WithPosition has_summernote :text - belongs_to :university belongs_to :laboratory, foreign_key: :research_laboratory_id def to_s diff --git a/app/models/research/thesis.rb b/app/models/research/thesis.rb index 48f1f4aed7fef891888d8c82c865841d681da385..e8fea9e2f80a318eb56e2da9b45d2fe429d622cd 100644 --- a/app/models/research/thesis.rb +++ b/app/models/research/thesis.rb @@ -31,8 +31,8 @@ # class Research::Thesis < ApplicationRecord include Sanitizable + include WithUniversity - belongs_to :university belongs_to :laboratory, foreign_key: :research_laboratory_id belongs_to :author, class_name: 'University::Person' belongs_to :director, class_name: 'University::Person' diff --git a/app/models/university/organization.rb b/app/models/university/organization.rb index 1df61f1f0f7d6124dd4a99e8820c0ca1ce5de6da..bf78d971719adc68cb90c56cdf778c9978ad5a45 100644 --- a/app/models/university/organization.rb +++ b/app/models/university/organization.rb @@ -31,11 +31,10 @@ class University::Organization < ApplicationRecord include WithGit include WithBlobs + include WithUniversity has_one_attached_deletable :logo - belongs_to :university - scope :ordered, -> { order(:name) } validates_presence_of :name diff --git a/app/models/university/organization/import.rb b/app/models/university/organization/import.rb index 421ad605b1483d4d6a3b6b5604fec5d37c8ab66f..34e9ba5534d71a8ddab1f6bb768ce51dce97abd9 100644 --- a/app/models/university/organization/import.rb +++ b/app/models/university/organization/import.rb @@ -19,7 +19,8 @@ # fk_rails_da057ff44d (user_id => users.id) # class University::Organization::Import < ApplicationRecord - belongs_to :university + include WithUniversity + belongs_to :user has_one_attached :file @@ -40,7 +41,7 @@ class University::Organization::Import < ApplicationRecord def parse csv.each do |row| - university.organizations.where(name: row['name']).first_or_create do |o| + university.organizations.where(university: university, name: row['name']).first_or_create do |o| [ :long_name, :kind, diff --git a/app/models/university/person.rb b/app/models/university/person.rb index dd1d4ca904a15750f75738f4c3fcd751d06de721..c98f4d96f03c82f3520e8866c0a90c016f48b3fd 100644 --- a/app/models/university/person.rb +++ b/app/models/university/person.rb @@ -32,6 +32,7 @@ # class University::Person < ApplicationRecord include Sanitizable + include WithUniversity include WithGit include WithBlobs include WithSlug @@ -40,7 +41,6 @@ class University::Person < ApplicationRecord has_summernote :biography - belongs_to :university belongs_to :user, optional: true has_and_belongs_to_many :research_journal_articles, diff --git a/app/models/university/person/involvement.rb b/app/models/university/person/involvement.rb index 648bcb59479a1474e4097afdcf05546e34d6a3d4..988be24c96c7fa28a9a6eb6c18f87487d5db8a04 100644 --- a/app/models/university/person/involvement.rb +++ b/app/models/university/person/involvement.rb @@ -25,11 +25,11 @@ # fk_rails_5c704f6338 (university_id => universities.id) # class University::Person::Involvement < ApplicationRecord + include WithUniversity include WithPosition enum kind: { administrator: 10, researcher: 20, teacher: 30 } - belongs_to :university belongs_to :person, class_name: 'University::Person' belongs_to :target, polymorphic: true diff --git a/app/models/university/role.rb b/app/models/university/role.rb index 7868717ae1dbeaa6a96bf3ae125febc69ec7f4ce..3e740ac5248e93ec6b98b178f8b8bf190d65c355 100644 --- a/app/models/university/role.rb +++ b/app/models/university/role.rb @@ -21,9 +21,9 @@ # fk_rails_8e52293a38 (university_id => universities.id) # class University::Role < ApplicationRecord + include WithUniversity include WithPosition - belongs_to :university belongs_to :target, polymorphic: true, optional: true has_many :involvements, class_name: 'University::Person::Involvement', as: :target, dependent: :destroy, inverse_of: :target has_many :people, through: :involvements diff --git a/app/models/user.rb b/app/models/user.rb index 0905f39afd7550372b7e3aa4a4242d179c7f00b0..7b81885d3f973407cb183d57143322436d968872 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -54,12 +54,12 @@ # class User < ApplicationRecord has_one_attached_deletable :picture # In this order, "resize avatar" callback will be fired after the others. + include WithUniversity include WithAuthentication include WithPerson include WithRoles include WithSyncBetweenUniversities - belongs_to :university belongs_to :language scope :ordered, -> { order(:last_name, :first_name) }