Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Show parent link on child works #849

Merged
merged 6 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/helpers/hyku_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ def admin_host?
def admin_only_tenant_creation?
ActiveModel::Type::Boolean.new.cast(ENV.fetch('HYKU_ADMIN_ONLY_TENANT_CREATION', false))
end

def parent_path(parent_doc)
model = parent_doc['has_model_ssim'].first
path = "hyrax_#{model.underscore}_path"
main_app.send(path, parent_doc.id)
end
end
12 changes: 12 additions & 0 deletions app/models/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,16 @@ def show_pdf_viewer
def show_pdf_download_button
self['show_pdf_download_button_tesim']
end

# @return [Array<SolrDocument>] a list of solr documents in no particular order
def load_parent_docs
query("member_ids_ssim: #{id}", rows: 1000)
.map { |res| ::SolrDocument.new(res) }
end

# Query solr using POST so that the query doesn't get too large for a URI
def query(query, **opts)
result = Hyrax::SolrService.post(query, **opts)
result.fetch('response').fetch('docs', [])
end
end
4 changes: 4 additions & 0 deletions app/presenters/hyku/work_show_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def show_pdf_download_button?
show_pdf_download_button.first.to_i.positive?
end

def parent_works
@parent_works ||= solr_document.load_parent_docs
end

private

