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

pulibrary / orangelight / 8d8095ce-9c0c-4438-bc6d-2798f6207bce

13 Dec 2024 09:08PM UTC coverage: 96.4% (-0.02%) from 96.415%
8d8095ce-9c0c-4438-bc6d-2798f6207bce

Pull #4646

circleci

christinach
[#4641]Bring production to the state where we have client side validation errors

Co-authored-by: Jane Sandberg <sandbergja@users.noreply.github.com>
Pull Request #4646: [#4641]Bring production to the state where we have client side validation errors

6051 of 6277 relevant lines covered (96.4%)

1546.87 hits per line

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

97.96
/app/controllers/account_controller.rb
1
# frozen_string_literal: true
2
require './lib/orangelight/illiad_patron_client.rb'
3✔
3
require './lib/orangelight/illiad_account.rb'
3✔
4

5
class AccountController < ApplicationController
3✔
6
  include ApplicationHelper
3✔
7

8
  before_action :read_only_redirect, except: [:user_id]
3✔
9
  before_action :check_for_authentication_provider, except: [:user_id]
3✔
10
  before_action :verify_user, except: [:user_id]
3✔
11

12
  def index
3✔
13
    redirect_to digitization_requests_path
1✔
14
  end
15

16
  def digitization_requests
3✔
17
    set_patron
5✔
18
  end
19

20
  def cancel_ill_requests
3✔
21
    set_patron
3✔
22
    response = Orangelight::IlliadPatronClient.new(@patron).cancel_ill_requests(params[:cancel_requests]) unless params[:cancel_requests].nil?
3✔
23
    illiad_patron_client(@patron)
3✔
24
    respond_to do |format|
3✔
25
      if params[:cancel_requests].nil?
3✔
26
        format.js { flash.now[:error] = I18n.t('blacklight.account.cancel_no_items') }
2✔
27
      elsif cancel_ill_success(response)
2✔
28
        format.js { flash.now[:success] = I18n.t('blacklight.account.cancel_success') }
2✔
29
      else
30
        format.js { flash.now[:error] = I18n.t('blacklight.account.cancel_fail') }
2✔
31
      end
32
    end
33
  end
34

35
  def user_id
3✔
36
    render json: { user_id: current_user&.uid }
×
37
  end
38

39
  protected
3✔
40

41
    def read_only_redirect
3✔
42
      if Orangelight.read_only_mode
11✔
43
        flash[:notice] = 'Account login unavailable during maintenace.'
1✔
44
        redirect_to(root_url) && return
1✔
45
      end
46
    end
47

48
    def check_for_authentication_provider
3✔
49
      raise ActionController::RoutingError, 'Not Found' unless has_user_authentication_provider?
10✔
50
    end
51

52
    def verify_user
3✔
53
      unless current_user
10✔
54
        flash[:error] = I18n.t('blacklight.saved_searches.need_login') &&
1✔
55
                        raise(Blacklight::Exceptions::AccessDenied)
56
      end
57
    end
58

59
    ## For local dev purposes hardcode a net id string in place of current_user.uid
60
    ## in this method. Hacky, but convienent to see what "real" data looks like for
61
    ## edge case patrons.
62
    def set_patron
3✔
63
      @netid = current_user.uid
8✔
64
      @patron = current_patron(current_user)
8✔
65
      illiad_patron_client(@patron)
8✔
66
    end
67

68
    def illiad_patron_client(patron)
3✔
69
      @illiad_transactions = []
11✔
70
      return unless patron && current_user.cas_provider?
11✔
71

72
      @illiad_account = Orangelight::IlliadAccount.new(patron)
9✔
73
      return unless @illiad_account.verify_user
9✔
74

75
      @illiad_transactions = Orangelight::IlliadPatronClient.new(patron).outstanding_ill_requests
8✔
76
    end
77

78
    def cancel_ill_success(response)
3✔
79
      bodies = response.map { |rep| JSON.parse(rep.body) }
4✔
80
      bodies.reject { |body| body['TransactionStatus'] =~ /^Cancelled/ }.empty?
4✔
81
    end
82

83
  private
3✔
84

85
    def current_patron(user)
3✔
86
      Bibdata.get_patron(user, ldap: false)
12✔
87
    end
88
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