strong_actions 0.0.6 → 0.0.7

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: b1012764428766d50f9c26c61ec9a92a2f3eeaf9
4
- data.tar.gz: 0da862ab3795a2e426dd8b7058285cbc1f5f57e2
3
+ metadata.gz: ca614b9e39bb1d36354f7acb67d35bbed3dce7c4
4
+ data.tar.gz: 58544302bc297db77b1ffc6240186b50a084f0de
5
5
  SHA512:
6
- metadata.gz: b0b8b1ebdbb1ff44ad641b52cfb098b15d4a1b7e44cfcbb04f4824c4a665cccc578c020b80b157ad3148466bc56c632504fa505dcf6096f0aeb0d026782b61a3
7
- data.tar.gz: 8301726f828161f264501e15548747dc3d255a3841dddea79d72ccb15b53268892aac272610d1aaa11a84e527438f4eaf4b5b55fc546660c092f36c6a744863e
6
+ metadata.gz: af45a6a6bd12d2087a2d8b5006029857b89ba03f87abc99046b5c147a80fefebac11a15c5c3cef6020ff823646484643cd911f4a0443d3bf7b64d37c1ceaaac3
7
+ data.tar.gz: 41ae17c38389bb6f2942274bf27ade8559090a6d1e58b09a36ae60257f1f9d010222f3d50056ff09f8ecc750a655a2ed682330da39e1a59f12dbc663cb93037e
data/.gitignore CHANGED
@@ -34,4 +34,5 @@ build/
34
34
  .rvmrc
35
35
 
36
36
  # Eclipse
37
+ /.buildpath
37
38
  /.project
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.3.3
6
+ - 2.2.6
7
+ - 2.1.9
8
+ script:
9
+ - bundle exec rake test
data/Gemfile.lock CHANGED
@@ -1,28 +1,28 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- strong_actions (0.0.6)
5
- actionpack (>= 3.2.0, < 5.0.0)
6
- activesupport (>= 3.2.0, < 5.0.0)
7
- railties (>= 3.2.0, < 5.0.0)
4
+ strong_actions (0.0.7)
5
+ actionpack (>= 4.0.0, < 5.0.0)
6
+ activesupport (>= 4.0.0, < 5.0.0)
7
+ railties (>= 4.0.0, < 5.0.0)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actionpack (4.2.1)
13
- actionview (= 4.2.1)
14
- activesupport (= 4.2.1)
12
+ actionpack (4.2.7.1)
13
+ actionview (= 4.2.7.1)
14
+ activesupport (= 4.2.7.1)
15
15
  rack (~> 1.6)
16
16
  rack-test (~> 0.6.2)
17
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)
18
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
19
+ actionview (4.2.7.1)
20
+ activesupport (= 4.2.7.1)
21
21
  builder (~> 3.1)
22
22
  erubis (~> 2.7.0)
23
23
  rails-dom-testing (~> 1.0, >= 1.0.5)
24
- rails-html-sanitizer (~> 1.0, >= 1.0.1)
25
- activesupport (4.2.1)
24
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
25
+ activesupport (4.2.7.1)
26
26
  i18n (~> 0.7)
27
27
  json (~> 1.7, >= 1.7.7)
28
28
  minitest (~> 5.1)
@@ -31,31 +31,31 @@ GEM
31
31
  builder (3.2.2)
32
32
  erubis (2.7.0)
33
33
  i18n (0.7.0)
34
- json (1.8.2)
35
- loofah (2.0.1)
34
+ json (1.8.3)
35
+ loofah (2.0.3)
36
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)
37
+ mini_portile2 (2.1.0)
38
+ minitest (5.10.1)
39
+ nokogiri (1.7.0.1)
40
+ mini_portile2 (~> 2.1.0)
41
+ rack (1.6.5)
42
42
  rack-test (0.6.3)
43
43
  rack (>= 1.0)
44
44
  rails-deprecated_sanitizer (1.0.3)
45
45
  activesupport (>= 4.2.0.alpha)
46
- rails-dom-testing (1.0.6)
46
+ rails-dom-testing (1.0.8)
47
47
  activesupport (>= 4.2.0.beta, < 5.0)
48
- nokogiri (~> 1.6.0)
48
+ nokogiri (~> 1.6)
49
49
  rails-deprecated_sanitizer (>= 1.0.1)
50
- rails-html-sanitizer (1.0.2)
50
+ rails-html-sanitizer (1.0.3)
51
51
  loofah (~> 2.0)
52
- railties (4.2.1)
53
- actionpack (= 4.2.1)
54
- activesupport (= 4.2.1)
52
+ railties (4.2.7.1)
53
+ actionpack (= 4.2.7.1)
54
+ activesupport (= 4.2.7.1)
55
55
  rake (>= 0.8.7)
56
56
  thor (>= 0.18.1, < 2.0)
57
- rake (10.4.2)
58
- thor (0.19.1)
57
+ rake (10.5.0)
58
+ thor (0.19.4)
59
59
  thread_safe (0.3.5)
60
60
  tzinfo (1.2.2)
61
61
  thread_safe (~> 0.1)