def extract_from_identifier(rgx)
Expand Down
6 changes: 5 additions & 1 deletion app/views/hyrax/base/_relationships.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@
<%= render 'relationships_parent_row', type: type, items: items, presenter: presenter %>
<% end %>
<% end %>
<%# Render a link back to its parent works %>
<% if presenter.parent_works.present? %>
<%= render 'relationships_parent_works_rows', presenter: presenter %>
<% end %>
</div>
<% end %>
<% end %>
12 changes: 12 additions & 0 deletions app/views/hyrax/base/_relationships_parent_works_rows.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<dt><%= t('hyrax.base.part_of.label') %></td></dt>
<dd>
<td>
<ul class="tabular">
<% presenter.parent_works.each do |parent_doc| %>
<li class='attribute attribute-title'>
<%= link_to parent_doc.title.first, parent_path(parent_doc) %>
</li>
<% end %>
</ul>
</td>
</dd>
4 changes: 1 addition & 3 deletions config/locales/devise_invitable.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ de:
accept: Die Einladung annehmen
accept_until: Diese Einladung wird in %{due_date} fällig.
hello: Hallo %{email}
ignore: |-
Wenn Sie die Einladung nicht akzeptieren möchten, ignorieren Sie bitte diese E-Mail.
Ihr Konto wird erst dann erstellt, wenn Sie auf den obigen Link zugreifen und Ihr Passwort festlegen.
ignore: "Wenn Sie die Einladung nicht akzeptieren möchten, ignorieren Sie bitte diese E-Mail. \nIhr Konto wird erst dann erstellt, wenn Sie auf den obigen Link zugreifen und Ihr Passwort festlegen."
someone_invited_you: Jemand hat Sie zu %{url} eingeladen, können Sie es über den Link unten akzeptieren.
subject: Einladungshinweise
time:
Expand Down
4 changes: 1 addition & 3 deletions config/locales/devise_invitable.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ es:
accept: Aceptar la invitacion
accept_until: Esta invitación será %{due_date}.
hello: Hola %{email}
ignore: |-
Si no desea aceptar la invitación, ignore este correo electrónico.
Su cuenta no se creará hasta que acceda al enlace anterior y establezca su contraseña.
ignore: "Si no desea aceptar la invitación, ignore este correo electrónico. \nSu cuenta no se creará hasta que acceda al enlace anterior y establezca su contraseña."
someone_invited_you: Alguien te ha invitado a %{url}, puedes aceptarlo a través del siguiente enlace.
subject: Instrucciones de invitación
time:
Expand Down
4 changes: 1 addition & 3 deletions config/locales/devise_invitable.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ fr:
accept: Accepter l'invitation
accept_until: Cette invitation sera due en %{due_date}.
hello: Bonjour %{email}
ignore: |-
Si vous ne souhaitez pas accepter l'invitation, ignorez ce courriel.
Votre compte ne sera créé que lorsque vous accédez au lien ci-dessus et définissez votre mot de passe.
ignore: "Si vous ne souhaitez pas accepter l'invitation, ignorez ce courriel. \nVotre compte ne sera créé que lorsque vous accédez au lien ci-dessus et définissez votre mot de passe."
someone_invited_you: Quelqu'un vous a invité %{url}, vous pouvez l'accepter par le lien ci-dessous.
subject: Instructions d'invitation
time:
Expand Down
4 changes: 1 addition & 3 deletions config/locales/devise_invitable.it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ it:
accept: Accetta l'invito
accept_until: Questo invito sarà dovuto in %{due_date}.
hello: Ciao %{email}
ignore: |-
Se non desideri accettare l'invito, ignora questa email.
Il tuo account non verrà creato finché non accedi al link precedente e imposta la tua password.
ignore: "Se non desideri accettare l'invito, ignora questa email. \nIl tuo account non verrà creato finché non accedi al link precedente e imposta la tua password."
someone_invited_you: Qualcuno ti ha invitato a %{url}, puoi accettarlo tramite il link qui sotto.
subject: Istruzioni di invito
time:
Expand Down
4 changes: 1 addition & 3 deletions config/locales/devise_invitable.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ pt-BR:
accept: Aceitar convite
accept_until: Este convite será devido em %{due_date}.
hello: Olá %{email}
ignore: |-
Se você não deseja aceitar o convite, ignore este e-mail.
Sua conta não será criada até você acessar o link acima e definir sua senha.
ignore: "Se você não deseja aceitar o convite, ignore este e-mail. \nSua conta não será criada até você acessar o link acima e definir sua senha."
someone_invited_you: Alguém convidou você para %{url}, você pode aceitá-lo através do link abaixo.
subject: Instruções de convite
time:
Expand Down
2 changes: 2 additions & 0 deletions config/locales/hyrax.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ de:
title: Titel
unauthorized: Es gibt keine öffentlich verfügbaren Artikel in diesem %{type}.
visibility: Sichtweite
part_of:
label: 'Teil von:'
relationships:
empty: Dieses %{type} befindet sich derzeit in keiner Sammlung.
header: Beziehungen
Expand Down
2 changes: 2 additions & 0 deletions config/locales/hyrax.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ en:
title: Title
unauthorized: There are no publicly available items in this %{type}.
visibility: Visibility
part_of:
label: "Part of:"
relationships:
empty: This %{type} is not currently in any collections.
header: Relationships
Expand Down
2 changes: 2 additions & 0 deletions config/locales/hyrax.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ es:
title: Título
unauthorized: No hay elementos disponibles públicamente en este %{type}.
visibility: Visibilidad
part_of:
label: 'Parte de:'
relationships:
empty: Este %{type} no se encuentra actualmente en ninguna colección.
header: Relaciones
Expand Down
2 changes: 2 additions & 0 deletions config/locales/hyrax.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ fr:
title: Titre
unauthorized: Il n'y a aucun élément accessible au public dans ce %{type}.
visibility: Visibilité
part_of:
label: 'Partie de:'
relationships:
empty: Ce %{type} n'est actuellement dans aucune collection.
header: Des relations
Expand Down
2 changes: 2 additions & 0 deletions config/locales/hyrax.it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ it:
title: Titolo
unauthorized: Non ci sono articoli disponibili pubblicamente in questo %{type}.
visibility: Visibilità
part_of:
label: 'Parte di:'
relationships:
empty: Questo %{type} non è attualmente in nessuna raccolta.
header: Le relazioni
Expand Down
2 changes: 2 additions & 0 deletions config/locales/hyrax.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ pt-BR:
title: Título
unauthorized: Não há itens disponíveis publicamente neste %{type}.
visibility: Visibilidade
part_of:
label: 'Parte de:'
relationships:
empty: Atualmente, este %{type} não está em nenhuma coleção.
header: Relacionamentos
Expand Down
2 changes: 2 additions & 0 deletions config/locales/hyrax.zh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ zh:
title: 标题
unauthorized: 此%{type}中没有公开可用的项目。
visibility: 能见度
part_of:
label: 部分:
relationships:
empty: 该%{type}当前不在任何集合中。
header: 人际关系
Expand Down
11 changes: 11 additions & 0 deletions spec/helpers/hyku_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

