Class: Dor::RightsAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/dor/rights_auth.rb

Overview

read rights_xml only once and create query-able methods for rights info

Constant Summary collapse

CONTAINS_STANFORD_XPATH =
"contains(translate(text(), 'STANFORD', 'stanford'), 'stanford')"
NO_DOWNLOAD_RULE =
'no-download'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRightsAuth

NOTE: index_elements is only valid for the xml as parsed, not after subsequent manipulation



44
45
46
47
48
# File 'lib/dor/rights_auth.rb', line 44

def initialize
  @file = {}
  @index_elements = {}
  @embargoed = false
end

Instance Attribute Details

#embargo_release_dateObject

Returns the value of attribute embargo_release_date.



40
41
42
# File 'lib/dor/rights_auth.rb', line 40

def embargo_release_date
  @embargo_release_date
end

#embargoedObject

Returns the value of attribute embargoed.



40
41
42
# File 'lib/dor/rights_auth.rb', line 40

def embargoed
  @embargoed
end

#fileObject

Returns the value of attribute file.



40
41
42
# File 'lib/dor/rights_auth.rb', line 40

def file
  @file
end

#index_elementsObject

Returns the value of attribute index_elements.



40
41
42
# File 'lib/dor/rights_auth.rb', line 40

def index_elements
  @index_elements
end

#obj_lvlObject

Returns the value of attribute obj_lvl.



40
41
42
# File 'lib/dor/rights_auth.rb', line 40

def obj_lvl
  @obj_lvl
end

Class Method Details

.extract_index_terms(doc) ⇒ Array<String>

Assemble various characterizing terms for index from XML

Parameters:

  • doc (Nokogiri::XML)

    the rightsMetadata document

Returns:

  • (Array<String>)

    Strings of interest to the Solr index



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/dor/rights_auth.rb', line 321

def self.extract_index_terms(doc)
  terms = []
  machine = doc.at_xpath("//rightsMetadata/access[@type='read' and not(file)]/machine")
  if doc.at_xpath("//rightsMetadata/access[@type='discover']/machine/none") ||
     doc.at_xpath("//rightsMetadata/access[@type='discover']/machine[not(*)]")
    terms.push 'none_discover'
  end
  terms.push 'world_discover' if doc.at_xpath("//rightsMetadata/access[@type='discover']/machine/world[not(@rule)]")
  return terms if machine.nil?

  terms.push 'has_group_rights' if machine.at_xpath('./group')
  terms.push 'has_rule' if machine.at_xpath('.//@rule')

  if machine.at_xpath("./group[#{CONTAINS_STANFORD_XPATH}]")
    terms.push 'group|stanford'
    terms.push 'group|stanford_with_rule' if machine.at_xpath("./group[@rule and #{CONTAINS_STANFORD_XPATH}]")
  elsif machine.at_xpath('./group')
    terms.push "group|#{machine.at_xpath('./group').value.downcase}"
  end

  ['location', 'agent'].each do |access_type|
    if machine.at_xpath("./#{access_type}")
      terms.push access_type
      terms.push "#{access_type}_with_rule" if machine.at_xpath("./#{access_type}")
    end
  end

  terms.push 'none_read_file' if doc.at_xpath("//rightsMetadata/access[@type='read' and file]/machine/none")

  if machine.at_xpath('./none')
    terms.push 'none_read'
  elsif machine.at_xpath('./world')
    terms.push 'world_read'
    terms.push "world|#{machine.at_xpath('./world/@rule').value.downcase}" if machine.at_xpath('./world/@rule')
  elsif machine.at_xpath('./cdl')
    terms.push 'cdl_none'
  end

  # now some statistical generation
  names = machine.element_children.collect(&:name)
  kidcount = names.each_with_object(Hash.new(0)) { |word, counts| counts[word] += 1 }
  countphrase = kidcount.sort.collect { |k, v| "#{k}#{v}" }.join('|')
  terms.push 'profile:' + countphrase unless countphrase.empty?

  filemachines = doc.xpath("//rightsMetadata/access[@type='read' and file]/machine")
  unless filemachines.empty?
    terms.push 'has_file_rights', "file_rights_count|#{filemachines.count}"
    counts = Hash.new(0)
    filemachines.each { |filemachine|
      filemachine.element_children.each { |node| counts[node.name] += 1 }
    }
    counts.each { |k, v|
      terms.push "file_has_#{k}", "file_rights_for_#{k}|#{v}"
    }
  end

  terms
