hydra-access-controls 8.2.0 → 9.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.textile +10 -10
  3. data/app/models/concerns/hydra/access_controls/access_right.rb +3 -2
  4. data/app/models/concerns/hydra/access_controls/embargoable.rb +120 -132
  5. data/app/models/concerns/hydra/access_controls/permissions.rb +137 -103
  6. data/app/models/concerns/hydra/access_controls/visibility.rb +3 -5
  7. data/app/models/concerns/hydra/access_controls.rb +0 -1
  8. data/app/models/concerns/hydra/admin_policy_behavior.rb +27 -2
  9. data/app/models/concerns/hydra/rights.rb +15 -0
  10. data/app/models/hydra/access_controls/access_control_list.rb +17 -0
  11. data/app/models/hydra/access_controls/embargo.rb +65 -0
  12. data/app/models/hydra/access_controls/lease.rb +66 -0
  13. data/app/models/hydra/access_controls/permission.rb +85 -0
  14. data/app/vocabularies/acl.rb +12 -0
  15. data/app/vocabularies/hydra/acl.rb +20 -0
  16. data/config/fedora.yml +4 -2
  17. data/hydra-access-controls.gemspec +6 -7
  18. data/lib/hydra/ability.rb +45 -43
  19. data/lib/hydra/access_controls_enforcement.rb +23 -25
  20. data/lib/hydra/admin_policy.rb +34 -11
  21. data/lib/hydra/config.rb +4 -15
  22. data/lib/hydra/permissions_query.rb +2 -2
  23. data/lib/hydra/permissions_solr_document.rb +4 -6
  24. data/lib/hydra/policy_aware_ability.rb +56 -53
  25. data/lib/hydra/policy_aware_access_controls_enforcement.rb +28 -18
  26. data/lib/hydra-access-controls.rb +1 -1
  27. data/spec/factories.rb +15 -15
  28. data/spec/services/embargo_service_spec.rb +6 -6
  29. data/spec/services/lease_service_spec.rb +6 -6
  30. data/spec/spec_helper.rb +20 -13
  31. data/spec/support/mods_asset.rb +3 -3
  32. data/spec/unit/ability_spec.rb +96 -121
  33. data/spec/unit/access_controls_enforcement_spec.rb +29 -27
  34. data/spec/unit/access_right_spec.rb +6 -1
  35. data/spec/unit/accessible_by_spec.rb +14 -5
  36. data/spec/unit/admin_policy_spec.rb +99 -92
  37. data/spec/unit/config_spec.rb +14 -15
  38. data/spec/unit/embargoable_spec.rb +26 -28
  39. data/spec/unit/permission_spec.rb +36 -16
  40. data/spec/unit/permissions_spec.rb +121 -65
  41. data/spec/unit/policy_aware_ability_spec.rb +64 -78
  42. data/spec/unit/policy_aware_access_controls_enforcement_spec.rb +81 -77
  43. data/spec/unit/role_mapper_spec.rb +10 -10
  44. data/spec/unit/with_access_right_spec.rb +1 -1
  45. metadata +29 -51
  46. data/lib/hydra/access_controls/permission.rb +0 -40
  47. data/lib/hydra/datastream/inheritable_rights_metadata.rb +0 -22
  48. data/lib/hydra/datastream/rights_metadata.rb +0 -276
  49. data/lib/hydra/datastream.rb +0 -7
  50. data/spec/unit/hydra_rights_metadata_persistence_spec.rb +0 -71
  51. data/spec/unit/hydra_rights_metadata_spec.rb +0 -301
  52. data/spec/unit/inheritable_rights_metadata_spec.rb +0 -65
