From a276760e4f9996d40ddaab912064ce11a495628f Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Mon, 21 Oct 2024 06:53:37 +0200 Subject: [PATCH 01/15] Use is_author again --- Gemfile.lock | 33 ++++++++++--------- .../admin/university/people_controller.rb | 2 +- app/models/university/person.rb | 1 + app/services/migrations/authors.rb | 9 +++++ .../websites/posts/_form.html.erb | 2 +- .../admin/university/people/_form.html.erb | 1 + lib/tasks/app.rake | 1 + 7 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 app/services/migrations/authors.rb diff --git a/Gemfile.lock b/Gemfile.lock index b644c8a67..39417c7c9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,7 +8,7 @@ GIT GIT remote: https://github.com/noesya/summernote-rails.git - revision: f7ce423738fa98a1a2bacc509d6906e03b498a0e + revision: 32fd182c929cdcacaa6e3bd3569871bd025fa669 specs: summernote-rails (0.8.20.1) nokogiri @@ -78,11 +78,11 @@ GEM erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - active_storage_validations (1.2.0) - activejob (>= 5.2.0) - activemodel (>= 5.2.0) - activestorage (>= 5.2.0) - activesupport (>= 5.2.0) + active_storage_validations (1.3.0) + activejob (>= 6.1.4) + activemodel (>= 6.1.4) + activestorage (>= 6.1.4) + activesupport (>= 6.1.4) activejob (7.2.1.1) activesupport (= 7.2.1.1) globalid (>= 0.3.6) @@ -123,17 +123,17 @@ GEM autoprefixer-rails (10.4.19.0) execjs (~> 2) aws-eventstream (1.3.0) - aws-partitions (1.991.0) - aws-sdk-core (3.209.1) + aws-partitions (1.992.0) + aws-sdk-core (3.210.0) aws-eventstream (~> 1, >= 1.3.0) - aws-partitions (~> 1, >= 1.651.0) + aws-partitions (~> 1, >= 1.992.0) aws-sigv4 (~> 1.9) jmespath (~> 1, >= 1.6.1) - aws-sdk-kms (1.94.0) - aws-sdk-core (~> 3, >= 3.207.0) + aws-sdk-kms (1.95.0) + aws-sdk-core (~> 3, >= 3.210.0) aws-sigv4 (~> 1.5) - aws-sdk-s3 (1.168.0) - aws-sdk-core (~> 3, >= 3.207.0) + aws-sdk-s3 (1.169.0) + aws-sdk-core (~> 3, >= 3.210.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.5) aws-sigv4 (1.10.0) @@ -530,7 +530,7 @@ GEM nokogiri (~> 1) rubyzip (>= 1.3.0, < 3.0.0) rotp (6.3.0) - rspec-core (3.13.1) + rspec-core (3.13.2) rspec-support (~> 3.13.0) rspec-expectations (3.13.3) diff-lcs (>= 1.2.0, < 2.0) @@ -672,13 +672,14 @@ GEM websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.7.0) + zeitwerk (2.7.1) zlib (2.1.1) PLATFORMS arm64-darwin-23 arm64-darwin-24 x86_64-darwin-23 + x86_64-darwin-24 x86_64-linux DEPENDENCIES @@ -769,4 +770,4 @@ RUBY VERSION ruby 3.3.5p100 BUNDLED WITH - 2.5.9 + 2.5.16 diff --git a/app/controllers/admin/university/people_controller.rb b/app/controllers/admin/university/people_controller.rb index 26a18ea59..f8b8f959e 100644 --- a/app/controllers/admin/university/people_controller.rb +++ b/app/controllers/admin/university/people_controller.rb @@ -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, diff --git a/app/models/university/person.rb b/app/models/university/person.rb index 78b69679f..3c1e4ac08 100644 --- a/app/models/university/person.rb +++ b/app/models/university/person.rb @@ -147,6 +147,7 @@ class University::Person < ApplicationRecord } 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) } diff --git a/app/services/migrations/authors.rb b/app/services/migrations/authors.rb new file mode 100644 index 000000000..3bc72b5a7 --- /dev/null +++ b/app/services/migrations/authors.rb @@ -0,0 +1,9 @@ +module Migrations + class Authors + def self.migrate + University::Person.find_each do |person| + person.update_column :is_author, person.communication_website_posts.any? + end + end + end +end \ No newline at end of file diff --git a/app/views/admin/communication/websites/posts/_form.html.erb b/app/views/admin/communication/websites/posts/_form.html.erb index ed50840d5..20c38113e 100644 --- a/app/views/admin/communication/websites/posts/_form.html.erb +++ b/app/views/admin/communication/websites/posts/_form.html.erb @@ -44,7 +44,7 @@ <% end %> <%= f.association :author, collection: osuny_collection( - current_university.people, + current_university.people.authors, localized: true, label_method: :to_s_alphabetical ) %> diff --git a/app/views/admin/university/people/_form.html.erb b/app/views/admin/university/people/_form.html.erb index 3ccc73289..97ce0d9f2 100644 --- a/app/views/admin/university/people/_form.html.erb +++ b/app/views/admin/university/people/_form.html.erb @@ -115,6 +115,7 @@ <%= f.input :is_teacher %> <%= f.input :is_administration %> <%= f.input :is_alumnus %> + <%= f.input :is_author %>
<%= f.input :tenure %> diff --git a/lib/tasks/app.rake b/lib/tasks/app.rake index dd0c0a430..e37fba677 100644 --- a/lib/tasks/app.rake +++ b/lib/tasks/app.rake @@ -8,6 +8,7 @@ namespace :app do desc 'Fix things' task fix: :environment do + Migrations::Authors.migrate end namespace :websites do From 6685b733e57bfa627505cc1697e232f378aabfe2 Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Mon, 21 Oct 2024 08:03:45 +0200 Subject: [PATCH 02/15] Symmetry --- .../admin/design-system/layout.sass | 2 +- .../admin/communication/authors_controller.rb | 29 ++++++++++++++++ app/models/communication.rb | 1 + app/services/icon.rb | 2 ++ .../communication/authors/_filters.html.erb | 11 +++++++ .../communication/authors/index.html.erb | 33 +++++++++++++++++++ .../admin/communication/authors/show.html.erb | 22 +++++++++++++ .../communication/websites/_list.html.erb | 13 +------- .../communication/websites/_website.html.erb | 12 +++++++ app/views/admin/dashboard/namespace.html.erb | 4 +-- app/views/admin/layouts/application.html.erb | 2 +- config/locales/communication/en.yml | 5 +++ config/locales/communication/fr.yml | 5 +++ config/locales/university/en.yml | 9 +++-- config/locales/university/fr.yml | 9 +++-- .../admin/communication_navigation.rb | 3 ++ .../navigation/admin_university_navigation.rb | 3 +- config/routes/admin/communication.rb | 6 +--- 18 files changed, 142 insertions(+), 29 deletions(-) create mode 100644 app/controllers/admin/communication/authors_controller.rb create mode 100644 app/views/admin/communication/authors/_filters.html.erb create mode 100644 app/views/admin/communication/authors/index.html.erb create mode 100644 app/views/admin/communication/authors/show.html.erb create mode 100644 app/views/admin/communication/websites/_website.html.erb diff --git a/app/assets/stylesheets/admin/design-system/layout.sass b/app/assets/stylesheets/admin/design-system/layout.sass index 3c7cf031e..5263539b7 100644 --- a/app/assets/stylesheets/admin/design-system/layout.sass +++ b/app/assets/stylesheets/admin/design-system/layout.sass @@ -9,6 +9,6 @@ body #{--bs-gutter-x}: 4rem main - min-height: 70vh + min-height: 50vh padding-bottom: pxToRem(100) position: relative diff --git a/app/controllers/admin/communication/authors_controller.rb b/app/controllers/admin/communication/authors_controller.rb new file mode 100644 index 000000000..365dd122a --- /dev/null +++ b/app/controllers/admin/communication/authors_controller.rb @@ -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 diff --git a/app/models/communication.rb b/app/models/communication.rb index 3c3458024..d73b81317 100644 --- a/app/models/communication.rb +++ b/app/models/communication.rb @@ -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], ] diff --git a/app/services/icon.rb b/app/services/icon.rb index fb0333eda..458c3fff6 100644 --- a/app/services/icon.rb +++ b/app/services/icon.rb @@ -2,6 +2,7 @@ class Icon DASHBOARD = 'fas fa-chart-line' + COMMUNICATION_AUTHOR = 'fas fa-users' COMMUNICATION_EXTRANET = 'fas fa-project-diagram' COMMUNICATION_WEBSITE = 'fas fa-sitemap' COMMUNICATION_WEBSITE_HOME = 'fas fa-home' @@ -59,6 +60,7 @@ class Icon UNIVERSITY_PERSON_ADMINISTRATORS = 'fas fa-users-cog' UNIVERSITY_PERSON_ALUMNUS = 'fas fa-user-graduate' UNIVERSITY_PERSON_LOCALIZATION_TEACHER = EDUCATION_TEACHER + UNIVERSITY_PERSON_LOCALIZATION_AUTHOR = COMMUNICATION_AUTHOR OSUNY_USER = 'fas fa-user' USER = OSUNY_USER diff --git a/app/views/admin/communication/authors/_filters.html.erb b/app/views/admin/communication/authors/_filters.html.erb new file mode 100644 index 000000000..50639be6d --- /dev/null +++ b/app/views/admin/communication/authors/_filters.html.erb @@ -0,0 +1,11 @@ +<%= simple_form_for :filters, url: current_path, method: :get do |f| %> + <%= filters_panel current_path: current_path, active_filters_count: active_filters_count do |form| %> + + <%= render_filter f, + :string, + :for_search_term, + label: t('search') + %> + + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/admin/communication/authors/index.html.erb b/app/views/admin/communication/authors/index.html.erb new file mode 100644 index 000000000..63ae07b4b --- /dev/null +++ b/app/views/admin/communication/authors/index.html.erb @@ -0,0 +1,33 @@ +<% content_for :title, University::Person::Localization::Author.model_name.human(count: 2) %> + +
+