end

.init_index_elements(doc) ⇒ Hash{Symbol => Object}

Give the index what it needs

:primary => '...',   # string of foremost rights category, if determinable
:errors  => [...],   # known error cases
:terms   => [...]    # array of non-error characterizations and stats strings

Parameters:

  • doc (Nokogiri::XML)

    the rightsMetadata document

Returns:

  • (Hash{Symbol => Object})

    Strings of interest to the Solr index, including:



388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'lib/dor/rights_auth.rb', line 388

def self.init_index_elements(doc)
  errors = validate_lite(doc)
  stuff = {
    :primary => nil,
    :errors => errors,
    :terms => [],
    :obj_groups => [],
    :obj_locations => [],
    :obj_agents => [],
    :file_groups => [],
    :file_locations => [],
    :file_agents => [],
    :obj_world_qualified => [],
    :obj_groups_qualified => [],
    :obj_locations_qualified => [],
    :obj_agents_qualified => [],
    :file_world_qualified => [],
    :file_groups_qualified => [],
    :file_locations_qualified => [],
    :file_agents_qualified => []
  }

  if errors.include? 'no_rightsMetadata'
    stuff[:primary] = 'dark'
    return stuff # short circuit if no metadata -- no point going on
  end

  stuff[:terms] = extract_index_terms(doc)
  stuff[:primary] = primary_access_rights stuff[:terms], errors

  stuff
end

.parse(xml, forindex = false) ⇒ Dor::RightsAuth

Create a Dor::RightsAuth object from xml

Parameters:

  • xml (String|Nokogiri::XML::Document)

    rightsMetadata xml that will be parsed to build a RightsAuth object

  • forindex, (Boolean)

    flag for requesting index_elements be parsed

Returns:



449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'lib/dor/rights_auth.rb', line 449