@@ -1,276 +0,0 @@
1
- require 'active_support/core_ext/string'
2
- module Hydra
3
- module Datastream
4
- # Implements Hydra RightsMetadata XML terminology for asserting access permissions
5
- class RightsMetadata < ActiveFedora::OmDatastream
6
-
7
- set_terminology do |t|
8
- t.root(:path=>"rightsMetadata", :xmlns=>"http://hydra-collab.stanford.edu/schemas/rightsMetadata/v1", :schema=>"http://github.com/projecthydra/schemas/tree/v1/rightsMetadata.xsd")
9
- t.copyright {
10
- ## BEGIN possible delete, justin 2012-06-22
11
- t.machine {
12
- t.cclicense
13
- t.license
14
- }
15
- t.human_readable(:path=>"human")
16
- t.license(:proxy=>[:machine, :license ])
17
- t.cclicense(:proxy=>[:machine, :cclicense ])
18
- ## END possible delete
19
-
20
- t.title(:path=>'human', :attributes=>{:type=>'title'})
21
- t.description(:path=>'human', :attributes=>{:type=>'description'})
22
- t.url(:path=>'machine', :attributes=>{:type=>'uri'})
23
- }
24
- t.access do
25
- t.human_readable(:path=>"human")
26
- t.machine {
27
- t.group
28
- t.person
29
- }
30
- t.person(:proxy=>[:machine, :person])
31
- t.group(:proxy=>[:machine, :group])
32
- # accessor :access_person, :term=>[:access, :machine, :person]
33
- end
34
- t.discover_access(:ref=>[:access], :attributes=>{:type=>"discover"})
35
- t.read_access(:ref=>[:access], :attributes=>{:type=>"read"})
36
- t.edit_access(:ref=>[:access], :attributes=>{:type=>"edit"})
37
- # A bug in OM prevnts us from declaring proxy terms at the root of a Terminology
38
- # t.access_person(:proxy=>[:access,:machine,:person])
39
- # t.access_group(:proxy=>[:access,:machine,:group])
40
-
41
- t.embargo {
42
- t.human_readable(path: "human")
43
- t.machine{
44
- t.date(type: :time, attributes: {type: "release"})
45
- t.date_deactivated(type: "deactivated")
46
- t.visibility_during(path: "visibility", attributes: {scope: 'during'})
47
- t.visibility_after(path: "visibility", attributes: {scope: 'after'})
48
- }
49
- }
50
-
51
- t.lease {
52
- t.human_readable(path: "human")
53
- t.machine{
54
- t.date(type: :time, attributes: {type: "expire"})
55
- t.date_deactivated(type: :time, attributes: {type: "deactivated"})
56
- t.visibility_during(path: "visibility", attributes: {scope: 'during'})
57
- t.visibility_after(path: "visibility", attributes: {scope: 'after'})
58
- }
59
- }
60
-
61
- t.license(:ref=>[:copyright])
62
-
63
- t.visibility_during_embargo proxy: [:embargo, :machine, :visibility_during]
64
- t.visibility_after_embargo proxy: [:embargo, :machine, :visibility_after]
65
- t.visibility_during_lease proxy: [:lease, :machine, :visibility_during]
66
- t.visibility_after_lease proxy: [:lease, :machine, :visibility_after]
67
- t.embargo_history proxy: [:embargo, :human_readable]
68
- t.lease_history proxy: [:lease, :human_readable]
69
- t.embargo_release_date proxy: [:embargo, :machine, :date], type: :time
70
- t.embargo_deactivation_date proxy: [:embargo, :machine, :date_deactivated]
71
- t.lease_expiration_date proxy: [:lease, :machine, :date], type: :time
72
- t.lease_deactivation_date proxy: [:lease, :machine, :date_deactivated]
73
-
74
- end
75
-
76
- # Generates an empty Mods Article (used when you call ModsArticle.new without passing in existing xml)
77
- def self.xml_template
78
- builder = Nokogiri::XML::Builder.new do |xml|
79
- xml.rightsMetadata(:version=>"0.1", "xmlns"=>"http://hydra-collab.stanford.edu/schemas/rightsMetadata/v1") {
80
- xml.copyright {
81
- xml.human(:type=>'title')
82
- xml.human(:type=>'description')
83
- xml.machine(:type=>'uri')
84
-
85
- }
86
- xml.access(:type=>"discover") {
87
- xml.human
88
- xml.machine
89
- }
90
- xml.access(:type=>"read") {
91
- xml.human
92
- xml.machine
93
- }
94
- xml.access(:type=>"edit") {
95
- xml.human
96
- xml.machine
97
- }
98
- xml.embargo{
99
- xml.machine
100
- }
101
- xml.lease{
102
- xml.machine
103
- }
104
- }
105
- end
106
- return builder.doc
107
- end
108
-
109
- # Returns the permissions for the selected person/group
110
- # If new_access_level is provided, updates the selected person/group access_level to the one specified
111
- # A new_access_level of "none" will remove all access_levels for the selected person/group
112
- # @param [Hash] selector hash in format {type => identifier}
113
- # @param new_access_level (default nil)
114
- # @return Hash in format {type => access_level}.
115
- #
116
- # ie.
117
- # permissions({:person=>"person123"})
118
- # => {"person123"=>"edit"}
119
- # permissions({:person=>"person123"}, "read")
120
- # => {"person123"=>"read"}
121
- # permissions({:person=>"person123"})
122
- # => {"person123"=>"read"}
123
- def permissions(selector, new_access_level=nil)
124
- type = selector.keys.first.to_sym
125
- actor = selector.values.first
126
- if new_access_level.nil?
127
- xpath = xpath(type, actor)
128
- nodeset = self.find_by_terms(xpath)
129
- if nodeset.empty?
130
- return "none"
131
- else
132
- return nodeset.first.ancestors("access").first.attributes["type"].text
133
- end
134
- else
135
- remove_all_permissions(selector)
136
- if new_access_level == "none"
137
- self.content = self.to_xml
138
- else
139
- access_type_symbol = "#{new_access_level}_access".to_sym
140
- current_values = term_values(access_type_symbol, type)
141
- self.update_values([access_type_symbol, type] => current_values + [actor] )
142
- end
143
- return new_access_level
144
- end
145
-
146
- end
147
-
148
- # Reports on which groups have which permissions
149
- # @return Hash in format {group_name => group_permissions, group_name => group_permissions}
150
- def groups
151
- return quick_search_by_type(:group)
152
- end
153
-
154
- # Reports on which users have which permissions
155
- # @return Hash in format {user_name => user_permissions, user_name => user_permissions}
156
- def users
157
- return quick_search_by_type(:person)
158
- end
159
-
160
- # Updates permissions for all of the persons and groups in a hash
161
- # @param params ex. {"group"=>{"group1"=>"discover","group2"=>"edit"}, "person"=>{"person1"=>"read","person2"=>"discover"}}
162
- # Currently restricts actor type to group or person. Any others will be ignored
163
- def update_permissions(params)
164
- params.fetch("group", {}).each_pair {|group_id, access_level| self.permissions({"group"=>group_id}, access_level)}
165
- params.fetch("person", {}).each_pair {|person_id, access_level| self.permissions({"person"=>person_id}, access_level)}
166
- end
167
-
168
- # Updates all permissions
169
- # @param params ex. {"group"=>{"group1"=>"discover","group2"=>"edit"}, "person"=>{"person1"=>"read","person2"=>"discover"}}
170
- # Restricts actor type to group or person. Any others will be ignored
171
- def permissions= (params)
172
- groups_for_update = params['group'] ? params['group'].keys : []
173
- group_ids = groups.keys | groups_for_update
174
- group_ids.each {|group_id| self.permissions({"group"=>group_id}, params['group'].fetch(group_id, 'none'))}
175
- users_for_update = params['person'] ? params['person'].keys : []
176
- user_ids = users.keys | users_for_update
177
- user_ids.each {|person_id| self.permissions({"person"=>person_id}, params['person'].fetch(person_id, 'none'))}
178
- end
179
-
180
- # @param [Symbol] type (either :group or :person)
181
- # @return
182
- # This method limits the response to known access levels. Probably runs a bit faster than .permissions().
183
- def quick_search_by_type(type)
184
- result = {}
185
- [{:discover_access=>"discover"},{:read_access=>"read"},{:edit_access=>"edit"}].each do |access_levels_hash|
186
- access_level = access_levels_hash.keys.first
187
- access_level_name = access_levels_hash.values.first
188
- self.find_by_terms(*[access_level, type]).each do |entry|
189
- result[entry.text] = access_level_name
190
- end
191
- end
192
- return result
193
- end
194
-
195
- def under_embargo?
196
- (embargo_release_date.present? && Date.today < embargo_release_date.first) ? true : false
197
- end
198
-
199
- def active_lease?
200
- lease_expiration_date.present? && Date.today < lease_expiration_date.first
201
- end
202
-
203
- def to_solr(solr_doc=Hash.new)
204
- [:discover, :read, :edit].each do |access|
205
- vals = send("#{access}_access").machine.group
206
- solr_doc[Hydra.config.permissions[access].group] = vals unless vals.empty?
207
- vals = send("#{access}_access").machine.person
208
- solr_doc[Hydra.config.permissions[access].individual] = vals unless vals.empty?
209
- end
210
- if embargo_release_date.present?
211
- key = Hydra.config.permissions.embargo.release_date.sub(/_[^_]+$/, '') #Strip off the suffix
212
- ::Solrizer.insert_field(solr_doc, key, embargo_release_date, :stored_sortable)
213
- end
214
- if lease_expiration_date.present?
215
- key = Hydra.config.permissions.lease.expiration_date.sub(/_[^_]+$/, '') #Strip off the suffix
216
- ::Solrizer.insert_field(solr_doc, key, lease_expiration_date, :stored_sortable)
217
- end
218
- solr_doc[::Solrizer.solr_name("visibility_during_embargo", :symbol)] = visibility_during_embargo unless visibility_during_embargo.nil?
219
- solr_doc[::Solrizer.solr_name("visibility_after_embargo", :symbol)] = visibility_after_embargo unless visibility_after_embargo.nil?
220
- solr_doc[::Solrizer.solr_name("visibility_during_lease", :symbol)] = visibility_during_lease unless visibility_during_lease.nil?
221
- solr_doc[::Solrizer.solr_name("visibility_after_lease", :symbol)] = visibility_after_lease unless visibility_after_lease.nil?
222
- solr_doc[::Solrizer.solr_name("embargo_history", :symbol)] = embargo_history unless embargo_history.nil?
223
- solr_doc[::Solrizer.solr_name("lease_history", :symbol)] = lease_history unless lease_history.nil?
224
- solr_doc
225
- end
226
-
227
- def indexer
228
- self.class.indexer
229
- end
230
-
231
- def self.indexer
232
- @indexer ||= Solrizer::Descriptor.new(:string, :stored, :indexed, :multivalued)
233
- end
234
-
235
- def date_indexer
236
- self.class.date_indexer
237
- end
238
-
239
- def self.date_indexer
240
- @date_indexer ||= Solrizer::Descriptor.new(:date, :stored, :indexed)
241
- end
242
-
243
- # Completely clear the permissions
244
- def clear_permissions!
245
- remove_all_permissions({:person=>true})
246
- remove_all_permissions({:group=>true})
247
- end
248
-
249
-
250
-
251
- private
252
- # Purge all access given group/person
253
- def remove_all_permissions(selector)
254
- return unless ng_xml
255
- type = selector.keys.first.to_sym
256
- actor = selector.values.first
257
- xpath = xpath(type, actor)
258
- nodes_to_purge = self.find_by_terms(xpath)
259
- nodes_to_purge.each {|node| node.remove}
260
- end
261
-
262
- # @param [Symbol] type (:group, :person)
263
- # @param [String,TrueClass] actor the user we want to find. If actor is true, then don't query.
264
- def xpath(type, actor)
265
- raise ArgumentError, "Type must either be ':group' or ':person'. You provided: '#{type.inspect}'" unless [:group, :person].include?(type)
266
- path = "//oxns:access/oxns:machine/oxns:#{type}"
267
- if actor.is_a? String
268
- clean_actor = actor.gsub("'", '')
269
- path += "[text() = '#{clean_actor}']"
270
- end
271
- path
272
- end
273
-
274
- end
275
- end
276
- end
@@ -1,7 +0,0 @@
1
- module Hydra
2
- module Datastream
3
- extend ActiveSupport::Autoload
4
- autoload :RightsMetadata
5
- autoload :InheritableRightsMetadata
6
- end
7
- end
@@ -1,71 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Hydra::Datastream::RightsMetadata do
4
- before :all do
5
- class RightsTest < ActiveFedora::Base
6
- include Hydra::AccessControls::Permissions
7
- end
8
- end
9
-
10
- after :all do
11
- Object.send(:remove_const,:RightsTest)
12
- end
13
-
14
- describe "rightsMetadata" do
15
- let!(:thing) {RightsTest.new}
16
-
17
- [:discover,:read, :edit].each do |mode|
18
- describe "##{mode}_users" do
19
- let(:get_method) {"#{mode}_users".to_sym}
20
- let(:set_method) {"#{mode}_users=".to_sym}
21
-
22
- before :each do
23
- thing.send(set_method, ['locutus@borg.collective.mil'])
24
- thing.save
25
- end
26
-
27
- it "should persist initial setting" do
28
- thing.reload.send(get_method).should == ['locutus@borg.collective.mil']
29
- end
30
-
31
- it "should persist changes" do
32
- thing.send(set_method, ['locutus@borg.collective.mil','sevenofnine@borg.collective.mil'])
33
- thing.save
34
- thing.reload.send(get_method).should =~ ['locutus@borg.collective.mil','sevenofnine@borg.collective.mil']
35
- end
36
-
37
- it "should persist emptiness" do
38
- thing.send(set_method, [])
39
- thing.save
40
- thing.reload.send(get_method).should == []
41
- end
42
- end
43
-
44
- describe "##{mode}_groups" do
45
- let(:get_method) {"#{mode}_groups".to_sym}
46
- let(:set_method) {"#{mode}_groups=".to_sym}
47
-
48
- before :each do
49
- thing.send(set_method, ['borg'])
50
- thing.save
51
- end
52
-
53
- it "should persist initial setting" do
54
- thing.reload.send(get_method).should == ['borg']
55
- end
56
-
57
- it "should persist changes" do
58
- thing.send(set_method, ['borg','federation'])
59
- thing.save
60
- thing.reload.send(get_method).should =~ ['borg','federation']
61
- end
62
-
63
- it "should persist emptiness" do
64
- thing.send(set_method, [])
65
- thing.save
66
- thing.reload.send(get_method).should == []
67
- end
68
- end
69
- end
70
- end
71
- end
@@ -1,301 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Hydra::Datastream::RightsMetadata do
4
-
5
- let(:obj) { ActiveFedora::Base.new }
6
- let(:sample) { Hydra::Datastream::RightsMetadata.new(obj.inner_object, nil) }
7
-
8
- describe "license" do
9
- before do
10
- sample.license.title = "Creative Commons Attribution 3.0 Unported License."
11
- sample.license.description = "This Creative Commons license lets others distribute, remix, tweak, and build upon your work, even commercially, as long as they credit you for the original creation. This is the most accommodating of licenses offered. Recommended for maximum dissemination and use of licensed materials."
12
- sample.license.url = "http://creativecommons.org/licenses/by/3.0/"
13
- end
14
- subject { sample.license}
15
- its(:title) {should == ["Creative Commons Attribution 3.0 Unported License."] }
16
- its(:description) { should == ["This Creative Commons license lets others distribute, remix, tweak, and build upon your work, even commercially, as long as they credit you for the original creation. This is the most accommodating of licenses offered. Recommended for maximum dissemination and use of licensed materials."] }
17
- its(:url) {should == ["http://creativecommons.org/licenses/by/3.0/"] }
18
-
19
- it "should be accessable as a term path" do
20
- # This enables us to use:
21
- # delegate :license_title, :to=>'rightsMetadata', :at=>[:license, :title]
22
- sample.term_values(:license, :title).should == ["Creative Commons Attribution 3.0 Unported License."]
23
- end
24
- end
25
-
26
- describe "permissions" do
27
- describe "setter" do
28
- it "should set person permissions" do
29
- sample.permissions = {"person"=>{"maria"=>"read","marcus"=>"discover"}}
30
- end
31
- it "should set group permissions" do
32
- sample.permissions = {"group"=>{"librarians"=>"read","students"=>"discover"}}
33
- end
34
- it "should create/update/delete permissions for the given user/group" do
35
- sample.class.terminology.xpath_for(:access, :person, "person_123").should == '//oxns:access/oxns:machine/oxns:person[contains(., "person_123")]'
36
-
37
- person_123_perms_xpath = sample.class.terminology.xpath_for(:access, :person, "person_123")
38
- group_zzz_perms_xpath = sample.class.terminology.xpath_for(:access, :group, "group_zzz")
39
-
40
- sample.find_by_terms(person_123_perms_xpath).should be_empty
41
- sample.permissions({"person"=>"person_123"}, "edit").should == "edit"
42
- sample.permissions({"group"=>"group_zzz"}, "edit").should == "edit"
43
-
44
- sample.find_by_terms(person_123_perms_xpath).first.ancestors("access").first.attributes["type"].text.should == "edit"
45
- sample.find_by_terms(group_zzz_perms_xpath).first.ancestors("access").first.attributes["type"].text.should == "edit"
46
-
47
- sample.permissions({"person"=>"person_123"}, "read")
48
- sample.permissions({"group"=>"group_zzz"}, "read")
49
- sample.find_by_terms(person_123_perms_xpath).length.should == 1
50
-
51
- sample.find_by_terms(person_123_perms_xpath).first.ancestors("access").first.attributes["type"].text.should == "read"
52
- sample.find_by_terms(group_zzz_perms_xpath).first.ancestors("access").first.attributes["type"].text.should == "read"
53
-
54
- sample.permissions({"person"=>"person_123"}, "none").should == "none"
55
- sample.permissions({"group"=>"group_zzz"}, "none").should == "none"
56
- sample.find_by_terms(person_123_perms_xpath).should be_empty
57
- sample.find_by_terms(person_123_perms_xpath).should be_empty
58
- end
59
- it "should remove existing permissions (leaving only one permission level per user/group)" do
60
- person_123_perms_xpath = sample.class.terminology.xpath_for(:access, :person, "person_123")
61
- group_zzz_perms_xpath = sample.class.terminology.xpath_for(:access, :group, "group_zzz")
62
-
63
- sample.find_by_terms(person_123_perms_xpath).length.should == 0
64
- sample.find_by_terms(group_zzz_perms_xpath).length.should == 0
65
- sample.permissions({"person"=>"person_123"}, "read")
66
- sample.permissions({"group"=>"group_zzz"}, "read")
67
- sample.find_by_terms(person_123_perms_xpath).length.should == 1
68
- sample.find_by_terms(group_zzz_perms_xpath).length.should == 1
69
-
70
- sample.permissions({"person"=>"person_123"}, "edit")
71
- sample.permissions({"group"=>"group_zzz"}, "edit")
72
- sample.find_by_terms(person_123_perms_xpath).length.should == 1
73
- sample.find_by_terms(group_zzz_perms_xpath).length.should == 1
74
- end
75
- it "should not impact other users permissions" do
76
- sample.permissions({"person"=>"person_123"}, "read")
77
- sample.permissions({"person"=>"person_789"}, "edit")
78
-
79
- sample.permissions({"person"=>"person_123"}).should == "read"
80
- sample.permissions({"person"=>"person_456"}, "read")
81
- sample.permissions({"person"=>"person_123"}).should == "read"
82
- sample.permissions({"person"=>"person_456"}).should == "read"
83
- sample.permissions({"person"=>"person_789"}).should == "edit"
84
-
85
-
86
- end
87
- end
88
- describe "getter" do
89
- it "should return permissions level for the given user/group" do
90
- sample.permissions({"person"=>"person_123"}, "edit")
91
- sample.permissions({"group"=>"group_zzz"}, "discover")
92
- sample.permissions({"person"=>"person_123"}).should == "edit"
93
- sample.permissions({"group"=>"group_zzz"}).should == "discover"
94
- sample.permissions({"group"=>"foo_people"}).should == "none"
95
- end
96
- end
97
- end
98
- describe "groups" do
99
- it "should return a hash of all groups with permissions set, along with their permission levels" do
100
- sample.permissions({"group"=>"group_zzz"}, "edit")
101
- sample.permissions({"group"=>"public"}, "discover")
102
-
103
- #sample.groups.should == {"group_zzz"=>"edit", "public"=>"discover"}
104
- sample.groups.should == {"public"=>"discover", "group_zzz"=>"edit"}
105
- end
106
- end
107
- describe "individuals" do
108
- it "should return a hash of all individuals with permissions set, along with their permission levels" do
109
- sample.permissions({"person"=>"person_123"}, "read")
110
- sample.permissions({"person"=>"person_456"}, "edit")
111
- expect(sample.users).to eq("person_123"=>"read", "person_456"=>"edit")
112
- end
113
- end
114
-
115
- describe "update_permissions" do
116
- it "should accept a hash of groups and persons, updating their permissions accordingly" do
117
- sample.should_receive(:permissions).with({"group" => "group1"}, "discover")
118
- sample.should_receive(:permissions).with({"group" => "group2"}, "edit")
119
- sample.should_receive(:permissions).with({"person" => "person1"}, "read")
120
- sample.should_receive(:permissions).with({"person" => "person2"}, "discover")
121
-
122
- sample.update_permissions( {"group"=>{"group1"=>"discover","group2"=>"edit"}, "person"=>{"person1"=>"read","person2"=>"discover"}} )
123
- end
124
- end
125
-
126
- describe "clear_permissions!" do
127
- before do
128
- sample.permissions({"person"=>"person_123"}, "read")
129
- sample.permissions({"person"=>"person_456"}, "edit")
130
- sample.permissions({"person"=>"person_789"}, "discover")
131
- sample.permissions({"group"=>"group_123"}, "read")
132
- sample.permissions({"group"=>"group_456"}, "edit")
133
- sample.permissions({"group"=>"group_789"}, "discover")
134
- end
135
- it "clears permissions" do
136
- sample.clear_permissions!
137
- expect(sample.users).to eq({})
138
- expect(sample.groups).to eq({})
139
- end
140
- end
141
-
142
- describe "to_solr" do
143
- it "should populate solr doc with the correct fields" do
144
- params = {[:edit_access, :person]=>"Lil Kim", [:edit_access, :group]=>["group1","group2"], [:discover_access, :group]=>["public"],[:discover_access, :person]=>["Joe Schmoe"]}
145
- sample.update_values(params)
146
- solr_doc = sample.to_solr
147
-
148
- solr_doc["edit_access_person_ssim"].should == ["Lil Kim"]
149
- solr_doc["edit_access_group_ssim"].sort.should == ["group1", "group2"]
150
- solr_doc["discover_access_person_ssim"].should == ["Joe Schmoe"]
151
- solr_doc["discover_access_group_ssim"].should == ["public"]
152
- end
153
- it "should solrize fixture content correctly" do
154
- lsample = Hydra::Datastream::RightsMetadata.new(nil, nil)
155
- lsample.update_permissions({'person' => {'researcher1' => 'edit'},
156
- 'group' => {'archivist' => 'edit', 'public' =>'read', 'bob'=>'discover'}})
157
-
158
- solr_doc = lsample.to_solr
159
- solr_doc["edit_access_person_ssim"].should == ["researcher1"]
160
- solr_doc["edit_access_group_ssim"].should == ["archivist"]
161
- solr_doc["read_access_group_ssim"].should == ["public"]
162
- solr_doc["discover_access_group_ssim"].should == ["bob"]
163
- end
164
-
165
- it "should solrize embargo information if set" do
166
- sample.embargo_release_date = DateTime.parse("2010-12-01T23:59:59+0")
167
- solr_doc = sample.to_solr
168
- expect(solr_doc["embargo_release_date_dtsi"]).to eq "2010-12-01T23:59:59Z"
169
- end
170
-
171
- it "should solrize lease information if set" do
172
- sample.lease_expiration_date = DateTime.parse("2010-12-01T23:59:59Z")
173
- solr_doc = sample.to_solr
174
- expect(solr_doc["lease_expiration_date_dtsi"]).to eq "2010-12-01T23:59:59Z"
175
- end
176
- end
177
-
178
- describe "embargo" do
179
- describe "embargo_release_date=" do
180
- it "should update the appropriate node with the value passed" do
181
- sample.embargo_release_date = Date.parse("2010-12-01")
182
- expect(sample.embargo_release_date).to eq [Date.parse("2010-12-01").to_time.utc]
183
- end
184
-
185
- it "should accept a nil value after having a date value" do
186
- sample.embargo_release_date = Date.parse("2010-12-01")
187
- sample.embargo_release_date = nil
188
- expect(sample.embargo_release_date).to be_empty
189
- end
190
- end
191
-
192
- describe "embargo_release_date" do
193
- it "should return solr formatted date" do
194
- sample.embargo_release_date = DateTime.parse("2010-12-01T23:59:59Z")
195
- expect(sample.embargo_release_date).to eq [DateTime.parse("2010-12-01T23:59:59Z")]
196
- end
197
- end
198
-
199
- describe "under_embargo?" do
200
- it "should return true if the current date is before the embargo release date" do
201
- sample.embargo_release_date=Date.today+1.month
202
- expect(sample).to be_under_embargo
203
- end
204
-
205
- it "should return false if the current date is after the embargo release date" do
206
- sample.embargo_release_date=Date.today-1.month
207
- expect(sample).to_not be_under_embargo
208
- end
209
-
210
- it "should return false if there is no embargo date" do
211
- sample.embargo_release_date = nil
212
- expect(sample).to_not be_under_embargo
213
- end
214
- end
215
-
216
- describe "visibility during/after embargo" do
217
- it "should track visibility values and index them into solr" do
218
- expect(sample.visibility_during_embargo).to be_empty
219
- expect(sample.visibility_after_embargo).to be_empty
220
- sample.visibility_during_embargo = "private"
221
- sample.visibility_after_embargo = "restricted"
222
- expect(sample.visibility_during_embargo).to eq ["private"]
223
- expect(sample.visibility_after_embargo).to eq ["restricted"]
224
- solr_doc = sample.to_solr
225
- expect(solr_doc["visibility_during_embargo_ssim"]).to eq ["private"]
226
- expect(solr_doc["visibility_after_embargo_ssim"]).to eq ["restricted"]
227
- end
228
-
229
- it "has the correct xpath" do
230
- expect(sample.visibility_during_embargo.xpath).to eq "//oxns:embargo/oxns:machine/oxns:visibility[@scope=\"during\"]"
231
- expect(sample.visibility_after_embargo.xpath).to eq "//oxns:embargo/oxns:machine/oxns:visibility[@scope=\"after\"]"
232
- end
233
- end
234
-
235
- describe 'embargo_history' do
236
- subject { sample.embargo_history }
237
- it "has the correct xpath" do
238
- expect(subject.xpath).to eq '//oxns:embargo/oxns:human'
239
- end
240
- end
241
- end
242
-
243
- describe "leases" do
244
-
245
- describe "lease_expiration_date=" do
246
- it "should update the appropriate node with the value passed" do
247
- sample.lease_expiration_date = "2010-12-01"
248
- expect(sample.lease_expiration_date).to eq [Date.parse("2010-12-01").to_time.utc]
249
- end
250
- it "should only accept valid date values" do
251
-
252
- end
253
- it "should accept a nil value after having a date value" do
254
- sample.lease_expiration_date = "2010-12-01"
255
- sample.lease_expiration_date = nil
256
- expect(sample.lease_expiration_date).to be_empty
257
- end
258
- end
259
-
260
- describe "active_lease?" do
261
- it "should return true if the current date is after the lease expiration date" do
262
- sample.lease_expiration_date = Date.today-1.month
263
- expect(sample).to_not be_active_lease
264
- end
265
- it "should return false if the current date is before the lease expiration date" do
266
- sample.lease_expiration_date = Date.today+1.month
267
- expect(sample).to be_active_lease
268
- end
269
- it "should return false if there is no lease expiration date" do
270
- sample.lease_expiration_date = nil
271
- expect(sample).to_not be_active_lease
272
- end
273
- end
274
-
275
- describe "visibility during/after lease" do
276
- it "should track visibility values and index them into solr" do
277
- expect(sample.visibility_during_lease).to be_empty
278
- expect(sample.visibility_after_lease).to be_empty
279
- sample.visibility_during_lease = "restricted"
280
- sample.visibility_after_lease = "private"
281
- expect(sample.visibility_during_lease).to eq ["restricted"]
282
- expect(sample.visibility_after_lease).to eq ["private"]
283
- solr_doc = sample.to_solr
284
- expect(solr_doc["visibility_during_lease_ssim"]).to eq ["restricted"]
285
- expect(solr_doc["visibility_after_lease_ssim"]).to eq ["private"]
286
- end
287
-
288
- it "has the correct xpath" do
289
- expect(sample.visibility_during_lease.xpath).to eq "//oxns:lease/oxns:machine/oxns:visibility[@scope=\"during\"]"
290
- expect(sample.visibility_after_lease.xpath).to eq "//oxns:lease/oxns:machine/oxns:visibility[@scope=\"after\"]"
291
- end
292
- end
293
-
294
- describe 'lease_history' do
295
- subject { sample.lease_history }
296
- it "has the correct xpath" do
297
- expect(subject.xpath).to eq '//oxns:lease/oxns:human'
298
- end
299
- end
300
- end
301
- end