dor-rights-auth 1.2.0 → 1.3.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 +40 -6
  3. metadata +3 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5cf8440dedbe7f16ab7b4c9e6ddb7b2915469fed
4
- data.tar.gz: f9af60728a4c488eebfd37f4812cedc90f243675
3
+ metadata.gz: f11af5041a20deb4cbbfb44ffc3a62683f4b1b1f
4
+ data.tar.gz: ebb61768470adb0888c612c13947e58125ca478a
5
5
  SHA512:
6
- metadata.gz: 318fbc547f7abd9bd91dc0199b3f5acd71985c04324cb2cdf7ebee64e324e10687ec727475a4ecb9e5523ba8e970ef55904fc9a63133dc7f2fce8454d9255e15
7
- data.tar.gz: df90d1277ddf87928a34ab995bbb596faaeb0c56b86f79f316a8589eb08e37154277b688dd69229dc98e0033c470c68242b7329aeb143364505fa0a2f9bed2dd
6
+ metadata.gz: 92a28e6e5f84bb81a71b69b8ff36c0cf7c661458260f7ec129ce5f1448eb19f5d91c5a17945b32ec609c30840ce33566e617e6718f2f19c5854cd33d3db54ddd
7
+ data.tar.gz: 31557219e0eda1041b8fe34ebc4e4fc52b8615c037c36af43d2939ba5453b6cef28b844dc2dc9561d90ee2eefce4a2bfb431f2dc54dc9d2c573e2cf7d14c59c6
@@ -32,6 +32,7 @@ module Dor
32
32
  class RightsAuth
33
33
 
34
34
  CONTAINS_STANFORD_XPATH = "contains(translate(text(), 'STANFORD', 'stanford'), 'stanford')".freeze
35
+ NO_DOWNLOAD_RULE = 'no-download'.freeze
35
36
 
36
37
  attr_accessor :obj_lvl, :file, :embargoed, :index_elements
37
38
 
@@ -53,7 +54,6 @@ module Dor
53
54
  def world_unrestricted?
54
55
  @obj_lvl.world.value && @obj_lvl.world.rule.nil?
55
56
  end
56
-
57
57
  alias_method :public_unrestricted?, :world_unrestricted?
58
58
 
59
59
  def readable?
@@ -61,12 +61,27 @@ module Dor
61
61
  public_unrestricted? || stanford_only_unrestricted?
62
62
  end
63
63
 
64
+ # Returns true if the object is readable AND allows download
65
+ # @return [Boolean]
66
+ def world_downloadable?
67
+ world_rule = @obj_lvl.world.rule
68
+ @obj_lvl.world.value && (world_rule.nil? || world_rule != NO_DOWNLOAD_RULE)
69
+ end
70
+ alias_method :public_downloadable?, :world_downloadable?
71
+
64
72
  # Returns true if the object is stanford-only readable AND has no rule attribute
65
73
  # @return [Boolean]
66
74
  def stanford_only_unrestricted?
67
75
  @obj_lvl.group[:stanford].value && @obj_lvl.group[:stanford].rule.nil?
68
76
  end
69
77
 
78
+ # Returns true if the object is stanford-only readable AND allows download
79
+ # @return [Boolean]
80
+ def stanford_only_downloadable?
81
+ stanford_rule = @obj_lvl.group[:stanford].rule
82
+ @obj_lvl.group[:stanford].value && (stanford_rule.nil? || stanford_rule != NO_DOWNLOAD_RULE)
83
+ end
84
+
70
85
  # Returns true if the passed in agent (usually an application) is allowed access to the object without a rule
71
86
  # @param [String] agent_name Name of the agent that wants to access this object
72
87
  # @return [Boolean]
@@ -74,7 +89,6 @@ module Dor
74
89
  return false unless @obj_lvl.agent.key? agent_name
75
90
  @obj_lvl.agent[agent_name].value && @obj_lvl.agent[agent_name].rule.nil?
