dor-rights-auth 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/dor/rights/auth.rb +2 -0
- data/lib/dor/rights_auth.rb +64 -40
- metadata +38 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f3461a34cc8edcf7b4362d1c6c58304bbe43a82fbd9edd16452ec02cf8a40204
|
4
|
+
data.tar.gz: 826e6ef53e3fec66cb97b1ab385793b9727ddc82bd81be1add9c46d285183303
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 196996c12540e5e17907865aabdff51c36afca65d59781d6cf08660d7c422b8bd26fefd699bc211c02ffc51e97ada62331fc19a701f5b39c5a9e15b90a1248f0
|
7
|
+
data.tar.gz: 9dd9fa090720a1f4cdf5f9673513153ae3d41a63b57aaac99385353f26c9e4d3e1fa0e8309d863d1c0f01ab29302a4b4def2ee0730336ee72ace62f920ab9477
|
data/lib/dor/rights/auth.rb
CHANGED
data/lib/dor/rights_auth.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'nokogiri'
|
2
4
|
require 'time'
|
3
5
|
|
@@ -8,7 +10,7 @@ module Dor
|
|
8
10
|
Rights = Struct.new(:value, :rule)
|
9
11
|
|
10
12
|
# Rights for an object or File
|
11
|
-
EntityRights = Struct.new(:world, :group, :agent, :location)
|
13
|
+
EntityRights = Struct.new(:world, :group, :agent, :location, :controlled_digital_lending)
|
12
14
|
# class EntityRights
|
13
15
|
# @world = #Rights
|
14
16
|
# @group {
|
@@ -18,6 +20,7 @@ module Dor
|
|
18
20
|
# 'app1' => #Rights,
|
19
21
|
# 'app2' => #Rights
|
20
22
|
# }
|
23
|
+
# @controlled_digital_lending = false
|
21
24
|
# end
|
22
25
|
|
23
26
|
# class Dor::RightsAuth
|
@@ -31,8 +34,8 @@ module Dor
|
|
31
34
|
# read rights_xml only once and create query-able methods for rights info
|
32
35
|
class RightsAuth
|
33
36
|
|
34
|
-
CONTAINS_STANFORD_XPATH = "contains(translate(text(), 'STANFORD', 'stanford'), 'stanford')"
|
35
|
-
NO_DOWNLOAD_RULE = 'no-download'
|
37
|
+
CONTAINS_STANFORD_XPATH = "contains(translate(text(), 'STANFORD', 'stanford'), 'stanford')"
|
38
|
+
NO_DOWNLOAD_RULE = 'no-download'
|
36
39
|
|
37
40
|
attr_accessor :obj_lvl, :file, :embargoed, :index_elements
|
38
41
|
|
@@ -94,6 +97,12 @@ module Dor
|
|
94
97
|
end
|
95
98
|
alias_method :public_downloadable?, :world_downloadable?
|
96
99
|
|
100
|
+
# Returns true if the object is enabled for controlled digital lending
|
101
|
+
# @return [Boolean]
|
102
|
+
def controlled_digital_lending?
|
103
|
+
@obj_lvl.controlled_digital_lending
|
104
|
+
end
|
105
|
+
|
97
106
|
# Returns true if the object is stanford-only readable AND has no rule attribute
|
98
107
|
# @return [Boolean]
|
99
108
|
def stanford_only_unrestricted?
|
@@ -112,6 +121,7 @@ module Dor
|
|
112
121
|
# @return [Boolean]
|
113
122
|
def agent_unrestricted?(agent_name)
|
114
123
|
return false unless @obj_lvl.agent.key? agent_name
|
124
|
+
|
115
125
|
@obj_lvl.agent[agent_name].value && @obj_lvl.agent[agent_name].rule.nil?
|
116
126
|
end
|
117
127
|
alias_method :allowed_read_agent?, :agent_unrestricted?
|
@@ -194,8 +204,8 @@ module Dor
|
|
194
204
|
# @return [Boolean] whether any location restrictions exist on the file or the
|
195
205
|
# object itself (in the absence of file-level rights)
|
196
206
|
def restricted_by_location?(file_name = nil)
|
197
|
-
any_file_location = @file[file_name]
|
198
|
-
any_object_location = @obj_lvl.location
|
207
|
+
any_file_location = @file[file_name]&.location&.any?
|
208
|
+
any_object_location = @obj_lvl.location&.any?
|
199
209
|
|
200
210
|
any_file_location || any_object_location
|
201
211
|
end
|
@@ -208,6 +218,7 @@ module Dor
|
|
208
218
|
# @note should be called after doing a check for world_unrestricted?
|
209
219
|
def agent_rights(agent_name)
|
210
220
|
return [false, nil] if @obj_lvl.agent[agent_name].nil?
|
221
|
+
|
211
222
|
[@obj_lvl.agent[agent_name].value, @obj_lvl.agent[agent_name].rule]
|
212
223
|
end
|
213
224
|
|
@@ -274,6 +285,7 @@ module Dor
|
|
274
285
|
# @return [Array] list of things that are wrong with it
|
275
286
|
def self.validate_lite(doc)
|
276
287
|
return ['no_rightsMetadata'] if doc.nil? || doc.at_xpath('//rightsMetadata').nil?
|
288
|
+
|
277
289
|
errors = []
|
278
290
|
maindiscover = doc.at_xpath("//rightsMetadata/access[@type='discover' and not(file)]")
|
279
291
|
mainread = doc.at_xpath("//rightsMetadata/access[@type='read' and not(file)]")
|
@@ -302,7 +314,10 @@ module Dor
|
|
302
314
|
def self.extract_index_terms(doc)
|
303
315
|
terms = []
|
304
316
|
machine = doc.at_xpath("//rightsMetadata/access[@type='read' and not(file)]/machine")
|
305
|
-
|
317
|
+
if doc.at_xpath("//rightsMetadata/access[@type='discover']/machine/none") ||
|
318
|
+
doc.at_xpath("//rightsMetadata/access[@type='discover']/machine[not(*)]")
|
319
|
+
terms.push 'none_discover'
|
320
|
+
end
|
306
321
|
terms.push 'world_discover' if doc.at_xpath("//rightsMetadata/access[@type='discover']/machine/world[not(@rule)]")
|
307
322
|
return terms if machine.nil?
|
308
323
|
|
@@ -323,15 +338,15 @@ module Dor
|
|
323
338
|
end
|
324
339
|
end
|
325
340
|
|
326
|
-
if doc.at_xpath("//rightsMetadata/access[@type='read' and file]/machine/none")
|
327
|
-
terms.push "none_read_file"
|
328
|
-
end
|
341
|
+
terms.push 'none_read_file' if doc.at_xpath("//rightsMetadata/access[@type='read' and file]/machine/none")
|
329
342
|
|
330
343
|
if machine.at_xpath('./none')
|
331
344
|
terms.push 'none_read'
|
332
345
|
elsif machine.at_xpath('./world')
|
333
346
|
terms.push 'world_read'
|
334
347
|
terms.push "world|#{machine.at_xpath('./world/@rule').value.downcase}" if machine.at_xpath('./world/@rule')
|
348
|
+
elsif machine.at_xpath('./cdl')
|
349
|
+
terms.push 'cdl_none'
|
335
350
|
end
|
336
351
|
|
337
352
|
# now some statistical generation
|
@@ -366,23 +381,23 @@ module Dor
|
|
366
381
|
def self.init_index_elements(doc)
|
367
382
|
errors = validate_lite(doc)
|
368
383
|
stuff = {
|
369
|
-
:primary
|
370
|
-
:errors
|
371
|
-
:terms
|
372
|
-
:obj_groups
|
373
|
-
:obj_locations
|
374
|
-
:obj_agents
|
375
|
-
:file_groups
|
376
|
-
:file_locations
|
377
|
-
:file_agents
|
378
|
-
:obj_world_qualified
|
379
|
-
:obj_groups_qualified
|
380
|
-
:obj_locations_qualified
|
381
|
-
:obj_agents_qualified
|
382
|
-
:file_world_qualified
|
383
|
-
:file_groups_qualified
|
384
|
+
:primary => nil,
|
385
|
+
:errors => errors,
|
386
|
+
:terms => [],
|
387
|
+
:obj_groups => [],
|
388
|
+
:obj_locations => [],
|
389
|
+
:obj_agents => [],
|
390
|
+
:file_groups => [],
|
391
|
+
:file_locations => [],
|
392
|
+
:file_agents => [],
|
393
|
+
:obj_world_qualified => [],
|
394
|
+
:obj_groups_qualified => [],
|
395
|
+
:obj_locations_qualified => [],
|
396
|
+
:obj_agents_qualified => [],
|
397
|
+
:file_world_qualified => [],
|
398
|
+
:file_groups_qualified => [],
|
384
399
|
:file_locations_qualified => [],
|
385
|
-
:file_agents_qualified
|
400
|
+
:file_agents_qualified => []
|
386
401
|
}
|
387
402
|
|
388
403
|
if errors.include? 'no_rightsMetadata'
|
@@ -404,6 +419,8 @@ module Dor
|
|
404
419
|
has_rule = index_terms.include? 'has_rule'
|
405
420
|
if index_terms.include?('none_discover')
|
406
421
|
'dark'
|
422
|
+
elsif index_terms.include?('cdl_none')
|
423
|
+
'controlled digital lending'
|
407
424
|
elsif errors.include?('no_discover_access') || errors.include?('no_discover_machine')
|
408
425
|
'dark'
|
409
426
|
elsif errors.include?('no_read_machine') || index_terms.include?('none_read')
|
@@ -440,7 +457,14 @@ module Dor
|
|
440
457
|
rights.obj_lvl.world.value = false
|
441
458
|
end
|
442
459
|
|
443
|
-
|
460
|
+
# TODO: we should also look for the <group rule="no-download">stanford</group> node and parse as needed
|
461
|
+
if doc.at_xpath("//rightsMetadata/access[@type='read' and not(file)]/machine/cdl")
|
462
|
+
rights.obj_lvl.controlled_digital_lending = true
|
463
|
+
else
|
464
|
+
rights.obj_lvl.controlled_digital_lending = false
|
465
|
+
end
|
466
|
+
|
467
|
+
rights.obj_lvl.group = { :stanford => Rights.new }
|
444
468
|
xpath = "//rightsMetadata/access[@type='read' and not(file)]/machine/group[#{CONTAINS_STANFORD_XPATH}]"
|
445
469
|
if doc.at_xpath(xpath)
|
446
470
|
rights.obj_lvl.group[:stanford].value = true
|
@@ -548,20 +572,20 @@ module Dor
|
|
548
572
|
end
|
549
573
|
|
550
574
|
if forindex
|
551
|
-
[
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
575
|
+
%i[obj_groups
|
576
|
+
obj_locations
|
577
|
+
obj_agents
|
578
|
+
file_groups
|
579
|
+
file_locations
|
580
|
+
file_agents
|
581
|
+
obj_world_qualified
|
582
|
+
obj_groups_qualified
|
583
|
+
obj_locations_qualified
|
584
|
+
obj_agents_qualified
|
585
|
+
file_world_qualified
|
586
|
+
file_groups_qualified
|
587
|
+
file_locations_qualified
|
588
|
+
file_agents_qualified].each { |index_elt| rights.index_elements[index_elt].uniq! }
|
565
589
|
end
|
566
590
|
|
567
591
|
rights
|
metadata
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dor-rights-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Willy Mene
|
8
8
|
- Joe Atzberger
|
9
|
+
- Johnathan Martin
|
10
|
+
- Naomi Dushay
|
9
11
|
autorequire:
|
10
12
|
bindir: bin
|
11
13
|
cert_chain: []
|
12
|
-
date:
|
14
|
+
date: 2020-08-26 00:00:00.000000000 Z
|
13
15
|
dependencies:
|
14
16
|
- !ruby/object:Gem::Dependency
|
15
17
|
name: nokogiri
|
@@ -25,6 +27,34 @@ dependencies:
|
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
27
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: codeclimate-test-reporter
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: coveralls
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
28
58
|
- !ruby/object:Gem::Dependency
|
29
59
|
name: rake
|
30
60
|
requirement: !ruby/object:Gem::Requirement
|
@@ -54,7 +84,7 @@ dependencies:
|
|
54
84
|
- !ruby/object:Gem::Version
|
55
85
|
version: '3.0'
|
56
86
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
87
|
+
name: rubocop
|
58
88
|
requirement: !ruby/object:Gem::Requirement
|
59
89
|
requirements:
|
60
90
|
- - ">="
|
@@ -68,7 +98,7 @@ dependencies:
|
|
68
98
|
- !ruby/object:Gem::Version
|
69
99
|
version: '0'
|
70
100
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
101
|
+
name: rubocop-rspec
|
72
102
|
requirement: !ruby/object:Gem::Requirement
|
73
103
|
requirements:
|
74
104
|
- - ">="
|
@@ -97,7 +127,7 @@ dependencies:
|
|
97
127
|
version: '0'
|
98
128
|
description: Parses rightsMetadata xml into a useable object
|
99
129
|
email:
|
100
|
-
-
|
130
|
+
- dlss-infrastructure-team@lists.stanford.edu
|
101
131
|
executables: []
|
102
132
|
extensions: []
|
103
133
|
extra_rdoc_files: []
|
@@ -120,17 +150,16 @@ require_paths:
|
|
120
150
|
- lib
|
121
151
|
required_ruby_version: !ruby/object:Gem::Requirement
|
122
152
|
requirements:
|
123
|
-
- - "
|
153
|
+
- - "~>"
|
124
154
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
155
|
+
version: '2.5'
|
126
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
157
|
requirements:
|
128
158
|
- - ">="
|
129
159
|
- !ruby/object:Gem::Version
|
130
160
|
version: 1.3.6
|
131
161
|
requirements: []
|
132
|
-
|
133
|
-
rubygems_version: 2.6.13
|
162
|
+
rubygems_version: 3.1.2
|
134
163
|
signing_key:
|
135
164
|
specification_version: 4
|
136
165
|
summary: Parses rightsMetadata xml into a useable object
|