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

curationexperts / laevigata / 0d10b93f-7d12-4108-bfd7-303659b33b6c

18 Jun 2025 03:38AM UTC coverage: 97.41% (-0.001%) from 97.411%
0d10b93f-7d12-4108-bfd7-303659b33b6c

Pull #2464

circleci

mark-dce
Disable embargo expiration notifications

Per discussions with SCO, they wish to reduce administrative overhead
by eliminating embargo expiration notifications.

We still need to process actual embargo expirations to change the
corresponding ETDs from a restricted to open status.

Therefore, this change leaves the schedule and service code in place
and simply comments out the calls to notification processing so that
we still get nightly expiration processing.
Pull Request #2464: Disable embargo expiration notifications

4 of 4 new or added lines in 1 file covered. (100.0%)

43 existing lines in 7 files now uncovered.

2821 of 2896 relevant lines covered (97.41%)

52.23 hits per line

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

100.0
/app/services/visibility_translator.rb
1
##
2
# Determines visibily for a given Etd.
3
#
4
# Etd visibility is extended from `Hyrax` and `Hydra::AccessControls` to
5
# include three additional visibility levels:
6
#
7
#   - `VisibilityTranslator::FILES_EMBARGOED`: indicates that the work is
8
#     under embargo, but that it is discoverable (not `restricted`/private).
9
#     FileSets that are members of the work should be under a parallel embargo,
10
#     making tthem private until the embargo end date.
11
#   - `VisibilityTranslator::TOC_EMBARGOED`: indicates that the work is
12
#     under embargo, as described above, and that the table of contents should
13
#     be suppressed for the duration of the embargo.
14
#   - `VisibilityTranslator::ALL_EMBARGOED`: indicates that the work is
15
#     under embargo, as described above, and that the table of contents *and*
16
#     abstract should be suppressed for the duration of the embargo.
17
#
18
# @see Hydra::AccessControls::Visibility
19
class VisibilityTranslator
4✔
20
  RESTRICTED      = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
4✔
21
  ALL_EMBARGOED   = 'all_restricted'.freeze
4✔
22
  FILES_EMBARGOED = 'files_restricted'.freeze
4✔
23
  TOC_EMBARGOED   = 'toc_restricted'.freeze
4✔
24
  OPEN            = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
4✔
25

26
  ##
27
  # @!attribute [rw] obj
28
  #   @return [FileSet]
29
  attr_accessor :obj
4✔
30

31
  ##
32
  # @param [FileSet] obj
33
  def initialize(obj:)
4✔
34
    self.obj = obj
2,369✔
35
  end
36

37
  def self.visibility(obj:)
4✔
38
    new(obj: obj).visibility
2✔
39
  end
40

41
  # There are visibility bugs caused by setting the value of obj.abstract_embargoed
42
  # to "true" (a String) instead of true (a Boolean). This is only true for works
43
  # created in Hyrax 1.x, but it's enough of our content under management that we need
44
  # to account for it.
45
  # When checking whether a value is true, check whether it has a "true" string too.
46
  def embargo_type
4✔
47
    return OPEN             if embargo_length_none?(obj)
487✔
48
    return ALL_EMBARGOED    if obj.abstract_embargoed.to_s == "true"
455✔
49
    return TOC_EMBARGOED    if obj.toc_embargoed.to_s == "true"
68✔
50
    return FILES_EMBARGOED  if obj.files_embargoed.to_s == "true"
51✔
51

52
    Rails.logger.error("Invalid embargo values. Returning RESTRICTED for ID: #{obj.id}")
32✔
53
    RESTRICTED
32✔
54
  end
55

56
  # When an object (ETD) is not under embargo, pass through to Hyrax visibility  via the proxy.
57
  # When an embargo is present or the object is hidden due to workflow settings,
58
  # return visibility based on the embargo_type determined by the ebmargo booleans
59
  def visibility
