dor-rights-auth 0.8.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/dor/rights_auth.rb +24 -8
  2. metadata +21 -36
@@ -1,7 +1,8 @@
1
1
  require 'nokogiri'
2
- #require 'helpers/cacheable'
2
+ require 'time'
3
3
 
4
4
  module Dor
5
+
5
6
  # The Individual Right
6
7
  Rights = Struct.new(:value, :rule)
7
8
 
@@ -27,12 +28,20 @@ module Dor
27
28
  # end
28
29
 
29
30
  class RightsAuth
31
+
32
+ CONTAINS_STANFORD_XPATH = "contains(translate(text(), 'STANFORD', 'stanford'), 'stanford')"
30
33
 
31
- attr_accessor :obj_lvl, :file
34
+ attr_accessor :obj_lvl, :file, :embargoed
32
35
 
33
36
  def initialize
34
37
  @file = {}
35
38
  end
39
+
40
+ # Returns true if the object is under embargo.
41
+ # @return [Boolean]
42
+ def embargoed?
43
+ @embargoed
44
+ end
36
45
 
37
46
  # Returns true if the object is world readable AND has no rule attribute
38
47
  # @return [Boolean]
@@ -154,8 +163,7 @@ module Dor
154
163
  [@file[file_name].agent[agent_name].value, @file[file_name].agent[agent_name].rule]
155
164
  end
156
165
 
157
- # Fetch the rightsMetadata xml from the RightsMD service
158
- # Parse the xml and create a Dor::RightsAuth object
166
+ # Create a Dor::RightsAuth object from xml
159
167
  # @param [String] xml rightsMetadata xml that will be parsed to build a RightsAuth object
160
168
  # @return Dor::RightsAuth created after parsing rightsMetadata xml
161
169
  def RightsAuth.parse(xml)
@@ -181,9 +189,9 @@ module Dor
181
189
 
182
190
  rights.obj_lvl.group = { :stanford => Rights.new }
183
191
 
184
- if(doc.at_xpath("//rightsMetadata/access[@type='read' and not(file)]/machine/group[text() = 'stanford']"))
192
+ if(doc.at_xpath("//rightsMetadata/access[@type='read' and not(file)]/machine/group[#{CONTAINS_STANFORD_XPATH}]"))
185
193
  rights.obj_lvl.group[:stanford].value = true
186
- rule = doc.at_xpath("//rightsMetadata/access[@type='read' and not(file)]/machine/group[text() = 'stanford']/@rule")
194
+ rule = doc.at_xpath("//rightsMetadata/access[@type='read' and not(file)]/machine/group[#{CONTAINS_STANFORD_XPATH}]/@rule")
187
195
  rights.obj_lvl.group[:stanford].rule = rule.value if(rule)
188
196
  else
189
197
  rights.obj_lvl.group[:stanford].value = false
@@ -196,14 +204,22 @@ module Dor
196
204
  r.rule = node['rule']
197
205
  rights.obj_lvl.agent[node.content] = r
198
206
  end
207
+
208
+ # Initialze embargo_status to false
209
+ rights.embargoed = false
210
+ embargo_node = doc.at_xpath("//rightsMetadata/access[@type='read']/machine/embargoReleaseDate")
211
+ if(embargo_node)
212
+ embargo_dt = Time.parse(embargo_node.content)
213
+ rights.embargoed = true if(embargo_dt > Time.now)
214
+ end
199
215
 
200
216
  access_with_files = doc.xpath( "//rightsMetadata/access[@type='read' and file]")
201
217
  access_with_files.each do |access_node|
202
218
  stanford_access = Rights.new
203
219
  world_access = Rights.new
204
- if access_node.at_xpath("machine/group[text()='stanford']")
220
+ if access_node.at_xpath("machine/group[#{CONTAINS_STANFORD_XPATH}]")
205
221
  stanford_access.value = true
206
- rule = access_node.at_xpath("machine/group[text()='stanford']/@rule")
222
+ rule = access_node.at_xpath("machine/group[#{CONTAINS_STANFORD_XPATH}]/@rule")
207
223
  stanford_access.rule = rule.value if (rule)
208
224
  else
209
225
  stanford_access.value = false
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dor-rights-auth
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
+ - 1
7
8
  - 0
8
- - 8
9
9
  - 0
10
- version: 0.8.0
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Willy Mene
@@ -15,10 +15,9 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-12 00:00:00 Z
18
+ date: 2012-10-09 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- prerelease: false
22
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
23
22
  none: false
24
23
  requirements:
@@ -28,11 +27,11 @@ dependencies:
28
27
  segments:
29
28
  - 0
30
29
  version: "0"
31
- requirement: *id001
32
- name: nokogiri
30
+ prerelease: false
33
31
  type: :runtime
32
+ name: nokogiri
33
+ requirement: *id001
34
34
  - !ruby/object:Gem::Dependency
35
- prerelease: false
36
35
  version_requirements: &id002 !ruby/object:Gem::Requirement
37
36
  none: false
38
37
  requirements:
@@ -42,26 +41,25 @@ dependencies:
42
41
  segments:
43
42
  - 0
44
43
  version: "0"
44
+ prerelease: false
45
+ type: :development
46
+ name: rspec
45
47
  requirement: *id002
46
- name: rest-client
47
- type: :runtime
48
48
  - !ruby/object:Gem::Dependency
49
- prerelease: false
50
49
  version_requirements: &id003 !ruby/object:Gem::Requirement
51
50
  none: false
52
51
  requirements:
53
- - - <
52
+ - - ">="
54
53
  - !ruby/object:Gem::Version
55
54
  hash: 3
56
55
  segments:
57
- - 2
58
56
  - 0
59
- version: "2.0"
60
- requirement: *id003
61
- name: rspec
57
+ version: "0"
58
+ prerelease: false
62
59
  type: :development
60
+ name: ruby-debug
61
+ requirement: *id003
63
62
  - !ruby/object:Gem::Dependency
64
- prerelease: false
65
63
  version_requirements: &id004 !ruby/object:Gem::Requirement
66
64
  none: false
67
65
  requirements:
@@ -71,11 +69,11 @@ dependencies:
71
69
  segments:
72
70
  - 0
73
71
  version: "0"
74
- requirement: *id004
75
- name: ruby-debug
72
+ prerelease: false
76
73
  type: :development
74
+ name: yard
75
+ requirement: *id004
77
76
  - !ruby/object:Gem::Dependency
78
- prerelease: false
79
77
  version_requirements: &id005 !ruby/object:Gem::Requirement
80
78
  none: false
81
79
  requirements:
@@ -85,23 +83,10 @@ dependencies:
85
83
  segments:
86
84
  - 0
87
85
  version: "0"
88
- requirement: *id005
89
- name: yard
90
- type: :development
91
- - !ruby/object:Gem::Dependency
92
86
  prerelease: false
93
- version_requirements: &id006 !ruby/object:Gem::Requirement
94
- none: false
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- hash: 3
99
- segments:
100
- - 0
101
- version: "0"
102
- requirement: *id006
103
- name: lyberteam-gems-devel
104
87
  type: :development
88
+ name: lyberteam-gems-devel
89
+ requirement: *id005
105
90
  description: Parses rightsMetadata xml into a useable object
106
91
  email:
107
92
  - wmene@stanford.edu
@@ -144,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
129
  requirements: []
145
130
 
146
131
  rubyforge_project:
147
- rubygems_version: 1.8.10
132
+ rubygems_version: 1.8.24
148
133
  signing_key:
149
134
  specification_version: 3
150
135
  summary: Parses rightsMetadata xml into a useable object