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

pulibrary / orangelight / 4c391e0e-519a-40cb-8ad3-354445f4ce03

12 Aug 2025 08:47PM UTC coverage: 85.348% (-10.0%) from 95.335%
4c391e0e-519a-40cb-8ad3-354445f4ce03

push

circleci

web-flow
[#5143] Use access restriction note as Aeon ItemInfo1 if available (#5173)

With this commit, if a user visits a record with an access
restrictions note and presses the Reading Room Request
button, they will get to an Aeon form with the 'Restrictions'
field pre-filled with the restriction note.

If the record does not have an access restrictions note,
the field will be pre-filled with 'Reading Room Access Only',
as it has been previously.

Closes #5143

5493 of 6436 relevant lines covered (85.35%)

251.82 hits per line

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

97.14
/app/models/bookmark.rb
1
# frozen_string_literal: true
2

3
class Bookmark < ApplicationRecord
1✔
4
  belongs_to :user, polymorphic: true
1✔
5

6
  # TODO: remove the following scope, since as of
7
  # migration 20230419231330, the database layer
8
  # will not allow bookmarks without a valid user
9
  scope :without_valid_user, -> { where('user_id NOT IN (SELECT id FROM users)') }
1✔
10

11
  def document_type
1✔
12
    SolrDocument
×
13
  end
14

15
  def self.destroy_without_solr_documents
1✔
16
    batch_size = Orangelight.config["bookmarks"]["batch_size"]
3✔
17
    Bookmark.find_in_batches(batch_size:).with_index do |bookmarks, batch|
3✔
18
      Rails.logger.info { "Processing destroy_without_solr_documents group ##{batch}" }
6✔
19
      bookmark_doc_ids = bookmark_doc_ids(bookmarks)
3✔
20
      doc_ids_without_solr_doc = bookmark_doc_ids - doc_ids_in_solr(bookmark_doc_ids)
3✔
21

22
      if doc_ids_without_solr_doc.present?
3✔
23
        doc_ids_without_solr_doc.each do |doc_id|
2✔
24
          Bookmark.where(document_id: doc_id)&.destroy_all
2✔
25
        end
26
      end
27
    end
28
  end
29

30
  def self.update_to_alma_ids
1✔
31
    Bookmark.where("LENGTH(document_id) <= 7").find_in_batches.with_index do |bookmarks, batch|
5✔
32
      Rails.logger.info { "Processing update_to_alma_ids group ##{batch}" }
10✔
33
      bookmarks.each do |bookmark|
5✔
34
        bookmark.document_id = bookmark.voyager_to_alma_id
7✔
35
        bookmark.save if bookmark.changed?
7✔
36
      end
37
    end
38
  end
39

40
  def self.bookmark_doc_ids(bookmarks)
1✔
41
    bookmarks.map(&:document_id).to_set
3✔
42
  end
43

44
  def self.doc_ids_in_solr(bookmark_doc_ids)
1✔
45
    solr = Blacklight.default_index.connection
3✔
46
    rows = Orangelight.config["bookmarks"]["batch_size"]
3✔
47
    response = solr.get 'select', params: { fq: "{!terms f=id}#{bookmark_doc_ids.join(',')}", fl: 'id', rows: }
3✔
48
    response["response"]["docs"].map { |doc| doc["id"] }
6✔
49
  end
50

51
  def voyager_to_alma_id
1✔
52
    return document_id if alma_id?(document_id) || special_system_id?(document_id)
7✔
53

54
    "99#{document_id}3506421"
4✔
55
  end
56

57
  private
1✔
58

59
    def alma_id?(document_id)
1✔
60
      document_id.length > 7 && document_id.start_with?("99")
7✔
61
    end
62

63
    # If the document_id includes letters, it is not a Voyager or Alma ID
64
    # It may be a coin, SCSB, or DSpace ID
65
    def special_system_id?(document_id)
1✔
66
      document_id.match?(/[a-zA-Z]/)
7✔
67
    end
68
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