RSpec.describe HykuHelper, type: :helper do
describe 'parent_path' do
let(:parent_doc) { SolrDocument.new(id: '123', has_model_ssim: ['GenericWork']) }

it 'returns the path to the parent' do
expect(helper.parent_path(parent_doc)).to eq("/concern/generic_works/#{parent_doc.id}")
end
end
end
44 changes: 44 additions & 0 deletions spec/models/solr_document_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe SolrDocument, type: :model do
let(:solr_document) { described_class.new }
let(:query_result) do
{ 'response' => { 'docs' => [
{ 'id' => '123', 'title_tesim' => ['Title 1'] },
{ 'id' => '456', 'title_tesim' => ['Title 2'] }
] } }
end

before do
allow(Hyrax::SolrService).to receive(:post).and_return(query_result)
end

describe '#load_parent_docs' do
it 'loads parent documents from Solr' do
parent_docs = solr_document.load_parent_docs
expect(parent_docs.first).to be_a SolrDocument
expect(parent_docs.size).to eq 2
expect(parent_docs.first.id).to eq '123'
end
end

describe '#query' do
it 'queries Solr with provided parameters' do
result = solr_document.query("some_query", rows: 2)
expect(result).to be_an Array
expect(result.size).to eq 2
expect(result.map { |r| r['id'] }).to eq ["123", "456"]
end

context 'when Solr response does not contain docs' do
let(:query_result) { { 'response' => {} } }

it 'returns an empty array' do
result = solr_document.query("some_query", rows: 2)
expect(result).to eq([])
end
end
end
end
12 changes: 12 additions & 0 deletions spec/presenters/hyku/work_show_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,17 @@
expect(presenter.isbns).to be_empty
end
end

describe "#parent_works" do
let(:parent_docs) { [double(SolrDocument), double(SolrDocument)] }

before do
allow(solr_document).to receive(:load_parent_docs).and_return(parent_docs)
end

it 'returns the parent works of the solr document' do
expect(presenter.parent_works).to eq(parent_docs)
end
end
end
end
43 changes: 43 additions & 0 deletions spec/views/hyrax/base/_relationships.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

RSpec.describe 'hyrax/base/relationships', type: :view do
let(:user) { FactoryBot.create(:user) }
let(:ability) { Ability.new(user) }
let(:parent_works) { [] }
let(:presenter) { Hyku::WorkShowPresenter.new(SolrDocument.new, ability) }
let(:generic_work) do
Hyrax::WorkShowPresenter.new(
SolrDocument.new(
id: '456',
has_model_ssim: ['GenericWork'],
title_tesim: ['Parent work']
),
ability
)
end
let(:page) { Capybara::Node::Simple.new(rendered) }

before do
allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:parent_path).with(generic_work).and_return("/concern/generic_works/#{generic_work.id}")
allow(presenter).to receive(:parent_works).and_return(parent_works)
end

context "when no parents are present" do
it "does not have links to parents" do
render 'hyrax/base/relationships', presenter: presenter

expect(page).not_to have_text 'Parent work'
end
end

context "when parents are present" do
let(:parent_works) { [generic_work] }

it "links to work and collection" do
render 'hyrax/base/relationships', presenter: presenter

expect(page).to have_link 'Parent work'
end
end
end