def self.parse(xml, forindex = false)
  rights = Dor::RightsAuth.new
  rights.obj_lvl = EntityRights.new
  rights.obj_lvl.world = Rights.new

  doc = xml.is_a?(Nokogiri::XML::Document) ? xml.clone : Nokogiri::XML(xml)

  rights.index_elements = init_index_elements(doc) if forindex

  if doc.at_xpath("//rightsMetadata/access[@type='read' and not(file)]/machine/world")
    rights.obj_lvl.world.value = true
    rule = doc.at_xpath("//rightsMetadata/access[@type='read' and not(file)]/machine/world/@rule")
    rights.obj_lvl.world.rule = rule.value if rule
    rights.index_elements[:obj_world_qualified] << { :rule => (rule ? rule.value : nil) } if forindex
  else
    rights.obj_lvl.world.value = false
  end

  # TODO: we should also look for the <group rule="no-download">stanford</group> node and parse as needed
  if doc.at_xpath("//rightsMetadata/access[@type='read' and not(file)]/machine/cdl")
    rights.obj_lvl.controlled_digital_lending = true
  else
    rights.obj_lvl.controlled_digital_lending = false
  end

  rights.obj_lvl.group = { :stanford => Rights.new }
  xpath = "//rightsMetadata/access[@type='read' and not(file)]/machine/group[#{CONTAINS_STANFORD_XPATH}]"
  if doc.at_xpath(xpath)
    rights.obj_lvl.group[:stanford].value = true
    rule = doc.at_xpath("#{xpath}/@rule")
    rights.obj_lvl.group[:stanford].rule = rule.value if rule
    if forindex
      rights.index_elements[:obj_groups_qualified] << { :group => 'stanford', :rule => (rule ? rule.value : nil) }
      rights.index_elements[:obj_groups] << 'stanford'
    end
  else
    rights.obj_lvl.group[:stanford].value = false
  end

  rights.obj_lvl.location = {}
  doc.xpath("//rightsMetadata/access[@type='read' and not(file)]/machine/location").each do |node|
    r = Rights.new
    r.value = true
    r.rule = node['rule']
    rights.obj_lvl.location[node.content] = r
    if forindex
      rights.index_elements[:obj_locations_qualified] << { :location => node.content, :rule => node['rule'] }
      rights.index_elements[:obj_locations] << node.content
    end
  end

  rights.obj_lvl.agent = {}
  doc.xpath("//rightsMetadata/access[@type='read' and not(file)]/machine/agent").each do |node|
    r = Rights.new
    r.value = true
    r.rule = node['rule']
    rights.obj_lvl.agent[node.content] = r
    if forindex
      rights.index_elements[:obj_agents_qualified] << { :agent => node.content, :rule => node['rule'] }
      rights.index_elements[:obj_agents] << node.content
    end
  end

  embargo_node = doc.at_xpath("//rightsMetadata/access[@type='read']/machine/embargoReleaseDate")
  if embargo_node
    embargo_dt = Time.parse(embargo_node.content)
    rights.embargoed = true if embargo_dt > Time.now
    rights.embargo_release_date = embargo_dt
  end

  access_with_files = doc.xpath("//rightsMetadata/access[@type='read' and file]")
  access_with_files.each do |access_node|
    stanford_access = Rights.new
    world_access    = Rights.new
    controlled_digital_lending = Rights.new
    if access_node.at_xpath("machine/group[#{CONTAINS_STANFORD_XPATH}]")
      stanford_access.value = true
      rule = access_node.at_xpath("machine/group[#{CONTAINS_STANFORD_XPATH}]/@rule")
      stanford_access.rule = rule.value if rule
      if forindex
        rights.index_elements[:file_groups_qualified] <<
          { :group => 'stanford', :rule => (rule ? rule.value : nil) }
        rights.index_elements[:file_groups] << 'stanford'
      end
    else
      stanford_access.value = false
    end

    if access_node.at_xpath('machine/cdl')
      controlled_digital_lending.value = true
      rule = access_node.at_xpath('machine/cdl/@rule')
      controlled_digital_lending.rule = rule.value if rule
    else
      controlled_digital_lending.value = false
    end

    if access_node.at_xpath('machine/world')
      world_access.value = true
      rule = access_node.at_xpath('machine/world/@rule')
      world_access.rule = rule.value if rule
      rights.index_elements[:file_world_qualified] << { :rule => (rule ? rule.value : nil) } if forindex
    else
      world_access.value = false
    end

    file_locations = {}
    access_node.xpath('machine/location').each do |node|
      r = Rights.new
      r.value = true
      r.rule = node['rule']
      file_locations[node.content] = r
      if forindex
        rights.index_elements[:file_locations_qualified] << { :location => node.content, :rule => node['rule'] }
        rights.index_elements[:file_locations] << node.content
      end
    end

    file_agents = {}
    access_node.xpath('machine/agent').each do |node|
      r = Rights.new
      r.value = true
      r.rule = node['rule']
      file_agents[node.content] = r
      if forindex
        rights.index_elements[:file_agents_qualified] << { :agent => node.content, :rule => node['rule'] }
        rights.index_elements[:file_agents] << node.content
      end
    end

    access_node.xpath('file').each do |f|
      file_rights = EntityRights.new
      file_rights.world = world_access
      file_rights.group = { :stanford => stanford_access }
      file_rights.agent = file_agents
      file_rights.location = file_locations
      file_rights.controlled_digital_lending = controlled_digital_lending
      rights.file[f.content] = file_rights
    end
  end

  if forindex
    %i[obj_groups
       obj_locations
       obj_agents
       file_groups
       file_locations
       file_agents
       obj_world_qualified
       obj_groups_qualified
       obj_locations_qualified
       obj_agents_qualified
       file_world_qualified
       file_groups_qualified
       file_locations_qualified
       file_agents_qualified].each { |index_elt| rights.index_elements[index_elt].uniq! }
  end

  rights
end

.primary_access_rights(index_terms, errors) ⇒ Object

“primary” access is a somewhat crude way of summarizing a whole object (possibly with many disparate interacting rights types) using one rights label. but it should still do a good job of capturing rights that make more sense at the object level (e.g. ‘dark’).



