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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31fc4f5e9191a56ec48d3f35fdb424deaa0371ae
4
- data.tar.gz: 8a4e24d7bb75c0930820a4856b87bfc1f56a6fc2
3
+ metadata.gz: b1012764428766d50f9c26c61ec9a92a2f3eeaf9
4
+ data.tar.gz: 0da862ab3795a2e426dd8b7058285cbc1f5f57e2
5
5
  SHA512:
6
- metadata.gz: d71a0a3d851fdd2b8e7b95706e4a4040849cf4fca180f1fb11d673bcee0f7c04f88a1072a1391b0a2d77ddf39c7a1003107e5cd87fcb5cce7f88ae7bf1d84615
7
- data.tar.gz: de3ee53a2db2ee226297b46a1e7dc1b9f54c6117e6992fb69a0d5266d1b13f8d52b3ba8935b657a69e61077cba2d73db55fdc6f38f5993b3800798f305bef44f
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)
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.6)
13
- actionview (= 4.1.6)
14
- activesupport (= 4.1.6)
15
- rack (~> 1.5.2)
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
- actionview (4.1.6)
18
- activesupport (= 4.1.6)
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
- activesupport (4.1.6)
22
- i18n (~> 0.6, >= 0.6.9)
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.1)
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.6.11)
30
- json (1.8.1)
31
- minitest (5.4.2)
32
- rack (1.5.2)
33
- rack-test (0.6.2)
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
- railties (4.1.6)
36
- actionpack (= 4.1.6)
37
- activesupport (= 4.1.6)
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.3.2)
57
+ rake (10.4.2)
41
58
  thor (0.19.1)
42
- thread_safe (0.3.4)
59
+ thread_safe (0.3.5)
43
60
  tzinfo (1.2.2)
44
61
  thread_safe (~> 0.1)
45
62
 
data/HISTORY.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # History
2
2
 
3
+ ## 0.0.6
4
+ * supprts controller_path
5
+
3
6
  ## 0.0.5
4
7
  * do not raise error when role is undefined but not needed.
5
8
 
File without changes
@@ -0,0 +1,2 @@
1
+ test:
2
+ secret_key_base: testtest
@@ -1,7 +1,7 @@
1
1
  require 'strong_actions/decision'
2
2
 
3
3
  module StrongActions
4
- module ControllerExtensions
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, controller_name, action_name, params)
22
- message = "#{controller_name.capitalize}Controller##{action_name} is not permitted for role #{role}"
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?(controller_name, action_name = nil, params = {})
28
+ def available?(controller_path, action_name = nil, params = {})
29
29
  StrongActions.config.roles.each do |role|
30
- return false unless judge(role, controller_name, action_name, params)
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, controller_name, action_name = nil, params = {})
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, controller_name, action_name, params)
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, controller_name, action_name = nil, params = {})
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[controller_name]
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)
@@ -3,7 +3,7 @@ module StrongActions
3
3
 
4
4
  initializer 'strong_actions' do
5
5
  ActiveSupport.on_load :action_controller do
6
- include StrongActions::ControllerExtensions
6
+ include StrongActions::Controller
7
7
  end
8
8
  end
9
9
 
@@ -1,3 +1,3 @@
1
1
  module StrongActions
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -2,7 +2,7 @@ require 'action_controller'
2
2
  require "strong_actions/version"
3
3
  require "strong_actions/config"
4
4
  require "strong_actions/forbidden_action"
5
- require 'strong_actions/controller_extensions'
5
+ require 'strong_actions/controller'
6
6
 
7
7
  module StrongActions
8
8
 
@@ -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
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class DecisionTest < Minitest::Test
4
4
 
5
5
  def setup
6
- StrongActions.config.config_files = File.join(File.dirname(__FILE__), 'config', 'acl.yml')
6
+ StrongActions.config.config_files = File.join('config', 'acl.yml')
7
7
  end
8
8
 
9
9
  def decision
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.5
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: 2014-10-20 00:00:00.000000000 Z
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/controller_extensions.rb
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/config/acl.yml
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.1
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/config/acl.yml
167
+ - test/controller_test.rb
166
168
  - test/decision_test.rb
167
169
  - test/test_helper.rb
168
- has_rdoc: