hydra-access-controls 9.2.0.rc1 → 9.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 361ce3b1b9ae7f917b0f671b2536f5965950ff28
4
- data.tar.gz: 43a7d26a5d9ad1f913b7827ce56abcd4455d7e73
3
+ metadata.gz: 253a587f6be8c789190ce4652d72a76c96192c1b
4
+ data.tar.gz: b8b48f8969ffac5925ad5a1f80c0a82de1e92c9c
5
5
  SHA512:
6
- metadata.gz: 6d003ee8f236a5fdc56bbe001e722439023e89d3a9d58b6bb4d6420dca05aa529ba164220b289c8a5e783cdbd3803e2c2d3ad6a626799e5ac58b27f72ef0847b
7
- data.tar.gz: abeb83a756abe8e91fe5f88f56e8e35a0918c5e5d27a2ba297868a436778272128474183976c2d61123a64bf86c1c46614fff3ea9bb87a4157fd5f34a4a34e95
6
+ metadata.gz: 48166e2c463853f451ca6526a160c50c458f9bcb7b0d18703c8f85db33a48160ebdd7e0a474b228c3d3304927892a82613474ddaa37d0eaa2c52288f74dbedd8
7
+ data.tar.gz: 1948d7ec0915657d4458ba332c751e554df761f72dbcd04320a1cb26c067e66ffd572b42b16c4e9e032a3b44eaed2da0cef38fcd40ce7a152c16dda813af1cff
@@ -392,9 +392,18 @@ module Hydra
392
392
  def search_by_type_and_mode(type, mode)
393
393
  case type
394
394
  when :group
395
- permissions.to_a.select { |p| group_agent?(p.agent) && p.mode.first.rdf_subject == mode }
395
+ search_by_mode(mode) { |agent| group_agent?(agent) }
396
396
  when :person
397
- permissions.to_a.select { |p| person_agent?(p.agent) && p.mode.first.rdf_subject == mode }
397
+ search_by_mode(mode) { |agent| person_agent?(agent) }
398
+ end
399
+ end
400
+
401
+ # @param [RDF::URI] mode One of the permissions modes, e.g. ACL.Write, ACL.Read, etc.
402
+ # @yieldparam [Array<ActiveFedora::Base>] agent the agent type assertions
403
+ # @return [Array<Permission>] list of permissions where the mode is as selected, the block evaluates to true and the target is not marked for delete
404
+ def search_by_mode(mode, &block)
405
+ permissions.to_a.select do |p|
406
+ yield(p.agent) && !p.marked_for_destruction? && p.mode.first.rdf_subject == mode
398
407
  end
399
408
  end
400
409
 
@@ -19,11 +19,11 @@ describe Hydra::AccessControls::Permissions do
19
19
  subject.read_groups=['group1', 'group2']
20
20
  subject.edit_users=['user1']
21
21
  subject.read_users=['user2', 'user3']
22
- expect(subject.permissions).to match_array [Hydra::AccessControls::Permission.new(:type=>"group", :access=>"read", :name=>"group1"),
23
- Hydra::AccessControls::Permission.new({:type=>"group", :access=>"read", :name=>"group2"}),
24
- Hydra::AccessControls::Permission.new({:type=>"person", :access=>"read", :name=>"user2"}),
25
- Hydra::AccessControls::Permission.new({:type=>"person", :access=>"read", :name=>"user3"}),
26
- Hydra::AccessControls::Permission.new({:type=>"person", :access=>"edit", :name=>"user1"})]
22
+ expect(subject.permissions).to match_array [Hydra::AccessControls::Permission.new(type: "group", access: "read", name: "group1"),
23
+ Hydra::AccessControls::Permission.new({ type: "group", access: "read", name: "group2" }),
24
+ Hydra::AccessControls::Permission.new({ type: "person", access: "read", name: "user2" }),
25
+ Hydra::AccessControls::Permission.new({ type: "person", access: "read", name: "user3" }),
26
+ Hydra::AccessControls::Permission.new({ type: "person", access: "edit", name: "user1" })]
27
27
  end
28
28
 
29
29
  describe "building a new permission" do
@@ -40,33 +40,33 @@ describe Hydra::AccessControls::Permissions do
40
40
  describe "with nested attributes" do
41
41
  before do
42
42
  subject.save!