425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# File 'lib/dor/rights_auth.rb', line 425

def self.primary_access_rights(index_terms, errors)
  has_rule = index_terms.include? 'has_rule'
  if index_terms.include?('none_discover') ||
     errors.include?('no_discover_access') ||
     errors.include?('no_discover_machine')
    'dark'
  elsif index_terms.include?('cdl_none')
    'controlled digital lending'
  elsif errors.include?('no_read_machine') || index_terms.include?('none_read')
    'citation'
  elsif index_terms.include? 'world_read'
    has_rule ? 'world_qualified' : 'world'
  elsif index_terms.include?('has_group_rights') ||
        index_terms.include?('location') || index_terms.include?('agent')
    has_rule ? 'access_restricted_qualified' : 'access_restricted'
  else # should never happen, but we might as well note it if it does
    has_rule ? 'UNKNOWN_qualified' : 'UNKNOWN'
  end
end

.validate_lite(doc) ⇒ Array

Check formedness of rightsMetadata – to be replaced with XSD once formalized, one fine day

Parameters:

  • doc (Nokogiri::XML)

    the rightsMetadata document

Returns:

  • (Array)

    list of things that are wrong with it



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/dor/rights_auth.rb', line 293

def self.validate_lite(doc)
  return ['no_rightsMetadata'] if doc.nil? || doc.at_xpath('//rightsMetadata').nil?

  errors = []
  maindiscover = doc.at_xpath("//rightsMetadata/access[@type='discover' and not(file)]")
  mainread     = doc.at_xpath("//rightsMetadata/access[@type='read'     and not(file)]")

  if maindiscover.nil?
    errors.push 'no_discover_access', 'no_discover_machine'
  elsif maindiscover.at_xpath('./machine').nil?
    errors.push 'no_discover_machine'
  elsif maindiscover.at_xpath('./machine/world[not(@rule)]').nil? && maindiscover.at_xpath('./machine/none').nil?
    errors.push 'discover_machine_unrecognized'
  end
  if mainread.nil?
    errors.push 'no_read_access', 'no_read_machine'
  elsif mainread.at_xpath('./machine').nil?
    errors.push 'no_read_machine'
    # else
    # TODO: deeper read validation?
  end

  errors
end

Instance Method Details

#agent_rights(agent_name) ⇒ Array<(Boolean, String)>

Note:

should be called after doing a check for world_unrestricted?

Returns whether an object-level agent node exists for the passed in agent, and the value of its rule attribute

Examples:

Using multiple variable assignment to read both array elements

agent_exists, agent_rule = rights.agent_rights('someapp')

Parameters:

  • agent_name (String)

    name of the app or thing that is tested for access

Returns:

  • (Array<(Boolean, String)>)

    First value: existence of node. Second Value: rule attribute, nil otherwise



226
227
228
229
230
# File 'lib/dor/rights_auth.rb', line 226

def agent_rights(agent_name)
  return [false, nil] if @obj_lvl.agent[agent_name].nil?

  [@obj_lvl.agent[agent_name].value, @obj_lvl.agent[agent_name].rule]
end

#agent_rights_for_file(file_name, agent_name) ⇒ Array<(Boolean, String)>

Returns whether a file-level agent-node exists, and the value of its rule attribute

If an agent-node does not exist for this file, then object-level agent rights are returned

Examples:

Using multiple variable assignment to read both array elements

agent_exists, agent_rule = rights.agent_rights_for_file('filex', 'someapp')

Parameters:

  • file_name (String)

    name of the file being tested

  • agent_name (String)

    name of the agent being tested

Returns:

  • (Array<(Boolean, String)>)

    First value: existence of node. Second Value: rule attribute, nil otherwise



281
282
283
284
285
286
287
288
# File 'lib/dor/rights_auth.rb', line 281

def agent_rights_for_file(file_name, agent_name)
  # look at object level agent rights if the file-name is not stored
  return agent_rights(agent_name) if @file[file_name].nil?

  return [false, nil] if @file[file_name].agent[agent_name].nil? # file rules exist, but not for this agent

  [@file[file_name].agent[agent_name].value, @file[file_name].agent[agent_name].rule]
