blacklight-access_controls 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/blacklight/access_controls/enforcement.rb +9 -7
- data/spec/unit/enforcement_spec.rb +16 -38
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df1f39af20b67cfc2e2c67c604b555349db0974f
|
4
|
+
data.tar.gz: fff1a1c47059217f4469cc263407787f12a66cd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4744d9de092e65196a7a3a7be04981496fff4277eb2fb48cfad7efb14ae2b6878c14562cd40149e95b812c2b7c28e8c97e6ac56ea92600281a6482bdbe541fb3
|
7
|
+
data.tar.gz: a42057263e9c5cd3fe599f4f833b0a18b0a26891fd0f31f64bd4d38ce39ec7043d0a6c590a9543477ff67e2e5cf00488c321c309b8e4364b93e3fc1be32926e4
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
@@ -68,13 +68,12 @@ module Blacklight
|
|
68
68
|
|
69
69
|
def apply_group_permissions(permission_types, ability = current_ability)
|
70
70
|
# for groups
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
71
|
+
permission_types.map do |type|
|
72
|
+
field = solr_field_for(type, 'group')
|
73
|
+
groups = ability.user_groups.map { |g| escape_value(g) }
|
74
|
+
# The parens are required to properly OR the cases together.
|
75
|
+
"({!terms f=#{field}}#{groups.join(',')})"
|
76
76
|
end
|
77
|
-
user_access_filters
|
78
77
|
end
|
79
78
|
|
80
79
|
def apply_user_permissions(permission_types, ability = current_ability)
|
@@ -97,9 +96,12 @@ module Blacklight
|
|
97
96
|
end
|
98
97
|
|
99
98
|
def escape_filter(key, value)
|
100
|
-
[key, value
|
99
|
+
[key, escape_value(value)].join(':')
|
101
100
|
end
|
102
101
|
|
102
|
+
def escape_value(value)
|
103
|
+
RSolr.solr_escape(value).gsub(/ /, '\ ')
|
104
|
+
end
|
103
105
|
end
|
104
106
|
end
|
105
107
|
end
|
@@ -27,7 +27,7 @@ describe Blacklight::AccessControls::Enforcement do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "Then I should be treated as a member of the 'public' group" do
|
30
|
-
expect(@solr_parameters[:fq].first).to eq 'discover_access_group_ssim
|
30
|
+
expect(@solr_parameters[:fq].first).to eq '({!terms f=discover_access_group_ssim}public) OR ({!terms f=read_access_group_ssim}public)'
|
31
31
|
end
|
32
32
|
|
33
33
|
it "Then I should not be treated as a member of the 'registered' group" do
|
@@ -46,26 +46,16 @@ describe Blacklight::AccessControls::Enforcement do
|
|
46
46
|
subject.send(:apply_gated_discovery, @solr_parameters)
|
47
47
|
end
|
48
48
|
|
49
|
-
it "
|
50
|
-
[
|
51
|
-
|
52
|
-
expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:registered/)
|
53
|
-
end
|
49
|
+
it "searches for my groups" do
|
50
|
+
expect(@solr_parameters[:fq].first).to match(%r{\{!terms f=discover_access_group_ssim\}public,faculty,africana\\-faculty,registered})
|
51
|
+
expect(@solr_parameters[:fq].first).to match(%r{\{!terms f=read_access_group_ssim\}public,faculty,africana\\-faculty,registered})
|
54
52
|
end
|
55
53
|
|
56
|
-
it "
|
54
|
+
it "searches for my user key" do
|
57
55
|
["discover","read"].each do |type|
|
58
56
|
expect(@solr_parameters[:fq].first).to match(/#{type}_access_person_ssim\:#{user.user_key}/)
|
59
57
|
end
|
60
58
|
end
|
61
|
-
|
62
|
-
it "Then I should see assets that my groups have discover or read access to" do
|
63
|
-
["faculty", "africana-faculty"].each do |group_id|
|
64
|
-
["discover","read"].each do |type|
|
65
|
-
expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:#{group_id}/)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
59
|
end
|
70
60
|
end
|
71
61
|
|
@@ -99,44 +89,35 @@ describe Blacklight::AccessControls::Enforcement do
|
|
99
89
|
|
100
90
|
before do
|
101
91
|
@solr_parameters = {}
|
92
|
+
subject.send(:apply_gated_discovery, @solr_parameters)
|
102
93
|
end
|
103
94
|
|
104
95
|
it "sets query fields for the user id checking against the discover, read fields" do
|
105
|
-
subject.send(:apply_gated_discovery, @solr_parameters)
|
106
96
|
["discover","read"].each do |type|
|
107
97
|
expect(@solr_parameters[:fq].first).to match(/#{type}_access_person_ssim\:#{user.user_key}/)
|
108
98
|
end
|
109
99
|
end
|
110
100
|
|
111
|
-
it "
|
112
|
-
|
113
|
-
[
|
114
|
-
expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:archivist/)
|
115
|
-
expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:researcher/)
|
116
|
-
end
|
101
|
+
it "queries roles the user is a member of checking against the discover, read fields" do
|
102
|
+
expect(@solr_parameters[:fq].first).to match(%r{\{!terms f=discover_access_group_ssim\}public,archivist,researcher,registered})
|
103
|
+
expect(@solr_parameters[:fq].first).to match(%r{\{!terms f=read_access_group_ssim\}public,archivist,researcher,registered})
|
117
104
|
end
|
118
105
|
|
119
106
|
context 'slashes in the group names' do
|
120
107
|
let(:groups) { ["abc/123","cde/567"] }
|
121
108
|
|
122
109
|
it "should escape slashes" do
|
123
|
-
|
124
|
-
[
|
125
|
-
expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:abc\\\/123/)
|
126
|
-
expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:cde\\\/567/)
|
127
|
-
end
|
110
|
+
expect(@solr_parameters[:fq].first).to match(%r{\{!terms f=discover_access_group_ssim\}public,abc\\/123,cde\\/567,registered})
|
111
|
+
expect(@solr_parameters[:fq].first).to match(%r{\{!terms f=read_access_group_ssim\}public,abc\\/123,cde\\/567,registered})
|
128
112
|
end
|
129
113
|
end
|
130
114
|
|
131
115
|
context 'spaces in the group names' do
|
132
116
|
let(:groups) { ["abc 123","cd/e 567"] }
|
133
117
|
|
134
|
-
it "
|
135
|
-
|
136
|
-
[
|
137
|
-
expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:abc\\ 123/)
|
138
|
-
expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:cd\\\/e\\ 567/)
|
139
|
-
end
|
118
|
+
it "escapes spaces in group names" do
|
119
|
+
expect(@solr_parameters[:fq].first).to match(%r{\{!terms f=discover_access_group_ssim\}public,abc\\ 123,cd\\/e\\ 567,registered})
|
120
|
+
expect(@solr_parameters[:fq].first).to match(%r{\{!terms f=read_access_group_ssim\}public,abc\\ 123,cd\\/e\\ 567,registered})
|
140
121
|
end
|
141
122
|
end
|
142
123
|
|
@@ -144,11 +125,8 @@ describe Blacklight::AccessControls::Enforcement do
|
|
144
125
|
let(:groups) { ["abc:123","cde:567"] }
|
145
126
|
|
146
127
|
it "should escape colons" do
|
147
|
-
|
148
|
-
[
|
149
|
-
expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:abc\\:123/)
|
150
|
-
expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:cde\\:567/)
|
151
|
-
end
|
128
|
+
expect(@solr_parameters[:fq].first).to match(%r{\{!terms f=discover_access_group_ssim\}public,abc\\:123,cde\\:567,registered})
|
129
|
+
expect(@solr_parameters[:fq].first).to match(%r{\{!terms f=read_access_group_ssim\}public,abc\\:123,cde\\:567,registered})
|
152
130
|
end
|
153
131
|
end
|
154
132
|
end
|