43
- subject.permissions_attributes = [{:type=>"person", :access=>"edit", :name=>"jcoyne"}]
43
+ subject.permissions_attributes = [{ type: "person", access: "edit", name: "jcoyne" }]
44
44
  end
45
45
  context "when a hash is passed" do
46
46
  before do
47
- subject.permissions_attributes = {'0' => {type: "group", access:"read", name:"group1"},
48
- '1' => {type: 'person', access: 'edit', name: 'user2'}}
47
+ subject.permissions_attributes = {'0' => { type: "group", access:"read", name:"group1" },
48
+ '1' => { type: 'person', access: 'edit', name: 'user2' }}
49
49
  end
50
50
  it "should handle a hash" do
51
51
  expect(subject.permissions.size).to eq 3
52
52
  expect(subject.permissions.to_a).to all(be_a(Hydra::AccessControls::Permission))
53
53
  expect(subject.permissions.map(&:to_hash)).to match_array [
54
- {type: "person", access: "edit", name: "jcoyne"},
55
- {type: "group", access: "read", name: "group1"},
56
- {type: "person", access: "edit", name: "user2"}]
54
+ { type: "person", access: "edit", name: "jcoyne" },
55
+ { type: "group", access: "read", name: "group1" },
56
+ { type: "person", access: "edit", name: "user2" }]
57
57
  end
58
58
  end
59
59
 
60
- it "should create new group permissions" do
61
- subject.permissions_attributes = [{type: "group", access: "read", name: "group1"}]
60
+ it "creates new group permissions" do
61
+ subject.permissions_attributes = [{ type: "group", access: "read", name: "group1" }]
62
62
  expect(subject.permissions.size).to eq 2
63
63
  expect(subject.permissions.to_a).to all(be_a(Hydra::AccessControls::Permission))
64
64
  expect(subject.permissions[0].to_hash).to eq(type: "person", access: "edit", name: "jcoyne")
65
65
  expect(subject.permissions[1].to_hash).to eq(type: "group", access: "read", name: "group1")
66
66
  end
67
67
 
68
- it "should create new user permissions" do
69
- subject.permissions_attributes = [{:type=>"person", :access=>"read", :name=>"user1"}]
68
+ it "creates new user permissions" do
69
+ subject.permissions_attributes = [{ type: "person", access: "read", name: "user1" }]
70
70
  expect(subject.permissions.size).to eq 2
71
71
  expect(subject.permissions.to_a).to all(be_a(Hydra::AccessControls::Permission))
72
72
  expect(subject.permissions[0].to_hash).to eq(type: "person", access: "edit", name: "jcoyne")
@@ -74,9 +74,9 @@ describe Hydra::AccessControls::Permissions do
74
74
  end
75
75
 
76
76
  context "when called multiple times" do
77
- it "should not replace existing groups" do
78
- subject.permissions_attributes = [{:type=>"group", :access=>"read", :name=>"group1"}]
79
- subject.permissions_attributes = [{:type=>"group", :access=>"read", :name=>"group2"}]
77
+ it "doesn't replace existing groups" do
78
+ subject.permissions_attributes = [{ type: "group", access: "read", name: "group1" }]
79
+ subject.permissions_attributes = [{ type: "group", access: "read", name: "group2" }]
80
80
  expect(subject.permissions.size).to eq 3
81
81
  expect(subject.permissions.to_a).to all(be_a(Hydra::AccessControls::Permission))
82
82
  expect(subject.permissions[0].to_hash).to eq(type: "person", access: "edit", name: "jcoyne")
@@ -84,9 +84,9 @@ describe Hydra::AccessControls::Permissions do
84
84
  expect(subject.permissions[2].to_hash).to eq(type: "group", access: "read", name: "group2")
85
85
  end
86
86
 
87
- it "should not replace existing users" do
88
- subject.permissions_attributes = [{:type=>"person", :access=>"read", :name=>"user1"}]
89
- subject.permissions_attributes = [{:type=>"person", :access=>"read", :name=>"user2"}]
87
+ it "doesn't replace existing users" do
88
+ subject.permissions_attributes = [{ type: "person", access: "read", name: "user1" }]
89
+ subject.permissions_attributes = [{ type: "person", access: "read", name: "user2" }]
90
90
  expect(subject.permissions.size).to eq 3
