• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / orangelight / 0e37073d-109c-440c-949f-49d2aa86311b

18 Aug 2025 09:05PM UTC coverage: 0.482% (-94.9%) from 95.343%
0e37073d-109c-440c-949f-49d2aa86311b

push

circleci

web-flow
Replace per_page_options_for_select with custom component to avoid deprecation issue (#5186)

* Start creating new component to address deprecaton warning

* Replace per_page_options_for_select with custom component to avoid deprecation issue

Co-authored-by: Jane Sandberg <sandbergja@users.noreply.github.com>

---------

Co-authored-by: Ryan Jensen <rj1044@princeton.edu>
Co-authored-by: Jane Sandberg <sandbergja@users.noreply.github.com>

0 of 33 new or added lines in 1 file covered. (0.0%)

9374 existing lines in 213 files now uncovered.

47 of 9753 relevant lines covered (0.48%)

0.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/controllers/requests/form_controller.rb
1
# frozen_string_literal: true
UNCOV
2
require 'faraday'
×
3

UNCOV
4
include Requests::ApplicationHelper
×
5

UNCOV
6
module Requests
×
UNCOV
7
  class FormController < ApplicationController
×
UNCOV
8
    before_action :authenticate_user!, except: [:index], unless: -> { aeon? }
×
9

UNCOV
10
    def index
×
UNCOV
11
      redirect_to('/')
×
UNCOV
12
    end
×
13

UNCOV
14
    def generate
×
UNCOV
15
      system_id = sanitize(params[:system_id])
×
UNCOV
16
      mfhd = sanitize(params[:mfhd])
×
UNCOV
17
      params.require(:mfhd) unless system_id.starts_with?("SCSB") # there are not multiple locations for shared items so no MFHD is passed
×
UNCOV
18
      @back_to_record_url = BackToRecordUrl.new(params)
×
19

UNCOV
20
      @user = current_or_guest_user
×
21

UNCOV
22
      @patron = Patron.authorize(user: @user)
×
UNCOV
23
      patron_errors = @patron.errors
×
UNCOV
24
      flash.now[:error] = patron_errors.join(", ") if patron_errors.present?
×
25

UNCOV
26
      @title = "Request ID: #{system_id}"
×
27

28
      # needed to see if we can suppress login for this item
UNCOV
29
      @request = FormDecorator.new(Requests::Form.new(system_id:, mfhd:, patron: @patron), view_context, @back_to_record_url)
×
UNCOV
30
    rescue ActionController::ParameterMissing
×
UNCOV
31
      render 'requests/form/no_location_specified'
×
UNCOV
32
    end
×
33

UNCOV
34
    def aeon?
×
UNCOV
35
      return true if params["aeon"] == 'true'
×
36

UNCOV
37
      false
×
UNCOV
38
    end
×
39

40
    # will post and a JSON document of selected "requestable" objects with selection parameters and
41
    # user information for further processing and distribution to various request endpoints.
UNCOV
42
    def submit
×
UNCOV
43
      @submission = Requests::Submission.new(sanitize_submission(params), Patron.new(user: current_or_guest_user))
×
UNCOV
44
      respond_to do |format|
×
UNCOV
45
        format.js do
×
UNCOV
46
          valid = @submission.valid?
×
UNCOV
47
          @services = @submission.process_submission if valid
×
UNCOV
48
          if valid && @submission.service_errors.blank?
×
UNCOV
49
            respond_to_submit_success(@submission)
×
UNCOV
50
          elsif valid # submission was valid, but service failed
×
UNCOV
51
            respond_to_service_error(@services)
×
UNCOV
52
          else
×
UNCOV
53
            respond_to_validation_error(@submission)
×
UNCOV
54
          end
×
UNCOV
55
        end
×
UNCOV
56
      end
×
UNCOV
57
    end
×
58

UNCOV
59
    private
×
60

UNCOV
61
      def mode
×
62
        return 'standard' if params[:mode].nil?
×
63
        sanitize(params[:mode])
×
UNCOV
64
      end
×
65

66
      # trusted params
UNCOV
67
      def request_params
×
68
        params.permit(:id, :system_id, :mfhd, :user_name, :email, :loc_code, :user, :requestable, :request, :barcode, :isbns).permit!
×
UNCOV
69
      end
×
70

UNCOV
71
      def sanitize_submission(params)
×
UNCOV
72
        params[:requestable].each do |requestable|
×
UNCOV
73
          params['user_supplied_enum'] = sanitize(requestable['user_supplied_enum']) if requestable.key? 'user_supplied_enum'
×
UNCOV
74
        end
×
UNCOV
75
        lparams = params.permit(bib: [:id, :title, :author, :isbn, :date])
×
UNCOV
76
        lparams[:requestable] = params[:requestable].map do |requestable|
×
UNCOV
77
          json_pick_up = requestable[:pick_up]
×
UNCOV
78
          requestable = requestable.merge(JSON.parse(json_pick_up)) if json_pick_up.present?
×
UNCOV
79
          requestable.permit!
×
UNCOV
80
        end
×
UNCOV
81
        lparams
×
UNCOV
82
      end
×
83

UNCOV
84
      def respond_to_submit_success(submission)
×
UNCOV
85
        flash.now[:success] = submission.success_messages.join(' ')
×
86
        # TODO: Why does this go into an infinite loop
87
        # logger.info "#Request Submission - #{submission.as_json}"
UNCOV
88
        logger.info "Request Sent"
×
UNCOV
89
      end
×
90

UNCOV
91
      def respond_to_service_error(services)
×
UNCOV
92
        errors = services.map(&:errors).flatten
×
UNCOV
93
        error_types = errors.pluck(:type).uniq
×
UNCOV
94
        flash.now[:error] = if error_types.include?("digitize")
×
UNCOV
95
                              errors[error_types.index("digitize")][:error]
×
UNCOV
96
                            else
×
UNCOV
97
                              I18n.t('requests.submit.service_error')
×
UNCOV
98
                            end
×
UNCOV
99
        logger.error "Request Service Error"
×
UNCOV
100
        service_errors = services.map(&:error_hash).inject(:merge)
×
UNCOV
101
        send_error_email(service_errors, @submission)
×
UNCOV
102
      end
×
103

UNCOV
104
      def respond_to_validation_error(submission)
×
UNCOV
105
        flash.now[:error] = I18n.t('requests.submit.error')
×
UNCOV
106
        logger.error "Request Submission #{submission.errors.messages.as_json}"
×
UNCOV
107
      end
×
108

UNCOV
109
      def sanitize(str)
×
UNCOV
110
        str.gsub(/[^A-Za-z0-9@\-_\.]/, '') if str.is_a? String
×
UNCOV
111
        str
×
UNCOV
112
      end
×
113

114
      # This has to be a utility function to prevent ActiveJob from trying to serialize too many objects
115
      # :reek:UtilityFunction
UNCOV
116
      def send_error_email(errors, submission)
×
UNCOV
117
        Requests::RequestMailer.send("service_error_email", errors, submission.to_h).deliver_later
×
UNCOV
118
      end
×
UNCOV
119
  end
×
UNCOV
120
end
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc