strong_actions 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +37 -20
- data/HISTORY.md +3 -0
- data/{test/config → config}/acl.yml +0 -0
- data/config/secrets.yml +2 -0
- data/lib/strong_actions/{controller_extensions.rb → controller.rb} +12 -7
- data/lib/strong_actions/decision.rb +2 -2
- data/lib/strong_actions/railtie.rb +1 -1
- data/lib/strong_actions/version.rb +1 -1
- data/lib/strong_actions.rb +1 -1
- data/test/controller_test.rb +44 -0
- data/test/decision_test.rb +1 -1
- data/test/test_helper.rb +25 -0
- metadata +29 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1012764428766d50f9c26c61ec9a92a2f3eeaf9
|
4
|
+
data.tar.gz: 0da862ab3795a2e426dd8b7058285cbc1f5f57e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0b8b1ebdbb1ff44ad641b52cfb098b15d4a1b7e44cfcbb04f4824c4a665cccc578c020b80b157ad3148466bc56c632504fa505dcf6096f0aeb0d026782b61a3
|
7
|
+
data.tar.gz: 8301726f828161f264501e15548747dc3d255a3841dddea79d72ccb15b53268892aac272610d1aaa11a84e527438f4eaf4b5b55fc546660c092f36c6a744863e
|
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.6)
|
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,37 +9,54 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
actionpack (4.1
|
13
|
-
actionview (= 4.1
|
14
|
-
activesupport (= 4.1
|
15
|
-
rack (~> 1.
|
12
|
+
actionpack (4.2.1)
|
13
|
+
actionview (= 4.2.1)
|
14
|
+
activesupport (= 4.2.1)
|
15
|
+
rack (~> 1.6)
|
16
16
|
rack-test (~> 0.6.2)
|
17
|
-
|
18
|
-
|
17
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
18
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
19
|
+
actionview (4.2.1)
|
20
|
+
activesupport (= 4.2.1)
|
19
21
|
builder (~> 3.1)
|
20
22
|
erubis (~> 2.7.0)
|
21
|
-
|
22
|
-
|
23
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
24
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
25
|
+
activesupport (4.2.1)
|
26
|
+
i18n (~> 0.7)
|
23
27
|
json (~> 1.7, >= 1.7.7)
|
24
28
|
minitest (~> 5.1)
|
25
|
-
thread_safe (~> 0.
|
29
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
26
30
|
tzinfo (~> 1.1)
|
27
31
|
builder (3.2.2)
|
28
32
|
erubis (2.7.0)
|
29
|
-
i18n (0.
|
30
|
-
json (1.8.
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
i18n (0.7.0)
|
34
|
+
json (1.8.2)
|
35
|
+
loofah (2.0.1)
|
36
|
+
nokogiri (>= 1.5.9)
|
37
|
+
mini_portile (0.6.2)
|
38
|
+
minitest (5.6.0)
|
39
|
+
nokogiri (1.6.6.2)
|
40
|
+
mini_portile (~> 0.6.0)
|
41
|
+
rack (1.6.0)
|
42
|
+
rack-test (0.6.3)
|
34
43
|
rack (>= 1.0)
|
35
|
-
|
36
|
-
|
37
|
-
|
44
|
+
rails-deprecated_sanitizer (1.0.3)
|
45
|
+
activesupport (>= 4.2.0.alpha)
|
46
|
+
rails-dom-testing (1.0.6)
|
47
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
48
|
+
nokogiri (~> 1.6.0)
|
49
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
50
|
+
rails-html-sanitizer (1.0.2)
|
51
|
+
loofah (~> 2.0)
|
52
|
+
railties (4.2.1)
|
53
|
+
actionpack (= 4.2.1)
|
54
|
+
activesupport (= 4.2.1)
|
38
55
|
rake (>= 0.8.7)
|
39
56
|
thor (>= 0.18.1, < 2.0)
|
40
|
-
rake (10.
|
57
|
+
rake (10.4.2)
|
41
58
|
thor (0.19.1)
|
42
|
-
thread_safe (0.3.
|
59
|
+
thread_safe (0.3.5)
|
43
60
|
tzinfo (1.2.2)
|
44
61
|
thread_safe (~> 0.1)
|
45
62
|
|
data/HISTORY.md
CHANGED
File without changes
|
data/config/secrets.yml
ADDED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'strong_actions/decision'
|
2
2
|
|
3
3
|
module StrongActions
|
4
|
-
module
|
4
|
+
module Controller
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
included do
|
@@ -18,25 +18,30 @@ module StrongActions
|
|
18
18
|
|
19
19
|
def authorize_roles!
|
20
20
|
StrongActions.config.roles.each do |role|
|
21
|
-
unless judge(role,
|
22
|
-
message = "#{
|
21
|
+
unless judge(role, controller_path, action_name, params)
|
22
|
+
message = "#{controller_path.capitalize}Controller##{action_name} is not permitted for role #{role}"
|
23
23
|
raise StrongActions::ForbiddenAction.new(message)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def available?(
|
28
|
+
def available?(controller_path, action_name = nil, params = {})
|
29
29
|
StrongActions.config.roles.each do |role|
|
30
|
-
return false unless judge(role,
|
30
|
+
return false unless judge(role, controller_path, action_name, params)
|
31
31
|
end
|
32
32
|
|
33
33
|
true
|
34
34
|
end
|
35
35
|
|
36
|
-
def judge(role,
|
36
|
+
def judge(role, controller_path, action_name = nil, params = {})
|
37
|
+
controller_path = normalize_controller_path(controller_path)
|
38
|
+
|
37
39
|
@decision ||= StrongActions::Decision.new(self)
|
38
|
-
@decision.call(role,
|
40
|
+
@decision.call(role, controller_path, action_name, params)
|
39
41
|
end
|
40
42
|
|
43
|
+
def normalize_controller_path(controller_path)
|
44
|
+
controller_path.start_with?('/') ? controller_path[1..-1] : controller_path
|
45
|
+
end
|
41
46
|
end
|
42
47
|
end
|
@@ -5,11 +5,11 @@ module StrongActions
|
|
5
5
|
@target = target
|
6
6
|
end
|
7
7
|
|
8
|
-
def call(role,
|
8
|
+
def call(role, controller_path, action_name = nil, params = {})
|
9
9
|
role_definition = StrongActions.config.role_definition(role)
|
10
10
|
return true unless role_definition
|
11
11
|
|
12
|
-
controller_value = role_definition[
|
12
|
+
controller_value = role_definition[controller_path]
|
13
13
|
return true if controller_value.nil?
|
14
14
|
|
15
15
|
if controller_value.is_a?(Hash)
|
data/lib/strong_actions.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class WelcomeController < ActionController::Base
|
4
|
+
include StrongActions::Controller
|
5
|
+
|
6
|
+
def index
|
7
|
+
head :ok
|
8
|
+
end
|
9
|
+
|
10
|
+
def destroy
|
11
|
+
head :ok
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def current_user
|
17
|
+
unless @current_user
|
18
|
+
@current_user = Object.new
|
19
|
+
@current_user.instance_eval do
|
20
|
+
def admin?
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
@current_user
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class ControllerTest < ActionController::TestCase
|
31
|
+
tests WelcomeController
|
32
|
+
|
33
|
+
def test_allowed
|
34
|
+
get :index
|
35
|
+
assert_response :ok
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_forbidden
|
39
|
+
assert_raise StrongActions::ForbiddenAction do
|
40
|
+
delete :destroy
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/test/decision_test.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -3,4 +3,29 @@ ENV["RAILS_ENV"] = "test"
|
|
3
3
|
|
4
4
|
require 'minitest/autorun'
|
5
5
|
require 'rails'
|
6
|
+
|
7
|
+
class FakeApplication < Rails::Application
|
8
|
+
end
|
9
|
+
|
10
|
+
Rails.application = FakeApplication
|
11
|
+
|
6
12
|
require 'strong_actions'
|
13
|
+
|
14
|
+
module ActionController
|
15
|
+
SharedTestRoutes = ActionDispatch::Routing::RouteSet.new
|
16
|
+
SharedTestRoutes.draw do
|
17
|
+
get ':controller(/:action)'
|
18
|
+
delete ':controller(/:action)'
|
19
|
+
end
|
20
|
+
|
21
|
+
class Base
|
22
|
+
include ActionController::Testing
|
23
|
+
include SharedTestRoutes.url_helpers
|
24
|
+
end
|
25
|
+
|
26
|
+
class ActionController::TestCase
|
27
|
+
setup do
|
28
|
+
@routes = SharedTestRoutes
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,115 +1,115 @@
|
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ichy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.2.0
|
20
|
-
- - <
|
20
|
+
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 5.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 3.2.0
|
30
|
-
- - <
|
30
|
+
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 5.0.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: actionpack
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- -
|
37
|
+
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: 3.2.0
|
40
|
-
- - <
|
40
|
+
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: 5.0.0
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- -
|
47
|
+
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: 3.2.0
|
50
|
-
- - <
|
50
|
+
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: 5.0.0
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: railties
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
|
-
- -
|
57
|
+
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: 3.2.0
|
60
|
-
- - <
|
60
|
+
- - "<"
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: 5.0.0
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: 3.2.0
|
70
|
-
- - <
|
70
|
+
- - "<"
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: 5.0.0
|
73
73
|
- !ruby/object:Gem::Dependency
|
74
74
|
name: bundler
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
|
-
- - ~>
|
77
|
+
- - "~>"
|
78
78
|
- !ruby/object:Gem::Version
|
79
79
|
version: '1.6'
|
80
80
|
type: :development
|
81
81
|
prerelease: false
|
82
82
|
version_requirements: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
|
-
- - ~>
|
84
|
+
- - "~>"
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '1.6'
|
87
87
|
- !ruby/object:Gem::Dependency
|
88
88
|
name: minitest
|
89
89
|
requirement: !ruby/object:Gem::Requirement
|
90
90
|
requirements:
|
91
|
-
- -
|
91
|
+
- - ">="
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
type: :development
|
95
95
|
prerelease: false
|
96
96
|
version_requirements: !ruby/object:Gem::Requirement
|
97
97
|
requirements:
|
98
|
-
- -
|
98
|
+
- - ">="
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '0'
|
101
101
|
- !ruby/object:Gem::Dependency
|
102
102
|
name: rake
|
103
103
|
requirement: !ruby/object:Gem::Requirement
|
104
104
|
requirements:
|
105
|
-
- -
|
105
|
+
- - ">="
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: '0'
|
108
108
|
type: :development
|
109
109
|
prerelease: false
|
110
110
|
version_requirements: !ruby/object:Gem::Requirement
|
111
111
|
requirements:
|
112
|
-
- -
|
112
|
+
- - ">="
|
113
113
|
- !ruby/object:Gem::Version
|
114
114
|
version: '0'
|
115
115
|
description: access control for rails controller/action
|
@@ -119,22 +119,24 @@ executables: []
|
|
119
119
|
extensions: []
|
120
120
|
extra_rdoc_files: []
|
121
121
|
files:
|
122
|
-
- .gitignore
|
122
|
+
- ".gitignore"
|
123
123
|
- Gemfile
|
124
124
|
- Gemfile.lock
|
125
125
|
- HISTORY.md
|
126
126
|
- LICENSE
|
127
127
|
- README.md
|
128
128
|
- Rakefile
|
129
|
+
- config/acl.yml
|
130
|
+
- config/secrets.yml
|
129
131
|
- lib/strong_actions.rb
|
130
132
|
- lib/strong_actions/config.rb
|
131
|
-
- lib/strong_actions/
|
133
|
+
- lib/strong_actions/controller.rb
|
132
134
|
- lib/strong_actions/decision.rb
|
133
135
|
- lib/strong_actions/forbidden_action.rb
|
134
136
|
- lib/strong_actions/railtie.rb
|
135
137
|
- lib/strong_actions/version.rb
|
136
138
|
- strong_actions.gemspec
|
137
|
-
- test/
|
139
|
+
- test/controller_test.rb
|
138
140
|
- test/decision_test.rb
|
139
141
|
- test/test_helper.rb
|
140
142
|
homepage: https://github.com/hybitz/strong_actions
|
@@ -147,22 +149,21 @@ require_paths:
|
|
147
149
|
- lib
|
148
150
|
required_ruby_version: !ruby/object:Gem::Requirement
|
149
151
|
requirements:
|
150
|
-
- -
|
152
|
+
- - ">="
|
151
153
|
- !ruby/object:Gem::Version
|
152
154
|
version: '0'
|
153
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
156
|
requirements:
|
155
|
-
- -
|
157
|
+
- - ">="
|
156
158
|
- !ruby/object:Gem::Version
|
157
159
|
version: '0'
|
158
160
|
requirements: []
|
159
161
|
rubyforge_project:
|
160
|
-
rubygems_version: 2.4.
|
162
|
+
rubygems_version: 2.4.5
|
161
163
|
signing_key:
|
162
164
|
specification_version: 4
|
163
165
|
summary: access control for rails controller/action
|
164
166
|
test_files:
|
165
|
-
- test/
|
167
|
+
- test/controller_test.rb
|
166
168
|
- test/decision_test.rb
|
167
169
|
- test/test_helper.rb
|
168
|
-
has_rdoc:
|