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

Submit biased results feedback #3822

Merged
merged 26 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9e20b8d
Started adding the form to submit biased results feedback
hectorcorrea Nov 8, 2023
810e779
Created a sample feedback form.
hectorcorrea Nov 8, 2023
33ed16a
Use form helpers for biased search results
leefaisonr Nov 9, 2023
bc994bb
Pass the search terms to the biased results form
hectorcorrea Nov 9, 2023
5271caf
Pass the entire query string from the search results to the biased re…
hectorcorrea Nov 9, 2023
0a47ce5
Merge branch 'main' into 3789-biased-results-form
Seanwarren77 Nov 14, 2023
7d224a8
First attempt at creating a modal form for reporting biased results. …
sdellis Nov 14, 2023
8d2298d
Fix routing
leefaisonr Nov 15, 2023
6f6ec47
Modal now works; added tests for the Form; updated config files
sdellis Nov 15, 2023
7c99311
Started a feature test for the modal form for reporting biased results
sdellis Nov 15, 2023
94c831f
Get the query out of the form
leefaisonr Nov 15, 2023
8950167
Moved test to controller tests
kelynch Nov 15, 2023
5a3e745
Added a link to the current search
leefaisonr Nov 15, 2023
d5155c6
rubocop corrections
leefaisonr Nov 15, 2023
102ef38
Adjust routes for form submission
leefaisonr Nov 16, 2023
e181449
Get test passing
sandbergja Nov 16, 2023
7b9b94e
Convert biased results form to simple_form and fix styling
sandbergja Nov 16, 2023
88f99af
Work toward passing full search query string in context
hackartisan Nov 16, 2023
b496c0b
Splits search query into separate parameters for safety and convenience
sdellis Nov 16, 2023
8909ea5
Render context into url and fix test
hackartisan Nov 16, 2023
4db209c
Remove `q` from report biased results form
hackartisan Nov 16, 2023
3c19d78
Pass the full url you're coming from
hackartisan Nov 16, 2023
8b99da7
Add integration test that email gets sent
hackartisan Nov 16, 2023
cd5b71f
Make search results link open in new tab
kelynch Nov 17, 2023
51321ed
Added indication that link opens in a new tab
kelynch Nov 20, 2023
f6212a7
Merge pull request #3842 from pulibrary/3789-biased-results-form-c
sandbergja Nov 20, 2023
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
4 changes: 4 additions & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,10 @@ def citation
end
end

def report_biased_results_form; end

def biased_results_submit; end

private

def render_empty_search
Expand Down
15 changes: 15 additions & 0 deletions app/controllers/contact_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ def report_harmful_language
end
end

def report_biased_results
@form = ReportBiasedResultsForm.new(report_biased_results_params)
if @form.valid? && @form.submit
flash[:success] = 'Your report has been submitted'

render "report_biased_results_success"
else
render partial: "catalog/report_biased_results_form", locals: { form: @form }, status: :unprocessable_entity
end
end

private

def question_params
Expand All @@ -46,4 +57,8 @@ def suggestion_params
def report_harmful_language_params
params[:report_harmful_language_form].permit!
end

def report_biased_results_params
params[:report_biased_results_form].permit!
end
end
17 changes: 17 additions & 0 deletions app/controllers/feedback_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class FeedbackController < ApplicationController
before_action :build_ask_a_question_form, only: [:ask_a_question]
before_action :build_suggest_correction_form, only: [:suggest_correction]
before_action :build_report_harmful_language_form, only: [:report_harmful_language]
before_action :build_report_biased_results_form, only: [:report_biased_results]

def new
@feedback_form = FeedbackForm.new if @feedback_form.nil?
Expand All @@ -31,6 +32,8 @@ def suggest_correction; end

def report_harmful_language; end

def report_biased_results; end

protected

def build_feedback_form
Expand Down Expand Up @@ -76,6 +79,20 @@ def harmful_language_params
params.require(:report_harmful_language_form).permit(:id, :title)
end

def build_report_biased_results_form
@biased_results_form = ReportBiasedResultsForm.new(
biased_results_params
)
end

def biased_results_params
params.require(:report_biased_results_form).permit(:context)
end

def search_results_url(_params)
search_catalog_url(q: biased_results_params['q'])
end

def page_url(params)
solr_document_url(id: params['id'])
end
Expand Down
33 changes: 33 additions & 0 deletions app/forms/report_biased_results_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true
class ReportBiasedResultsForm < MailForm::Base
include ActiveModel::Model
attr_accessor :name, :email, :message, :context

validates :message, presence: true
attribute :feedback_desc, captcha: true

def email_subject
"[Possible Biased Results]"
end