@@ -64,7 +64,10 @@ PLATFORMS
64
64
  ruby
65
65
 
66
66
  DEPENDENCIES
67
- bundler (~> 1.6)
67
+ bundler (~> 1.7)
68
68
  minitest
69
- rake
69
+ rake (~> 10.0)
70
70
  strong_actions!
71
+
72
+ BUNDLED WITH
73
+ 1.13.7
data/HISTORY.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # History
2
2
 
3
+ ## 0.0.7
4
+ * drop support for ruby-2.0
5
+ * drop support for rails-3.2
6
+
3
7
  ## 0.0.6
4
8
  * supprts controller_path
5
9
 
data/README.md CHANGED
@@ -37,6 +37,23 @@ then prepare config/acl.yml
37
37
 
38
38
  In above case, when a non-admin user try to access new_user_path, StrongActions::ForbiddenAction is thrown.
39
39
 
40
+ if all actions are restricted in the same way, you can make a definition on controller level.
41
+
42
+ current_user:
43
+ users: admin?
44
+
45
+ controller definition can be namespaced.
46
+
47
+ current_user:
48
+ admin/users: admin?
49
+
50
+ if you have multiple controllers under a namespace, namespace can be used.
51
+ ending with '/' indicates that is for namespace 'admin' and not controller 'admin'.
52
+
53
+ current_user:
54
+ admin/: admin?
55
+
56
+
40
57
  ### Handling error in controller
41
58
 
42
59
  In application_controller.rb, the error should be rescued like
data/config/acl.yml CHANGED
@@ -4,7 +4,12 @@ current_user:
4
4
  destroy: false
5
5
  books: true
6
6
  end_of_services: false
7
+ sessions:
8
+ index: false
7
9
  stores:
8
10
  new: admin?
9
- sessions:
10
- index: false
11
+ sys_admin/: sys_admin?
12
+ sys_admin/sys_config:
13
+ show: true
14
+ edit: sys_admin?
15
+
@@ -19,7 +19,7 @@ module StrongActions
19
19
  def authorize_roles!
20
20
  StrongActions.config.roles.each do |role|
21
21
  unless judge(role, controller_path, action_name, params)
22
- message = "#{controller_path.capitalize}Controller##{action_name} is not permitted for role #{role}"
22
+ message = "#{controller_path.classify}Controller##{action_name} is not permitted for role #{role}"
23
23
  raise StrongActions::ForbiddenAction.new(message)
24
24
  end
25
25
  end
@@ -6,27 +6,31 @@ module StrongActions
6
6
  end
7
7
 
8
8
  def call(role, controller_path, action_name = nil, params = {})
9
+ action_name ||= 'index'
9
10
  role_definition = StrongActions.config.role_definition(role)
10
11
  return true unless role_definition
11
12
 
12
- controller_value = role_definition[controller_path]
13
- return true if controller_value.nil?
13
+ controller_names_for(controller_path).each do |controller_name|
14
+ controller_value = role_definition[controller_name]
15
+ next if controller_value.nil?
14
16
 
15
- if controller_value.is_a?(Hash)
16
- action_name ||= 'index'
17
- action_value = controller_value[action_name]
18
- else
19
- action_value = controller_value
20
- end
21
- return true if action_value.nil?
17
+ if controller_value.is_a?(Hash)
18
+ action_value = controller_value[action_name]
19
+ else
20
+ action_value = controller_value
21
+ end
22
+ next if action_value.nil?
22
23
 
23
- action_value = [action_value] unless action_value.is_a?(Array)
24
- action_value.each do |definition|
25
- next if definition === true
26
- return false unless definition
24
+ action_values = Array(action_value)
25
+ action_values.each do |definition|
26
+ next if definition === true
27
+ return false if definition === false
27
28
 
28
- role_object = role_object_for(role)
29
- return false unless role_object.instance_eval(definition)
29
+ role_object = role_object_for(role)
30
+ return false unless role_object.instance_eval(definition)
31
+ end
32
+
33
+ break
30
34
  end
31
35
 
32
36
  true
@@ -40,5 +44,21 @@ module StrongActions
40
44
  end
41
45
  end
42
46
 
47
+ def controller_names_for(controller_path)
48
+ ret = []
49
+
50
+ path_elements = controller_path.split('/')
51
+ if path_elements.size == 1
52
+ ret = path_elements
53
+ else
54
+ path_elements.each_with_index do |path_element, i|
55
+ ret << ret.last.to_s + path_element + (i < path_elements.size - 1 ? '/' : '')
56
+ end
57
+ ret.reverse!
58
+ end
59
+
60
+ ret
61
+ end
62
+
43
63
  end
44
64
  end
@@ -1,3 +1,3 @@
1
1
  module StrongActions
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -17,11 +17,13 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency "activesupport", '>= 3.2.0', '< 5.0.0'
21
- spec.add_dependency "actionpack", '>= 3.2.0', '< 5.0.0'
22
- spec.add_dependency "railties", '>= 3.2.0', '< 5.0.0'
20
+ spec.required_ruby_version = '~> 2.1'
23
21
 
