Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gestion unifiée des auteurs et autrices #2352

Merged
merged 31 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a276760
Use is_author again
arnaudlevy Oct 21, 2024
6685b73
Symmetry
arnaudlevy Oct 21, 2024
9c9d5f6
Merge branch 'main' into filter-authors
arnaudlevy Oct 21, 2024
ca1cbda
Merge branch 'main' into filter-authors
arnaudlevy Oct 21, 2024
e128930
Merge branch 'main' into filter-authors
arnaudlevy Oct 22, 2024
019880a
Merge branch 'main' into filter-authors
arnaudlevy Oct 28, 2024
a09ac21
Merge branch 'main' into filter-authors
arnaudlevy Oct 29, 2024
31e3747
meilleure migration
arnaudlevy Oct 29, 2024
bda8013
Merge branch 'filter-authors' of github.com:osunyorg/admin into filte…
arnaudlevy Oct 29, 2024
f814350
Clean
arnaudlevy Oct 29, 2024
f63576a
climate
arnaudlevy Oct 29, 2024
5504c8c
Merge branch 'main' into filter-authors
arnaudlevy Oct 29, 2024
da3681c
Merge branch 'main' into filter-authors
arnaudlevy Oct 29, 2024
2b521f8
Merge branch 'main' into filter-authors
arnaudlevy Oct 30, 2024
cee7bc1
Merge branch 'main' into filter-authors
arnaudlevy Oct 31, 2024
6344345
fix
SebouChu Oct 31, 2024
3537ba3
Merge branch 'main' into filter-authors
arnaudlevy Oct 31, 2024
d504ea1
Merge branch 'main' into filter-authors
arnaudlevy Oct 31, 2024
9743736
Update app/views/admin/communication/authors/index.html.erb
SebouChu Oct 31, 2024
e077d6c
Update app/views/admin/communication/authors/show.html.erb
arnaudlevy Oct 31, 2024
3ea1569
Update app/views/admin/communication/authors/show.html.erb
arnaudlevy Oct 31, 2024
f13aa8f
update_author_status_if_necessary
SebouChu Oct 31, 2024
009e43b
Merge branch 'filter-authors' of github.com:noesya/osuny into filter-…
SebouChu Oct 31, 2024
473b77d
author
arnaudlevy Oct 31, 2024
a3ff3b9
find_cohorts
SebouChu Oct 31, 2024
2ead744
Merge branch 'filter-authors' of github.com:noesya/osuny into filter-…
SebouChu Oct 31, 2024
7c0fcec
fix
SebouChu Oct 31, 2024
cf86189
fix
arnaudlevy Oct 31, 2024
1a54ae7
Merge branch 'filter-authors' of github.com:osunyorg/admin into filte…
arnaudlevy Oct 31, 2024
e24c3d4
fix
SebouChu Oct 31, 2024
189e0f9
Merge branch 'filter-authors' of github.com:noesya/osuny into filter-…
SebouChu Oct 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -770,4 +770,4 @@ RUBY VERSION
ruby 3.3.5p100

BUNDLED WITH
2.5.9
2.5.16
2 changes: 1 addition & 1 deletion app/assets/stylesheets/admin/design-system/layout.sass
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ body
#{--bs-gutter-x}: 4rem

main
min-height: 70vh
min-height: 50vh
padding-bottom: pxToRem(100)
position: relative
29 changes: 29 additions & 0 deletions app/controllers/admin/communication/authors_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Admin::Communication::AuthorsController < Admin::Communication::ApplicationController
load_and_authorize_resource class: "University::Person",
through: :current_university,
through_association: :people

include Admin::Localizable

def index
@authors = current_university.people
.authors
.filter_by(params[:filters], current_language)
.ordered(current_language)
.page(params[:page])
breadcrumb
end

def show
breadcrumb
add_breadcrumb @l10n
end

protected

def breadcrumb
super
add_breadcrumb University::Person::Localization::Author.model_name.human(count: 2), admin_communication_authors_path
end