+ <%= @authors.total_count %> + <%= University::Person::Localization::Author.model_name.human(count: @authors.total_count).downcase %> +

+ <%= render 'filters', current_path: admin_communication_authors_path %> +
+ +
+ <% @authors.each do |person| %> +
+
+ <%= osuny_thumbnail_localized person, large: true %> +
+

+ <%= osuny_link_localized person, + admin_communication_author_path(person), + classes: 'stretched-link' %> +

+ <% if person.communication_website_posts.any? %> +

+ <%= person.communication_website_posts.size %> + <%= Communication::Website::Post.model_name.human(count: person.communication_website_posts.size).downcase %> +

+ <% end %> +
+
+
+ <% end %> +
+<%= paginate @authors %> diff --git a/app/views/admin/communication/authors/show.html.erb b/app/views/admin/communication/authors/show.html.erb new file mode 100644 index 000000000..9d2ddf734 --- /dev/null +++ b/app/views/admin/communication/authors/show.html.erb @@ -0,0 +1,22 @@ +<% content_for :title, @l10n %> + +
+

<%= t('admin.communication.author.show_person_html') %>

+ <%= link_to t('show'), admin_university_person_path(@author) %> +
+ +<% @author.author_websites.each do |website| %> +
+
+ <%= render 'admin/communication/websites/website', website: website %> +
+
+

