Skip to content

Commit

Permalink
Merge pull request #1223 from noesya/researchers-in-laboratories
Browse files Browse the repository at this point in the history
Connexion des chercheurs et chercheuses aux laboratoires de recherche
  • Loading branch information
arnaudlevy committed Aug 30, 2023
2 parents 21da6c6 + a4121e1 commit f81609f
Show file tree
Hide file tree
Showing 32 changed files with 221 additions and 86 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/university/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def person_params
:biography, :picture, :picture_delete, :picture_infos,
:habilitation, :tenure, :url, :linkedin, :twitter, :mastodon,
:is_researcher, :is_teacher, :is_administration, :is_alumnus, :user_id,
category_ids: []
research_laboratory_ids: [], category_ids: []
).merge(university_id: current_university.id)
end
end
6 changes: 3 additions & 3 deletions app/models/communication/website/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ class Communication::Website::Category < ApplicationRecord
dependent: :destroy
has_and_belongs_to_many :posts,
class_name: 'Communication::Website::Post',
join_table: 'communication_website_categories_posts',
foreign_key: 'communication_website_category_id',
association_foreign_key: 'communication_website_post_id'
join_table: :communication_website_categories_posts,
foreign_key: :communication_website_category_id,
association_foreign_key: :communication_website_post_id

validates :name, presence: true

Expand Down
6 changes: 3 additions & 3 deletions app/models/communication/website/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class Communication::Website::Post < ApplicationRecord
optional: true
has_and_belongs_to_many :categories,
class_name: 'Communication::Website::Category',
join_table: 'communication_website_categories_posts',
foreign_key: 'communication_website_post_id',
association_foreign_key: 'communication_website_category_id'
join_table: :communication_website_categories_posts,
foreign_key: :communication_website_post_id,
association_foreign_key: :communication_website_category_id

validates :title, presence: true

Expand Down
6 changes: 3 additions & 3 deletions app/models/communication/website/with_languages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ module Communication::Website::WithLanguages
belongs_to :default_language, class_name: "Language"
has_and_belongs_to_many :languages,
class_name: 'Language',
join_table: 'communication_websites_languages',
foreign_key: 'communication_website_id',
association_foreign_key: 'language_id',
join_table: :communication_websites_languages,
foreign_key: :communication_website_id,
association_foreign_key: :language_id,
after_remove: :flag_languages_change

validates :languages, length: { minimum: 1 }
Expand Down
9 changes: 7 additions & 2 deletions app/models/concerns/with_translations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ module WithTranslations
attr_accessor :newly_translated

belongs_to :language
belongs_to :original, class_name: base_class.to_s, optional: true
has_many :translations, class_name: base_class.to_s, foreign_key: :original_id, dependent: :nullify
belongs_to :original,
class_name: base_class.to_s,
optional: true
has_many :translations,
class_name: base_class.to_s,
foreign_key: :original_id,
dependent: :nullify

scope :for_language, -> (language) { for_language_id(language.id) }
# The for_language_id scope can be used when you have the ID without needing to load the Language itself
Expand Down
4 changes: 2 additions & 2 deletions app/models/education/academic_year.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class Education::AcademicYear < ApplicationRecord
# Dénormalisation des alumni pour le faceted search
has_and_belongs_to_many :university_people,
class_name: 'University::Person',
foreign_key: 'education_academic_year_id',
association_foreign_key: 'university_person_id'
foreign_key: :education_academic_year_id,
association_foreign_key: :university_person_id
has_many :people,
class_name: 'University::Person',
through: :education_cohorts
Expand Down
4 changes: 2 additions & 2 deletions app/models/education/cohort.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class Education::Cohort < ApplicationRecord

has_and_belongs_to_many :people,
class_name: 'University::Person',
foreign_key: 'education_cohort_id',
association_foreign_key: 'university_person_id'
foreign_key: :education_cohort_id,
association_foreign_key: :university_person_id

validates_associated :school, :academic_year, :program
validates :year, presence: true
Expand Down
4 changes: 2 additions & 2 deletions app/models/education/program/with_alumni.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ module Education::Program::WithAlumni
# Dénormalisation des alumni pour le faceted search
has_and_belongs_to_many :university_people,
class_name: 'University::Person',
foreign_key: 'education_program_id',
association_foreign_key: 'university_person_id'
foreign_key: :education_program_id,
association_foreign_key: :university_person_id

# NOTE: Find a fix for wrong table name on WHERE clause
# SELECT "education_academic_years".*
Expand Down
6 changes: 3 additions & 3 deletions app/models/education/program/with_schools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module Education::Program::WithSchools
included do
has_and_belongs_to_many :schools,
class_name: 'Education::School',
join_table: 'education_programs_schools',
foreign_key: 'education_program_id',
association_foreign_key: 'education_school_id'
join_table: :education_programs_schools,
foreign_key: :education_program_id,
association_foreign_key: :education_school_id
end
end
12 changes: 6 additions & 6 deletions app/models/education/school/with_programs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ module Education::School::WithPrograms
included do
has_and_belongs_to_many :programs,
class_name: 'Education::Program',
join_table: 'education_programs_schools',
foreign_key: 'education_school_id',
association_foreign_key: 'education_program_id'
join_table: :education_programs_schools,
foreign_key: :education_school_id,
association_foreign_key: :education_program_id

