dor-rights-auth 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dor/rights_auth.rb +98 -19
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81837a8bfa8d33081376601a6efeea90ecb80d3f
4
- data.tar.gz: a2131d7af706414648f74399efc22cdda0f4cf27
3
+ metadata.gz: 5cf8440dedbe7f16ab7b4c9e6ddb7b2915469fed
4
+ data.tar.gz: f9af60728a4c488eebfd37f4812cedc90f243675
5
5
  SHA512:
6
- metadata.gz: 1eddc3db3b13e12b7c20809622f28b4c088da471c08f2b0da4ea8a67e68583765c28cd3dd3a2c99f54b602af2e59a527d8875fd0649a0d4fd1c69c352f8745f3
7
- data.tar.gz: 3adfce85f7b21e86f70d73f1eefce1c1f04968f50efb057d4f5bac18c3fe082126cb2f83e474fba1cdae90783256f9b96d19c84a31d691e70cc380d81b3c695c
6
+ metadata.gz: 318fbc547f7abd9bd91dc0199b3f5acd71985c04324cb2cdf7ebee64e324e10687ec727475a4ecb9e5523ba8e970ef55904fc9a63133dc7f2fce8454d9255e15
7
+ data.tar.gz: df90d1277ddf87928a34ab995bbb596faaeb0c56b86f79f316a8589eb08e37154277b688dd69229dc98e0033c470c68242b7329aeb143364505fa0a2f9bed2dd
@@ -44,7 +44,7 @@ module Dor
44
44
 
45
45
  # Returns true if the object is under embargo.
46
46
  # @return [Boolean]
47
- def embargoed? # rubocop:disable Style/TrivialAccessors
47
+ def embargoed?
48
48
  @embargoed
49
49
  end
50
50
 
@@ -257,6 +257,17 @@ module Dor
257
257
  terms.push "group|#{machine.at_xpath('./group').value.downcase}"
258
258
  end
259
259
 
260
+ ['location', 'agent'].each do |access_type|
261
+ if machine.at_xpath("./#{access_type}")
262
+ terms.push access_type
263
+ terms.push "#{access_type}_with_rule" if machine.at_xpath("./#{access_type}")
264
+ end
265
+ end
266
+
267
+ if doc.at_xpath("//rightsMetadata/access[@type='read' and file]/machine/none")
268
+ terms.push "none_read_file"
269
+ end
270
+
260
271
  if machine.at_xpath('./none')
261
272
  terms.push 'none_read'
262
273
  elsif machine.at_xpath('./world')
@@ -293,12 +304,26 @@ module Dor
293
304
  # :errors => [...], # known error cases
294
305
  # :terms => [...] # array of non-error characterizations and stats strings
295
306
  # }
296
- def self.extract_access_rights(doc)
307
+ def self.init_index_elements(doc)
297
308
  errors = validate_lite(doc)
298
309
  stuff = {
299
- :primary => nil,
300
- :errors => errors,
301
- :terms => []
310
+ :primary => nil,
311
+ :errors => errors,
312
+ :terms => [],
313
+ :obj_groups => [],
314
+ :obj_locations => [],
315
+ :obj_agents => [],
316
+ :file_groups => [],
317
+ :file_locations => [],
318
+ :file_agents => [],
319
+ :obj_world_qualified => [],
320
+ :obj_groups_qualified => [],
321
+ :obj_locations_qualified => [],
322
+ :obj_agents_qualified => [],
323
+ :file_world_qualified => [],
324
+ :file_groups_qualified => [],
325
+ :file_locations_qualified => [],
326
+ :file_agents_qualified => []
302
327
  }
303
328
 
304
329
  if errors.include? 'no_rightsMetadata'
@@ -307,22 +332,31 @@ module Dor
307
332
  end
308
333
 
309
334
  stuff[:terms] = extract_index_terms(doc)
310
- has_rule = stuff[:terms].include? 'has_rule'
335
+ stuff[:primary] = primary_access_rights stuff[:terms], errors
311
336
 