+ <%= posts.count %> + <%= Communication::Website::Post.model_name.human(count: posts.count).downcase %> +

+ <%= render 'admin/communication/websites/posts/list', posts: posts %> +
+
+<% end %> diff --git a/app/views/admin/communication/websites/_list.html.erb b/app/views/admin/communication/websites/_list.html.erb index 8f956a25a..7995ffa0f 100644 --- a/app/views/admin/communication/websites/_list.html.erb +++ b/app/views/admin/communication/websites/_list.html.erb @@ -1,18 +1,7 @@
<% websites.each do |website| %>
-
-
- <%= kamifusen_tag website.screenshot, width: 500, class:'img-fluid rounded' if website.screenshot.attached? %> -
-

- <%= osuny_link_localized website, - admin_communication_website_path( - id: website.id - ), - classes: 'stretched-link' %> -

-
+ <%= render 'admin/communication/websites/website', website: website %>
<% end %>
\ No newline at end of file diff --git a/app/views/admin/communication/websites/_website.html.erb b/app/views/admin/communication/websites/_website.html.erb new file mode 100644 index 000000000..6bc589049 --- /dev/null +++ b/app/views/admin/communication/websites/_website.html.erb @@ -0,0 +1,12 @@ +
+
+ <%= kamifusen_tag website.screenshot, width: 500, class:'img-fluid rounded' if website.screenshot.attached? %> +
+

+ <%= osuny_link_localized website, + admin_communication_website_path( + id: website.id + ), + classes: 'stretched-link' %> +

+
diff --git a/app/views/admin/dashboard/namespace.html.erb b/app/views/admin/dashboard/namespace.html.erb index 1d959a8d1..acb4199c7 100644 --- a/app/views/admin/dashboard/namespace.html.erb +++ b/app/views/admin/dashboard/namespace.html.erb @@ -2,7 +2,7 @@ <% content_for :realm do %>
-
+

<%= t "#{@namespace.to_s.underscore}.description.text_html" %> @@ -40,7 +40,7 @@ key = "#{@namespace.to_s.underscore.gsub('/', '.')}.description.parts.#{class_name.to_s.demodulize.downcase}" description = t "#{key}.description" %> -

+

<%= title %>

<%= description %>

