strong_actions 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/Gemfile.lock +42 -24
- data/HISTORY.md +6 -2
- data/Rakefile +10 -0
- data/lib/strong_actions.rb +1 -0
- data/lib/strong_actions/config.rb +14 -15
- data/lib/strong_actions/controller_extensions.rb +5 -30
- data/lib/strong_actions/decision.rb +40 -0
- data/lib/strong_actions/version.rb +1 -1
- data/strong_actions.gemspec +1 -0
- data/test/config/acl.yml +10 -0
- data/test/decision_test.rb +56 -0
- data/test/test_helper.rb +6 -0
- metadata +24 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f33bd237fe0db5884816fedd3d3d8be5c61bc65
|
4
|
+
data.tar.gz: d61a5a34fde02ded12c2943e5d22ed0c7382b4f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea2429d1c839a9b318f7bca17dea13be8cc60448856165c2d996e3baf2913e31aa17d5f4608e0f724bb3b43ecad811d33f3d2ae8f230da2a700ac324190eab2c
|
7
|
+
data.tar.gz: 7cf82ccdebb20b21bb570372144f46edd20aa30c71c828f8396ab7c205e7aec92089c56c67ebf576cb20bab605d9d5059834c2df361d8bc72258220fa6a3d431
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
strong_actions (0.0.
|
4
|
+
strong_actions (0.0.4)
|
5
5
|
actionpack (>= 3.2.0, < 5.0.0)
|
6
6
|
activesupport (>= 3.2.0, < 5.0.0)
|
7
7
|
railties (>= 3.2.0, < 5.0.0)
|
@@ -9,44 +9,62 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
actionpack (
|
13
|
-
|
14
|
-
activesupport (=
|
15
|
-
|
16
|
-
rack-test (~> 0.6.2)
|
17
|
-
actionview (4.1.5)
|
18
|
-
activesupport (= 4.1.5)
|
19
|
-
builder (~> 3.1)
|
12
|
+
actionpack (3.2.19)
|
13
|
+
activemodel (= 3.2.19)
|
14
|
+
activesupport (= 3.2.19)
|
15
|
+
builder (~> 3.0.0)
|
20
16
|
erubis (~> 2.7.0)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
17
|
+
journey (~> 1.0.4)
|
18
|
+
rack (~> 1.4.5)
|
19
|
+
rack-cache (~> 1.2)
|
20
|
+
rack-test (~> 0.6.1)
|
21
|
+
sprockets (~> 2.2.1)
|
22
|
+
activemodel (3.2.19)
|
23
|
+
activesupport (= 3.2.19)
|
24
|
+
builder (~> 3.0.0)
|
25
|
+
activesupport (3.2.19)
|
26
|
+
i18n (~> 0.6, >= 0.6.4)
|
27
|
+
multi_json (~> 1.0)
|
28
|
+
builder (3.0.4)
|
28
29
|
erubis (2.7.0)
|
30
|
+
hike (1.2.3)
|
29
31
|
i18n (0.6.11)
|
32
|
+
journey (1.0.4)
|
30
33
|
json (1.8.1)
|
31
34
|
minitest (5.4.1)
|
32
|
-
|
35
|
+
multi_json (1.10.1)
|
36
|
+
rack (1.4.5)
|
37
|
+
rack-cache (1.2)
|
38
|
+
rack (>= 0.4)
|
39
|
+
rack-ssl (1.3.4)
|
40
|
+
rack
|
33
41
|
rack-test (0.6.2)
|
34
42
|
rack (>= 1.0)
|
35
|
-
railties (
|
36
|
-
actionpack (=
|
37
|
-
activesupport (=
|
43
|
+
railties (3.2.19)
|
44
|
+
actionpack (= 3.2.19)
|
45
|
+
activesupport (= 3.2.19)
|
46
|
+
rack-ssl (~> 1.3.2)
|
38
47
|
rake (>= 0.8.7)
|
39
|
-
|
48
|
+
rdoc (~> 3.4)
|
49
|
+
thor (>= 0.14.6, < 2.0)
|
40
50
|
rake (10.3.2)
|
51
|
+
rdoc (3.12.2)
|
52
|
+
json (~> 1.4)
|
53
|
+
sprockets (2.2.2)
|
54
|
+
hike (~> 1.2)
|
55
|
+
multi_json (~> 1.0)
|
56
|
+
rack (~> 1.0)
|
57
|
+
tilt (~> 1.1, != 1.3.0)
|
41
58
|
thor (0.19.1)
|
42
|
-
|
43
|
-
tzinfo (1.2.2)
|
44
|
-
thread_safe (~> 0.1)
|
59
|
+
tilt (1.4.1)
|
45
60
|
|
46
61
|
PLATFORMS
|
47
62
|
ruby
|
48
63
|
|
49
64
|
DEPENDENCIES
|
65
|
+
actionpack (~> 3.2.0)
|
50
66
|
bundler (~> 1.6)
|
67
|
+
minitest
|
68
|
+
railties (~> 3.2.0)
|
51
69
|
rake
|
52
70
|
strong_actions!
|
data/HISTORY.md
CHANGED
data/Rakefile
CHANGED
data/lib/strong_actions.rb
CHANGED
@@ -5,8 +5,7 @@ module StrongActions
|
|
5
5
|
include Singleton
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
@config_files
|
9
|
-
load_config_files
|
8
|
+
@config_files ||= ['config/acl.yml']
|
10
9
|
end
|
11
10
|
|
12
11
|
def config_files
|
@@ -14,31 +13,31 @@ module StrongActions
|
|
14
13
|
end
|
15
14
|
|
16
15
|
def config_files=(files)
|
17
|
-
config_files = files
|
18
|
-
load_config_files
|
16
|
+
@config_files = ([] << files).flatten
|
19
17
|
end
|
20
18
|
|
21
19
|
def roles
|
22
|
-
|
23
|
-
@acl.keys
|
20
|
+
definitions.keys
|
24
21
|
end
|
25
22
|
|
26
23
|
def role_definition(role)
|
27
|
-
|
28
|
-
@acl[role]
|
24
|
+
definitions[role]
|
29
25
|
end
|
30
26
|
|
31
27
|
private
|
32
28
|
|
33
|
-
def
|
34
|
-
@acl
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
29
|
+
def definitions
|
30
|
+
if @acl.nil? or Rails.env.development?
|
31
|
+
@acl = {}
|
32
|
+
config_files.each do |config_file|
|
33
|
+
yml = YAML.load_file(config_file)
|
34
|
+
yml.each do |role, values|
|
35
|
+
raise "role #{role} is already defined." if @acl.has_key?(role)
|
36
|
+
@acl[role] = values
|
37
|
+
end
|
40
38
|
end
|
41
39
|
end
|
40
|
+
@acl
|
42
41
|
end
|
43
42
|
|
44
43
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'strong_actions/decision'
|
2
|
+
|
1
3
|
module StrongActions
|
2
4
|
module ControllerExtensions
|
3
5
|
extend ActiveSupport::Concern
|
@@ -24,8 +26,6 @@ module StrongActions
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def available?(controller_name, action_name = nil, params = {})
|
27
|
-
action_name ||= 'index'
|
28
|
-
|
29
29
|
StrongActions.config.roles.each do |role|
|
30
30
|
return false unless judge(role, controller_name, action_name, params)
|
31
31
|
end
|
@@ -33,34 +33,9 @@ module StrongActions
|
|
33
33
|
true
|
34
34
|
end
|
35
35
|
|
36
|
-
def judge(role, controller_name, action_name, params)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
begin
|
41
|
-
role_object = eval(role)
|
42
|
-
rescue NameError
|
43
|
-
raise "role #{role} is not defined in controller"
|
44
|
-
end
|
45
|
-
|
46
|
-
controller_value = role_definition[controller_name]
|
47
|
-
return true if controller_value.nil?
|
48
|
-
|
49
|
-
if controller_value.is_a?(Hash)
|
50
|
-
action_value = controller_value[action_name]
|
51
|
-
else
|
52
|
-
action_value = controller_value
|
53
|
-
end
|
54
|
-
return true if action_value.nil?
|
55
|
-
|
56
|
-
action_value = [action_value] unless action_value.is_a?(Array)
|
57
|
-
action_value.each do |definition|
|
58
|
-
next if definition === true
|
59
|
-
return false unless definition
|
60
|
-
return false unless role_object.instance_eval(definition)
|
61
|
-
end
|
62
|
-
|
63
|
-
true
|
36
|
+
def judge(role, controller_name, action_name = nil, params = {})
|
37
|
+
@decision ||= StrongActions::Decision.new(self)
|
38
|
+
@decision.call(role, controller_name, action_name, params)
|
64
39
|
end
|
65
40
|
|
66
41
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module StrongActions
|
2
|
+
class Decision
|
3
|
+
|
4
|
+
def initialize(target)
|
5
|
+
@target = target
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(role, controller_name, action_name = nil, params = {})
|
9
|
+
role_definition = StrongActions.config.role_definition(role)
|
10
|
+
return true unless role_definition
|
11
|
+
|
12
|
+
begin
|
13
|
+
role_object = @target.instance_eval(role)
|
14
|
+
rescue NameError
|
15
|
+
raise "role #{role} is not defined in controller"
|
16
|
+
end
|
17
|
+
|
18
|
+
controller_value = role_definition[controller_name]
|
19
|
+
return true if controller_value.nil?
|
20
|
+
|
21
|
+
if controller_value.is_a?(Hash)
|
22
|
+
action_name ||= 'index'
|
23
|
+
action_value = controller_value[action_name]
|
24
|
+
else
|
25
|
+
action_value = controller_value
|
26
|
+
end
|
27
|
+
return true if action_value.nil?
|
28
|
+
|
29
|
+
action_value = [action_value] unless action_value.is_a?(Array)
|
30
|
+
action_value.each do |definition|
|
31
|
+
next if definition === true
|
32
|
+
return false unless definition
|
33
|
+
return false unless role_object.instance_eval(definition)
|
34
|
+
end
|
35
|
+
|
36
|
+
true
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/strong_actions.gemspec
CHANGED
data/test/config/acl.yml
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DecisionTest < Minitest::Test
|
4
|
+
|
5
|
+
def setup
|
6
|
+
StrongActions.config.config_files = File.join(File.dirname(__FILE__), 'config', 'acl.yml')
|
7
|
+
end
|
8
|
+
|
9
|
+
def decision
|
10
|
+
@decision ||= StrongActions::Decision.new(self)
|
11
|
+
end
|
12
|
+
|
13
|
+
def current_user
|
14
|
+
@user ||= User.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_controller_true
|
18
|
+
assert decision.call('current_user', 'books')
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_controller_false
|
22
|
+
assert ! decision.call('current_user', 'end_of_services')
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_action_true
|
26
|
+
assert decision.call('current_user', 'welcome', 'index')
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_action_false
|
30
|
+
assert ! decision.call('current_user', 'welcome', 'destroy')
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_action_default_to_index
|
34
|
+
assert decision.call('current_user', 'welcome')
|
35
|
+
assert ! decision.call('current_user', 'sessions')
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_admin_for_new
|
39
|
+
current_user.admin = false
|
40
|
+
assert decision.call('current_user', 'stores')
|
41
|
+
assert ! decision.call('current_user', 'stores', 'new')
|
42
|
+
|
43
|
+
current_user.admin = true
|
44
|
+
assert decision.call('current_user', 'stores')
|
45
|
+
assert decision.call('current_user', 'stores', 'new')
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
class User
|
51
|
+
attr_accessor :admin
|
52
|
+
|
53
|
+
def admin?
|
54
|
+
admin
|
55
|
+
end
|
56
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strong_actions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ichy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -84,6 +84,20 @@ dependencies:
|
|
84
84
|
- - ~>
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '1.6'
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
name: minitest
|
89
|
+
requirement: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
type: :development
|
95
|
+
prerelease: false
|
96
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
87
101
|
- !ruby/object:Gem::Dependency
|
88
102
|
name: rake
|
89
103
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,10 +129,14 @@ files:
|
|
115
129
|
- lib/strong_actions.rb
|
116
130
|
- lib/strong_actions/config.rb
|
117
131
|
- lib/strong_actions/controller_extensions.rb
|
132
|
+
- lib/strong_actions/decision.rb
|
118
133
|
- lib/strong_actions/forbidden_action.rb
|
119
134
|
- lib/strong_actions/railtie.rb
|
120
135
|
- lib/strong_actions/version.rb
|
121
136
|
- strong_actions.gemspec
|
137
|
+
- test/config/acl.yml
|
138
|
+
- test/decision_test.rb
|
139
|
+
- test/test_helper.rb
|
122
140
|
homepage: https://github.com/hybitz/strong_actions
|
123
141
|
licenses:
|
124
142
|
- MIT
|
@@ -143,4 +161,7 @@ rubygems_version: 2.2.2
|
|
143
161
|
signing_key:
|
144
162
|
specification_version: 4
|
145
163
|
summary: access control for rails controller/action
|
146
|
-
test_files:
|
164
|
+
test_files:
|
165
|
+
- test/config/acl.yml
|
166
|
+
- test/decision_test.rb
|
167
|
+
- test/test_helper.rb
|