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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffbb2c368a44b27a8f4f2f2d8a1dcaf9e852d1d2
4
- data.tar.gz: 8bbce1c96b6dc86e87bdc34e0ee0fb38d3fd1a29
3
+ metadata.gz: df1f39af20b67cfc2e2c67c604b555349db0974f
4
+ data.tar.gz: fff1a1c47059217f4469cc263407787f12a66cd4
5
5
  SHA512:
6
- metadata.gz: 609ee8e41330854b9e56b63739244696f50d2caf110117cf6581b974ad25a4e5526e9aebece6d51774f81c816cda17fbaa6ef5d9b1eb6db375eacf817125b751
7
- data.tar.gz: dab7487a3bb03d5bd9133f91e9a4cb1650e43a371adf08fdd22d8ff961619c8629aeb1f7174f2f11cdf1455649d275bf669c981b12cfe224de25283bb163f4a7
6
+ metadata.gz: 4744d9de092e65196a7a3a7be04981496fff4277eb2fb48cfad7efb14ae2b6878c14562cd40149e95b812c2b7c28e8c97e6ac56ea92600281a6482bdbe541fb3
7
+ data.tar.gz: a42057263e9c5cd3fe599f4f833b0a18b0a26891fd0f31f64bd4d38ce39ec7043d0a6c590a9543477ff67e2e5cf00488c321c309b8e4364b93e3fc1be32926e4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
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
- user_access_filters = []
72
- ability.user_groups.each_with_index do |group, i|
73
- permission_types.each do |type|
74
- user_access_filters << escape_filter(solr_field_for(type, 'group'), group)
75
- end
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.gsub(/[ :\/]/, ' ' => '\ ', '/' => '\/', ':' => '\:')].join(':')
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:public OR read_access_group_ssim:public'
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 "Then I should be treated as a member of the 'public' and 'registered' groups" do
50
- ["discover","read"].each do |type|
51
- expect(@solr_parameters[:fq].first).to match(/#{type}_access_group_ssim\:public/)
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 "Then I should see assets that I have discover or read access to" do
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 "sets query fields for all roles the user is a member of checking against the discover, read fields" do
112
- subject.send(:apply_gated_discovery, @solr_parameters)
113
- ["discover","read"].each do |type|
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
- subject.send(:apply_gated_discovery, @solr_parameters)
124
- ["discover","read"].each do |type|
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 "should escape spaces" do
135
- subject.send(:apply_gated_discovery, @solr_parameters)
136
- ["discover","read"].each do |type|
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
- subject.send(:apply_gated_discovery, @solr_parameters)
148
- ["discover","read"].each do |type|
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight-access_controls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer