access_policy_rails 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/access_policy_rails/controller_extensions.rb +7 -1
- data/lib/access_policy_rails/version.rb +1 -1
- data/spec/acceptance/expose_as_helper_spec.rb +42 -0
- data/spec/acceptance/support/feature.rb +1 -1
- data/spec/support/base_controller_dummy.rb +1 -1
- data/spec/unit/lib/access_policy_rails/controller_extensions_spec.rb +6 -0
- 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: 87547ac0de14fb1192be856e09b806c8e4ca0b99
|
4
|
+
data.tar.gz: dfb335dce94875c436775a02f90ec8fc15fd4c6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5e671362763aa7ac22e8f282f2239cf95ce584b5cb0fdb8c3eb9811eac15059c2f610168cfb01e4e43869f6089e446bb6deb63498ae4b3ddbb7b0a29c6b9fd5
|
7
|
+
data.tar.gz: a1345b03dfb575e2fb48f11c7da48d513166d621ca262b296f841cd991a678b74352efe8999eea10d298a180fa20e1632839c056d6226804543d7311f4b9546a
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# AccessPolicyRails [![Code Climate](https://codeclimate.com/github/slowjack2k/access_policy_rails.png)](https://codeclimate.com/github/slowjack2k/access_policy_rails) [![Build Status](https://travis-ci.org/slowjack2k/access_policy_rails.png?branch=master)](https://travis-ci.org/slowjack2k/access_policy_rails) [![Coverage Status](https://coveralls.io/repos/slowjack2k/access_policy_rails/badge.png?branch=master)](https://coveralls.io/r/slowjack2k/access_policy_rails?branch=master) [![Gem Version](https://badge.fury.io/rb/access_policy_rails.png)](http://badge.fury.io/rb/access_policy_rails)
|
2
2
|
|
3
|
-
Rails extension for AccessPolicy. Stores the policy_check_user (default current_user)
|
3
|
+
Rails extension for [AccessPolicy](https://github.com/slowjack2k/access_policy). Stores the policy_check_user (default current_user)
|
4
4
|
in a RequestLocalStorage. So it is not needed to pass the user around.
|
5
5
|
|
6
6
|
Further more some macros are provided to query permissions and protect actions.
|
@@ -24,7 +24,7 @@ Or install it yourself as:
|
|
24
24
|
```ruby
|
25
25
|
|
26
26
|
class DummyController < ActionController::Base
|
27
|
-
|
27
|
+
# ... typical controller stuff
|
28
28
|
|
29
29
|
# instead of
|
30
30
|
#
|
@@ -12,8 +12,10 @@ module AccessPolicyRails
|
|
12
12
|
hide_action :policy_check_user
|
13
13
|
hide_action :authorize
|
14
14
|
hide_action :policy_for
|
15
|
+
hide_action :policy
|
15
16
|
|
16
17
|
helper_method :policy_for
|
18
|
+
helper_method :policy
|
17
19
|
|
18
20
|
end
|
19
21
|
|
@@ -26,8 +28,12 @@ module AccessPolicyRails
|
|
26
28
|
end
|
27
29
|
|
28
30
|
def policy_for(object_to_guard=self)
|
31
|
+
PolicyWrapper.new(policy(object_to_guard))
|
32
|
+
end
|
33
|
+
|
34
|
+
def policy(object_to_guard=self)
|
29
35
|
_guard.send(:switched_user_or_role, policy_check_user) do
|
30
|
-
|
36
|
+
_guard.policy_for(object_to_guard)
|
31
37
|
end
|
32
38
|
end
|
33
39
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'acceptance_spec_helper'
|
2
|
+
|
3
|
+
feature 'Expose helper', %q{
|
4
|
+
In order to change views dependent on permissions
|
5
|
+
as a developer
|
6
|
+
I want to be able to query permissions in views
|
7
|
+
}, type: :helper do
|
8
|
+
|
9
|
+
given(:service_object){
|
10
|
+
Class.new() do
|
11
|
+
include AccessPolicy
|
12
|
+
|
13
|
+
def self.policy_class
|
14
|
+
Struct.new(:current_user, :service_object) do
|
15
|
+
def create?
|
16
|
+
!!(current_user && current_user.create_allowed?)
|
17
|
+
end
|
18
|
+
|
19
|
+
def show?
|
20
|
+
!!(current_user && current_user.show_allowed?)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end.new
|
26
|
+
}
|
27
|
+
|
28
|
+
given(:a_user){
|
29
|
+
double('user', create_allowed?: false, show_allowed?: true)
|
30
|
+
}
|
31
|
+
|
32
|
+
scenario 'action is allowed' do
|
33
|
+
allow(controller).to receive(:current_user).and_return a_user
|
34
|
+
expect(helper.policy_for(service_object).allow?(:show)).to be_truthy
|
35
|
+
end
|
36
|
+
|
37
|
+
scenario 'action is forbidden' do
|
38
|
+
allow(controller).to receive(:current_user).and_return a_user
|
39
|
+
expect(helper.policy_for(service_object).allow?(:create)).to be_falsy
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -85,5 +85,11 @@ module AccessPolicyRails
|
|
85
85
|
expect(subject.new(user).policy_for).to be_kind_of PolicyWrapper
|
86
86
|
end
|
87
87
|
end
|
88
|
+
|
89
|
+
describe '#policy' do
|
90
|
+
it 'returns a policy' do
|
91
|
+
expect(subject.new(user).policy).to be_kind_of subject.policy_class
|
92
|
+
end
|
93
|
+
end
|
88
94
|
end
|
89
95
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: access_policy_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dieter Späth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: access_policy
|
@@ -296,6 +296,7 @@ files:
|
|
296
296
|
- spec/acceptance/dummy/public/favicon.ico
|
297
297
|
- spec/acceptance/enables_permission_query_spec.rb
|
298
298
|
- spec/acceptance/enforce_authorize_outside_of_action_spec.rb
|
299
|
+
- spec/acceptance/expose_as_helper_spec.rb
|
299
300
|
- spec/acceptance/protect_controller_actions_spec.rb
|
300
301
|
- spec/acceptance/support/dummy_controller.rb
|
301
302
|
- spec/acceptance/support/dummy_controller_policy.rb
|
@@ -373,6 +374,7 @@ test_files:
|
|
373
374
|
- spec/acceptance/dummy/public/favicon.ico
|
374
375
|
- spec/acceptance/enables_permission_query_spec.rb
|
375
376
|
- spec/acceptance/enforce_authorize_outside_of_action_spec.rb
|
377
|
+
- spec/acceptance/expose_as_helper_spec.rb
|
376
378
|
- spec/acceptance/protect_controller_actions_spec.rb
|
377
379
|
- spec/acceptance/support/dummy_controller.rb
|
378
380
|
- spec/acceptance/support/dummy_controller_policy.rb
|