# Why not programs.published ?
has_and_belongs_to_many :published_programs,
-> { published },
class_name: 'Education::Program',
join_table: 'education_programs_schools',
foreign_key: 'education_school_id',
association_foreign_key: 'education_program_id'
join_table: :education_programs_schools,
foreign_key: :education_school_id,
association_foreign_key: :education_program_id

has_many :diplomas, -> { distinct },
through: :programs,
Expand Down
4 changes: 2 additions & 2 deletions app/models/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class Language < ApplicationRecord
has_many :users
has_and_belongs_to_many :communication_websites,
class_name: 'Communication::Website',
join_table: 'communication_websites_languages',
association_foreign_key: 'communication_website_id'
join_table: :communication_websites_languages,
association_foreign_key: :communication_website_id

validates_presence_of :iso_code
validates_uniqueness_of :iso_code
Expand Down
6 changes: 3 additions & 3 deletions app/models/research/hal/author.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class Research::Hal::Author < ApplicationRecord

has_and_belongs_to_many :publications,
foreign_key: 'research_hal_publication_id',
association_foreign_key: 'research_hal_author_id'
association_foreign_key: :research_hal_author_id
has_and_belongs_to_many :university_person_researchers,
class_name: 'University::Person',
foreign_key: 'university_person_id',
association_foreign_key: 'research_hal_author_id'
foreign_key: :university_person_id,
association_foreign_key: :research_hal_author_id
alias :researchers :university_person_researchers

scope :ordered, -> { order(:last_name, :first_name, :docid)}
Expand Down
8 changes: 4 additions & 4 deletions app/models/research/hal/publication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ class Research::Hal::Publication < ApplicationRecord

has_and_belongs_to_many :researchers,
class_name: 'University::Person',
foreign_key: 'university_person_id',
association_foreign_key: 'research_hal_publication_id'
foreign_key: :university_person_id,
association_foreign_key: :research_hal_publication_id

has_and_belongs_to_many :authors,
foreign_key: 'research_hal_author_id',
association_foreign_key: 'research_hal_publication_id'
foreign_key: :research_hal_author_id,
association_foreign_key: :research_hal_publication_id

validates_presence_of :docid

Expand Down
37 changes: 29 additions & 8 deletions app/models/research/journal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,35 @@ class Research::Journal < ApplicationRecord
include WithGitFiles
include WithUniversity

has_many :communication_websites, class_name: 'Communication::Website', as: :about, dependent: :nullify
has_many :volumes, foreign_key: :research_journal_id, dependent: :destroy
has_many :published_volumes, -> { published }, class_name: 'Research::Journal::Volume', foreign_key: :research_journal_id, dependent: :destroy
has_many :papers, foreign_key: :research_journal_id, dependent: :destroy
has_many :published_papers, -> { published }, class_name: 'Research::Journal::Paper', foreign_key: :research_journal_id, dependent: :destroy
has_many :people, -> { distinct }, through: :papers
has_many :people_through_published_papers, -> { distinct }, through: :published_papers, source: :people
has_many :kinds, class_name: 'Research::Journal::Paper::Kind'
has_many :communication_websites,
class_name: 'Communication::Website',
as: :about,
dependent: :nullify
has_many :volumes,
foreign_key: :research_journal_id,
dependent: :destroy
has_many :published_volumes,
-> { published },
class_name: 'Research::Journal::Volume',
foreign_key: :research_journal_id,
dependent: :destroy
has_many :papers,
foreign_key: :research_journal_id,
dependent: :destroy
has_many :published_papers,
-> { published },
class_name: 'Research::Journal::Paper',
foreign_key: :research_journal_id,
dependent: :destroy
has_many :people,
-> { distinct },
through: :papers
has_many :people_through_published_papers,
-> { distinct },
through: :published_papers,
source: :people
has_many :kinds,
class_name: 'Research::Journal::Paper::Kind'