4✔
60
    return proxy.visibility if obj.hidden? || !obj.under_embargo?
1,590✔
61

62
    embargo_type
474✔
63
  end
64

65
  def visibility=(value)
4✔
66
    case value
395✔
67
    when FILES_EMBARGOED
68
      raise(InvalidVisibilityError.new('Invalid embargo visibility level:', value, obj)) unless
69
        obj.under_embargo?
9✔
70

71
      obj.files_embargoed    = true
7✔
72
      obj.toc_embargoed      = false
7✔
73
      obj.abstract_embargoed = false
7✔
74
      proxy.visibility       = OPEN
7✔
75
    when TOC_EMBARGOED
76
      raise(InvalidVisibilityError.new('Invalid embargo visibility level:', value, obj)) unless
77
        obj.under_embargo?
7✔
78

79
      obj.files_embargoed    = true
4✔
80
      obj.toc_embargoed      = true
4✔
81
      obj.abstract_embargoed = false
4✔
82
      proxy.visibility       = OPEN
4✔
83
    when ALL_EMBARGOED
84
      raise(InvalidVisibilityError.new('Invalid embargo visibility level:', value, obj)) unless
UNCOV
85
        obj.under_embargo?
5✔
86

UNCOV
87
      obj.files_embargoed    = true
3✔
UNCOV
88
      obj.toc_embargoed      = true
3✔
UNCOV
89
      obj.abstract_embargoed = true
3✔
UNCOV
90
      proxy.visibility       = OPEN
3✔
91
    else
92
      proxy.visibility = value
374✔
93
    end
94
  end
95

96
  def proxy
4✔
97
    VisibilityProxy.new(obj)
1,876✔
98
  end
99

100
  def embargo_length_none?(obj)
4✔
101
    # cast length to a String in case obj is a SolrDocument and obj.embargo_length is an arrray
102
    length = obj.embargo_length.to_s
487✔
103
    Rails.logger.warn "Treating nil embargo_length as open for ID: #{obj.id}" if length.empty?
487✔
104
    if length.empty? || length.downcase.include?('none')
487✔
105
      if obj.abstract_embargoed.to_s == "true" || obj.toc_embargoed.to_s == "true" || obj.files_embargoed.to_s == "true"
32✔
106
        Rails.logger.error "Boolean embargo values conflict with embargo_length in ID: #{obj.id}"
17✔
107
      end
108

109
      return true
32✔
110
    end
111

112
    false
455✔
113
  end
114

115
  class InvalidVisibilityError < ArgumentError
4✔
116
    def initialize(msg = 'Invalid visibility level:', level = nil, obj = nil)
4✔
117
      @level = level
7✔
118
      @obj   = obj
7✔
119
      @msg   = msg + " #{level}\nNo embargo is set on #{obj ? obj.id : 'the object'}."
7✔
120
    end
121

122
    def message
4✔
123
      @msg
1✔
124
    end
125
  end
126

127
  ##
128
  # Determines the value of the default `#visibility` method as implemented in
129
  # `Hydra::AccessControls::Visibility` for the provided `source`. Since we
130
  # expect this method to be overridden in `pcdm_object`s passed to
131
  # `VisibilityTranslator`, we need a proxy object to ensure we can access the
132
  # original implementation.
133
  #
134
  # @example
135
  #   my_model = ModelWithCustomVisibility.new
136
  #   my_model.visibility # => 'some custom value`
137
  #   VisibilityTranslator::VisibilityProxy.new(my_model).visibility # => 'open'
138
  #
139
  # @see Hydra::AccessControls::Visibility
140
  class VisibilityProxy
4✔
141
    extend Forwardable
4✔
142
    include Hydra::AccessControls::Visibility
4✔
143

144
    def_delegator :@original, :read_groups
4✔
145
    def_delegator :@original, :set_read_groups
4✔
146

147
    def initialize(original)
4✔
148
      @original = original
1,876✔
149
    end
150
  end
151
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