end
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 @@ -99,7 +99,7 @@ def person_params
:picture, :picture_delete, :picture_infos,
:habilitation, :tenure,
:linkedin_visibility, :twitter_visibility, :mastodon_visibility,
:is_researcher, :is_teacher, :is_administration, :is_alumnus, :user_id,
:is_researcher, :is_teacher, :is_administration, :is_alumnus, :is_author, :user_id,
research_laboratory_ids: [], category_ids: [],
localizations_attributes: [
:id, :slug, :first_name, :last_name,
Expand Down
1 change: 1 addition & 0 deletions app/models/communication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def self.table_name_prefix

def self.parts
[
[University::Person::Localization::Author, :admin_communication_authors_path],
[Communication::Website, :admin_communication_websites_path],
[Communication::Extranet, :admin_communication_extranets_path],
]
Expand Down
79 changes: 7 additions & 72 deletions app/models/university/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,19 @@ class University::Person < ApplicationRecord
include Filterable
include Sanitizable
include Localizable
include WithAlumnus
include WithBlobs
include WithCountry
# WithRoles included before WithEducation because needed for the latter
include WithRoles
include WithEducation
include WithExperiences
include WithFacets
include WithInvolvements
include WithPersonalData
include WithPicture
include WithResearch
include WithRealmAdministration
include WithRealmCommunication
include WithRealmEducation
include WithRealmResearch
include WithUniversity

LIST_OF_ROLES = [
:administration,
:teacher,
:researcher,
:alumnus,
:author
].freeze

enum :gender, { male: 0, female: 1, non_binary: 2 }

belongs_to :user, optional: true
Expand All @@ -75,37 +69,6 @@ class University::Person < ApplicationRecord
class_name: 'University::Person::Category',
join_table: :university_people_categories

has_and_belongs_to_many :research_journal_papers,
class_name: 'Research::Journal::Paper',
join_table: :research_journal_papers_researchers,
foreign_key: :researcher_id

has_many :communication_website_posts,
class_name: 'Communication::Website::Post',
foreign_key: :author_id,
dependent: :nullify

has_many :involvements,
class_name: 'University::Person::Involvement',
dependent: :destroy

has_many :author_websites,
-> { distinct },
through: :communication_website_posts,
source: :website

has_many :researcher_websites,
-> { distinct },
through: :research_journal_papers,
source: :websites

has_many :teacher_websites,
-> { distinct },
through: :education_programs,
source: :websites

accepts_nested_attributes_for :involvements

validates :email,
uniqueness: { scope: :university_id },
allow_blank: true,
Expand Down Expand Up @@ -146,12 +109,6 @@ class University::Person < ApplicationRecord
.order("localization_last_name ASC, localization_first_name ASC")
}

scope :administration, -> { where(is_administration: true) }
scope :teachers, -> { where(is_teacher: true) }
scope :researchers, -> { where(is_researcher: true) }
scope :alumni, -> { where(is_alumnus: true) }
scope :with_habilitation, -> { where(habilitation: true) }
scope :for_role, -> (role, language = nil) { where("is_#{role}": true) }
scope :for_category, -> (category_id, language = nil) { joins(:categories).where(university_person_categories: { id: category_id }).distinct }
scope :for_program, -> (program_id, language = nil) {
left_joins(:education_programs_as_administrator, :education_programs_as_teacher)
Expand Down Expand Up @@ -188,34 +145,12 @@ class University::Person < ApplicationRecord
", term: "%#{sanitize_sql_like(term)}%")
}

def roles
LIST_OF_ROLES.reject do |role|
!public_send("is_#{role}")
end
end

def dependencies
localizations +
categories +
active_storage_blobs
end

def administrator_facets
@administrator_facets ||= University::Person::Localization::Administrator.where(id: localization_ids)
end

def author_facets
@author_facets ||= University::Person::Localization::Author.where(id: localization_ids)
end

def researcher_facets
@researcher_facets ||= University::Person::Localization::Researcher.where(id: localization_ids)
end

def teacher_facets
@teacher_facets ||= University::Person::Localization::Teacher.where(id: localization_ids)
end

def full_street_address
return nil if [address, zipcode, city].all?(&:blank?)
[address, "#{zipcode} #{city} #{country}".strip].join(', ')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
module University::Person::WithEducation
module University::Person::WithAlumnus
extend ActiveSupport::Concern

included do
has_many :involvements_as_teacher,
-> { where(kind: 'teacher') },
class_name: 'University::Person::Involvement',
dependent: :destroy

has_many :education_programs_as_teacher,
through: :involvements_as_teacher,
source: :target,
source_type: "Education::Program"

has_many :education_programs_as_administrator,
-> { distinct },
through: :roles_as_administrator,
source: :target,
source_type: "Education::Program"

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

accepts_nested_attributes_for :cohorts,
reject_if: :all_blank,
allow_destroy: true
before_validation :find_cohorts
validates_associated :cohorts

