Skip to content

Commit

Permalink
support mutliple flagging levels
Browse files Browse the repository at this point in the history
render popup modal for explicit; warning pseudo-flash for offensive
  • Loading branch information
ebenenglish committed Feb 23, 2021
1 parent 0487fd6 commit 965c330
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module CatalogHelperBehavior
include CommonwealthVlrEngine::ImagesHelperBehavior
include CommonwealthVlrEngine::LicenseHelperBehavior
include CommonwealthVlrEngine::MetadataHelperBehavior
include CommonwealthVlrEngine::FlaggedHelperBehavior

def has_image_files? files_hash
files_hash[:images].present?
Expand Down
15 changes: 15 additions & 0 deletions app/helpers/commonwealth_vlr_engine/flagged_helper_behavior.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module CommonwealthVlrEngine
module FlaggedHelperBehavior
# return the correct name of the institution to link to for OAI objects
def show_explicit_warning?(document)
document[blacklight_config.flagged_field.to_sym] == 'explicit'
end

# return the correct name of the institution to link to for OAI objects
def show_content_warning?(document)
document[blacklight_config.flagged_field.to_sym] == 'offensive'
end
end
end
4 changes: 2 additions & 2 deletions app/helpers/commonwealth_vlr_engine/images_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def index_relation_base_icon document

# return the URL of an image to display in the catalog#index slideshow view
def index_slideshow_img_url(document)
if document[:exemplary_image_ssi] && !document[blacklight_config.flagged_field.to_sym]
if document[:exemplary_image_ssi] && document[blacklight_config.flagged_field.to_sym] != 'explicit'
if document[blacklight_config.index.display_type_field.to_sym] == 'OAIObject' || document[:exemplary_image_ssi].match(/oai/)
thumbnail_url(document)
else
Expand All @@ -67,7 +67,7 @@ def institution_icon_path

# override Blacklight::CatalogHelperBehavior: don't want to pull thumbnail url from Solr
def thumbnail_url(document)
if document[:exemplary_image_ssi] && !document[blacklight_config.flagged_field.to_sym]
if document[:exemplary_image_ssi] && document[blacklight_config.flagged_field.to_sym] != 'explicit'
datastream_disseminator_url(document[:exemplary_image_ssi], 'thumbnail300')
elsif document[:type_of_resource_ssim]
render_object_icon_path(document[:type_of_resource_ssim].first)
Expand Down
1 change: 1 addition & 0 deletions app/views/catalog/_show_default.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<% book_reader = has_searchable_text?(@document) ? true : false %>
<% video = has_video_files?(@object_files) %>
<% oai_object = @document[blacklight_config.show.display_type_field.to_sym] == 'OAIObject' ? true : false %>
<% if !book_reader && has_image_files?(@object_files) %>
<% case @object_files[:images].length %>
<% when 1 %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
</button>
</div>
<div id="flagged_warning_text" class="modal-body">
<div><strong>This item contains content that could be offensive to some viewers or inappropriate for minors.</strong></div>
<div>Click "View Content" to continue to the item or "Back to Search" to return to the search results page.</div>
<%= render partial: 'catalog/_show_partials/show_flagged_modal_text' %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-warning" data-dismiss="modal">View Content</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div><strong>This item contains content that could be offensive to some viewers or inappropriate for minors.</strong></div>
<div>Click "View Content" to continue to the item or "Back to Search" to return to the search results page.</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div id="flagged_content_warning" class="alert alert-warning">
<%= t('blacklight.flagged.warning') %>
</div>
11 changes: 8 additions & 3 deletions app/views/catalog/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<%# override so we can add flagged popup and render sidebar elsewhere %>
<% if @document[blacklight_config.flagged_field.to_sym] %>
<%= render partial: 'catalog/_show_partials/show_flagged_notice' %>
<%# override so we can add flagged behavior and render sidebar elsewhere %>
<% if show_explicit_warning?(@document) %>
<%= render partial: 'catalog/_show_partials/show_flagged_modal' %>
<% end %>
<% if show_content_warning?(@document) %>
<%= render partial: 'catalog/_show_partials/show_flagged_warning',
locals: { document: @document } %>
<% end %>
<%= render_document_main_content_partial %>
3 changes: 3 additions & 0 deletions config/locales/commonwealth-vlr-engine.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ en:
message: 'Message: '
topic: 'Topic: '

flagged:
warning: 'NOTICE: The item below may include offensive, harmful, or inappropriate imagery or language.'

formats:
page_title: 'Formats - %{application_name}'

Expand Down
10 changes: 10 additions & 0 deletions spec/features/catalog/_show_partials/_show_flagged_warning_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require 'rails_helper'

describe 'flagged item warning' do
it 'displays the flagged item warning' do
visit solr_document_path(id: 'bpl-dev:g445cd14k')
expect(page).to have_selector('#flagged_content_warning')
end
end
4 changes: 3 additions & 1 deletion spec/fixtures/sample_solr_documents.yml
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@
- bpl
harvesting_status_bsi:
- true
flagged_content_ssi:
- offensive
timestamp:
- '2015-07-31T15:11:28.837Z'
- system_create_dtsi:
Expand Down Expand Up @@ -803,7 +805,7 @@
exemplary_image_ssi:
- bpl-dev:000000086
flagged_content_ssi:
- true
- explicit
destination_site_ssim:
- commonwealth
- bpl
Expand Down
27 changes: 27 additions & 0 deletions spec/helpers/flagged_helper_behavior_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require 'rails_helper'

describe CommonwealthVlrEngine::FlaggedHelperBehavior do
let(:blacklight_config) { CatalogController.blacklight_config }

before(:each) do
allow(helper).to receive_messages(blacklight_config: blacklight_config)
end

describe '#show_explicit_warning?' do
let(:document) { SolrDocument.find('bpl-dev:00000007x') }

it 'returns true if the item is explicit' do
expect(helper.show_explicit_warning?(document)).to be_truthy
end
end

describe '#show_content_warning?' do
let(:document) { SolrDocument.find('bpl-dev:g445cd14k') }

it 'returns true if the item is offensive' do
expect(helper.show_content_warning?(document)).to be_truthy
end
end
end

0 comments on commit 965c330

Please sign in to comment.