end

#agent_unrestricted?(agent_name) ⇒ Boolean Also known as: allowed_read_agent?

Returns true if the passed in agent (usually an application) is allowed access to the object without a rule

Parameters:

  • agent_name (String)

    Name of the agent that wants to access this object

Returns:

  • (Boolean)


123
124
125
126
127
# File 'lib/dor/rights_auth.rb', line 123

def agent_unrestricted?(agent_name)
  return false unless @obj_lvl.agent.key? agent_name

  @obj_lvl.agent[agent_name].value && @obj_lvl.agent[agent_name].rule.nil?
end

#cdl_rights_for_file(file_name) ⇒ Object



174
175
176
177
178
# File 'lib/dor/rights_auth.rb', line 174

def cdl_rights_for_file(file_name)
  return controlled_digital_lending? if @file[file_name].nil? || @file[file_name].controlled_digital_lending.nil?

  @file[file_name].controlled_digital_lending.value
end

#check_index_elements_calculated!Object

summary level rights info is mostly used for object-level indexing/faceting. thus, we currently only calculate it when parsing object rights for indexing. to keep from having to refactor or duplicate code right now, we’ll just leverage what we’ve got, checking whether index_elements is populated, and raising an error if the object wasn’t instantiated in a way that makes those calculations.



61
62
63
64
65
# File 'lib/dor/rights_auth.rb', line 61

def check_index_elements_calculated!
  unless index_elements.size > 0
    raise "primary access rights not calculated.  instantiate by calling '.parse(xml, forindex = true)'."
  end
end

#citation_only?Boolean

this is just a convenience method for asking whether an object’s rights would classify it as ‘citation only’.

Returns:

  • (Boolean)


76
77
78
79
# File 'lib/dor/rights_auth.rb', line 76

def citation_only?
  check_index_elements_calculated!
  index_elements[:primary] == 'citation'
end

#controlled_digital_lending?Boolean

Returns true if the object is enabled for controlled digital lending

Returns:

  • (Boolean)


103
104
105
# File 'lib/dor/rights_auth.rb', line 103

def controlled_digital_lending?
  @obj_lvl.controlled_digital_lending
end

#dark?Boolean

this is just a convenience method for asking whether an object’s rights would classify it as ‘dark’.

Returns:

  • (Boolean)


69
70
71
72
# File 'lib/dor/rights_auth.rb', line 69

def dark?
  check_index_elements_calculated!
  index_elements[:primary] == 'dark'
end

#embargoed?Boolean

Returns true if the object is under embargo.

Returns:

  • (Boolean)


52
53
54
# File 'lib/dor/rights_auth.rb', line 52

def embargoed?
  @embargoed
end

#location_rights(location_name) ⇒ Array<(Boolean, String)>

Returns whether an object-level location node exists for the passed in location, and the

value of its rule attribute

Examples:

Using multiple variable assignment to read both array elements

location_exists, location_rule = rights.location_rights('spec_coll_reading_room')

Parameters:

  • location_name (String)

    name of the location that is tested for access

Returns:

  • (Array<(Boolean, String)>)

    First value: existence of node. Second Value: rule attribute, nil otherwise



202
203
204
205
206
# File 'lib/dor/rights_auth.rb', line 202

def location_rights(location_name)
  return [false, nil] if @obj_lvl.location[location_name].nil?

  [@obj_lvl.location[location_name].value, @obj_lvl.location[location_name].rule]
end

#location_rights_for_file(file_name, location_name) ⇒ Array<(Boolean, String)>

Returns whether a file-level location-node exists, and the value of its rule attribute

If a location-node does not exist for this file, then object-level location rights are returned

Examples:

Using multiple variable assignment to read both array elements

location_exists, location_rule = rightslocation_rights_for_file('filex', 'spec_coll_reading_room')

Parameters:

  • file_name (String)

    name of the file being tested

  • location_name (String)

    name of the location being tested

Returns:

  • (Array<(Boolean, String)>)

    First value: existence of node. Second Value: rule attribute, nil otherwise