# Dénormalisation des liens via cohorts, pour la recherche par facettes
has_and_belongs_to_many :diploma_years,
Expand All @@ -38,8 +23,22 @@ module University::Person::WithEducation
foreign_key: :university_person_id,
association_foreign_key: :education_program_id

before_validation :find_cohorts
validates_associated :cohorts
has_many :experiences,
class_name: "University::Person::Experience",
dependent: :destroy

accepts_nested_attributes_for :experiences,
reject_if: :all_blank,
allow_destroy: true

validates_associated :experiences

scope :for_alumni_organization, -> (organization_ids, language = nil) {
left_joins(:experiences)
.where(university_person_experiences: { organization_id: organization_ids })
.select("university_people.*")
.distinct
}

scope :for_alumni_program, -> (program_ids, language = nil) {
left_joins(:cohorts)
Expand All @@ -55,12 +54,6 @@ module University::Person::WithEducation
}
end

def add_to_cohort(cohort)
cohorts << cohort unless cohort.in?(cohorts)
diploma_years << cohort.academic_year unless cohort.academic_year.in? diploma_years
diploma_programs << cohort.program unless cohort.program.in? diploma_programs
end

def find_cohorts
# based on https://stackoverflow.com/questions/3579924/accepts-nested-attributes-for-with-find-or-create
cohorts = []
Expand All @@ -77,5 +70,4 @@ def find_cohorts
end
self.cohorts = cohorts
end

end
end
25 changes: 0 additions & 25 deletions app/models/university/person/with_experiences.rb

This file was deleted.

43 changes: 43 additions & 0 deletions app/models/university/person/with_facets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module University::Person::WithFacets
extend ActiveSupport::Concern

included do
LIST_OF_FACETS = [
:administration,
:teacher,
:researcher,
:alumnus,
:author
].freeze

scope :administration, -> { where(is_administration: true) }
scope :authors, -> { where(is_author: true) }
scope :teachers, -> { where(is_teacher: true) }
scope :researchers, -> { where(is_researcher: true) }
scope :alumni, -> { where(is_alumnus: true) }
scope :with_habilitation, -> { where(habilitation: true) }
scope :for_facet, -> (facet, language = nil) { where("is_#{facet}": true) }
end

def facets
LIST_OF_FACETS.reject do |facet|
!public_send("is_#{facet}")
end
end

def administrator_facets
@administrator_facets ||= University::Person::Localization::Administrator.where(id: localization_ids)
end

def author_facets
@author_facets ||= University::Person::Localization::Author.where(id: localization_ids)
end

def researcher_facets
@researcher_facets ||= University::Person::Localization::Researcher.where(id: localization_ids)
end

def teacher_facets
@teacher_facets ||= University::Person::Localization::Teacher.where(id: localization_ids)
end
end
11 changes: 11 additions & 0 deletions app/models/university/person/with_involvements.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module University::Person::WithInvolvements
extend ActiveSupport::Concern

included do
has_many :involvements,
class_name: 'University::Person::Involvement',
dependent: :destroy

accepts_nested_attributes_for :involvements
end
end
21 changes: 21 additions & 0 deletions app/models/university/person/with_realm_administration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module University::Person::WithRealmAdministration
extend ActiveSupport::Concern

included do
has_many :involvements_as_administrator,
-> { where(kind: 'administrator') },
class_name: 'University::Person::Involvement',
dependent: :destroy

has_many :roles_as_administrator,
through: :involvements_as_administrator,
source: :target,
source_type: 'University::Role'

has_many :education_programs_as_administrator,
-> { distinct },
through: :roles_as_administrator,
source: :target,
source_type: 'Education::Program'
end
end
29 changes: 29 additions & 0 deletions app/models/university/person/with_realm_communication.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module University::Person::WithRealmCommunication
extend ActiveSupport::Concern

included do
has_many :communication_website_posts,
class_name: 'Communication::Website::Post',
foreign_key: :author_id,
dependent: :nullify

has_many :author_websites,
-> { distinct },
through: :communication_website_posts,
source: :website

has_many :communication_extranet_posts,
class_name: 'Communication::Extranet::Post',
foreign_key: :author_id,
dependent: :nullify

has_many :author_extranets,
-> { distinct },
through: :communication_extranet_posts,
source: :extranet
end

def posts
communication_website_posts + communication_extranet_posts
end
end
Loading
Loading