diff --git a/.env.development b/.env.development index ba127777..38019897 100644 --- a/.env.development +++ b/.env.development @@ -44,10 +44,6 @@ SCHOLAR_ANALYTICS_PRIVKEY_PATH=analytics_privkey_path SCHOLAR_ANALYTICS_PRIVKEY_SECRET=analytics_privkey_secret SCHOLAR_ANALYTICS_CLIENT_EMAIL=analytics_client_email -# Google Re-captcha -SCHOLAR_CAPTCHA_SITE_KEY=captcha_site_key -SCHOLAR_CAPTCHA_SECRET_KEY=captcha_secret_key - # ORCID ORCID_AUTHORIZE_URL=change_me ORCID_APP_ID=change_me diff --git a/.env.test b/.env.test index 80fc5ec4..adf36754 100644 --- a/.env.test +++ b/.env.test @@ -43,10 +43,6 @@ SCHOLAR_ANALYTICS_PRIVKEY_PATH=analytics_privkey_path SCHOLAR_ANALYTICS_PRIVKEY_SECRET=analytics_privkey_secret SCHOLAR_ANALYTICS_CLIENT_EMAIL=analytics_client_email -# Google Re-captcha -SCHOLAR_CAPTCHA_SITE_KEY=captcha_site_key -SCHOLAR_CAPTCHA_SECRET_KEY=captcha_secret_key - # ORCID ORCID_AUTHORIZE_URL=change_me ORCID_APP_ID=change_me @@ -77,4 +73,4 @@ SCHOLAR_DOI_URL=https://api.test.datacite.org/dois API_KEY={ :development => 'testKey'} # XRay max log size in MB, must be an integer value -SCHOLAR_XRAY_MAX_LOG_SIZE=10 \ No newline at end of file +SCHOLAR_XRAY_MAX_LOG_SIZE=10 diff --git a/app/assets/stylesheets/hyrax.scss b/app/assets/stylesheets/hyrax.scss index e55f2d1f..2bf36c6d 100644 --- a/app/assets/stylesheets/hyrax.scss +++ b/app/assets/stylesheets/hyrax.scss @@ -32,11 +32,6 @@ padding-bottom: 10px; } -.g-recaptcha { - margin-bottom: 20px; -} - - div.profile a.btn-primary { margin-bottom: 20px; } diff --git a/app/controllers/hyrax/contact_form_controller.rb b/app/controllers/hyrax/contact_form_controller.rb deleted file mode 100644 index aa599ab1..00000000 --- a/app/controllers/hyrax/contact_form_controller.rb +++ /dev/null @@ -1,60 +0,0 @@ -# frozen_string_literal: false - -module Hyrax - class ContactFormController < ApplicationController - extend ActiveSupport::Concern - before_action :build_contact_form - - def new; end - - def create - # not spam and a valid form - if @contact_form.valid? && passes_captcha_or_is_logged_in? - Hyrax::ContactMailer.contact(@contact_form).deliver_now - flash.now[:notice] = 'Thank you for your message!' - after_deliver - @contact_form = ContactForm.new - else - flash.now[:error] = 'Sorry, this message was not sent successfully. ' - flash.now[:error] << 'You must complete the Captcha to confirm the form. ' unless passes_captcha_or_is_logged_in? - flash.now[:error] << @contact_form.errors.full_messages.map(&:to_s).join(", ") - end - render :new - rescue RuntimeError => exception - handle_create_exception(exception) - end - - 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 - - # Override this method if you want to perform additional operations - # when a email is successfully sent, such as sending a confirmation - # response to the user. - def after_deliver; end - - def verify_google_recaptcha(key, response) - status = `curl "https://www.google.com/recaptcha/api/siteverify?secret=#{key}&response=#{response}"` - hash = JSON.parse(status) - hash["success"] == true - end - - protected - - def build_contact_form - @contact_form = Hyrax::ContactForm.new(contact_form_params) - end - - def contact_form_params - return {} unless params.key?(:contact_form) - params.require(:contact_form).permit(:contact_method, :category, :name, :email, :subject, :message) - end - - def passes_captcha_or_is_logged_in? - return true if current_user.present? - verify_google_recaptcha(CAPTCHA_SERVER['secret_key'], params["g-recaptcha-response"]) - end - end -end diff --git a/app/models/hyrax/contact_form.rb b/app/models/hyrax/contact_form.rb deleted file mode 100644 index c9335800..00000000 --- a/app/models/hyrax/contact_form.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true -module Hyrax - class ContactForm - include ActiveModel::Model - attr_accessor :contact_method, :category, :name, :email, :subject, :message - validates :email, :name, :subject, :message, presence: true - validates :email, format: /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i, allow_blank: true - - # - can't use this without ActiveRecord::Base validates_inclusion_of :category, in: self.class.issue_types_for_locale - - # They should not have filled out the `contact_method' field. That's there to prevent spam. - def spam? - contact_method.present? - end - - # Declare the e-mail headers. It accepts anything the mail method - # in ActionMailer accepts. - def headers - { - subject: "#{Hyrax.config.subject_prefix} #{subject}", - to: Hyrax.config.contact_email, - from: email - } - end - - def self.issue_types_for_locale - [ - I18n.t('hyrax.contact_form.issue_types.depositing'), - I18n.t('hyrax.contact_form.issue_types.changing'), - I18n.t('hyrax.contact_form.issue_types.browsing'), - I18n.t('hyrax.contact_form.issue_types.reporting'), - I18n.t('hyrax.contact_form.issue_types.general') - ] - end - end -end diff --git a/app/views/hyrax/contact_form/_directions.html.erb b/app/views/hyrax/contact_form/_directions.html.erb deleted file mode 100644 index eb6b09da..00000000 --- a/app/views/hyrax/contact_form/_directions.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= t('hyrax.contact_form.notice_html', href: link_to(t("hyrax.contact_form.help_resources_href"), main_app.help_path)) %> diff --git a/app/views/hyrax/contact_form/new.html.erb b/app/views/hyrax/contact_form/new.html.erb index a8df4174..0825b817 100644 --- a/app/views/hyrax/contact_form/new.html.erb +++ b/app/views/hyrax/contact_form/new.html.erb @@ -1,47 +1,97 @@ - -
- <%= render 'directions' %> -
-

