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

Create a Accessibility Remediation Request Form #2696

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .rubocop_fix_me.yml
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ RSpec/NestedGroups:
Exclude:
- "spec/models/default_spec.rb"
- "spec/controllers/hyrax/contact_form_controller_spec.rb"
- "spec/controllers/scholars_archive/accessibility_request_form_controller_spec.rb"

RSpec/ExpectInHook:
Exclude:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module ScholarsArchive
# CLASS: Torrent Form Recaptcha Controller
module AccessibilityRequestFormRecaptchaBehavior
# METHOD: Check the recaptcha to see if verify or not
def check_recaptcha
if is_recaptcha?
if verify_recaptcha(model: @accessibility_request_form)
true
else
flash[:error] = 'Captcha did not verify properly.'
false
end
else
true
end
end

# METHOD: A check method to see if recaptcha exist
# rubocop:disable Naming/PredicateName
def is_recaptcha?
Hyrax.config.recaptcha?
end
# rubocop:enable Naming/PredicateName
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

module ScholarsArchive
# CLASS: Accessibility Request Form Controller
class AccessibilityRequestFormController < ApplicationController
# ACTION: Before page load, build the form with all the params
include ScholarsArchive::AccessibilityRequestFormRecaptchaBehavior
before_action :build_accessibility_request_form
invisible_captcha only: [:create]
layout 'homepage'

def new; end

# rubocop:disable Metrics/MethodLength
def create
# CHECK: See if the form is valid
if @accessibility_form.valid?
# IF: If recaptcha present, then send the email and reload the new form for submission
if check_recaptcha
ScholarsArchive::AccessibilityFormMailer.auto_contact(@accessibility_form).deliver_now
ScholarsArchive::AccessibilityFormMailer.admin_contact(@accessibility_form).deliver_now
flash.now[:notice] = t('hyrax.accessibility_request_form.success_email')
after_deliver
@accessibility_form = ScholarsArchive::AccessibilityRequestForm.new
end
else
flash.now[:error] = t('hyrax.accessibility_request_form.failed_email')
end
render :new
rescue RuntimeError => e
handle_create_exception(e)
end
# rubocop:enable Metrics/MethodLength

# METHOD: Create a handler for the exception
def handle_create_exception(exception)
logger.error("Contact form failed to send: #{exception.inspect}")
flash.now[:error] = 'Sorry, this message was not delivered.'
render :new
end

# NOTE: Override if needed to perform after email delivery
def after_deliver; end

private

# METHOD: Create a new form with all the params
def build_accessibility_request_form
@accessibility_form = ScholarsArchive::AccessibilityRequestForm.new(accessibility_request_form_params)
end

# METHOD: Permits all the required params
def accessibility_request_form_params
return {} unless params.key?(:scholars_archive_accessibility_request_form)

params.require(:scholars_archive_accessibility_request_form).permit(:accessibility_method, :email, :name, :url_link, :details, :additional, :phone, :date)
end
end
end
24 changes: 24 additions & 0 deletions app/mailers/scholars_archive/accessibility_form_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module ScholarsArchive
# CLASS: Accessibility Form Mailer for contacting the administrator & depositor request
class AccessibilityFormMailer < ApplicationMailer
# METHOD: A method to send an auto confirmation email
def auto_contact(accessibility_form)
@accessibility_form = accessibility_form
# Check for spam
return if @accessibility_form.spam?

mail(@accessibility_form.auto_headers)
end

# METHOD: A method to send an confirmation email to admin
def admin_contact(accessibility_form)
@accessibility_form = accessibility_form
# Check for spam
return if @accessibility_form.spam?

mail(@accessibility_form.headers)
end
end
end
37 changes: 37 additions & 0 deletions app/models/scholars_archive/accessibility_request_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

module ScholarsArchive
# CLASS: Accessibility Request Form Model
class AccessibilityRequestForm
include ActiveModel::Model
# ADD: Add in accessors to map out on field that will be use in the form
attr_accessor :accessibility_method, :email, :name, :url_link, :details, :additional, :phone, :date

# VALIDATION: Add in validation to these variables to check before pass the form
validates :email, :name, :url_link, :details, presence: true
validates :email, format: /\A([\w.%+-]+)@([\w-]+\.)+(\w{2,})\z/i, allow_blank: true

# SPAM: Check to make sure this section isn't fill, if so, it might be a spam
def spam?
accessibility_method.present?
end

# HEADER: Declare the e-mail headers. It accepts anything the mail method in ActionMailer accepts
def headers
{
subject: 'Scholars Archive Accessibility Request Form: Request on Work',
to: Hyrax.config.contact_email,
from: email
}
end

