Skip to content

Commit

Permalink
allows to add draft work to collection, adds state badge
Browse files Browse the repository at this point in the history
  • Loading branch information
Banu Kutlu committed Mar 1, 2022
1 parent 3f45a4b commit c79f0df
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 9 deletions.
13 changes: 13 additions & 0 deletions app/models/concerns/catalog_search_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,23 @@ def limit_to_public_resources(solr_parameters)

solr_parameters[:fq] ||= []
solr_parameters[:fq] << '-embargoed_until_dtsi:[NOW TO *]'
end

def limit_to_published_resources(solr_parameters)
return if current_user.admin?

solr_parameters[:fq] ||= []
solr_parameters[:fq] << '-aasm_state_tesim:draft'
solr_parameters[:fq] << '-aasm_state_tesim:withdrawn'
end

def exclude_withdrawn_resources(solr_parameters)
return if current_user.admin?

solr_parameters[:fq] ||= []
solr_parameters[:fq] << '-aasm_state_tesim:withdrawn'
end

def apply_gated_edit(solr_parameters)
return if current_user.admin?

Expand Down
1 change: 1 addition & 0 deletions app/models/dashboard/member_works_search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class MemberWorksSearchBuilder < Blacklight::SearchBuilder
restrict_search_to_work_titles
apply_gated_edit
limit_to_public_resources
exclude_withdrawn_resources
)

# @note Builds a Solr query to return a list of all the works a user may add to a collection
Expand Down
1 change: 1 addition & 0 deletions app/models/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class SearchBuilder < Blacklight::SearchBuilder
restrict_search_to_works_and_collections
apply_gated_discovery
limit_to_public_resources
limit_to_published_resources
exclude_empty_collections
)

Expand Down
1 change: 0 additions & 1 deletion app/views/dashboard/form/members/_search.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<div class="form-wrapper form-wrapper--wide">
<div class="keyline keyline--left mb-3">
<h4><%= t('dashboard.form.members.search_heading') %></h4>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
<div class="col-8 pr-2">
<%= form.hidden_field :work_id %>
<%= form.hidden_field :position, class: 'js-position-index' %>
<h3>
<h3 class="h4">
<%= link_to work_version.title, resource_path(work_version.uuid) %>
<%= render WorkVersions::StatusBadgeComponent.new(work_version: work_version) %>
</h3>
<%= render WorkVersionMetadataComponent.new(work_version: work_version, mini: true) %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ en:
move_up: "Move %{name} one position earlier"
move_down: "Move %{name} one position later"
search: >
You can search for works by title
You can search for works by title. Draft works will not appear on the collection's public page until they are published.
search_heading: Add works to collection
search_label: Search works
search_results: Search Results
Expand Down
6 changes: 3 additions & 3 deletions spec/features/dashboard/collection_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,21 @@ def mock_solr_indexing_job

find_all('.select2').first.click

expect(page).to have_selector('li[data-select2-id]', count: 4)
expect(page).to have_selector('li[data-select2-id]', count: 5)

expect(page).to have_selector('li[data-select2-id]', text: published_work.representative_version.title)
expect(page).to have_selector('li[data-select2-id]', text: published_work_with_draft.representative_version.title)
expect(page).to have_selector('li[data-select2-id]', text: proxy_work.representative_version.title)
expect(page).to have_selector('li[data-select2-id]', text: edit_work.representative_version.title)
expect(page).not_to have_selector('li[data-select2-id]', text: draft_work.representative_version.title)
expect(page).to have_selector('li[data-select2-id]', text: draft_work.representative_version.title)
expect(page).not_to have_selector('li[data-select2-id]', text: other_work.representative_version.title)

mock_solr_indexing_job
FeatureHelpers::DashboardForm.select_work(published_work.representative_version.title)

# Test that the work that was selected no longer appears in the dropdown
find_all('.select2').first.click
expect(page).to have_selector('li[data-select2-id]', count: 3)
expect(page).to have_selector('li[data-select2-id]', count: 4)
expect(page).not_to have_selector('li[data-select2-id]', text: published_work.representative_version.title)

FeatureHelpers::DashboardForm.finish
Expand Down
11 changes: 9 additions & 2 deletions spec/models/dashboard/member_works_search_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,25 @@
is_expected.to include(
:restrict_search_to_work_titles,
:apply_gated_edit,
:limit_to_public_resources
:limit_to_public_resources,
:exclude_withdrawn_resources
)
end
end

describe '#processed_parameters' do
let(:parameters) { builder.processed_parameters }

it 'searches only published work versions' do
it 'searches published and draft work versions' do
expect(parameters['fq']).to include(
'{!terms f=model_ssi}Work'
)
end

it 'excludes withdrawn works' do
expect(parameters['fq']).to include(
'-aasm_state_tesim:withdrawn'
)
end
end
end
15 changes: 15 additions & 0 deletions spec/models/search_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
:restrict_search_to_works_and_collections,
:apply_gated_discovery,
:limit_to_public_resources,
:limit_to_published_resources,
:exclude_empty_collections
)
end
Expand All @@ -32,6 +33,13 @@
)
end

it 'restricts to published works' do
expect(parameters['fq']).to include(
'-aasm_state_tesim:draft',
'-aasm_state_tesim:withdrawn'
)
end

it 'excludes empty collections' do
expect(parameters['fq']).to include('-is_empty_bi:true')
end
Expand All @@ -51,6 +59,13 @@
it 'excludes empty collections' do
expect(parameters['fq']).to include('-is_empty_bi:true')
end

it 'restricts to published works' do
expect(parameters['fq']).to include(
'-aasm_state_tesim:draft',
'-aasm_state_tesim:withdrawn'
)
end
end

context 'with an admin user' do
Expand Down
2 changes: 1 addition & 1 deletion spec/support/feature_helpers/dashboard_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def self.select_work(title)
.select { |option| option.text == title }
.first
.click
while page.has_no_selector?('h3', text: title)
while page.has_no_selector?('h3', text: /#{title}/i)
sleep 0.1
end
end
Expand Down

0 comments on commit c79f0df

Please sign in to comment.