diff --git a/app/views/admin/layouts/application.html.erb b/app/views/admin/layouts/application.html.erb index 21e979d88..604a5855d 100644 --- a/app/views/admin/layouts/application.html.erb +++ b/app/views/admin/layouts/application.html.erb @@ -14,7 +14,6 @@ <%= render "admin/application/components/nav" %> - <%= render "admin/application/components/realm" %> <%= render "admin/application/components/subnav" %> <%= render "admin/application/components/hero" %> <%= render 'application/notice' %> @@ -26,6 +25,7 @@ <%= render 'admin/application/preview' if @preview %> <%= render "admin/application/components/commands" %> + <%= render "admin/application/components/realm" %> <%= render "admin/application/components/footer" %> <%= javascript_include_tag 'admin' %> <%= render 'bugsnag' %> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 12955916f..7b599d8c3 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -338,6 +338,8 @@ en: other: Other title: Categories communication: + author: + show_person_html: "This page only shows posts written by the person as an author.
If you wish to view or modify the person's details, click on the link below." block: copied: The block has been copied to clipboard! drag_and_drop: Drag and drop @@ -429,6 +431,9 @@ en: other: Authors description: parts: + author: + description: People writing posts in websites or extranets + description_non_university: People writing posts in websites or extranets extranet: description: Secure exchange areas dedicated to authenticated users description_non_university: Secure exchange areas dedicated to authenticated users diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 04dabf032..25d3d2a6b 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -338,6 +338,8 @@ fr: other: Autres title: Catégories communication: + author: + show_person_html: "Cette page montre uniquement les actualités écrites par la personne, en tant qu'auteur ou autrice.
Si vous voulez voir ou modifier les informations sur la personne, cliquez sur le lien ci-dessous." block: copied: Le bloc a bien été copié dans le presse-papier. drag_and_drop: Drag and drop @@ -429,6 +431,9 @@ fr: other: Auteur·rice·s description: parts: + author: + description: Personnes écrivant des actualités dans des sites Web ou des Extranets + description_non_university: Personnes écrivant des actualités dans des sites Web ou des Extranets extranet: description: Espaces d'échanges sécurisés dédiés aux utilisateur·rice·s authentifié·e·s description_non_university: Espaces d'échanges sécurisés dédiés aux utilisateur·rice·s authentifié·e·s diff --git a/config/locales/university/en.yml b/config/locales/university/en.yml index 4a5084286..987544b3e 100644 --- a/config/locales/university/en.yml +++ b/config/locales/university/en.yml @@ -165,15 +165,18 @@ en: university/person/category: one: Category other: Categories - university/person/involvement: - one: Involvement - other: Involvements university/person/alumnus: one: Alumnus other: Alumni university/person/experience: one: Professional experience other: Professional experiences + university/person/involvement: + one: Involvement + other: Involvements + university/person/localization/author: + one: Author + other: Authors university/organization: one: Organization other: Organizations diff --git a/config/locales/university/fr.yml b/config/locales/university/fr.yml index de33c05bc..837da31c6 100644 --- a/config/locales/university/fr.yml +++ b/config/locales/university/fr.yml @@ -165,15 +165,18 @@ fr: university/person/category: one: Catégorie other: Catégories - university/person/involvement: - one: Implication - other: Implications university/person/alumnus: one: Alumnus other: Alumni university/person/experience: one: Expérience professionnelle other: Expériences professionnelles + university/person/involvement: + one: Implication + other: Implications + university/person/localization/author: + one: Auteur·ice + other: Auteur·ices university/organization: one: Organisation other: Organisations diff --git a/config/navigation/admin/communication_navigation.rb b/config/navigation/admin/communication_navigation.rb index 89f7d75b5..1b9fee3cb 100644 --- a/config/navigation/admin/communication_navigation.rb +++ b/config/navigation/admin/communication_navigation.rb @@ -11,6 +11,9 @@ highlights_on: lambda { controller_name == "dashboard" && action_name == "index" } + primary.item :subnav_authors, + University::Person::Localization::Author.model_name.human(count: 2), + admin_communication_authors_path primary.item :subnav_websites, Communication::Website.model_name.human(count: 2), admin_communication_websites_path diff --git a/config/navigation/admin_university_navigation.rb b/config/navigation/admin_university_navigation.rb index 6edfda708..95f572d81 100644 --- a/config/navigation/admin_university_navigation.rb +++ b/config/navigation/admin_university_navigation.rb @@ -10,8 +10,7 @@ def load_from_parts class_name, primary identifier = class_name.to_s.to_sym label = class_name.model_name.human(count: 2) path = send part.last, lang: current_language.iso_code - icon = Icon.icon_for class_name - primary.item identifier, label, path, { icon: icon } if can?(:read, class_name) + primary.item identifier, label, path if can?(:read, class_name) end end diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index 66c1059d0..2a783b68a 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -1,4 +1,5 @@ namespace :communication do + resources :authors, only: [:index, :show] scope 'photo-imports' do get 'unsplash' => 'photo_imports#unsplash' get 'pexels' => 'photo_imports#pexels' @@ -176,10 +177,5 @@ end resources :jobs, controller: 'extranets/jobs' end - resources :alumni do - collection do - resources :imports, only: [:index, :show, :new, :create] - end - end root to: 'dashboard#index' end From 31e3747c98d8d6d779eb894653cbee245751eafd Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Tue, 29 Oct 2024 08:46:01 +0100 Subject: [PATCH 03/15] meilleure migration --- app/services/migrations/authors.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/services/migrations/authors.rb b/app/services/migrations/authors.rb index 3bc72b5a7..c4dcf7bb3 100644 --- a/app/services/migrations/authors.rb +++ b/app/services/migrations/authors.rb @@ -1,9 +1,11 @@ module Migrations class Authors def self.migrate - University::Person.find_each do |person| - person.update_column :is_author, person.communication_website_posts.any? - end + authors_ids = Communication::Website::Post.pluck(:author_id) + Communication::Extranet::Post.pluck(:author_id) + authors_ids.uniq! + .compact! + puts "#{authors_ids.count} authors" + University::Person.where(id: authors_ids).update_all(is_author: true) end end end \ No newline at end of file From f81435041e8d01a11b7f8c287bbaffebe6bb51ba Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Tue, 29 Oct 2024 09:27:20 +0100 Subject: [PATCH 04/15] Clean --- app/models/university/person.rb | 80 ++----------------- .../{with_education.rb => with_alumnus.rb} | 42 +++++----- .../university/person/with_experiences.rb | 25 ------ app/models/university/person/with_facets.rb | 43 ++++++++++ .../university/person/with_involvements.rb | 11 +++ .../person/with_realm_administration.rb | 21 +++++ .../person/with_realm_communication.rb | 29 +++++++ .../university/person/with_realm_education.rb | 20 +++++ ...ith_research.rb => with_realm_research.rb} | 12 ++- app/models/university/person/with_roles.rb | 15 ---- .../application/favorites/_show.html.erb | 2 +- .../communication/authors/index.html.erb | 4 +- .../admin/communication/authors/show.html.erb | 18 ++++- .../extranets/_extranet.html.erb | 9 +++ .../admin/education/teachers/show.html.erb | 2 +- .../admin/research/researchers/show.html.erb | 2 +- .../admin/university/people/_filters.html.erb | 11 ++- .../admin/university/people/show.html.erb | 2 +- config/locales/en.yml | 1 + config/locales/fr.yml | 1 + 20 files changed, 204 insertions(+), 146 deletions(-) rename app/models/university/person/{with_education.rb => with_alumnus.rb} (76%) delete mode 100644 app/models/university/person/with_experiences.rb create mode 100644 app/models/university/person/with_facets.rb create mode 100644 app/models/university/person/with_involvements.rb create mode 100644 app/models/university/person/with_realm_administration.rb create mode 100644 app/models/university/person/with_realm_communication.rb create mode 100644 app/models/university/person/with_realm_education.rb rename app/models/university/person/{with_research.rb => with_realm_research.rb} (81%) delete mode 100644 app/models/university/person/with_roles.rb create mode 100644 app/views/admin/communication/extranets/_extranet.html.erb diff --git a/app/models/university/person.rb b/app/models/university/person.rb index 3c1e4ac08..6352d632c 100644 --- a/app/models/university/person.rb +++ b/app/models/university/person.rb @@ -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 @@ -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, @@ -146,13 +109,6 @@ class University::Person < ApplicationRecord .order("localization_last_name ASC, localization_first_name ASC") } - 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_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) @@ -189,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(', ') diff --git a/app/models/university/person/with_education.rb b/app/models/university/person/with_alumnus.rb similarity index 76% rename from app/models/university/person/with_education.rb rename to app/models/university/person/with_alumnus.rb index 3ce9574c2..e9739020e 100644 --- a/app/models/university/person/with_education.rb +++ b/app/models/university/person/with_alumnus.rb @@ -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, @@ -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) @@ -77,5 +76,4 @@ def find_cohorts end self.cohorts = cohorts end - -end +end \ No newline at end of file diff --git a/app/models/university/person/with_experiences.rb b/app/models/university/person/with_experiences.rb deleted file mode 100644 index 27cf18ef8..000000000 --- a/app/models/university/person/with_experiences.rb +++ /dev/null @@ -1,25 +0,0 @@ -module University::Person::WithExperiences - extend ActiveSupport::Concern - - included do - - 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 - } - - end - -end diff --git a/app/models/university/person/with_facets.rb b/app/models/university/person/with_facets.rb new file mode 100644 index 000000000..d73e7585f --- /dev/null +++ b/app/models/university/person/with_facets.rb @@ -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 \ No newline at end of file diff --git a/app/models/university/person/with_involvements.rb b/app/models/university/person/with_involvements.rb new file mode 100644 index 000000000..ce10d28d8 --- /dev/null +++ b/app/models/university/person/with_involvements.rb @@ -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 diff --git a/app/models/university/person/with_realm_administration.rb b/app/models/university/person/with_realm_administration.rb new file mode 100644 index 000000000..4694414fa --- /dev/null +++ b/app/models/university/person/with_realm_administration.rb @@ -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 \ No newline at end of file diff --git a/app/models/university/person/with_realm_communication.rb b/app/models/university/person/with_realm_communication.rb new file mode 100644 index 000000000..073365790 --- /dev/null +++ b/app/models/university/person/with_realm_communication.rb @@ -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 \ No newline at end of file diff --git a/app/models/university/person/with_realm_education.rb b/app/models/university/person/with_realm_education.rb new file mode 100644 index 000000000..d992192be --- /dev/null +++ b/app/models/university/person/with_realm_education.rb @@ -0,0 +1,20 @@ +module University::Person::WithRealmEducation + 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 :teacher_websites, + -> { distinct }, + through: :education_programs, + source: :websites + end +end diff --git a/app/models/university/person/with_research.rb b/app/models/university/person/with_realm_research.rb similarity index 81% rename from app/models/university/person/with_research.rb rename to app/models/university/person/with_realm_research.rb index fc137e00e..2428db0ce 100644 --- a/app/models/university/person/with_research.rb +++ b/app/models/university/person/with_realm_research.rb @@ -1,4 +1,4 @@ -module University::Person::WithResearch +module University::Person::WithRealmResearch extend ActiveSupport::Concern included do @@ -24,12 +24,22 @@ module University::Person::WithResearch association_foreign_key: :research_publication_id alias :publications :research_publications + has_and_belongs_to_many :research_journal_papers, + class_name: 'Research::Journal::Paper', + join_table: :research_journal_papers_researchers, + foreign_key: :researcher_id + has_and_belongs_to_many :research_laboratories, class_name: 'Research::Laboratory', foreign_key: :university_person_id, association_foreign_key: :research_laboratory_id alias :laboratories :research_laboratories + has_many :researcher_websites, + -> { distinct }, + through: :research_journal_papers, + source: :websites + scope :with_hal_identifier, -> { where.not(hal_form_identifier: [nil,'']) } end diff --git a/app/models/university/person/with_roles.rb b/app/models/university/person/with_roles.rb deleted file mode 100644 index d9742809f..000000000 --- a/app/models/university/person/with_roles.rb +++ /dev/null @@ -1,15 +0,0 @@ -module University::Person::WithRoles - 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" - end -end diff --git a/app/views/admin/application/favorites/_show.html.erb b/app/views/admin/application/favorites/_show.html.erb index d7a696dd2..f4fee7d50 100644 --- a/app/views/admin/application/favorites/_show.html.erb +++ b/app/views/admin/application/favorites/_show.html.erb @@ -22,7 +22,7 @@ if current_user.favorites.none?