265
266
267
268
269
270
271
272
# File 'lib/dor/rights_auth.rb', line 265

def location_rights_for_file(file_name, location_name)
  file_rights = @file[file_name]
  return location_rights(location_name) if file_rights.nil?

  return [false, nil] if file_rights.location[location_name].nil?

  [file_rights.location[location_name].value, file_rights.location[location_name].rule]
end

#readable?Boolean

Returns:

  • (Boolean)


88
89
90
91
# File 'lib/dor/rights_auth.rb', line 88

def readable?
  # TODO: stanford_only or public with rule, figure out if this is still a legit method
  public_unrestricted? || stanford_only_unrestricted?
end

#restricted_by_location?(file_name = nil) ⇒ Boolean

Returns whether a given file has any location restrictions and falls back to

the object behavior in the absence of the file.

Parameters:

  • file_name (String) (defaults to: nil)

    name of the file being tested

Returns:

  • (Boolean)

    whether any location restrictions exist on the file or the object itself (in the absence of file-level rights)



213
214
215
216
217
218
# File 'lib/dor/rights_auth.rb', line 213

def restricted_by_location?(file_name = nil)
  any_file_location = @file[file_name]&.location&.any?
  any_object_location = @obj_lvl.location&.any?

  any_file_location || any_object_location
end

#stanford_only_downloadable?Boolean

Returns true if the object is stanford-only readable AND allows download

Returns:

  • (Boolean)


115
116
117
118
# File 'lib/dor/rights_auth.rb', line 115

def stanford_only_downloadable?
  stanford_rule = @obj_lvl.group[:stanford].rule
  @obj_lvl.group[:stanford].value && (stanford_rule.nil? || stanford_rule != NO_DOWNLOAD_RULE)
end

#stanford_only_downloadable_file?(file_name) ⇒ Boolean

Returns:

  • (Boolean)


167
168
169
170
171
172
# File 'lib/dor/rights_auth.rb', line 167

def stanford_only_downloadable_file?(file_name)
  return stanford_only_downloadable? if @file[file_name].nil? || @file[file_name].group[:stanford].nil?

  stanford_rule = @file[file_name].group[:stanford].rule
  @file[file_name].group[:stanford].value && (stanford_rule.nil? || stanford_rule != NO_DOWNLOAD_RULE)
end

#stanford_only_rightsArray<(Boolean, String)>

Returns whether an object-level group/stanford node exists, and the value of its rule attribute

Examples:

Using multiple variable assignment to read both array elements

su_only_exists, su_only_rule = rights.stanford_only_rights

Returns:

  • (Array<(Boolean, String)>)

    First value: existence of node. Second Value: rule attribute, nil otherwise



192
193
194
# File 'lib/dor/rights_auth.rb', line 192

def stanford_only_rights
  [@obj_lvl.group[:stanford].value, @obj_lvl.group[:stanford].rule]
end

#stanford_only_rights_for_file(file_name) ⇒ Array<(Boolean, String)>

Returns whether a file-level group/stanford node exists, and the value of its rule attribute

If a group/stanford node does not exist for this file, then object-level group/stanford rights are returned

Examples:

Using multiple variable assignment to read both array elements

su_only_exists, su_only_rule = rights.stanford_only_rights_for_file('somefile')

Parameters:

  • file_name (String)

    name of the file being tested

Returns:

  • (Array<(Boolean, String)>)

    First value: existence of node. Second Value: rule attribute, nil otherwise

See Also:



252
253
254
255
256
# File 'lib/dor/rights_auth.rb', line 252

def stanford_only_rights_for_file(file_name)
  return stanford_only_rights if @file[file_name].nil? || @file[file_name].group[:stanford].nil?

  [@file[file_name].group[:stanford].value, @file[file_name].group[:stanford].rule]
end

#stanford_only_unrestricted?Boolean

Returns true if the object is stanford-only readable AND has no rule attribute

Returns:

  • (Boolean)


109
110
111
# File 'lib/dor/rights_auth.rb', line 109

def stanford_only_unrestricted?
  @obj_lvl.group[:stanford].value && @obj_lvl.group[:stanford].rule.nil?
end

#stanford_only_unrestricted_file?(file_name) ⇒ Boolean

