openstax_utilities 4.2.0 → 4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openstax/utilities/access_policy.rb +2 -2
- data/lib/openstax/utilities/version.rb +1 -1
- data/spec/dummy/app/access_policies/dummier_access_policy.rb +10 -0
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/lib/openstax/utilities/access_policy_spec.rb +15 -14
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4772e799075a8e6e6fb5d6b670be36448369e87e
|
4
|
+
data.tar.gz: e7fd112367bbfec2cc3047963c71289a980deb78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 364297c1c70a6218b52ca4eac44e8917bbb97cea1981a55c54fa174488cf831b34fc2a418e5dae66c01e9ccacf9939d7e01042aefbbc80b6cb1116e3588569d2
|
7
|
+
data.tar.gz: af1ec77a057b82d86586e644fae8546bab74fcccc92f00810a35c692880ebd3e73c876e3f62d50f481b14cf049c207c166a2a503ab89418f23a8e6224f84d723
|
@@ -38,7 +38,7 @@ module OpenStax
|
|
38
38
|
end
|
39
39
|
|
40
40
|
resource_class = resource.is_a?(Class) ? resource : resource.class
|
41
|
-
policy_class = instance.resource_policy_map[resource_class.to_s]
|
41
|
+
policy_class = instance.resource_policy_map[resource_class.to_s].try(:constantize)
|
42
42
|
|
43
43
|
# If there is no policy registered, we by default deny access
|
44
44
|
return false if policy_class.nil?
|
@@ -47,7 +47,7 @@ module OpenStax
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def self.register(resource_class, policy_class)
|
50
|
-
self.instance.resource_policy_map[resource_class.to_s] = policy_class
|
50
|
+
self.instance.resource_policy_map[resource_class.to_s] = policy_class.to_s
|
51
51
|
end
|
52
52
|
|
53
53
|
end
|
@@ -13,7 +13,7 @@ Rails.application.configure do
|
|
13
13
|
config.eager_load = false
|
14
14
|
|
15
15
|
# Configure static asset server for tests with Cache-Control for performance.
|
16
|
-
config.
|
16
|
+
config.serve_static_files = true
|
17
17
|
config.static_cache_control = 'public, max-age=3600'
|
18
18
|
|
19
19
|
# Show full error reports and disable caching.
|
@@ -24,30 +24,31 @@ module OpenStax
|
|
24
24
|
|
25
25
|
it 'delegates checks to policy classes based on resource class' do
|
26
26
|
dummy_object = double('Dummy')
|
27
|
-
dummy_policy = double('Dummy Policy', :action_allowed? => true)
|
28
27
|
|
29
28
|
AccessPolicy.register(User, DummyAccessPolicy)
|
30
|
-
AccessPolicy.register(dummy_object.class,
|
29
|
+
AccessPolicy.register(dummy_object.class, DummierAccessPolicy)
|
31
30
|
|
32
31
|
DummyAccessPolicy.last_action = nil
|
33
32
|
DummyAccessPolicy.last_requestor = nil
|
34
33
|
DummyAccessPolicy.last_resource = nil
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
expect{AccessPolicy.require_action_allowed!(:read, user, dummy_object)
|
40
|
-
}.not_to raise_error
|
35
|
+
DummierAccessPolicy.last_action = nil
|
36
|
+
DummierAccessPolicy.last_requestor = nil
|
37
|
+
DummierAccessPolicy.last_resource = nil
|
41
38
|
|
42
|
-
expect(
|
43
|
-
expect
|
44
|
-
|
39
|
+
expect(AccessPolicy.action_allowed?(:read, user, dummy_object)).to eq true
|
40
|
+
expect{
|
41
|
+
AccessPolicy.require_action_allowed!(:read, user, dummy_object)
|
42
|
+
}.not_to raise_error
|
45
43
|
|
46
|
-
expect(
|
47
|
-
|
44
|
+
expect(DummierAccessPolicy.last_action).to eq(:read)
|
45
|
+
expect(DummierAccessPolicy.last_requestor).to eq(user)
|
46
|
+
expect(DummierAccessPolicy.last_resource).to eq(dummy_object)
|
48
47
|
|
49
|
-
expect
|
50
|
-
|
48
|
+
expect(AccessPolicy.action_allowed?(:create, user, User.new)).to eq true
|
49
|
+
expect{
|
50
|
+
AccessPolicy.require_action_allowed!(:create, user, User.new)
|
51
|
+
}.not_to raise_error
|
51
52
|
|
52
53
|
expect(DummyAccessPolicy.last_action).to eq(:create)
|
53
54
|
expect(DummyAccessPolicy.last_requestor).to eq(user)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openstax_utilities
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.2.
|
4
|
+
version: 4.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JP Slavinsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- lib/openstax_utilities.rb
|
161
161
|
- spec/dummy/README.md
|
162
162
|
- spec/dummy/Rakefile
|
163
|
+
- spec/dummy/app/access_policies/dummier_access_policy.rb
|
163
164
|
- spec/dummy/app/access_policies/dummy_access_policy.rb
|
164
165
|
- spec/dummy/app/assets/javascripts/application.js
|
165
166
|
- spec/dummy/app/assets/stylesheets/application.css
|
@@ -230,6 +231,7 @@ signing_key:
|
|
230
231
|
specification_version: 4
|
231
232
|
summary: Utilities for OpenStax web sites
|
232
233
|
test_files:
|
234
|
+
- spec/dummy/app/access_policies/dummier_access_policy.rb
|
233
235
|
- spec/dummy/app/access_policies/dummy_access_policy.rb
|
234
236
|
- spec/dummy/app/assets/javascripts/application.js
|
235
237
|
- spec/dummy/app/assets/stylesheets/application.css
|