<%= about.class.model_name.human %>

<%= link_to t('show'), [:admin, about], - class: 'stretched-link' %> + class: 'action stretched-link' %> <% end %>
<% end %> diff --git a/app/views/admin/communication/authors/index.html.erb b/app/views/admin/communication/authors/index.html.erb index 63ae07b4b..e96059bd9 100644 --- a/app/views/admin/communication/authors/index.html.erb +++ b/app/views/admin/communication/authors/index.html.erb @@ -19,9 +19,9 @@ admin_communication_author_path(person), classes: 'stretched-link' %>

- <% if person.communication_website_posts.any? %> + <% if person.posts.any? %>

- <%= person.communication_website_posts.size %> + <%= person.posts.size %> <%= Communication::Website::Post.model_name.human(count: person.communication_website_posts.size).downcase %>

<% end %> diff --git a/app/views/admin/communication/authors/show.html.erb b/app/views/admin/communication/authors/show.html.erb index 9d2ddf734..ae51d835d 100644 --- a/app/views/admin/communication/authors/show.html.erb +++ b/app/views/admin/communication/authors/show.html.erb @@ -2,7 +2,7 @@

<%= t('admin.communication.author.show_person_html') %>

- <%= link_to t('show'), admin_university_person_path(@author) %> + <%= link_to t('show'), admin_university_person_path(@author), class: 'action' %>
<% @author.author_websites.each do |website| %> @@ -20,3 +20,19 @@
<% end %> + +<% @author.author_extranets.each do |extranet| %> +
+
+ <%= render 'admin/communication/extranets/extranet', extranet: extranet %> +
+
+