24
- spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_dependency "activesupport", '>= 4.0.0', '< 5.0.0'
23
+ spec.add_dependency "actionpack", '>= 4.0.0', '< 5.0.0'
24
+ spec.add_dependency "railties", '>= 4.0.0', '< 5.0.0'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.7"
25
27
  spec.add_development_dependency "minitest"
26
- spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rake", "~> 10.0"
27
29
  end
@@ -0,0 +1,54 @@
1
+ require 'test_helper'
2
+
3
+ module SysAdmin
4
+ class SysAdmin::SysConfigController < ActionController::Base
5
+ include StrongActions::Controller
6
+
7
+ def show
8
+ head :ok
9
+ end
10
+
11
+ def edit
12
+ head :ok
13
+ end
14
+
15
+ def update
16
+ head :ok
17
+ end
18
+
19
+ private
20
+
21
+ def current_user
22
+ unless @current_user
23
+ @current_user = Object.new
24
+ @current_user.instance_eval do
25
+ def sys_admin?
26
+ false
27
+ end
28
+ end
29
+ end
30
+
31
+ @current_user
32
+ end
33
+
34
+ end
35
+ end
36
+
37
+ class NamespaceTest < ActionController::TestCase
38
+ tests SysAdmin::SysConfigController
39
+
40
+ def test_allowed
41
+ get :show
42
+ assert_response :ok
43
+ end
44
+
45
+ def test_forbidden
46
+ assert_raise StrongActions::ForbiddenAction do
47
+ get :edit
48
+ end
49
+ assert_raise StrongActions::ForbiddenAction do
50
+ patch :update
51
+ end
52
+ end
53
+
54
+ end
data/test/test_helper.rb CHANGED
@@ -4,6 +4,8 @@ ENV["RAILS_ENV"] = "test"
4
4
  require 'minitest/autorun'
5
5
  require 'rails'
6
6
 
7
+ ActiveSupport.test_order = :sorted
8
+
7
9
  class FakeApplication < Rails::Application
8
10
  end
9
11
 
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.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - ichy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-17 00:00:00.000000000 Z
11
+ date: 2017-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.0
19
+ version: 4.0.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: 5.0.0
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 3.2.0
29
+ version: 4.0.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 5.0.0
@@ -36,7 +36,7 @@ dependencies:
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 3.2.0
39
+ version: 4.0.0
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
42
  version: 5.0.0
@@ -46,7 +46,7 @@ dependencies:
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 3.2.0
49
+ version: 4.0.0
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: 5.0.0
@@ -56,7 +56,7 @@ dependencies:
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 3.2.0
59
+ version: 4.0.0
60
60
  - - "<"
61
61
  - !ruby/object:Gem::Version
62
62
  version: 5.0.0
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: 3.2.0
69
+ version: 4.0.0
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
72
  version: 5.0.0
@@ -76,14 +76,14 @@ dependencies:
76
76
  requirements:
77
77
  - - "~>"
78
78
  - !ruby/object:Gem::Version
79
- version: '1.6'
79
+ version: '1.7'
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
- version: '1.6'
86
+ version: '1.7'
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: minitest
89
89
  requirement: !ruby/object:Gem::Requirement
@@ -102,16 +102,16 @@ dependencies:
102
102
  name: rake
103
103
  requirement: !ruby/object:Gem::Requirement
104
104
  requirements:
105
- - - ">="
105
+ - - "~>"
106
106
  - !ruby/object:Gem::Version
107
- version: '0'
107
+ version: '10.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
- version: '0'
114
+ version: '10.0'
115
115
  description: access control for rails controller/action
116
116
  email:
117
117
  - ichylinux@gmail.com
@@ -120,6 +120,7 @@ extensions: []
120
120
  extra_rdoc_files: []
121
121
  files:
122
122
  - ".gitignore"
123
+ - ".travis.yml"
123
124
  - Gemfile
124
125
  - Gemfile.lock
125
126
  - HISTORY.md
@@ -138,6 +139,7 @@ files:
138
139
  - strong_actions.gemspec
139
140
  - test/controller_test.rb
140
141
  - test/decision_test.rb
142
+ - test/namespace_test.rb
141
143
  - test/test_helper.rb
142
144
  homepage: https://github.com/hybitz/strong_actions
143
145
  licenses:
@@ -149,9 +151,9 @@ require_paths:
149
151
  - lib
150
152
  required_ruby_version: !ruby/object:Gem::Requirement
151
153
  requirements:
152
- - - ">="
154
+ - - "~>"
153
155
  - !ruby/object:Gem::Version
154
- version: '0'
156
+ version: '2.1'
155
157
  required_rubygems_version: !ruby/object:Gem::Requirement
156
158
  requirements:
157
159
  - - ">="
@@ -159,11 +161,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
161
  version: '0'
160
162
  requirements: []
161
163
  rubyforge_project:
162
- rubygems_version: 2.4.5
164
+ rubygems_version: 2.6.4
163
165
  signing_key:
164
166
  specification_version: 4
165
167
  summary: access control for rails controller/action
166
168
  test_files:
167
169
  - test/controller_test.rb
168
170
  - test/decision_test.rb
171
+ - test/namespace_test.rb
169
172
  - test/test_helper.rb