312
- if stuff[:terms].include?('none_discover')
313
- stuff[:primary] = 'dark'
337
+ stuff
338
+ end
339
+
340
+ # "primary" access is a somewhat crude way of summarizing a whole
341
+ # object (possibly with many disparate interacting rights types)
342
+ # using one rights label. but it should still do a good job of capturing
343
+ # rights that make more sense at the object level (e.g. 'dark').
344
+ def self.primary_access_rights(index_terms, errors)
345
+ has_rule = index_terms.include? 'has_rule'
346
+ if index_terms.include?('none_discover')
347
+ 'dark'
314
348
  elsif errors.include?('no_discover_access') || errors.include?('no_discover_machine')
315
- stuff[:primary] = 'dark'
316
- elsif errors.include?('no_read_machine') || stuff[:terms].include?('none_read')
317
- stuff[:primary] = 'citation'
318
- elsif stuff[:terms].include? 'world_read'
319
- stuff[:primary] = has_rule ? 'world_qualified' : 'world'
320
- elsif stuff[:terms].include? 'group|stanford'
321
- stuff[:primary] = has_rule ? 'stanford_qualified' : 'stanford'
349
+ 'dark'
350
+ elsif errors.include?('no_read_machine') || index_terms.include?('none_read')
351
+ 'citation'
352
+ elsif index_terms.include? 'world_read'
353
+ has_rule ? 'world_qualified' : 'world'
354
+ elsif index_terms.include?('has_group_rights') ||
355
+ index_terms.include?('location') || index_terms.include?('agent')
356
+ has_rule ? 'access_restricted_qualified' : 'access_restricted'
322
357
  else # should never happen, but we might as well note it if it does
323
- stuff[:primary] = has_rule ? 'UNKNOWN_qualified' : 'UNKNOWN'
358
+ has_rule ? 'UNKNOWN_qualified' : 'UNKNOWN'
324
359
  end
325
- stuff
326
360
  end
327
361
 
328
362
  # Create a Dor::RightsAuth object from xml
@@ -335,22 +369,28 @@ module Dor
335
369
  rights.obj_lvl.world = Rights.new
336
370
 
337
371
  doc = xml.is_a?(Nokogiri::XML::Document) ? xml.clone : Nokogiri::XML(xml)
372
+
373
+ rights.index_elements = init_index_elements(doc) if forindex
374
+
338
375
  if doc.at_xpath("//rightsMetadata/access[@type='read' and not(file)]/machine/world")
339
376
  rights.obj_lvl.world.value = true
340
377
  rule = doc.at_xpath("//rightsMetadata/access[@type='read' and not(file)]/machine/world/@rule")
341
378
  rights.obj_lvl.world.rule = rule.value if rule
379
+ rights.index_elements[:obj_world_qualified] << { :rule => (rule ? rule.value : nil) } if forindex
342
380
  else
343
381
  rights.obj_lvl.world.value = false
344
382
  end
345
383
 
346
384
  rights.obj_lvl.group = { :stanford => Rights.new }
347
- rights.index_elements = extract_access_rights(doc) if forindex
348
-
349
385
  xpath = "//rightsMetadata/access[@type='read' and not(file)]/machine/group[#{CONTAINS_STANFORD_XPATH}]"
350
386
  if doc.at_xpath(xpath)
351
387
  rights.obj_lvl.group[:stanford].value = true
352
388
  rule = doc.at_xpath("#{xpath}/@rule")
353
389
  rights.obj_lvl.group[:stanford].rule = rule.value if rule
390
+ if forindex
391
+ rights.index_elements[:obj_groups_qualified] << { :group => 'stanford', :rule => (rule ? rule.value : nil) }
392
+ rights.index_elements[:obj_groups] << 'stanford'
393
+ end
354
394
  else
355
395
  rights.obj_lvl.group[:stanford].value = false
356
396
  end