+ <%= posts.count %> + <%= Communication::Extranet::Post.model_name.human(count: posts.count).downcase %> +

+ <%= render 'admin/communication/extranets/posts/list', posts: posts %> +
+
+<% end %> diff --git a/app/views/admin/communication/extranets/_extranet.html.erb b/app/views/admin/communication/extranets/_extranet.html.erb new file mode 100644 index 000000000..7a095f85a --- /dev/null +++ b/app/views/admin/communication/extranets/_extranet.html.erb @@ -0,0 +1,9 @@ +
+

+ <%= osuny_link_localized extranet, + admin_communication_extranet_path( + id: extranet.id + ), + classes: 'stretched-link' %> +

+
diff --git a/app/views/admin/education/teachers/show.html.erb b/app/views/admin/education/teachers/show.html.erb index 0c8d26904..f368f8534 100644 --- a/app/views/admin/education/teachers/show.html.erb +++ b/app/views/admin/education/teachers/show.html.erb @@ -32,7 +32,7 @@

<%= t('admin.education.programs.teacher.show_person_html') %>

- <%= link_to t('show'), admin_university_person_path(@teacher) %> + <%= link_to t('show'), admin_university_person_path(@teacher), class: 'action' %>
<% content_for :action_bar_left do %> diff --git a/app/views/admin/research/researchers/show.html.erb b/app/views/admin/research/researchers/show.html.erb index 1d8378557..37f8037b0 100644 --- a/app/views/admin/research/researchers/show.html.erb +++ b/app/views/admin/research/researchers/show.html.erb @@ -5,7 +5,7 @@

<%= t('admin.research.researcher.show_person_html') %>

- <%= link_to t('show'), admin_university_person_path(@researcher) %> + <%= link_to t('show'), admin_university_person_path(@researcher), class: 'action' %>
diff --git a/app/views/admin/university/people/_filters.html.erb b/app/views/admin/university/people/_filters.html.erb index 587c4e999..4698c7f3b 100644 --- a/app/views/admin/university/people/_filters.html.erb +++ b/app/views/admin/university/people/_filters.html.erb @@ -19,9 +19,14 @@ <%= render_filter f, :select, - :for_role, - label: t('filters.attributes.role'), - collection: University::Person::LIST_OF_ROLES.map { |r| { to_s: University::Person.human_attribute_name(r), id: r } } + :for_facet, + label: t('filters.attributes.facet'), + collection: University::Person::LIST_OF_FACETS.map { |facet| + { + to_s: University::Person.human_attribute_name(facet), + id: facet + } + } %> <% end %> diff --git a/app/views/admin/university/people/show.html.erb b/app/views/admin/university/people/show.html.erb index ae624b833..5f45314db 100644 --- a/app/views/admin/university/people/show.html.erb +++ b/app/views/admin/university/people/show.html.erb @@ -142,7 +142,7 @@ <% if @teacher_involvements.any? %> <%= osuny_panel t('education.teachings') do %>

<%= "#{@teacher_involvements.count} #{Education::Program.model_name.human(count: @teacher_involvements.count).downcase}" %>

- <%= link_to t('show'), admin_education_teacher_path(@person) %> + <%= link_to t('show'), admin_education_teacher_path(@person), class: 'action' %> <% end %> <% end %> <% if @administrator_involvements.any? %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 9d040bd85..d05c5fa09 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -248,6 +248,7 @@ en: category: Filter by category date: Filter by date element: Filter by %{element} + facet: Filter by responsibility kind: Filter by kind role: Filter by role buttons: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 23275eb55..de3cbde09 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -248,6 +248,7 @@ fr: category: Filtrer par catégorie date: Filtrer par date element: Filtrer par %{element} + facet: Filtrer par responsabilité kind: Filtrer par type role: Filtrer par rôle buttons: From f63576a3b4bd5392386840b357585373d557bbd8 Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Tue, 29 Oct 2024 09:38:45 +0100 Subject: [PATCH 05/15] climate --- app/models/university/person/with_alumnus.rb | 6 ------ app/services/importers/hash_to_cohort.rb | 11 +++++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/models/university/person/with_alumnus.rb b/app/models/university/person/with_alumnus.rb index e9739020e..69bdf448b 100644 --- a/app/models/university/person/with_alumnus.rb +++ b/app/models/university/person/with_alumnus.rb @@ -54,12 +54,6 @@ module University::Person::WithAlumnus } 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 = [] diff --git a/app/services/importers/hash_to_cohort.rb b/app/services/importers/hash_to_cohort.rb index 086a6b138..c120809ae 100644 --- a/app/services/importers/hash_to_cohort.rb +++ b/app/services/importers/hash_to_cohort.rb @@ -27,6 +27,17 @@ def error protected + + def add_to_cohort(person, cohort) + add_object_if_necessary cohort, person.cohorts + add_object_if_necessary cohort.academic_year, person.diploma_years + add_object_if_necessary cohort.program, person.diploma_programs + end + + def add_object_if_necessary(object, list) + list << object unless object.in?(list) + end + def extract_variables @school_id = @hash[18].to_s.strip @program_id = @hash[19].to_s.strip From 6344345a274e62c133c4d3e239403b6c637d7a34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Thu, 31 Oct 2024 09:46:16 +0100 Subject: [PATCH 06/15] fix --- app/services/importers/hash_to_cohort.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/importers/hash_to_cohort.rb b/app/services/importers/hash_to_cohort.rb index c120809ae..fb6a80ac2 100644 --- a/app/services/importers/hash_to_cohort.rb +++ b/app/services/importers/hash_to_cohort.rb @@ -5,7 +5,7 @@ def initialize(person, hash) @hash = hash @error = nil extract_variables - person.add_to_cohort cohort if valid? + add_to_cohort(person, cohort) if valid? end def valid? From 9743736199dbd1993855293312130f9b90c6eb51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Thu, 31 Oct 2024 09:56:10 +0100 Subject: [PATCH 07/15] Update app/views/admin/communication/authors/index.html.erb --- app/views/admin/communication/authors/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/communication/authors/index.html.erb b/app/views/admin/communication/authors/index.html.erb index e96059bd9..e4325e2e3 100644 --- a/app/views/admin/communication/authors/index.html.erb +++ b/app/views/admin/communication/authors/index.html.erb @@ -22,7 +22,7 @@ <% if person.posts.any? %>