def submit
ContactMailer.with(form: self).biased_results.deliver unless spam?
@submitted = true
@name = ""
@email = ""
@message = ""
end

def submitted?
@submitted == true
end

def routed_mail_to
Orangelight.config["report_biased_results_form"]["to"]
end

# If the form does not include an email, use the routed_mail_to email for the "from" field
def from_email
@from_email ||= @email.presence || routed_mail_to
end
end
5 changes: 5 additions & 0 deletions app/mailers/contact_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ def harmful_language
@form = params[:form]
mail(to: @form.routed_mail_to, from: @form.from_email, subject: @form.email_subject)
end

def biased_results
@form = params[:form]
mail(to: @form.routed_mail_to, from: @form.from_email, subject: @form.email_subject)
end
end
43 changes: 43 additions & 0 deletions app/views/catalog/_report_biased_results_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<div class="modal-body">
<%= render :partial=>'shared/flash_msg' %>
<div>
Library holdings and catalog search results can reflect discriminatory attitudes and assumptions.
<br/>
<br/>
You can help us address this issue by reporting any biased or harmful results you encounter on Library search tools by using the form below. If you would prefer to report this anonomously, you may leave the name end email fields blank.
<br/>
<br/>
You are reporting bias in the following <%= link_to 'search results <i class="fa fa-external-link new-tab-icon-padding" aria-label="opens in new tab" role="img"></i>'.html_safe, form.context, target: '_blank', title: 'opens in a new tab' %>
<br/>
<br/>
</div>

<%= simple_form_for(
form,
url: contact_report_biased_results_path,
data: { blacklight_modal: 'trigger' },
html: { class: "modal_form" }
) do |f|
%>
<div>
<%= f.label :message %><br>
<%= f.input_field :message, as: :text, style: "width: 100%" %><br>
</div>

<div>
<%= f.label :name, style: "width: 100%", label: 'Name (optional)' %><br>
<%= f.input_field :name, style: "width: 100%" %><br>
</div>

<div>
<%= f.label :email, label: 'Email (optional)' %><br>
<%= f.input_field :email, style: "width: 100%" %><br>
</div>

<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<%= f.submit "Send", class: "btn btn-primary", id: 'submit-question' %>
</div>
<% end %>

</div>
1 change: 0 additions & 1 deletion app/views/catalog/_search_results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@
<%- else %>
<%= render_document_index @response.documents %>
<%- end %>

<%= render 'results_pagination' %>
15 changes: 14 additions & 1 deletion app/views/catalog/_search_results_banner.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
<div id="results-banner-text">
<h3>Do these search results seem biased?</h3>
We are working to address bias in the library's search results. If these results
appear biased, please let us know!
appear biased,
<%= link_to(
'please let us know',
{
controller: "feedback",
action: "report_biased_results",
report_biased_results_form: {
context: request.original_url
}
},
title: "Report Biased Results",
class: "report-biased-results",
data: { blacklight_modal: 'trigger' }
) %>!
</div>
</div>
10 changes: 10 additions & 0 deletions app/views/contact/report_biased_results_success.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%= render Blacklight::System::ModalComponent.new do |component| %>
<% component.title { t('blacklight.report_harmful_language.form.title') } %>

<%= render partial: '/shared/flash_msg' %>
<p>Thank you for helping us identify an instance of bias in our Catalog Search Results.
Staff will review your report and assess options to address this based on your feedback.
If you have submitted your email address, we may reach out to you if we have questions.
We appreciate your feedback.</p>

<% end %>
5 changes: 5 additions & 0 deletions app/views/contact_mailer/biased_results.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Name: <%= @form.name %><br>
Email: <%= @form.email %><br>
Subject: <%= @form.email_subject %><br>
Context: <%= @form.context %><br>
Comments: <%= @form.message %><br>
8 changes: 8 additions & 0 deletions app/views/feedback/report_biased_results.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%= render Blacklight::System::ModalComponent.new do |component| %>
<% component.title { t('blacklight.report_biased_results.form.title') } %>
<% component.body do %>
<%= render partial: "catalog/report_biased_results_form",
locals: { form: @biased_results_form }
%>
<% end %>
<% end %>
3 changes: 3 additions & 0 deletions config/locales/blacklight.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ en:
report_harmful_language:
form:
title: 'Report Harmful Language'
report_biased_results:
form:
title: 'Report Biased Results'
email:
form:
title: 'Email the catalog record and (optional) message.'
Expand Down
6 changes: 6 additions & 0 deletions config/orangelight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ defaults: &defaults
to: <%= ENV['OL_CATALOGING_TO'] %>
report_harmful_language_form:
to: <%= ENV['OL_HARMFUL_CONTENT_TO'] %>
report_biased_results_form:
to: <%= ENV['OL_BIASED_RESULTS_TO'] %>
firestone_locator_base_url: https://locator-prod.princeton.edu
redis:
host: 'localhost'
Expand All @@ -34,6 +36,8 @@ development:
to: '[email protected]'
report_harmful_language_form:
to: '[email protected]'
report_biased_results_form:
to: '[email protected]'
test:
<<: *defaults
feedback_form:
Expand All @@ -49,6 +53,8 @@ test:
to: '[email protected]'
report_harmful_language_form:
to: '[email protected]'
report_biased_results_form:
to: '[email protected]'