scope :ordered, -> { order(:title) }
scope :for_search_term, -> (term) {
Expand Down
14 changes: 10 additions & 4 deletions app/models/research/journal/paper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,16 @@ class Research::Journal::Paper < ApplicationRecord
has_summernote :text
has_one_attached :pdf

belongs_to :journal, foreign_key: :research_journal_id
belongs_to :volume, foreign_key: :research_journal_volume_id, optional: true
belongs_to :kind, class_name: 'Research::Journal::Paper::Kind', optional: true
belongs_to :updated_by, class_name: 'User'
belongs_to :journal,
foreign_key: :research_journal_id
belongs_to :volume,
foreign_key: :research_journal_volume_id,
optional: true
belongs_to :kind,
class_name: 'Research::Journal::Paper::Kind',
optional: true
belongs_to :updated_by,
class_name: 'User'
has_and_belongs_to_many :people,
class_name: 'University::Person',
join_table: :research_journal_papers_researchers,
Expand Down
11 changes: 8 additions & 3 deletions app/models/research/journal/volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ class Research::Journal::Volume < ApplicationRecord

has_summernote :text

belongs_to :journal, foreign_key: :research_journal_id
has_many :papers, foreign_key: :research_journal_volume_id, dependent: :nullify
has_many :people, -> { distinct }, through: :papers
belongs_to :journal,
foreign_key: :research_journal_id
has_many :papers,
foreign_key: :research_journal_volume_id,
dependent: :nullify
has_many :people,
-> { distinct },
through: :papers

scope :ordered, -> { order(number: :desc, published_at: :desc) }

Expand Down
13 changes: 11 additions & 2 deletions app/models/research/laboratory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class Research::Laboratory < ApplicationRecord
foreign_key: :research_laboratory_id,
dependent: :destroy

has_and_belongs_to_many :researchers,
class_name: 'University::Person::Researcher',
foreign_key: :university_person_id,
association_foreign_key: :research_laboratory_id

validates :name, :address, :city, :zipcode, :country, presence: true

scope :ordered, -> { order(:name) }
Expand All @@ -62,13 +67,17 @@ def git_path(website)
"data/laboratory.yml"
end

def dependencies
axes +
researchers.map(&:researcher)
end

def has_administrators?
false
end

def has_researchers?
# TODO: Ajouter les researchers quand ils existeront
false
researchers.any?
end

def has_teachers?
Expand Down
3 changes: 2 additions & 1 deletion app/models/research/laboratory/axis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class Research::Laboratory::Axis < ApplicationRecord

has_summernote :text

belongs_to :laboratory, foreign_key: :research_laboratory_id
belongs_to :laboratory,
foreign_key: :research_laboratory_id

def to_s
"#{name}"
Expand Down
9 changes: 6 additions & 3 deletions app/models/research/thesis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ class Research::Thesis < ApplicationRecord
include Sanitizable
include WithUniversity

belongs_to :laboratory, foreign_key: :research_laboratory_id
belongs_to :author, class_name: 'University::Person'
belongs_to :director, class_name: 'University::Person'
belongs_to :laboratory,
foreign_key: :research_laboratory_id
belongs_to :author,
class_name: 'University::Person'
belongs_to :director,
class_name: 'University::Person'

scope :ordered, -> { order(:title) }
scope :for_search_term, -> (term) {
Expand Down
12 changes: 6 additions & 6 deletions app/models/university/person/with_education.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ module University::Person::WithEducation

has_and_belongs_to_many :cohorts,
class_name: '::Education::Cohort',
foreign_key: 'university_person_id',
association_foreign_key: 'education_cohort_id'
foreign_key: :university_person_id,
association_foreign_key: :education_cohort_id

accepts_nested_attributes_for :cohorts,
reject_if: :all_blank,
Expand All @@ -30,13 +30,13 @@ module University::Person::WithEducation
# Dénormalisation des liens via cohorts, pour la recherche par facettes
has_and_belongs_to_many :diploma_years,
class_name: 'Education::AcademicYear',
foreign_key: 'university_person_id',
association_foreign_key: 'education_academic_year_id'
foreign_key: :university_person_id,
association_foreign_key: :education_academic_year_id

has_and_belongs_to_many :diploma_programs,
class_name: 'Education::Program',
foreign_key: 'university_person_id',
association_foreign_key: 'education_program_id'
foreign_key: :university_person_id,
association_foreign_key: :education_program_id

before_validation :find_cohorts
validates_associated :cohorts
Expand Down
18 changes: 12 additions & 6 deletions app/models/university/person/with_research.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,33 @@ module University::Person::WithResearch
included do
has_and_belongs_to_many :research_hal_authors,
class_name: 'Research::Hal::Author',
foreign_key: 'research_hal_author_id',
association_foreign_key: 'university_person_id'
foreign_key: :research_hal_author_id,
association_foreign_key: :university_person_id
alias :hal_authors :research_hal_authors

has_and_belongs_to_many :research_hal_publications,
class_name: 'Research::Hal::Publication',
foreign_key: 'research_hal_publication_id',
association_foreign_key: 'university_person_id'
foreign_key: :research_hal_publication_id,
association_foreign_key: :university_person_id
alias :hal_publications :research_hal_publications
alias :publications :research_hal_publications

has_many :authored_research_theses,
class_name: 'Research::Thesis',
foreign_key: 'author_id',
foreign_key: :author_id,
dependent: :destroy

has_many :directed_research_theses,
class_name: 'Research::Thesis',
foreign_key: 'director_id',
foreign_key: :director_id,
dependent: :nullify

has_and_belongs_to_many :research_laboratories,
class_name: 'Research::Laboratory',
foreign_key: :research_laboratory_id,
association_foreign_key: :university_person_id
alias :laboratories :research_laboratories

scope :with_hal_identifier, -> { where.not(hal_form_identifier: [nil,'']) }
end

Expand Down
Loading

0 comments on commit f81609f

Please sign in to comment.