From c49979690d798a1c7e8c7dbbd91c58dac03ffda8 Mon Sep 17 00:00:00 2001 From: Audrey Hamelers Date: Tue, 30 Jul 2024 20:57:37 +0200 Subject: [PATCH 1/6] remove recursive checks --- .../stash_engine/publication_updater_controller.rb | 2 +- .../publication_updater/_proposed_change_line.html.erb | 4 ++-- app/views/stash_engine/publication_updater/index.csv.erb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/stash_engine/publication_updater_controller.rb b/app/controllers/stash_engine/publication_updater_controller.rb index 9c523c93e..275d64744 100644 --- a/app/controllers/stash_engine/publication_updater_controller.rb +++ b/app/controllers/stash_engine/publication_updater_controller.rb @@ -103,7 +103,7 @@ def setup_counts(proposed_changes) def check_status @proposed_change = authorize StashEngine::ProposedChange.find(params[:id]) - @resource = @proposed_change.identifier&.latest_resource if @proposed_change.present? + @resource = @proposed_change&.latest_resource if @proposed_change.present? refresh_error if @proposed_change.approved? || @proposed_change.rejected? end diff --git a/app/views/stash_engine/publication_updater/_proposed_change_line.html.erb b/app/views/stash_engine/publication_updater/_proposed_change_line.html.erb index 2f5efb8aa..2b5aa0b3a 100644 --- a/app/views/stash_engine/publication_updater/_proposed_change_line.html.erb +++ b/app/views/stash_engine/publication_updater/_proposed_change_line.html.erb @@ -1,6 +1,6 @@ <% - existing_pubname = resource.identifier.journal_name_datum&.value || 'Not available' - existing_pubissn = resource.identifier.journal&.issn_array || resource.identifier.journal_datum&.value || 'Not available' + existing_pubname = resource.resource_publication&.publication_name || 'Not available' + existing_pubissn = resource.journal&.issn_array || resource.resource_publication&.publication_issn || 'Not available' existing_pubdoi = fetch_related_primary_article(resource: resource) %> diff --git a/app/views/stash_engine/publication_updater/index.csv.erb b/app/views/stash_engine/publication_updater/index.csv.erb index f3c908e80..96c5b96cf 100644 --- a/app/views/stash_engine/publication_updater/index.csv.erb +++ b/app/views/stash_engine/publication_updater/index.csv.erb @@ -19,8 +19,8 @@ resource = @resources.select{ |r| r.identifier_id == proposed_change.identifier_id }.first next if resource.blank? - existing_pubname = resource.identifier.journal_name_datum&.value || 'Not available' - existing_pubissn = resource.identifier.journal&.issn_array || resource.identifier.journal_datum&.value || 'Not available' + existing_pubname = resource.resource_publication&.publication_name || 'Not available' + existing_pubissn = resource.journal&.issn_array || resource.resource_publication&.publication_issn || 'Not available' existing_pubdoi = fetch_related_primary_article(resource: resource) row = [ resource.title, From fd33079dd41c203cd43a2628db31e4263636c429 Mon Sep 17 00:00:00 2001 From: Audrey Hamelers Date: Tue, 30 Jul 2024 21:29:06 +0200 Subject: [PATCH 2/6] try to make journals page not break whole site! --- .../stash_engine/journals_controller.rb | 14 +++++++------- app/models/stash_engine/journal.rb | 2 +- app/views/stash_engine/journals/index.html.erb | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/controllers/stash_engine/journals_controller.rb b/app/controllers/stash_engine/journals_controller.rb index 07d7c29b3..f8f3ec525 100644 --- a/app/controllers/stash_engine/journals_controller.rb +++ b/app/controllers/stash_engine/journals_controller.rb @@ -6,18 +6,18 @@ class JournalsController < ApplicationController def index params.permit(:q) params[:sort] = 'title' if params[:sort].blank? - metadata_journal_clause = 'stash_engine_journals.id IN ' \ - "(select distinct journal_id from stash_engine_manuscripts where created_at > '#{1.year.ago.iso8601}')" - @metadata_journals = Journal.where(metadata_journal_clause).map(&:id) + @metadata_journals = Journal.joins(:manuscripts).where("stash_engine_manuscripts.created_at > '#{1.year.ago.iso8601}'").distinct.map(&:id) @api_journals = StashEngine::User.joins('inner join oauth_applications on owner_id = stash_engine_users.id') - .joins(:roles).where(roles: { role_object_type: ['StashEngine::Journal', 'StashEngine::JournalOrganization'] }) - .distinct.map(&:journals_as_admin).flatten.uniq.map(&:id) + .joins( + "inner join stash_engine_roles on stash_engine_users.id = stash_engine_roles.user_id + and role_object_type in ('StashEngine::Journal', 'StashEngine::JournalOrganization')" + ).distinct.map(&:journals_as_admin).flatten.uniq.map(&:id) sponsoring_journals = Journal.where.not(payment_plan_type: [nil, '']).map(&:id) display_journals = @metadata_journals | sponsoring_journals | @api_journals ord = helpers.sortable_table_order(whitelist: %w[title issn allow_blackout payment_plan_type name parent_org_id sponsor_id default_to_ppr]) - @journals = Journal.left_outer_joins(:sponsor).where(id: display_journals) - .order(ord, title: :asc).preload(:issns).preload(:manuscripts).preload(:sponsor) + @journals = Journal.left_outer_joins(:sponsor).where(id: display_journals).order(ord, title: :asc) + .preload(:sponsor).preload(:issns) respond_to do |format| format.html diff --git a/app/models/stash_engine/journal.rb b/app/models/stash_engine/journal.rb index 9e07caa51..271afc97d 100644 --- a/app/models/stash_engine/journal.rb +++ b/app/models/stash_engine/journal.rb @@ -33,7 +33,7 @@ class Journal < ApplicationRecord has_many :alternate_titles, class_name: 'StashEngine::JournalTitle', dependent: :destroy has_many :roles, class_name: 'StashEngine::Role', as: :role_object, dependent: :destroy has_many :users, through: :roles - has_many :manuscripts, -> { order(created_at: :asc) }, class_name: 'StashEngine::Manuscript' + has_many :manuscripts, -> { order(created_at: :desc) }, class_name: 'StashEngine::Manuscript' belongs_to :sponsor, class_name: 'StashEngine::JournalOrganization', optional: true def payment_plans = %w[SUBSCRIPTION PREPAID DEFERRED TIERED] diff --git a/app/views/stash_engine/journals/index.html.erb b/app/views/stash_engine/journals/index.html.erb index f0148dafa..6a32626ad 100644 --- a/app/views/stash_engine/journals/index.html.erb +++ b/app/views/stash_engine/journals/index.html.erb @@ -53,11 +53,11 @@ Dryad member, you will be responsible for paying the DPC as well as any overage <% if policy(@journals).detail? %> <%= journal.payment_plan_type %> <%= journal.sponsor&.name %> - <%= journal.top_level_org&.name %> + <%= journal.top_level_org&.name == journal.sponsor&.name ? '' : journal.top_level_org&.name %> <% end %> <% if @api_journals.include?(journal.id) || @metadata_journals.include?(journal.id) %>Data integrated<% end %> <% if policy(@journals).detail? %> - <%= journal.manuscripts&.last&.created_at.presence || @api_journals.include?(journal.id) ? 'API journal' : ''%> + <%= journal.manuscripts.limit(1).first&.created_at.presence || @api_journals.include?(journal.id) ? 'API journal' : ''%> <% if journal.default_to_ppr? %>Default<% end %> <% end %> From 5ed70f613d068908728f8609ded8ea3a7102aebb Mon Sep 17 00:00:00 2001 From: Audrey Hamelers Date: Tue, 30 Jul 2024 22:06:53 +0200 Subject: [PATCH 3/6] trying even harder with the journals page --- .../stash_engine/journals_controller.rb | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/app/controllers/stash_engine/journals_controller.rb b/app/controllers/stash_engine/journals_controller.rb index f8f3ec525..100c1032f 100644 --- a/app/controllers/stash_engine/journals_controller.rb +++ b/app/controllers/stash_engine/journals_controller.rb @@ -7,11 +7,7 @@ def index params.permit(:q) params[:sort] = 'title' if params[:sort].blank? @metadata_journals = Journal.joins(:manuscripts).where("stash_engine_manuscripts.created_at > '#{1.year.ago.iso8601}'").distinct.map(&:id) - @api_journals = StashEngine::User.joins('inner join oauth_applications on owner_id = stash_engine_users.id') - .joins( - "inner join stash_engine_roles on stash_engine_users.id = stash_engine_roles.user_id - and role_object_type in ('StashEngine::Journal', 'StashEngine::JournalOrganization')" - ).distinct.map(&:journals_as_admin).flatten.uniq.map(&:id) + setup_api_journals sponsoring_journals = Journal.where.not(payment_plan_type: [nil, '']).map(&:id) display_journals = @metadata_journals | sponsoring_journals | @api_journals @@ -26,5 +22,22 @@ def index end end end + + private + + def setup_api_journals + api_journals = StashEngine::User.joins('inner join oauth_applications on owner_id = stash_engine_users.id') + .joins( + "inner join stash_engine_roles on stash_engine_users.id = stash_engine_roles.user_id and role_object_type='StashEngine::Journal'" + ).select('stash_engine_roles.role_object_id').distinct.map(&:role_object_id) + api_journals2 = StashEngine::User.joins('inner join oauth_applications on owner_id = stash_engine_users.id') + .joins( + "inner join stash_engine_roles on stash_engine_users.id = stash_engine_roles.user_id + and role_object_type = 'StashEngine::JournalOrganization'" + ).joins( + 'inner join stash_engine_journals on sponsor_id = stash_engine_roles.role_object_id' + ).select('stash_engine_journals.id').distinct.map(&:id) + @api_journals = api_journals | api_journals2 + end end end From e9437044d00c2b58421ff12aa2523f56f779aa63 Mon Sep 17 00:00:00 2001 From: Audrey Hamelers Date: Tue, 30 Jul 2024 22:09:03 +0200 Subject: [PATCH 4/6] fix import manuscript --- .../stash_datacite/publications_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/stash_datacite/publications_controller.rb b/app/controllers/stash_datacite/publications_controller.rb index 13e9ecf68..b6689d7f4 100644 --- a/app/controllers/stash_datacite/publications_controller.rb +++ b/app/controllers/stash_datacite/publications_controller.rb @@ -147,15 +147,15 @@ def update_manuscript_metadata return end return if params[:publication].blank? # keeps the default fill-in message - return if @pub_issn&.value.blank? - return if @msid&.value.blank? + return if @pub_issn.blank? + return if @msid.blank? - journal = StashEngine::Journal.find_by_issn(@pub_issn.value) + journal = StashEngine::Journal.find_by_issn(@pub_issn) if journal.blank? @error = 'Journal not recognized by Dryad' return end - manu = StashEngine::Manuscript.where(journal: journal, manuscript_number: @msid.value).first + manu = StashEngine::Manuscript.where(journal: journal, manuscript_number: @msid).first if manu.blank? @error = 'We could not find metadata to import for this manuscript.' return @@ -164,7 +164,7 @@ def update_manuscript_metadata dryad_import = Stash::Import::DryadManuscript.new(resource: @resource, manuscript: manu) dryad_import.populate rescue HTTParty::Error, SocketError => e - logger.error("Dryad manuscript API returned a HTTParty/Socket error for ISSN: #{@pub_issn.value}, MSID: #{@msid.value}\r\n #{e}") + logger.error("Dryad manuscript API returned a HTTParty/Socket error for ISSN: #{@pub_issn}, MSID: #{@msid}\r\n #{e}") @error = 'We could not find metadata to import for this manuscript.' end From fc8f58c41cca971b6ea418fa6230c669ff48b633 Mon Sep 17 00:00:00 2001 From: Audrey Hamelers Date: Tue, 30 Jul 2024 22:27:36 +0200 Subject: [PATCH 5/6] fix invisible pub information --- .../react/components/MetadataEntry/PrelimInfo.jsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/javascript/react/components/MetadataEntry/PrelimInfo.jsx b/app/javascript/react/components/MetadataEntry/PrelimInfo.jsx index c0fbdfe6a..83b7a2f11 100644 --- a/app/javascript/react/components/MetadataEntry/PrelimInfo.jsx +++ b/app/javascript/react/components/MetadataEntry/PrelimInfo.jsx @@ -14,9 +14,9 @@ function PrelimInfo( const tempVal = importInfo; - const [acText, setAcText] = useState(publication_name?.value || ''); - const [acID, setAcID] = useState(publication_issn?.value || ''); - const [msId, setMsId] = useState(msid?.value || ''); + const [acText, setAcText] = useState(publication_name || ''); + const [acID, setAcID] = useState(publication_issn || ''); + const [msId, setMsId] = useState(msid || ''); const [importType, setImportType] = useState(tempVal); const [relatedIdentifier, setRelatedIdentifier] = useState(related_identifier); @@ -136,9 +136,9 @@ PrelimInfo.propTypes = { importInfo: PropTypes.string.isRequired, // the type of import it is doing resourceId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, identifierId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, - publication_name: PropTypes.object.isRequired, - publication_issn: PropTypes.object.isRequired, - msid: PropTypes.object.isRequired, + publication_name: PropTypes.string.isRequired, + publication_issn: PropTypes.string.isRequired, + msid: PropTypes.string.isRequired, related_identifier: PropTypes.string.isRequired, api_journals: PropTypes.array.isRequired, }; From 8c988faa556199e3ce1badf0917b5c4fa5bf3f06 Mon Sep 17 00:00:00 2001 From: Audrey Hamelers Date: Tue, 30 Jul 2024 22:53:58 +0200 Subject: [PATCH 6/6] allow javascript in search form (so dropdowns work) --- app/views/stash_engine/admin_dashboard/results.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/stash_engine/admin_dashboard/results.js.erb b/app/views/stash_engine/admin_dashboard/results.js.erb index 22bbb6fa9..9885f6a95 100644 --- a/app/views/stash_engine/admin_dashboard/results.js.erb +++ b/app/views/stash_engine/admin_dashboard/results.js.erb @@ -6,7 +6,7 @@ urlparams.set('page', '<%= params[:page] %>') window.history.pushState({}, null, `${window.location.pathname}?${urlparams.toString()}`) document.getElementById('search_results').innerHTML = "<%= escape_javascript(render(partial: 'results')) %>"; document.getElementById('save_buttons').innerHTML = "<%= escape_javascript(render(partial: 'save_buttons')) %>"; -document.getElementById('search_form').innerHTML = "<%= escape_javascript(render(partial: 'search_form')) %>"; +$('#search_form').html = "<%= escape_javascript(render(partial: 'search_form')) %>"; document.getElementById('edit_fields-help').addEventListener('click', (e) => { e.preventDefault() document.getElementById('edit_fields-form').classList.toggle('show-help')