production:
<<: *defaults
Expand Down
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
get "/report_harmful_language", to: "feedback#report_harmful_language"
post "/contact/report_harmful_language", to: "contact#report_harmful_language"

# For "Reporting Biased Search Results" form
# TODO: change get route to '/report_biased_results'
get '/feedback/biased_results', to: 'feedback#report_biased_results', as: 'feedback_biased_results'
post '/contact/report_biased_results', to: 'contact#report_biased_results'

get '/thumbnail/:id', to: 'thumbnail#show'

# error pages
Expand Down
11 changes: 11 additions & 0 deletions solr/conf/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,17 @@
<field name="title_display" type="text" indexed="true" stored="true" multiValued="false"/>
<field name="title_vern_display" type="text" indexed="true" stored="true" multiValued="false"/>

<!-- this field is required to be explicitly defined for search highlighing -->
<field name="author_display" type="text" indexed="true" stored="true" multiValued="true"/>
<field name="subject_display" type="text" indexed="true" stored="true" multiValued="true"/>
<field name="lc_subject_display" type="text" indexed="true" stored="true" multiValued="true"/>
<field name="siku_subject_display" type="text" indexed="true" stored="true" multiValued="true"/>
<field name="homoit_subject_display" type="text" indexed="true" stored="true" multiValued="true"/>
<field name="lcgft_s" type="text" indexed="true" stored="true" multiValued="true"/>
<field name="homoit_genre_s" type="text" indexed="true" stored="true" multiValued="true"/>
<field name="rbgenr_s" type="text" indexed="true" stored="true" multiValued="true"/>
<field name="aat_s" type="text" indexed="true" stored="true" multiValued="true"/>
<field name="notes_display" type="text" indexed="true" stored="true" multiValued="true"/>

<!-- these fields are also used for display, so they must be stored -->
<field name="isbn_t" type="isbn" indexed="true" stored="true" multiValued="true"/>
Expand Down
3 changes: 2 additions & 1 deletion solr/conf/solrconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@
<!-- HighlightComponent using unified highlighter -->
<str name="hl">true</str>
<str name="hl.method">unified</str>
<str name="hl.fl">author_display title_display title_vern_display</str>
<str name="hl.fl">author_display title_display title_vern_display subject_display lc_subject_display siku_subject_display homoit_subject_display lcgft_s homoit_genre_s rbgenr_s aat_s notes_display</str>
<str name="hl.usePhraseHighlighter">false</str>

<!-- boost local holdings (add 50 to the score) to reduce unnecessary requests -->
<str name="bf">if(field(numeric_id_b),50,0)</str>
Expand Down
11 changes: 11 additions & 0 deletions spec/controllers/feedback_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,15 @@
expect(response).to be_successful
end
end

describe "#report_biased_results" do
it "routes to the Report Biased Results form" do
get :report_biased_results, params: {
report_biased_results_form: {
q: "cats"
}
}
expect(response).to be_successful
end
end
end
33 changes: 33 additions & 0 deletions spec/features/feedback_biased_results_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require 'rails_helper'

describe 'submitting biased results', js: true do
before do
allow(Flipflop).to receive(:search_result_form?).and_return(true)
end

it 'shows the search query with facets and submits the form' do
stub_holding_locations
visit '/catalog'
fill_in('q', with: 'roman')
click_on('search')
click_on('Manuscript')
click_link('please let us know')

expect(page).to have_link('search results', href: "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}/?f%5Bformat%5D%5B%5D=Manuscript&q=roman&search_field=all_fields")
# accessible close icon
# expect(page).to have_selector '.icon-moveback[aria-hidden="true"]'

# form fields
fill_in('Name (optional)', with: 'John Smith')
fill_in('Email (optional)', with: '[email protected]')
fill_in('Message', with: 'Lorem ipsum dolor sit amet, consectetur...')

click_on('Send')

expect(page).to have_content('Your report has been submitted')
expect(page).to have_content('Thank you for helping us identify an instance of bias in our Catalog Search Results.')
expect(ActionMailer::Base.deliveries.length).to eq 1
end
end
Loading