- <%= t('hyrax.contact_form.header') %> -

- -<% if user_signed_in? %> - <% nm = current_user.name %> - <% em = current_user.email %> -<% else %> - <% nm = '' %> - <% em = '' %> -<% end %> - -<%= form_for @contact_form, url: hyrax.contact_form_index_path, - html: { class: 'form-horizontal' } do |f| %> - <%= f.text_field :contact_method, class: 'hide' %> - -
- <%= f.label :name, t('hyrax.contact_form.name_label'), class: "col-sm-2 control-label" %> -
<%= f.text_field :name, value: nm, class: 'form-control', required: true %>
-
- -
- <%= f.label :email, t('hyrax.contact_form.email_label'), class: "col-sm-2 control-label" %> -
<%= f.text_field :email, value: em, class: 'form-control', required: true %>
-
- -
- <%= f.label :subject, t('hyrax.contact_form.subject_label'), class: "col-sm-2 control-label" %> -
<%= f.text_field :subject, class: 'form-control', required: true %>
-
- -
- <%= f.label :message, t('hyrax.contact_form.message_label'), class: "col-sm-2 control-label" %> -
<%= f.text_area :message, rows: 4, class: 'form-control', required: true %>
-
- - <% if current_user.blank? %> -
- <% end %> - - <%= f.submit value: t('hyrax.contact_form.button_label'), class: "btn btn-primary" %> -<% end %> + + diff --git a/config/initializers/hyrax.rb b/config/initializers/hyrax.rb index 83f82b56..a8d248bc 100644 --- a/config/initializers/hyrax.rb +++ b/config/initializers/hyrax.rb @@ -28,10 +28,10 @@ # config.admin_set_predicate = ::RDF::DC.isPartOf # Email recipient of messages sent via the contact form - config.contact_email = "scholar@uc.edu" + # config.contact_email = "scholar@uc.edu" # Text prefacing the subject entered in the contact form - config.subject_prefix = "Scholar@UC Contact form:" + # config.subject_prefix = "Scholar@UC Contact form:" # How many notifications should be displayed on the dashboard # config.max_notifications_for_dashboard = 5 diff --git a/config/initializers/load_captcha_configs.rb b/config/initializers/load_captcha_configs.rb deleted file mode 100644 index 8fbf89e4..00000000 --- a/config/initializers/load_captcha_configs.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -CAPTCHA_SERVER = YAML.safe_load(ERB.new(File.read(Rails.root.join('config', 'recaptcha.yml'))).result)[Rails.env] diff --git a/config/locales/hyrax.en.yml b/config/locales/hyrax.en.yml index 17e86122..81a39842 100644 --- a/config/locales/hyrax.en.yml +++ b/config/locales/hyrax.en.yml @@ -98,10 +98,6 @@ en: results_per_page: Results per page sort_by: Sort by works_in_collection: Items in this Collection - contact_form: - header: Contact the Scholar@UC Team - notice_html: 'Please us this form to send questions, feedback, or report a problem to the Scholar@UC team. You can also check %{href} for more information' - help_resources_href: 'Help Resources' file_sets: show_details: fixity_check: Fixity Check diff --git a/config/recaptcha.yml b/config/recaptcha.yml deleted file mode 100644 index bb64e721..00000000 --- a/config/recaptcha.yml +++ /dev/null @@ -1,11 +0,0 @@ -# stores ReCaptcha image server url - -development: - site_key: <%= ENV["SCHOLAR_CAPTCHA_SITE_KEY"] %> - secret_key: <%= ENV["SCHOLAR_CAPTCHA_SECRET_KEY"] %> -test: - site_key: <%= ENV["SCHOLAR_CAPTCHA_SITE_KEY"] %> - secret_key: <%= ENV["SCHOLAR_CAPTCHA_SECRET_KEY"] %> -production: - site_key: <%= ENV["SCHOLAR_CAPTCHA_SITE_KEY"] %> - secret_key: <%= ENV["SCHOLAR_CAPTCHA_SECRET_KEY"] %> diff --git a/spec/controllers/hyrax/contact_form_controller_spec.rb b/spec/controllers/hyrax/contact_form_controller_spec.rb deleted file mode 100644 index ecce82cf..00000000 --- a/spec/controllers/hyrax/contact_form_controller_spec.rb +++ /dev/null @@ -1,122 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe Hyrax::ContactFormController do - routes { Hyrax::Engine.routes } - let(:user) { create(:user) } - let(:required_params) do - { - category: "Depositing content", - name: "Gandalf the Grey", - email: "gandalf@middle.earth", - subject: "When in doubt,", - message: "Follow your nose!" - } - end - - describe 'while user is unauthenticated' do - it 'successfully allows reCaptcha' do - described_class.any_instance.stub(:verify_google_recaptcha).and_return(true) - Hyrax::ContactMailer.any_instance.stub(:mail).and_return(true) - post :create, params: { contact_form: required_params } - expect(flash[:notice]).to match(/Thank you for your message/) - end - - it 'fails on reCaptcha failure' do - post :create, params: { contact_form: required_params } - expect(flash[:error]).to match(/You must complete the Captcha to confirm the form/) - end - end - - describe "while user is authenticated" do - before { sign_in(user) } - - describe "#new" do - subject { response } - - before { get :new } - it { is_expected.to be_success } - end - - describe "#create" do - subject { flash } - - before { post :create, params: { contact_form: params } } - context "with the required parameters" do - let(:params) { required_params } - - its(:notice) { is_expected.to eq("Thank you for your message!") } - end - - context "without a name" do - let(:params) { required_params.except(:name) } - - its([:error]) { is_expected.to eq("Sorry, this message was not sent successfully. Name can't be blank") } - end - - context "without an email" do - let(:params) { required_params.except(:email) } - - its([:error]) { is_expected.to eq("Sorry, this message was not sent successfully. Email can't be blank") } - end - - context "without a subject" do - let(:params) { required_params.except(:subject) } - - its([:error]) { is_expected.to eq("Sorry, this message was not sent successfully. Subject can't be blank") } - end - - context "without a message" do - let(:params) { required_params.except(:message) } - - its([:error]) { is_expected.to eq("Sorry, this message was not sent successfully. Message can't be blank") } - end - - context "with an invalid email" do - let(:params) { required_params.merge(email: "bad-wolf") } - - its([:error]) { is_expected.to eq("Sorry, this message was not sent successfully. Email is invalid") } - end - end - - describe "#after_deliver" do - context "with a successful email" do - it "calls #after_deliver" do - expect(controller).to receive(:after_deliver) - post :create, params: { contact_form: required_params } - end - end - context "with an unsuccessful email" do - it "does not call #after_deliver" do - expect(controller).not_to receive(:after_deliver) - post :create, params: { contact_form: required_params.except(:email) } - end - end - end - - describe "test configuration values" do - context "for the contact form" do - it "check contact email" do - expect(Hyrax.config.contact_email).to eq 'scholar@uc.edu' - end - it "check form name" do - expect(Hyrax.config.subject_prefix).to eq 'Scholar@UC Contact form:' - end - end - end - - context "when encoutering a RuntimeError" do - let(:logger) { double(info?: true) } - - before do - allow(controller).to receive(:logger).and_return(logger) - allow(Hyrax::ContactMailer).to receive(:contact).and_raise(RuntimeError) - end - it "is logged via Rails" do - expect(logger).to receive(:error).with("Contact form failed to send: #") - post :create, params: { contact_form: required_params } - end - end - end -end diff --git a/spec/features/hyrax/contact_form_spec.rb b/spec/features/hyrax/contact_form_spec.rb index 2ef2bb2a..779753d2 100644 --- a/spec/features/hyrax/contact_form_spec.rb +++ b/spec/features/hyrax/contact_form_spec.rb @@ -3,31 +3,12 @@ require 'rails_helper' RSpec.describe "Sending an email via the contact form", type: :feature do - let(:user) { create(:user) } - - describe "with unauthenticated user" do + describe "with Jot Iframe" do it "shows recaptcha dialog" do visit '/' click_link "Contact", match: :first - expect(page).to have_css('div.g-recaptcha') - end - end - - describe "with authenticated user" do - before { sign_in(user) } - - it "sends mail" do - visit '/' - click_link "Contact", match: :first - expect(page).to have_content "Contact the Scholar@UC Team" - expect(page).to have_link "Help Resources" - expect(page).not_to have_content "Issue Type" - fill_in "Your Name", with: "Test McPherson" - fill_in "Your Email", with: "archivist1@example.com" - fill_in "Message", with: "I am contacting you regarding ScholarSphere." - fill_in "Subject", with: "My Subject is Cool" - click_button "Send" - expect(page).to have_content "Thank you for your message!" + expect(page).to have_css('iframe') + page.html.should include('') end end end