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 all 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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def preview

def new
if current_user.person.present?
current_user.person&.update_column(:is_author, true)
@post.author = current_user.person
end
breadcrumb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ def preview
end

def new
if current_user.person.present?
current_user.person.update_column(:is_author, true)
@post.author = current_user.person
end
@categories = categories
@post.author_id = current_user.person&.id
breadcrumb
end

Expand Down
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
12 changes: 10 additions & 2 deletions app/models/communication/extranet/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ class Communication::Extranet::Post < ApplicationRecord
belongs_to :category, class_name: 'Communication::Extranet::Post::Category', optional: true
belongs_to :extranet, class_name: 'Communication::Extranet'

scope :published, -> (language) {
after_save_commit :update_author_status_if_necessary!, if: :saved_change_to_author_id?

scope :published, -> (language) {
joins(:localizations)
.where(communication_extranet_post_localizations: { language_id: language.id, published: true })
.where('communication_extranet_post_localizations.published_at <= ?', Time.zone.now)
}

scope :ordered, -> (language) {
localization_published_at_select = <<-SQL
COALESCE(
Expand Down Expand Up @@ -66,4 +68,10 @@ class Communication::Extranet::Post < ApplicationRecord
.group("communication_extranet_posts.id")
.order("localization_pinned DESC, localization_published_at DESC, created_at DESC")
}

protected

def update_author_status_if_necessary!
author.update(is_author: true) if author && !author.is_author?
end
end
10 changes: 3 additions & 7 deletions app/models/communication/website/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Communication::Website::Post < ApplicationRecord
foreign_key: :communication_website_post_id,
association_foreign_key: :communication_website_category_id

after_save_commit :update_authors_statuses!, if: :saved_change_to_author_id?
after_save_commit :update_author_status_if_necessary!, if: :saved_change_to_author_id?

scope :ordered, -> (language) {
localization_published_at_select = <<-SQL
Expand Down Expand Up @@ -108,12 +108,8 @@ def published_at_in(language)

protected

def update_authors_statuses!
old_author = University::Person.find_by(id: author_id_before_last_save)
if old_author && old_author.communication_website_posts.none?
old_author.update(is_author: false)
end
author.update(is_author: true) if author_id
def update_author_status_if_necessary!
author.update(is_author: true) if author && !author.is_author?
end

def abouts_with_post_block
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,27 +54,27 @@ 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 = []
cohorts_ids = []
self.cohorts.map do |object|
academic_year = Education::AcademicYear.where(university_id: university_id, year: object.year).first_or_create
cohort = Education::Cohort.where(university_id: university_id, school_id: object.school_id, program_id: object.program_id, academic_year_id: academic_year.id).first_or_initialize
return unless cohort.valid?
cohort.save if cohort.new_record?
unless cohorts_ids.include?(cohort.reload.id) || object._destroy
cohorts_ids << cohort.id unless cohort.id.nil?
cohorts << cohort
end
cohorts_to_set = []
cohorts_ids_to_set = []
undestroyed_cohorts = self.cohorts.reject(&:_destroy)
undestroyed_cohorts.each do |object|
cohort = find_cohort_for_nested(object)
next if cohorts_ids_to_set.include?(cohort.id)
cohorts_ids_to_set << cohort.id unless cohort.id.nil?
cohorts_to_set << cohort
end
self.cohorts = cohorts
self.cohorts = cohorts_to_set
end

end
private

def find_cohort_for_nested(object)
academic_year = Education::AcademicYear.where(university_id: university_id, year: object.year).first_or_create
cohort = Education::Cohort.where(university_id: university_id, school_id: object.school_id, program_id: object.program_id, academic_year_id: academic_year.id).first_or_initialize
return unless cohort.valid?
cohort.save if cohort.new_record?
cohort.reload
end
end
25 changes: 0 additions & 25 deletions app/models/university/person/with_experiences.rb

This file was deleted.

Loading
Loading