@@ -361,6 +401,10 @@ module Dor
361
401
  r.value = true
362
402
  r.rule = node['rule']
363
403
  rights.obj_lvl.location[node.content] = r
404
+ if forindex
405
+ rights.index_elements[:obj_locations_qualified] << { :location => node.content, :rule => node['rule'] }
406
+ rights.index_elements[:obj_locations] << node.content
407
+ end
364
408
  end
365
409
 
366
410
  rights.obj_lvl.agent = {}
@@ -369,6 +413,10 @@ module Dor
369
413
  r.value = true
370
414
  r.rule = node['rule']
371
415
  rights.obj_lvl.agent[node.content] = r
416
+ if forindex
417
+ rights.index_elements[:obj_agents_qualified] << { :agent => node.content, :rule => node['rule'] }
418
+ rights.index_elements[:obj_agents] << node.content
419
+ end
372
420
  end
373
421
 
374
422
  # Initialze embargo_status to false
@@ -387,6 +435,11 @@ module Dor
387
435
  stanford_access.value = true
388
436
  rule = access_node.at_xpath("machine/group[#{CONTAINS_STANFORD_XPATH}]/@rule")
389
437
  stanford_access.rule = rule.value if rule
438
+ if forindex
439
+ rights.index_elements[:file_groups_qualified] <<
440
+ { :group => 'stanford', :rule => (rule ? rule.value : nil) }
441
+ rights.index_elements[:file_groups] << 'stanford'
442
+ end
390
443
  else
391
444
  stanford_access.value = false
392
445
  end
@@ -395,6 +448,7 @@ module Dor
395
448
  world_access.value = true
396
449
  rule = access_node.at_xpath('machine/world/@rule')
397
450
  world_access.rule = rule.value if rule
451
+ rights.index_elements[:file_world_qualified] << { :rule => (rule ? rule.value : nil) } if forindex
398
452
  else
399
453
  world_access.value = false
400
454
  end
@@ -405,6 +459,10 @@ module Dor
405
459
  r.value = true
406
460
  r.rule = node['rule']
407
461
  file_locations[node.content] = r
462
+ if forindex
463
+ rights.index_elements[:file_locations_qualified] << { :location => node.content, :rule => node['rule'] }
464
+ rights.index_elements[:file_locations] << node.content
465
+ end
408
466
  end
409
467
 
410
468
  file_agents = {}
@@ -413,6 +471,10 @@ module Dor
413
471
  r.value = true
414
472
  r.rule = node['rule']
415
473
  file_agents[node.content] = r
474
+ if forindex
475
+ rights.index_elements[:file_agents_qualified] << { :agent => node.content, :rule => node['rule'] }
476
+ rights.index_elements[:file_agents] << node.content
477
+ end
416
478
  end
417
479
 
418
480
  access_node.xpath('file').each do |f|
@@ -426,6 +488,23 @@ module Dor
426
488
  end
427
489
  end
428
490
 
491
+ if forindex
492
+ [:obj_groups,
493
+ :obj_locations,
494
+ :obj_agents,
495
+ :file_groups,
496
+ :file_locations,
497
+ :file_agents,
498
+ :obj_world_qualified,
499
+ :obj_groups_qualified,
500
+ :obj_locations_qualified,
501
+ :obj_agents_qualified,
502
+ :file_world_qualified,
503
+ :file_groups_qualified,
504
+ :file_locations_qualified,
505
+ :file_agents_qualified].each { |index_elt| rights.index_elements[index_elt].uniq! }
506
+ end
507
+
429
508
  rights
430
509
  end
431
510
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dor-rights-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willy Mene
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-06 00:00:00.000000000 Z
12
+ date: 2016-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  version: 1.3.6
132
132
  requirements: []
133
133
  rubyforge_project:
134
- rubygems_version: 2.4.5.1
134
+ rubygems_version: 2.4.8
135
135
  signing_key:
136
136
  specification_version: 4
137
137
  summary: Parses rightsMetadata xml into a useable object