<%= person.posts.size %> - <%= Communication::Website::Post.model_name.human(count: person.communication_website_posts.size).downcase %> + <%= Communication::Website::Post.model_name.human(count: person.posts.size).downcase %>

<% end %>
From e077d6c7e3047872b451a6e4ccf969b127b8391a Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Thu, 31 Oct 2024 09:59:12 +0100 Subject: [PATCH 08/15] Update app/views/admin/communication/authors/show.html.erb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sébastien Gaya --- app/views/admin/communication/authors/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/communication/authors/show.html.erb b/app/views/admin/communication/authors/show.html.erb index ae51d835d..49586772d 100644 --- a/app/views/admin/communication/authors/show.html.erb +++ b/app/views/admin/communication/authors/show.html.erb @@ -11,7 +11,7 @@ <%= render 'admin/communication/websites/website', website: website %>
+ <% posts = @author.communication_website_posts.where(website: website).limit(5) %>

<%= posts.count %> <%= Communication::Website::Post.model_name.human(count: posts.count).downcase %> From 3ea156912d7af9cd54bfa0e7070441645cec00f6 Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Thu, 31 Oct 2024 09:59:18 +0100 Subject: [PATCH 09/15] Update app/views/admin/communication/authors/show.html.erb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sébastien Gaya --- app/views/admin/communication/authors/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/communication/authors/show.html.erb b/app/views/admin/communication/authors/show.html.erb index 49586772d..b20bb21b4 100644 --- a/app/views/admin/communication/authors/show.html.erb +++ b/app/views/admin/communication/authors/show.html.erb @@ -27,7 +27,7 @@ <%= render 'admin/communication/extranets/extranet', extranet: extranet %>

+ <% posts = @author.communication_extranet_posts.where(extranet: extranet).limit(5) %>