76
91
  end
77
-
78
92
  alias_method :allowed_read_agent?, :agent_unrestricted?
79
93
 
80
94
  # Returns true if the file is stanford-only readable AND has no rule attribute
@@ -98,18 +112,38 @@ module Dor
98
112
 
99
113
  @file[file_name].world.value && @file[file_name].world.rule.nil?
100
114
  end
101
-
102
115
  alias_method :public_unrestricted_file?, :world_unrestricted_file?
103
116
 
117
+ # Returns true if the file is world readable AND either has no rule attribute or
118
+ # the rule attribute is not 'no-download'
119
+ # If world rights do not exist for this file, then object level rights are returned
120
+ # @see #world_downloadable?
121
+ # @param [String] file_name name of the file being tested
122
+ # @return (see #world_rights)
123
+ def world_downloadable_file?(file_name)
124
+ return world_downloadable? if @file[file_name].nil? || @file[file_name].world.nil?
125
+
126
+ world_rule = @file[file_name].world.rule
127
+ @file[file_name].world.value && (world_rule.nil? || world_rule != NO_DOWNLOAD_RULE)
128
+ end
129
+ alias_method :public_downloadable_file?, :world_downloadable_file?
130
+
131
+ def stanford_only_downloadable_file?(file_name)
132
+ return stanford_only_downloadable? if @file[file_name].nil? || @file[file_name].group[:stanford].nil?
133
+
134
+ stanford_rule = @file[file_name].group[:stanford].rule
135
+ @file[file_name].group[:stanford].value && (stanford_rule.nil? || stanford_rule != NO_DOWNLOAD_RULE)
136
+ end
137
+
104
138
  # Returns whether an object-level world node exists, and the value of its rule attribute
105
- # @return [Array<(Boolean, String)>] First value: existance of node. Second Value: rule attribute, nil otherwise
139
+ # @return [Array<(Boolean, String)>] First value: existence of node. Second Value: rule attribute, nil otherwise
106
140
  # @example Using multiple variable assignment to read both array elements
107
141
  # world_exists, world_rule = rights.world_rights
108
142
  def world_rights
109
143
  [@obj_lvl.world.value, @obj_lvl.world.rule]
110
144
  end
111
145
 
112
- # Returns whether and object-level group/stanford node exists, and the value of its rule attribute
146
+ # Returns whether an object-level group/stanford node exists, and the value of its rule attribute
113
147
  # @return (see #world_rights)
114
148
  # @example Using multiple variable assignment to read both array elements
115
149
  # su_only_exists, su_only_rule = rights.stanford_only_rights
@@ -168,7 +202,7 @@ module Dor
168
202
  # Returns whether a file-level group/stanford node exists, and the value of its rule attribute
169
203
  # If a group/stanford node does not exist for this file, then object-level group/stanford rights are returned
170
204
  # @see #stanford_only_rights
171
- # @param (see #world_rights_for_file)
205
+ # @param [String] file_name name of the file being tested
172
206
  # @return (see #world_rights)
173
207
  # @example Using multiple variable assignment to read both array elements
174
208
  # su_only_exists, su_only_rule = rights.stanford_only_rights_for_file('somefile')
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.2.0
4
+ version: 1.3.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-07-06 00:00:00.000000000 Z
12
+ date: 2016-11-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -97,7 +97,6 @@ dependencies:
97
97
  version: '0'
98
98
  description: Parses rightsMetadata xml into a useable object
99
99
  email:
100
- - wmene@stanford.edu
101
100
  - atz@stanford.edu
102
101
  executables: []
103
102
  extensions: []
@@ -131,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
130
  version: 1.3.6
132
131
  requirements: []
133
132
  rubyforge_project:
134
- rubygems_version: 2.4.8
133
+ rubygems_version: 2.4.5.1
135
134
  signing_key:
136
135
  specification_version: 4
137
136
  summary: Parses rightsMetadata xml into a useable object