# HEADER: Declare the e-mail headers. It accepts anything the mail method in ActionMailer accepts
def auto_headers
{
subject: 'Scholars Archive Accessibility Request Form: Request Confirmation',
to: email,
from: Hyrax.config.contact_email
}
end
end
end
2 changes: 2 additions & 0 deletions app/views/hyrax/base/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
<div class="col-sm-3 text-center">
<%= render 'representative_media', presenter: @presenter, viewer: false unless @presenter.universal_viewer? %>
<%= render 'citations', presenter: @presenter %>
<%# ADD: Add a new render field for accessibility request %>
<%= render 'scholars_archive/base/accessibility_request' %>
<%= render 'social_media' %>
</div>
<div class="col-sm-9">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p>Dear Admin,</p>
<p>One of the user: <%= @accessibility_form.name%>, is asking to request an accessibility on one of the work on Scholars Archive.</p>
<br/>
<p>Here is a copy of the information that was provided about this request:</p>
<br/>
<p>User's Email: <%= @accessibility_form.email %></p>
<p>Item's Link: <%= @accessibility_form.url_link %></p>
<p>Request Detail: <%= @accessibility_form.details %></p>
<p>Additional Detail: <%= @accessibility_form.additional.blank? ? 'None' : @accessibility_form.additional %></p>
<p>Date Needed: <%= @accessibility_form.date.blank? ? 'None' : @accessibility_form.date %></p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<p>Dear <%= @accessibility_form.name %>,</p>
<p>Your accessibility remediation request has been received and is being routed to the OSU Libraries team who manages this type of content. We will reach out if we have any follow up questions and/or when we have completed your request.</p>
<br/>
<p>Here is a copy of the information you provided about this request:</p>
<br/>
<p>Item's Link: <%= @accessibility_form.url_link %></p>
<p>Request Detail: <%= @accessibility_form.details %></p>
<p>Additional Detail: <%= @accessibility_form.additional.blank? ? 'None' : @accessibility_form.additional %></p>
<p>Date Needed: <%= @accessibility_form.date.blank? ? 'None' : @accessibility_form.date %></p>
78 changes: 78 additions & 0 deletions app/views/scholars_archive/accessibility_request_form/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<h1>
<%= t('hyrax.accessibility_request_form.header') %>
</h1>

<p>
ScholarsArchive@OSU has long accepted scholarly content from the OSU community in many formats. We are aware that not all items in the repository are fully accessible to all of our users at this time, and we are working hard to bring all content up to the standards outlined in OSU’s Digital Accessibility Policy. For more information about this work, see the OSU Libraries Accessibility Statement [coming soon].
<br/><br/>
To request a remediated version of inaccessible content, such as a PDF document or media file, please complete the form below and OSU Libraries staff will accommodate your request. Some types of remediation take a substantial amount of staff time, so please give as much advance notice as possible.
<br/><br/>
If you are looking for help with a different topic in ScholarsArchive@OSU, use the Contact Us form.
</p>

<br/>

<h2>
<%= t('hyrax.accessibility_request_form.sub_header') %>
</h2>
<p>
Fields marked with <span style="color:red"> * </span> are required.
</p>

<%# FORM: Create the form view page to submit the accessibility form %>
<%= form_for @accessibility_form, url: accessibility_request_form_index_path,
html: { class: 'form-horizontal' } do |f| %>
<%# HIDDEN FIELD: This field is hidden to check for spam %>
<%= f.text_field :accessibility_method, class: 'hide' %>

<%# NAME: Set the naming box %>
<div class="form-group">
<p> <%= f.label :name, t('hyrax.accessibility_request_form.name'), class: "control-label" %> <span style="color:red"> * </span> </p>
<div class="accessibility-name"><%= f.text_field :name, value: user_signed_in? ? current_user.name : '', class: 'form-control', required: true %></div>
</div>

<%# EMAIL: Set the email layout to enter in email, if login use their email %>
<div class="form-group">
<p> <%= f.label :email, t('hyrax.accessibility_request_form.email'), class: "control-label" %> <span style="color:red"> * </span> </p>
<div class="accessibility-email"><%= f.text_field :email, value: user_signed_in? ? current_user.email : '', class: 'form-control', required: true %></div>
</div>

<%# PHONE: Provide the phone number option %>
<div class="form-group">
<%= f.label :phone, t('hyrax.accessibility_request_form.phone'), class: "control-label" %>
<div class="accessibility-phone"><%= f.text_field :phone, value: '', class: 'form-control' %></div>
</div>

<%# LINK: Provide the link to let user gives the link to access accessibility %>
<div class="form-group">
<p> <%= f.label :url_link, t('hyrax.accessibility_request_form.link'), class: "control-label" %> <span style="color:red"> * </span> </p>
<div class="accessibility-url-link"><%= f.text_field :url_link, value: '', class: 'form-control', required: true %></div>
<p><em>Please include the full link to the item that you would like us to remediate.</em></p>
</div>