<%= posts.count %> <%= Communication::Extranet::Post.model_name.human(count: posts.count).downcase %> From f13aa8fc31c7f052d81d75b2571bc89c822ea5e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Thu, 31 Oct 2024 10:02:39 +0100 Subject: [PATCH 10/15] update_author_status_if_necessary --- app/models/communication/extranet/post.rb | 12 ++++++++++-- app/models/communication/website/post.rb | 10 +++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/models/communication/extranet/post.rb b/app/models/communication/extranet/post.rb index f1fe0a1e3..deeb7e7de 100644 --- a/app/models/communication/extranet/post.rb +++ b/app/models/communication/extranet/post.rb @@ -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( @@ -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 diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 8941e140a..6f74219de 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -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 @@ -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 From 473b77dde42e73fb1c0d8f98001d52ba16d02a25 Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Thu, 31 Oct 2024 10:05:27 +0100 Subject: [PATCH 11/15] author --- .../admin/communication/extranets/posts_controller.rb | 1 + .../admin/communication/websites/posts_controller.rb | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/communication/extranets/posts_controller.rb b/app/controllers/admin/communication/extranets/posts_controller.rb index 5fab6e574..87675a1b0 100644 --- a/app/controllers/admin/communication/extranets/posts_controller.rb +++ b/app/controllers/admin/communication/extranets/posts_controller.rb @@ -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 diff --git a/app/controllers/admin/communication/websites/posts_controller.rb b/app/controllers/admin/communication/websites/posts_controller.rb index 78b9d5230..218f0c828 100644 --- a/app/controllers/admin/communication/websites/posts_controller.rb +++ b/app/controllers/admin/communication/websites/posts_controller.rb @@ -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 From a3ff3b90ee11c0f0237025c97dfeea703fda628d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Thu, 31 Oct 2024 10:07:41 +0100 Subject: [PATCH 12/15] find_cohorts --- app/models/university/person/with_alumnus.rb | 30 ++++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/app/models/university/person/with_alumnus.rb b/app/models/university/person/with_alumnus.rb index 69bdf448b..a4c15f74a 100644 --- a/app/models/university/person/with_alumnus.rb +++ b/app/models/university/person/with_alumnus.rb @@ -56,18 +56,24 @@ module University::Person::WithAlumnus 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 = [] + self.cohorts.each do |object| + cohort = find_cohort_for_nested(object) + next if cohorts_ids_to_set.include?(cohort.reload.id) || object._destroy + cohorts_ids_to_set << cohort.id unless cohort.id.nil? + cohorts_to_set << cohort end - self.cohorts = cohorts + self.cohorts = cohorts_to_set + 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 end end \ No newline at end of file From 7c0fcec035395dc5bee9023ce71eb46ab51f7df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Thu, 31 Oct 2024 10:17:53 +0100 Subject: [PATCH 13/15] fix --- app/models/university/person/with_alumnus.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/university/person/with_alumnus.rb b/app/models/university/person/with_alumnus.rb index a4c15f74a..cee05ba5a 100644 --- a/app/models/university/person/with_alumnus.rb +++ b/app/models/university/person/with_alumnus.rb @@ -58,9 +58,9 @@ def find_cohorts # based on https://stackoverflow.com/questions/3579924/accepts-nested-attributes-for-with-find-or-create cohorts_to_set = [] cohorts_ids_to_set = [] - self.cohorts.each do |object| + self.cohorts.reject(&:_destroy).each do |object| cohort = find_cohort_for_nested(object) - next if cohorts_ids_to_set.include?(cohort.reload.id) || object._destroy + next if cohorts_ids_to_set.include?(cohort.reload.id) cohorts_ids_to_set << cohort.id unless cohort.id.nil? cohorts_to_set << cohort end From cf861894ac74d684374a7284d022596ffd724460 Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Thu, 31 Oct 2024 10:18:55 +0100 Subject: [PATCH 14/15] fix --- .../admin/communication/authors/show.html.erb | 21 ++++++++++++------- config/locales/communication/en.yml | 2 +- config/locales/communication/fr.yml | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/views/admin/communication/authors/show.html.erb b/app/views/admin/communication/authors/show.html.erb index b20bb21b4..dd9e47b53 100644 --- a/app/views/admin/communication/authors/show.html.erb +++ b/app/views/admin/communication/authors/show.html.erb @@ -11,12 +11,15 @@ <%= render 'admin/communication/websites/website', website: website %>

+ <% + total_posts = @author.communication_website_posts.where(website: website) + recent_posts = total_posts.ordered(current_language).limit(5) + %>

- <%= posts.count %> - <%= Communication::Website::Post.model_name.human(count: posts.count).downcase %> + <%= total_posts.count %> + <%= Communication::Website::Post.model_name.human(count: total_posts.count).downcase %>

- <%= render 'admin/communication/websites/posts/list', posts: posts %> + <%= render 'admin/communication/websites/posts/list', posts: recent_posts %>
<% end %> @@ -27,12 +30,14 @@ <%= render 'admin/communication/extranets/extranet', extranet: extranet %>
+ <% + total_posts = @author.communication_extranet_posts.where(extranet: extranet) + recent_posts = total_posts.ordered(current_language).limit(5) %>

- <%= posts.count %> - <%= Communication::Extranet::Post.model_name.human(count: posts.count).downcase %> + <%= total_posts.count %> + <%= Communication::Extranet::Post.model_name.human(count: total_posts.count).downcase %>

- <%= render 'admin/communication/extranets/posts/list', posts: posts %> + <%= render 'admin/communication/extranets/posts/list', posts: recent_posts %>
<% end %> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index b80e36ab9..cf408ad41 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -339,7 +339,7 @@ en: title: Categories communication: author: - show_person_html: "This page only shows posts written by the person as an author.
If you wish to view or modify the person's details, click on the link below." + show_person_html: "This page only shows the last posts written by the person as an author.
If you wish to view or modify the person's details, click on the link below." block: copied: The block has been copied to clipboard! drag_and_drop: Drag and drop diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index bbaabfcde..15c841616 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -339,7 +339,7 @@ fr: title: Catégories communication: author: - show_person_html: "Cette page montre uniquement les actualités écrites par la personne, en tant qu'auteur ou autrice.
Si vous voulez voir ou modifier les informations sur la personne, cliquez sur le lien ci-dessous." + show_person_html: "Cette page montre uniquement les dernières actualités écrites par la personne, en tant qu'auteur ou autrice.
Si vous voulez voir ou modifier les informations sur la personne, cliquez sur le lien ci-dessous." block: copied: Le bloc a bien été copié dans le presse-papier. drag_and_drop: Drag and drop From e24c3d4d58fc919c45326083fdbcb90947f84dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Thu, 31 Oct 2024 10:20:40 +0100 Subject: [PATCH 15/15] fix --- app/models/university/person/with_alumnus.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/university/person/with_alumnus.rb b/app/models/university/person/with_alumnus.rb index cee05ba5a..512de3d0b 100644 --- a/app/models/university/person/with_alumnus.rb +++ b/app/models/university/person/with_alumnus.rb @@ -58,9 +58,10 @@ def find_cohorts # based on https://stackoverflow.com/questions/3579924/accepts-nested-attributes-for-with-find-or-create cohorts_to_set = [] cohorts_ids_to_set = [] - self.cohorts.reject(&:_destroy).each do |object| + 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.reload.id) + next if cohorts_ids_to_set.include?(cohort.id) cohorts_ids_to_set << cohort.id unless cohort.id.nil? cohorts_to_set << cohort end @@ -74,6 +75,6 @@ def find_cohort_for_nested(object) 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 + cohort.reload end end \ No newline at end of file