91
91
  expect(subject.permissions.to_a).to all(be_a(Hydra::AccessControls::Permission))
92
92
  expect(subject.permissions[0].to_hash).to eq(type: "person", access: "edit", name: "jcoyne")
@@ -94,49 +94,74 @@ describe Hydra::AccessControls::Permissions do
94
94
  expect(subject.permissions[2].to_hash).to eq(type: "person", access: "read", name: "user2")
95
95
  end
96
96
 
97
- it "should update permissions on existing users" do
98
- subject.update permissions_attributes: [{:type=>"person", :access=>"read", :name=>"user1"}]
99
- subject.update permissions_attributes: [{:type=>"person", :access=>"edit", :name=>"user1"}]
97
+ it "updates permissions on existing users" do
98
+ subject.update permissions_attributes: [{ type: "person", access: "read", name: "user1" }]
99
+ subject.update permissions_attributes: [{ type: "person", access: "edit", name: "user1" }]
100
100
  expect(subject.permissions.size).to eq 2
101
101
  expect(subject.permissions.to_a).to all(be_a(Hydra::AccessControls::Permission))
102
102
  expect(subject.permissions[0].to_hash).to eq(type: "person", access: "edit", name: "jcoyne")
103
103
  expect(subject.permissions[1].to_hash).to eq(type: "person", access: "edit", name: "user1")
104
104
  end
105
105
 
106
- it "should update permissions on existing groups" do
107
- subject.update permissions_attributes: [{:type=>"group", :access=>"read", :name=>"group1"}]
108
- subject.update permissions_attributes: [{:type=>"group", :access=>"edit", :name=>"group1"}]
106
+ it "updates permissions on existing groups" do
107
+ subject.update permissions_attributes: [{ type: "group", access: "read", name: "group1" }]
108
+ subject.update permissions_attributes: [{ type: "group", access: "edit", name: "group1" }]
109
109
  expect(subject.permissions.map(&:to_hash)).to match_array [
110
- {:type=>"group", :access=>"edit", :name=>"group1"},
111
- {:type=>"person", :access=>"edit", :name=>"jcoyne"}]
110
+ { type: "group", access: "edit", name: "group1" },
111
+ { type: "person", access: "edit", name: "jcoyne" }]
112
112
  end
113
113
  end
114
114
 
115
- it "should remove permissions on existing users" do
116
- subject.update permissions_attributes: [{:type=>"person", :access=>"read", :name=>"user1"}]
117
- subject.update permissions_attributes: [{:id=>ActiveFedora::Base.uri_to_id(subject.permissions.last.rdf_subject.to_s), :type=>"person", :access=>"edit", :name=>"user1", _destroy: true}]
118
- expect(subject.permissions.reload.map(&:to_hash)).to eq [{ :name=>"jcoyne", :type=>"person", :access=>"edit" }]
119
- end
115
+ context "when the destroy flag is set" do
116
+ let(:reloaded) { subject.permissions.reload.map(&:to_hash) }
117
+ let(:permissions_id) { ActiveFedora::Base.uri_to_id(subject.permissions.last.rdf_subject.to_s) }
118
+
119
+ context "to a truthy value" do
120
+ context "when updating users" do
121
+ before do
122
+ subject.update permissions_attributes: [{ type: "person", access: "read", name: "user1" }]
123
+ subject.update permissions_attributes: [{ id: permissions_id, type: "person", access: "edit", name: "user1", _destroy: true}]
124
+ end
125
+
126
+ it "removes permissions on existing users" do
127
+ indexed_result = ActiveFedora::SolrService.query("id:#{subject.id}").first['edit_access_person_ssim']
128
+ expect(indexed_result).to eq ['jcoyne']
129
+ expect(reloaded).to eq [{ name: "jcoyne", type: "person", access: "edit" }]
130
+ end
131
+ end
132
+
133
+ context "when updating groups" do
134
+ before do
135
+ subject.update permissions_attributes: [{ type: "group", access: "read", name: "group1" }]
136
+ subject.update permissions_attributes: [{ id: permissions_id, type: "group", access: "edit", name: "group1", _destroy: '1' }]
137
+ end
138
+
139
+ it "removes permissions on existing groups" do
140
+ #See what actually gets stored in solr
141
+ indexed_result = ActiveFedora::SolrService.query("id:#{subject.id}").first['edit_access_group_ssim']
142
+ expect(indexed_result).to be_nil
143
+ expect(reloaded).to eq [{ type: "person", access: "edit", name: "jcoyne" }]
144
+ end
145
+ end
146
+ end
120
147
 