<%# DESCRIPTION: Provide the detail about the accessibility %>
<div class="form-group">
<p> <%= f.label :details, t('hyrax.accessibility_request_form.details'), class: "control-label" %> <span style="color:red"> * </span> </p>
<div class="accessibility-details"><%= f.text_area :details, value: '', rows: 4, class: 'form-control', required: true %></div>
<p><em>Please describe the type of accommodation that you need (for example, written transcription, compatibility with a particular assistive device, preferred file formats, etc.). Include details about what particular parts of the content are inaccessible, if applicable.</em></p>
</div>

<%# DESCRIPTION: Provide the additional detail about the accessibility %>
<div class="form-group">
<%= f.label :additional, t('hyrax.accessibility_request_form.additional'), class: "control-label" %>
<div class="accessibility-additional"><%= f.text_area :additional, value: '', rows: 4, class: 'form-control' %></div>
<p><em>List any other ScholarsArchive@OSU items you would like remediated as part of this request.</em></p>
</div>

<%# DATE: Provide the date needed for request %>
<div class="form-group">
<%= f.label :date, t('hyrax.accessibility_request_form.date'), class: "control-label" %>
<div class="accessibility-date"><%= f.text_field :date, value: '', class: 'form-control' %></div>
<p><em>If you need this item by a particular date, let us know and we will do our best to deliver by your deadline.</em></p>
</div>

<%# CAPTCHA: Add in the captcha on form %>
<%= recaptcha_tags if Hyrax.config.recaptcha? %>
<%= invisible_captcha %>
<%= f.submit value: t('hyrax.accessibility_request_form.button'), class: "btn btn-primary" %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%# VIEW: Add in a new view that has a button to guide to a form on request %>
<div class="accessibility-request">
<%= link_to "Request Accessible Version", polymorphic_path([main_app, :accessibility_request]), id: 'accessibility-request', 'aria-label': 'Request Accessible Version', class: 'btn btn-default' %>
</div>
13 changes: 13 additions & 0 deletions config/locales/hyrax.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ en:
general: General inquiry or request
reporting: Reporting a problem
statistic: Requesting download statistics
accessibility_request_form:
button: Send
email: Your Email
name: Your Name
phone: Your Phone
link: Link to the Item
details: Request Details
additional: Additional Items Requested
date: Date Needed
header: Accessibility Remediation Request Form
sub_header: Accessibility Request
success_email: Thank you for your message!
failed_email: Sorry, this message was not sent successfully.
dashboard:
proxies_heading: "Manage Proxies"
proxies_explainer: "ScholarsArchive@OSU allows users to have a proxy user deposit content on their behalf. If you would like to have a proxy user, please search for them below and add them as a proxy."
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,7 @@
end

# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
# ACCESSIBILITY REQUEST FORM ROUTE: Setup the routes for the accessibility form
get 'accessibility_request', to: 'scholars_archive/accessibility_request_form#new', controller: 'scholars_archive/accessibility_request_form'
post 'accessibility_request', to: 'scholars_archive/accessibility_request_form#create', as: :accessibility_request_form_index, controller: 'scholars_archive/accessibility_request_form'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe ScholarsArchive::AccessibilityRequestFormController, type: :controller do
let(:user) { User.new(email: '[email protected]', guest: false) { |u| u.save!(validate: false) } }
let(:required_params) do
{
email: '[email protected]',
name: 'Test Name',
url_link: 'www.test.com',
details: 'test detail',
additional: 'additional detail',
phone: '123456789',
date: 'Test Date'
}
end

let(:accessibility_form) { ScholarsArchive::AccessibilityRequestForm.new(required_params) }

routes { Hyrax::Engine.routes }

before do
sign_in(user)
end

# TEST #1: Check if recaptcha work on the controller
describe '#check_recaptcha' do
before do
controller.instance_variable_set(:@accessibility_form, accessibility_form)
end

context 'when recaptcha is enabled' do
let(:params) { required_params }

before do
allow(controller).to receive(:is_recaptcha?).and_return(true)
end

context 'with the recaptcha is not verified' do
before do
allow(controller).to receive(:verify_recaptcha).and_return(false)
end

it 'returns false and throws an error' do
expect(controller.check_recaptcha).to eq(false)
end
end

context 'with the recaptcha is verified' do
before do
allow(controller).to receive(:verify_recaptcha).and_return(true)
end

it 'returns a true value' do
expect(controller.check_recaptcha).to eq(true)
end
end
end

context 'when recaptcha is not enabled' do
let(:params) { required_params }

before do
allow(controller).to receive(:is_recaptcha?).and_return(false)
end

it 'returns true and processes the email normally' do
expect(controller.check_recaptcha).to eq(true)
end
end
end
end