From 7891853773ee93ea8352984a7813deab3aecbb68 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Fri, 17 Feb 2023 21:51:50 +0100 Subject: [PATCH] hal namespace --- .../research/hal/publications_controller.rb | 36 +++++++++ .../admin/research/publications_controller.rb | 36 --------- .../admin/research/researchers_controller.rb | 2 +- app/models/research.rb | 2 +- app/models/research/hal.rb | 8 ++ app/models/research/{ => hal}/publication.rb | 10 +-- app/models/university/person/with_research.rb | 15 ++-- app/services/icon.rb | 1 + .../{ => hal}/publications/_list.html.erb | 6 +- .../research/hal/publications/index.html.erb | 4 + .../{ => hal}/publications/show.html.erb | 10 +-- .../{ => hal}/publications/static.html.erb | 0 .../research/publications/index.html.erb | 4 - .../admin/research/researchers/index.html.erb | 4 +- .../admin/research/researchers/show.html.erb | 4 +- config/locales/research/en.yml | 22 +++--- config/locales/research/fr.yml | 22 +++--- config/routes/admin/research.rb | 8 +- ...20230217202815_move_publications_in_hal.rb | 7 ++ db/schema.rb | 78 +++++++++++-------- 20 files changed, 154 insertions(+), 125 deletions(-) create mode 100644 app/controllers/admin/research/hal/publications_controller.rb delete mode 100644 app/controllers/admin/research/publications_controller.rb create mode 100644 app/models/research/hal.rb rename app/models/research/{ => hal}/publication.rb (87%) rename app/views/admin/research/{ => hal}/publications/_list.html.erb (73%) create mode 100644 app/views/admin/research/hal/publications/index.html.erb rename app/views/admin/research/{ => hal}/publications/show.html.erb (78%) rename app/views/admin/research/{ => hal}/publications/static.html.erb (100%) delete mode 100644 app/views/admin/research/publications/index.html.erb create mode 100644 db/migrate/20230217202815_move_publications_in_hal.rb diff --git a/app/controllers/admin/research/hal/publications_controller.rb b/app/controllers/admin/research/hal/publications_controller.rb new file mode 100644 index 000000000..d206f43b8 --- /dev/null +++ b/app/controllers/admin/research/hal/publications_controller.rb @@ -0,0 +1,36 @@ +class Admin::Research::Hal::PublicationsController < Admin::Research::ApplicationController + before_action :load_publication, except: :index + + def index + @publications = Research::Hal::Publication.ordered.page(params[:page]) + breadcrumb + end + + def show + breadcrumb + end + + def static + @about = @publication + render layout: false + end + + def destroy + @publication.destroy + redirect_to admin_research_hal_publications_path + end + + protected + + def load_publication + @publication = Research::Hal::Publication.find params[:id] + end + + def breadcrumb + super + add_breadcrumb Research::Hal::Publication.model_name.human(count: 2), + admin_research_hal_publications_path + breadcrumb_for @publication + end + +end diff --git a/app/controllers/admin/research/publications_controller.rb b/app/controllers/admin/research/publications_controller.rb deleted file mode 100644 index e03e1f4d2..000000000 --- a/app/controllers/admin/research/publications_controller.rb +++ /dev/null @@ -1,36 +0,0 @@ -class Admin::Research::PublicationsController < Admin::Research::ApplicationController - before_action :load_publication, except: :index - - def index - @publications = Research::Publication.ordered.page(params[:page]) - breadcrumb - end - - def show - breadcrumb - end - - def static - @about = @publication - render layout: false - end - - def destroy - @publication.destroy - redirect_to admin_research_publications_path - end - - protected - - def load_publication - @publication = Research::Publication.find params[:id] - end - - def breadcrumb - super - add_breadcrumb Research::Publication.model_name.human(count: 2), - admin_research_publications_path - breadcrumb_for @publication - end - -end diff --git a/app/controllers/admin/research/researchers_controller.rb b/app/controllers/admin/research/researchers_controller.rb index a96265b0c..9a2bb07e4 100644 --- a/app/controllers/admin/research/researchers_controller.rb +++ b/app/controllers/admin/research/researchers_controller.rb @@ -29,7 +29,7 @@ class Admin::Research::ResearchersController < Admin::Research::ApplicationContr ].each do |key| @researcher.update_column key, params[key] if params.has_key?(key) end - @researcher.import_research_publications_from_hal_without_delay! + @researcher.import_research_hal_publications! redirect_to admin_research_researcher_path(@researcher) end diff --git a/app/models/research.rb b/app/models/research.rb index 0c9050ee5..ed1172dce 100644 --- a/app/models/research.rb +++ b/app/models/research.rb @@ -12,7 +12,7 @@ module Research [Research::Laboratory, :admin_research_laboratories_path], [Research::Thesis, :admin_research_theses_path], [Research::Journal, :admin_research_journals_path], - [Research::Publication, :admin_research_publications_path], + [Research::Hal::Publication, :admin_research_hal_publications_path], ] end end diff --git a/app/models/research/hal.rb b/app/models/research/hal.rb new file mode 100644 index 000000000..36168ff47 --- /dev/null +++ b/app/models/research/hal.rb @@ -0,0 +1,8 @@ +module Research::Hal + extend ActiveModel::Naming + extend ActiveModel::Translation + + def self.table_name_prefix + 'research_hal_' + end +end diff --git a/app/models/research/publication.rb b/app/models/research/hal/publication.rb similarity index 87% rename from app/models/research/publication.rb rename to app/models/research/hal/publication.rb index ef061ce7d..302b61872 100644 --- a/app/models/research/publication.rb +++ b/app/models/research/hal/publication.rb @@ -1,6 +1,6 @@ # == Schema Information # -# Table name: research_publications +# Table name: research_hal_publications # # id :uuid not null, primary key # data :jsonb @@ -17,9 +17,9 @@ # # Indexes # -# index_research_publications_on_docid (docid) +# index_research_hal_publications_on_docid (docid) # -class Research::Publication < ApplicationRecord +class Research::Hal::Publication < ApplicationRecord include WithGit include WithSlug @@ -52,8 +52,8 @@ class Research::Publication < ApplicationRecord def self.update_from_hal University::Person::Researcher.with_hal_identifier.find_each do |researcher| - puts "Loading publications for #{researcher} (#{researcher.university})" - researcher.import_research_publications_from_hal! + # puts "Loading publications for #{researcher} (#{researcher.university})" + researcher.import_research_hal_publications! end end diff --git a/app/models/university/person/with_research.rb b/app/models/university/person/with_research.rb index dd3f01ead..febdd4246 100644 --- a/app/models/university/person/with_research.rb +++ b/app/models/university/person/with_research.rb @@ -2,11 +2,12 @@ module University::Person::WithResearch extend ActiveSupport::Concern included do - has_and_belongs_to_many :research_publications, - class_name: 'Research::Publication', + has_and_belongs_to_many :research_hal_publications, + class_name: 'Research::Hal::Publication', foreign_key: 'research_publication_id', association_foreign_key: 'university_person_id' - alias :publications :research_publications + alias :publications :research_hal_publications + alias :hal_publications :research_hal_publications scope :with_hal_identifier, -> { where.not(hal_form_identifier: [nil,'']) } end @@ -15,17 +16,17 @@ module University::Person::WithResearch hal_form_identifier.present? end - def import_research_publications_from_hal! + def import_research_hal_publications! return unless hal_identity? response = HalOpenscience::Document.search "authIdForm_i:#{hal_form_identifier}", fields: ["*"], limit: 1000 response.results.each do |doc| - publication = Research::Publication.create_from doc - research_publications << publication unless publication.in?(research_publications) + publication = Research::Hal::Publication.create_from doc + publications << publication unless publication.in?(publications) end end - handle_asynchronously :import_research_publications_from_hal! + handle_asynchronously :import_research_hal_publications! def possible_hal_authors HalOpenscience::Author.search(to_s, fields: ["*"]).results diff --git a/app/services/icon.rb b/app/services/icon.rb index 02c54be4f..9d9210585 100644 --- a/app/services/icon.rb +++ b/app/services/icon.rb @@ -32,6 +32,7 @@ class Icon RESEARCH_WATCH = 'fas fa-eye' UNIVERSITY_PERSON_RESEARCHER = RESEARCH_RESEARCHER RESEARCH_THESIS = RESEARCH_THESE + RESEARCH_HAL_PUBLICATION = RESEARCH_PUBLICATION ADMINISTRATION_CAMPUS = 'fas fa-map-marker-alt' ADMINISTRATION_ADMISSIONS = 'fas fa-door-open' diff --git a/app/views/admin/research/publications/_list.html.erb b/app/views/admin/research/hal/publications/_list.html.erb similarity index 73% rename from app/views/admin/research/publications/_list.html.erb rename to app/views/admin/research/hal/publications/_list.html.erb index c39bd0e12..32d1cea4d 100644 --- a/app/views/admin/research/publications/_list.html.erb +++ b/app/views/admin/research/hal/publications/_list.html.erb @@ -2,15 +2,15 @@ <table class="<%= table_classes %>"> <thead> <tr> - <th><%= Research::Publication.human_attribute_name('title') %></th> - <th><%= Research::Publication.human_attribute_name('publication_date') %></th> + <th><%= Research::Hal::Publication.human_attribute_name('title') %></th> + <th><%= Research::Hal::Publication.human_attribute_name('publication_date') %></th> <th><%= t('research.researchers', count: 2) %></th> </tr> </thead> <tbody> <% publications.each do |publication| %> <tr> - <td><%= link_to publication, admin_research_publication_path(publication) %></td> + <td><%= link_to publication, admin_research_hal_publication_path(publication) %></td> <td><%= l publication.publication_date %></td> <td> <% publication.researchers.each do |researcher| %> diff --git a/app/views/admin/research/hal/publications/index.html.erb b/app/views/admin/research/hal/publications/index.html.erb new file mode 100644 index 000000000..5b34326d7 --- /dev/null +++ b/app/views/admin/research/hal/publications/index.html.erb @@ -0,0 +1,4 @@ +<% content_for :title, Research::Hal::Publication.model_name.human(count: 2) %> +<% content_for :title_right, "#{ @publications.total_count }" %> +<%= render 'admin/research/hal/publications/list', publications: @publications %> +<%= paginate @publications, theme: 'bootstrap-5' %> diff --git a/app/views/admin/research/publications/show.html.erb b/app/views/admin/research/hal/publications/show.html.erb similarity index 78% rename from app/views/admin/research/publications/show.html.erb rename to app/views/admin/research/hal/publications/show.html.erb index 2488cf532..5caee22de 100644 --- a/app/views/admin/research/publications/show.html.erb +++ b/app/views/admin/research/hal/publications/show.html.erb @@ -5,18 +5,18 @@ <p class="lead mb-4"><%= sanitize @publication.ref %></p> <div class="row"> <div class="col-lg-6"> - <%= osuny_label Research::Publication.human_attribute_name('docid') %> + <%= osuny_label Research::Hal::Publication.human_attribute_name('docid') %> <p><%= @publication.docid %></p> </div> <div class="col-lg-6"> - <%= osuny_label Research::Publication.human_attribute_name('publication_date') %> + <%= osuny_label Research::Hal::Publication.human_attribute_name('publication_date') %> <p><%= l @publication.publication_date %></p> </div> <% [:url, :hal_url, :doi_url].each do |key| %> <% value = @publication.send key %> <% next if value.blank? %> <div class="col-lg-6"> - <%= osuny_label Research::Publication.human_attribute_name(key) %> + <%= osuny_label Research::Hal::Publication.human_attribute_name(key) %> <p><%= link_to value, value, target: :_blank %></p> </div> <% end %> @@ -40,11 +40,11 @@ <% content_for :action_bar_left do %> <% if current_user.server_admin? %> <%= link_to t('delete'), - admin_research_publication_path(@publication), + admin_research_hal_publication_path(@publication), method: :delete, class: button_classes_danger %> <%= link_to t('static'), - static_admin_research_publication_path(@publication), + static_admin_research_hal_publication_path(@publication), class: button_classes('btn-light') %> <% end %> <% end %> diff --git a/app/views/admin/research/publications/static.html.erb b/app/views/admin/research/hal/publications/static.html.erb similarity index 100% rename from app/views/admin/research/publications/static.html.erb rename to app/views/admin/research/hal/publications/static.html.erb diff --git a/app/views/admin/research/publications/index.html.erb b/app/views/admin/research/publications/index.html.erb deleted file mode 100644 index aa076147c..000000000 --- a/app/views/admin/research/publications/index.html.erb +++ /dev/null @@ -1,4 +0,0 @@ -<% content_for :title, Research::Publication.model_name.human(count: 2) %> -<% content_for :title_right, "#{ @publications.total_count }" %> -<%= render 'admin/research/publications/list', publications: @publications %> -<%= paginate @publications, theme: 'bootstrap-5' %> diff --git a/app/views/admin/research/researchers/index.html.erb b/app/views/admin/research/researchers/index.html.erb index 6e6def800..d2af199c9 100644 --- a/app/views/admin/research/researchers/index.html.erb +++ b/app/views/admin/research/researchers/index.html.erb @@ -9,7 +9,7 @@ <th><%= University::Person.human_attribute_name('name') %></th> <th><%= University::Person.human_attribute_name('first_name') %></th> <th><%= University::Person.human_attribute_name('picture') %></th> - <th><%= Research::Publication.model_name.human(count: 2) %></th> + <th><%= Research::Hal::Publication.model_name.human(count: 2) %></th> <th><%= Research::Journal::Paper.model_name.human(count: 2) %></th> <th width="160"></th> </tr> @@ -25,7 +25,7 @@ <%= kamifusen_tag researcher.best_picture, width: 60 %> <% end %> </td> - <td><%= researcher.research_publications.count %></td> + <td><%= researcher.hal_publications.count %></td> <td><%= researcher.research_journal_papers.count %></td> <td></td> </tr> diff --git a/app/views/admin/research/researchers/show.html.erb b/app/views/admin/research/researchers/show.html.erb index d53cf3dac..dcbd2f426 100644 --- a/app/views/admin/research/researchers/show.html.erb +++ b/app/views/admin/research/researchers/show.html.erb @@ -9,10 +9,10 @@ <% end %> <% end %> -<%= osuny_panel Research::Publication.model_name.human(count: 2), action: @researcher.research_publications.count do %> +<%= osuny_panel Research::Hal::Publication.model_name.human(count: 2), action: @researcher.hal_publications.count do %> <% if @researcher.hal_identity? %> <div class="table-responsive"> - <%= render 'admin/research/publications/list', publications: @researcher.research_publications.ordered %> + <%= render 'admin/research/hal/publications/list', publications: @researcher.hal_publications.ordered %> </div> <% else %> <p><%= t 'research.hal.select_identifier' %><p> diff --git a/config/locales/research/en.yml b/config/locales/research/en.yml index 309b6ec33..a6805e9c0 100644 --- a/config/locales/research/en.yml +++ b/config/locales/research/en.yml @@ -7,6 +7,9 @@ en: university/person/researcher: one: Researcher other: Researchers + research/hal/publication: + one: Publication + other: Publications research/journal: one: Journal other: Journals @@ -25,13 +28,18 @@ en: research/laboratory/axis: one: Axis other: Axes - research/publication: - one: Publication - other: Publications research/thesis: one: Thesis other: Theses attributes: + research/hal/publication: + description: Publications scientifiques importées automatiquement de HAL + docid: Identifier + doi_url: URL DOI + publication_date: Publication date + title: Title + url: URL + hal_url: URL HAL research/journal: description: Journaux en accès ouvert (open access) permettant aux chercheur·e·s de contribuer à la recherche issn: ISSN @@ -69,14 +77,6 @@ en: name: Name short_name: Short name text: Text - research/publication: - description: Publications scientifiques importées automatiquement de HAL - docid: Identifier - doi_url: URL DOI - publication_date: Publication date - title: Title - url: URL - hal_url: URL HAL research/thesis: abstract: Abstract author: Author diff --git a/config/locales/research/fr.yml b/config/locales/research/fr.yml index 74bde5489..f2eb4e9f3 100644 --- a/config/locales/research/fr.yml +++ b/config/locales/research/fr.yml @@ -7,6 +7,9 @@ fr: university/person/researcher: one: Chercheur·e other: Chercheur·e·s + research/hal/publication: + one: Publication + other: Publications research/journal: one: Revue scientifique other: Revues scientifiques @@ -25,13 +28,18 @@ fr: research/laboratory/axis: one: Axe other: Axes - research/publication: - one: Publication - other: Publications research/thesis: one: Thèse other: Thèses attributes: + research/hal/publication: + description: Publications scientifiques importées automatiquement de HAL + docid: Identifiant + doi_url: URL DOI + publication_date: Date de publication + title: Titre + url: URL + hal_url: URL HAL research/journal: description: Journaux en accès ouvert (open access) permettant aux chercheur·e·s de contribuer à la recherche issn: ISSN @@ -69,14 +77,6 @@ fr: name: Nom short_name: Nom court text: Texte - research/publication: - description: Publications scientifiques importées automatiquement de HAL - docid: Identifiant - doi_url: URL DOI - publication_date: Date de publication - title: Titre - url: URL - hal_url: URL HAL research/thesis: abstract: Résumé author: Auteur·rice diff --git a/config/routes/admin/research.rb b/config/routes/admin/research.rb index 25c9842ba..9bf9266f4 100644 --- a/config/routes/admin/research.rb +++ b/config/routes/admin/research.rb @@ -1,8 +1,10 @@ namespace :research do resources :researchers, only: [:index, :show, :update] - resources :publications, only: [:index, :show, :destroy] do - member do - get :static + namespace :hal do + resources :publications, only: [:index, :show, :destroy] do + member do + get :static + end end end resources :journals do diff --git a/db/migrate/20230217202815_move_publications_in_hal.rb b/db/migrate/20230217202815_move_publications_in_hal.rb new file mode 100644 index 000000000..bff467d72 --- /dev/null +++ b/db/migrate/20230217202815_move_publications_in_hal.rb @@ -0,0 +1,7 @@ +class MovePublicationsInHal < ActiveRecord::Migration[7.0] + def change + rename_table :research_publications, :research_hal_publications + rename_table :research_publications_university_people, :research_hal_publications_university_people + drop_table :research_laboratories_publications + end +end diff --git a/db/schema.rb b/db/schema.rb index bd7fe33c8..be3d3b1ef 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_02_13_083544) do +ActiveRecord::Schema[7.0].define(version: 2023_02_17_202815) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -151,6 +151,21 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_13_083544) do t.index ["communication_website_post_id", "communication_website_category_id"], name: "post_category" end + create_table "communication_website_connections", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "university_id", null: false + t.uuid "website_id", null: false + t.string "object_type", null: false + t.uuid "object_id", null: false + t.string "source_type" + t.uuid "source_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["object_type", "object_id"], name: "index_communication_website_connections_on_object" + t.index ["source_type", "source_id"], name: "index_communication_website_connections_on_source" + t.index ["university_id"], name: "index_communication_website_connections_on_university_id" + t.index ["website_id"], name: "index_communication_website_connections_on_website_id" + end + create_table "communication_website_git_files", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "previous_path" t.string "about_type", null: false @@ -339,7 +354,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_13_083544) do t.index ["university_id"], name: "index_communication_website_pages_on_university_id" end - create_table "communication_website_permalinks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_permalinks", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false t.string "about_type", null: false @@ -577,6 +592,28 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_13_083544) do t.string "summernote_locale" end + create_table "research_hal_publications", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "docid" + t.jsonb "data" + t.string "title" + t.string "url" + t.string "ref" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "hal_url" + t.date "publication_date" + t.string "doi" + t.string "slug" + t.index ["docid"], name: "index_research_hal_publications_on_docid" + end + + create_table "research_hal_publications_university_people", id: false, force: :cascade do |t| + t.uuid "research_publication_id", null: false + t.uuid "university_person_id", null: false + t.index ["research_publication_id", "university_person_id"], name: "index_publication_person" + t.index ["university_person_id", "research_publication_id"], name: "index_person_publication" + end + create_table "research_journal_paper_kinds", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "journal_id", null: false @@ -664,13 +701,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_13_083544) do t.index ["university_id"], name: "index_research_laboratories_on_university_id" end - create_table "research_laboratories_publications", id: false, force: :cascade do |t| - t.uuid "research_publication_id", null: false - t.uuid "research_laboratory_id", null: false - t.index ["research_laboratory_id", "research_publication_id"], name: "index_laboratory_publication" - t.index ["research_publication_id", "research_laboratory_id"], name: "index_publication_laboratory" - end - create_table "research_laboratory_axes", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "research_laboratory_id", null: false @@ -685,28 +715,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_13_083544) do t.index ["university_id"], name: "index_research_laboratory_axes_on_university_id" end - create_table "research_publications", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.string "docid" - t.jsonb "data" - t.string "title" - t.string "url" - t.string "ref" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "hal_url" - t.date "publication_date" - t.string "doi" - t.string "slug" - t.index ["docid"], name: "index_research_publications_on_docid" - end - - create_table "research_publications_university_people", id: false, force: :cascade do |t| - t.uuid "research_publication_id", null: false - t.uuid "university_person_id", null: false - t.index ["research_publication_id", "university_person_id"], name: "index_publication_person" - t.index ["university_person_id", "research_publication_id"], name: "index_person_publication" - end - create_table "research_theses", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "research_laboratory_id", null: false @@ -811,12 +819,12 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_13_083544) do t.string "zipcode" t.string "city" t.string "country" - t.string "mastodon" - t.uuid "language_id", null: false - t.uuid "original_id" t.string "hal_person_identifier" t.string "hal_doc_identifier" t.string "hal_form_identifier" + t.string "mastodon" + t.uuid "language_id", null: false + t.uuid "original_id" t.index ["language_id"], name: "index_university_people_on_language_id" t.index ["original_id"], name: "index_university_people_on_original_id" t.index ["university_id"], name: "index_university_people_on_university_id" @@ -921,6 +929,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_13_083544) do add_foreign_key "communication_website_categories", "education_programs", column: "program_id" add_foreign_key "communication_website_categories", "languages" add_foreign_key "communication_website_categories", "universities" + add_foreign_key "communication_website_connections", "communication_websites", column: "website_id" + add_foreign_key "communication_website_connections", "universities" add_foreign_key "communication_website_git_files", "communication_websites", column: "website_id" add_foreign_key "communication_website_imported_authors", "communication_website_imported_websites", column: "website_id" add_foreign_key "communication_website_imported_authors", "universities" -- GitLab