121
- it "should remove permissions on existing groups" do
122
- subject.update permissions_attributes: [{:type=>"group", :access=>"read", :name=>"group1"}]
123
- subject.update permissions_attributes: [{:id=>ActiveFedora::Base.uri_to_id(subject.permissions.last.rdf_subject.to_s), :type=>"group", :access=>"edit", :name=>"group1", _destroy: '1'}]
124
- expect(subject.permissions.reload.map(&:to_hash)).to eq [{:type=>"person", :access=>"edit", :name=>"jcoyne"}]
125
- end
148
+ context "to a falsy value" do
126
149
 
127
- it "should not remove when destroy flag is falsy" do
128
- subject.update permissions_attributes: [{:type=>"group", :access=>"read", :name=>"group1"}]
129
- subject.update permissions_attributes: [{:id=>ActiveFedora::Base.uri_to_id(subject.permissions.last.rdf_subject.to_s), :type=>"group", :access=>"edit", :name=>"group1", _destroy: '0'}]
130
- expect(subject.permissions.reload.map(&:to_hash)).to match_array [{:type=>"group", :access=>"edit", :name=>"group1"},
131
- {:type=>"person", :access=>"edit", :name=>"jcoyne"}]
150
+ it "doesn't remove the record" do
151
+ subject.update permissions_attributes: [{ type: "group", access: "read", name: "group1" }]
152
+ subject.update permissions_attributes: [{ id: permissions_id, type: "group", access: "edit", name: "group1", _destroy: '0' }]
153
+ expect(reloaded).to match_array [{ type: "group", access: "edit", name: "group1" },
154
+ { type: "person", access: "edit", name: "jcoyne" }]
155
+ end
156
+ end
132
157
  end
133
158
  end
134
159
 
135
160
  describe "with the setter" do
136
161
  before do
137
162
  subject.permissions = [
138
- Hydra::AccessControls::Permission.new(:type=>"group", :access=>"edit", :name=>"group1"),
139
- Hydra::AccessControls::Permission.new(:type=>"person", :access=>"edit", :name=>"jcoyne")]
163
+ Hydra::AccessControls::Permission.new(type: "group", access: "edit", name: "group1"),
164
+ Hydra::AccessControls::Permission.new(type: "person", access: "edit", name: "jcoyne")]
140
165
  subject.save!
141
166
  end
142
167
  it "should set the permissions" do
@@ -177,12 +202,12 @@ describe Hydra::AccessControls::Permissions do
177
202
  subject.set_read_groups(['group-2', 'group-3'], ['group-6'])
178
203
  # 'group-7' is not eligible to be revoked
179
204
  expect(subject.permissions.map(&:to_hash)).to match_array([
180
- {name: 'group-2', type: 'group', access: 'read'},
181
- {name: 'group-3', type: 'group', access: 'read'},
182
- {name: 'group-7', type: 'group', access: 'read'},
183
- {name: 'group-8', type: 'group', access: 'edit'},
184
- {name: 'person1', type: 'person', access: 'read'},
185
- {name: 'person2', type: 'person', access: 'discover'}])
205
+ { name: 'group-2', type: 'group', access: 'read' },
206
+ { name: 'group-3', type: 'group', access: 'read' },
207
+ { name: 'group-7', type: 'group', access: 'read' },
208
+ { name: 'group-8', type: 'group', access: 'edit' },
209
+ { name: 'person1', type: 'person', access: 'read' },
210
+ { name: 'person2', type: 'person', access: 'discover' }])
186
211
  end
187
212
  end
188
213
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-access-controls
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.2.0.rc1
4
+ version: 9.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-06-30 00:00:00.000000000 Z
13
+ date: 2015-07-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -213,9 +213,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
213
  version: 1.9.3
214
214
  required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  requirements:
216
- - - ">"
216
+ - - ">="
217
217
  - !ruby/object:Gem::Version
218
- version: 1.3.1
218
+ version: '0'
219
219
  requirements: []
220
220
  rubyforge_project:
221
221
  rubygems_version: 2.4.8