Returns true if the file is stanford-only readable AND has no rule attribute

If rights do not exist for this file, then object level rights are returned

Parameters:

  • file_name (String)

    Name of the file that is tested for stanford_only rights

Returns:

  • (Boolean)

See Also:



135
136
137
138
139
# File 'lib/dor/rights_auth.rb', line 135

def stanford_only_unrestricted_file?(file_name)
  return stanford_only_unrestricted? if @file[file_name].nil? || @file[file_name].group[:stanford].nil?

  @file[file_name].group[:stanford].value && @file[file_name].group[:stanford].rule.nil?
end

#world_downloadable?Boolean Also known as: public_downloadable?

Returns true if the object is readable AND allows download

Returns:

  • (Boolean)


95
96
97
98
# File 'lib/dor/rights_auth.rb', line 95

def world_downloadable?
  world_rule = @obj_lvl.world.rule
  @obj_lvl.world.value && (world_rule.nil? || world_rule != NO_DOWNLOAD_RULE)
end

#world_downloadable_file?(file_name) ⇒ Boolean, Array<(Boolean, String)> Also known as: public_downloadable_file?

Returns true if the file is world readable AND either has no rule attribute or the rule attribute is not ‘no-download’

If world rights do not exist for this file, then object level rights are returned

Parameters:

  • file_name (String)

    name of the file being tested

Returns:

  • (Boolean)
  • (Array<(Boolean, String)>)

    First value: existence of node. Second Value: rule attribute, nil otherwise

See Also:



159
160
161
162
163
164
# File 'lib/dor/rights_auth.rb', line 159

def world_downloadable_file?(file_name)
  return world_downloadable? if @file[file_name].nil? || @file[file_name].world.nil?

  world_rule = @file[file_name].world.rule
  @file[file_name].world.value && (world_rule.nil? || world_rule != NO_DOWNLOAD_RULE)
end

#world_rightsArray<(Boolean, String)>

Returns whether an object-level world node exists, and the value of its rule attribute

Examples:

Using multiple variable assignment to read both array elements

world_exists, world_rule = rights.world_rights

Returns:

  • (Array<(Boolean, String)>)

    First value: existence of node. Second Value: rule attribute, nil otherwise



184
185
186
# File 'lib/dor/rights_auth.rb', line 184

def world_rights
  [@obj_lvl.world.value, @obj_lvl.world.rule]
end

#world_rights_for_file(file_name) ⇒ Array<(Boolean, String)>

Returns whether a file-level world node exists, and the value of its rule attribute

If a world node does not exist for this file, then object-level world rights are returned

Examples:

Using multiple variable assignment to read both array elements

world_exists, world_rule = rights.world_rights_for_file('somefile')

Parameters:

  • file_name (String)

    name of the file

Returns:

  • (Array<(Boolean, String)>)

    First value: existence of node. Second Value: rule attribute, nil otherwise

See Also:



239
240
241
242
243
# File 'lib/dor/rights_auth.rb', line 239

def world_rights_for_file(file_name)
  return world_rights if @file[file_name].nil? || @file[file_name].world.nil?

  [@file[file_name].world.value, @file[file_name].world.rule]
end

#world_unrestricted?Boolean Also known as: public_unrestricted?

Returns true if the object is world readable AND has no rule attribute

Returns:

  • (Boolean)


83
84
85
# File 'lib/dor/rights_auth.rb', line 83

def world_unrestricted?
  @obj_lvl.world.value && @obj_lvl.world.rule.nil?
end

#world_unrestricted_file?(file_name) ⇒ Boolean Also known as: public_unrestricted_file?

Returns true if the file is world readable AND has no rule attribute

If world rights do not exist for this file, then object level rights are returned

Parameters:

  • file_name (String)

    Name of file that is tested for world rights

Returns:

  • (Boolean)

See Also:



146
147
148
149
150
# File 'lib/dor/rights_auth.rb', line 146

def world_unrestricted_file?(file_name)
  return world_unrestricted? if @file[file_name].nil? || @file[file_name].world.nil?

  @file[file_name].world.value && @file[file_name].world.rule.nil?
end