zuul 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,15 +4,17 @@ Zuul provides a simple role-based authorization framework for Rails apps.
4
4
 
5
5
  ==Quick Start
6
6
 
7
- Add a +role+ to your +users+ table
7
+ Zuul expects that you have a +current_user+ method available.
8
+
9
+ Add a +role+ to your +users+ table.
8
10
 
9
11
  add_column :users, :role, :string
10
12
 
11
- In your +User+ model, specify the valid roles
13
+ In your +User+ model, specify the valid roles.
12
14
 
13
15
  valid_roles :guest, :member, :admin
14
16
 
15
- In your +ApplicationController+, enable access restrictions
17
+ In your +ApplicationController+, enable access restrictions.
16
18
 
17
19
  include Zuul::RestrictAccess
18
20
  restrict_access
@@ -45,6 +47,9 @@ You can pass +require_user+ a list of roles and also indicate which actions to a
45
47
 
46
48
  <code>require_no_user :only => :edit, :update</code>
47
49
 
50
+ == Credits
51
+
52
+ Thanks to {Les Hill}[http://github.com/leshill] for help testing the +ApplicationController+ mixins.
48
53
 
49
54
  == Note on Patches/Pull Requests
50
55
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -53,54 +53,52 @@ module Zuul
53
53
  self.access_denied_message = options[:access_denied_message] || "You must be logged in to access this page"
54
54
  self.require_no_user_message = options[:require_no_user_message] || "You must be logged out to access this page"
55
55
  self.unauthorized_redirect_path = options[:unauthorized_redirect_path] || :unauthorized_path
56
- include ApplicationController::InstanceMethods
56
+ include InstanceMethods
57
57
  end
58
58
  end
59
59
 
60
- module ApplicationController
61
- module InstanceMethods
62
- def require_user(*roles)
63
- roles.flatten!
64
- return true if current_user && roles.empty?
65
- deny_access unless roles.any? do |role|
66
- method = (role.to_s + "?").to_sym
67
- if current_user && current_user.respond_to?(method)
68
- current_user.send(method)
69
- else
70
- false
71
- end
72
- end
73
- end
74
- private :require_user
75
-
76
- def require_no_user
77
- if current_user
78
- store_location
79
- flash[:notice] = self.class.require_no_user_message
80
- redirect_to send(self.class.unauthorized_redirect_path)
81
- return false
60
+ module InstanceMethods
61
+ def require_user(*roles)
62
+ roles.flatten!
63
+ return true if current_user && roles.empty?
64
+ deny_access unless roles.any? do |role|
65
+ method = (role.to_s + "?").to_sym
66
+ if current_user && current_user.respond_to?(method)
67
+ current_user.send(method)
68
+ else
69
+ false
82
70
  end
83
71
  end
84
- private :require_no_user
72
+ end
73
+ private :require_user
85
74
 
86
- def deny_access
75
+ def require_no_user
76
+ if current_user
87
77
  store_location
88
- flash[:notice] = self.class.access_denied_message
78
+ flash[:notice] = self.class.require_no_user_message
89
79
  redirect_to send(self.class.unauthorized_redirect_path)
90
80
  return false
91
81
  end
92
- private :deny_access
82
+ end
83
+ private :require_no_user
93
84
 
94
- def store_location
95
- session[:return_to] = request.request_uri
96
- end
97
- private :store_location
85
+ def deny_access
86
+ store_location
87
+ flash[:notice] = self.class.access_denied_message
88
+ redirect_to send(self.class.unauthorized_redirect_path)
89
+ return false
90
+ end
91
+ private :deny_access
98
92
 
99
- def unauthorized_path
100
- "/"
101
- end
102
- private :unauthorized_path
93
+ def store_location
94
+ session[:return_to] = request.request_uri
95
+ end
96
+ private :store_location
97
+
98
+ def unauthorized_path
99
+ "/"
103
100
  end
101
+ private :unauthorized_path
104
102
  end
105
103
  end
106
104
  end
Binary file
@@ -5201,4 +5201,188 @@ Processing StockController3#index (for 0.0.0.0 at 2009-11-01 06:15:03) [GET]
5201
5201
  Redirected to http://test.host/
5202
5202
  Filter chain halted as [#<Proc:0x024fc3b8@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:32>] rendered_or_redirected.
5203
5203
  Completed in 1ms (DB: 0) | 302 Found [http://test.host/stock_controller3]
5204
+ WARNING: Can't mass-assign these protected attributes: role
5205
+ SQL (0.7ms) select sqlite_version(*)
5206
+ SQL (0.9ms)  SELECT name
5207
+ FROM sqlite_master
5208
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
5209
+ 
5210
+ SQL (2.2ms) DROP TABLE "users"
5211
+ SQL (2.4ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "first_name" varchar(255), "last_name" varchar(255), "email" varchar(255), "username" varchar(255), "role" varchar(255)) 
5212
+
5213
+
5214
+ Processing Stock1Controller#index (for 0.0.0.0 at 2009-11-04 15:47:33) [GET]
5215
+ Redirected to http://test.host/
5216
+ Filter chain halted as [#<Proc:0x024fc69c@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:22>] rendered_or_redirected.
5217
+ Completed in 2ms (DB: 6) | 302 Found [http://test.host/stock1]
5218
+
5219
+
5220
+ Processing Stock1Controller#index (for 0.0.0.0 at 2009-11-04 15:47:33) [GET]
5221
+ Completed in 14ms (View: 1, DB: 0) | 200 OK [http://test.host/stock1]
5222
+
5223
+
5224
+ Processing Stock1Controller#index (for 0.0.0.0 at 2009-11-04 15:47:33) [GET]
5225
+ Redirected to http://test.host/
5226
+ Filter chain halted as [#<Proc:0x024fc69c@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:22>] rendered_or_redirected.
5227
+ Completed in 2ms (DB: 0) | 302 Found [http://test.host/stock1]
5228
+
5229
+
5230
+ Processing Stock1Controller#show (for 0.0.0.0 at 2009-11-04 15:47:33) [GET]
5231
+ Redirected to http://test.host/
5232
+ Filter chain halted as [#<Proc:0x024fc69c@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:22>] rendered_or_redirected.
5233
+ Completed in 2ms (DB: 0) | 302 Found [http://test.host/stock1]
5234
+
5235
+
5236
+ Processing Stock2Controller#show (for 0.0.0.0 at 2009-11-04 15:47:33) [GET]
5237
+ Redirected to http://test.host/
5238
+ Filter chain halted as [#<Proc:0x024fc69c@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:22>] rendered_or_redirected.
5239
+ Completed in 2ms (DB: 0) | 302 Found [http://test.host/stock2/show]
5240
+
5241
+
5242
+ Processing Stock2Controller#show (for 0.0.0.0 at 2009-11-04 15:47:33) [GET]
5243
+ Completed in 15ms (View: 1, DB: 0) | 200 OK [http://test.host/stock2/show]
5244
+
5245
+
5246
+ Processing Stock2Controller#index (for 0.0.0.0 at 2009-11-04 15:47:33) [GET]
5247
+ Completed in 2ms (View: 1, DB: 0) | 200 OK [http://test.host/stock2]
5248
+
5249
+
5250
+ Processing Stock3Controller#show (for 0.0.0.0 at 2009-11-04 15:47:33) [GET]
5251
+ Redirected to http://test.host/
5252
+ Filter chain halted as [#<Proc:0x024fc69c@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:22>] rendered_or_redirected.
5253
+ Completed in 1ms (DB: 0) | 302 Found [http://test.host/stock3/show]
5254
+
5255
+
5256
+ Processing Stock3Controller#show (for 0.0.0.0 at 2009-11-04 15:47:33) [GET]
5257
+ Completed in 13ms (View: 1, DB: 0) | 200 OK [http://test.host/stock3/show]
5258
+
5259
+
5260
+ Processing Stock3Controller#index (for 0.0.0.0 at 2009-11-04 15:47:33) [GET]
5261
+ Completed in 2ms (View: 1, DB: 0) | 200 OK [http://test.host/stock3]
5262
+
5263
+
5264
+ Processing Stock4Controller#index (for 0.0.0.0 at 2009-11-04 15:47:33) [GET]
5265
+ Redirected to http://test.host/
5266
+ Filter chain halted as [#<Proc:0x024fc69c@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:22>] rendered_or_redirected.
5267
+ Completed in 1ms (DB: 0) | 302 Found [http://test.host/stock4]
5268
+
5269
+
5270
+ Processing Stock4Controller#show (for 0.0.0.0 at 2009-11-04 15:47:33) [GET]
5271
+ Completed in 13ms (View: 1, DB: 0) | 200 OK [http://test.host/stock4/show]
5272
+
5273
+
5274
+ Processing Stock5Controller#index (for 0.0.0.0 at 2009-11-04 15:47:33) [GET]
5275
+ Redirected to http://test.host/
5276
+ Filter chain halted as [#<Proc:0x024fc3b8@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:32>] rendered_or_redirected.
5277
+ Completed in 1ms (DB: 0) | 302 Found [http://test.host/stock5]
5278
+
5279
+
5280
+ Processing StockController1#index (for 0.0.0.0 at 2009-11-04 15:47:33) [GET]
5281
+ Redirected to http://test.host/
5282
+ Filter chain halted as [#<Proc:0x024fc69c@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:22>] rendered_or_redirected.
5283
+ Completed in 1ms (DB: 0) | 302 Found [http://test.host/stock_controller1]
5284
+
5285
+
5286
+ Processing StockController2#index (for 0.0.0.0 at 2009-11-04 15:47:33) [GET]
5287
+ Redirected to http://test.host/signup
5288
+ Filter chain halted as [#<Proc:0x024fc69c@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:22>] rendered_or_redirected.
5289
+ Completed in 1ms (DB: 0) | 302 Found [http://test.host/stock_controller2]
5290
+
5291
+
5292
+ Processing StockController3#index (for 0.0.0.0 at 2009-11-04 15:47:33) [GET]
5293
+ Redirected to http://test.host/
5294
+ Filter chain halted as [#<Proc:0x024fc3b8@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:32>] rendered_or_redirected.
5295
+ Completed in 1ms (DB: 0) | 302 Found [http://test.host/stock_controller3]
5296
+ WARNING: Can't mass-assign these protected attributes: role
5297
+ SQL (0.6ms) select sqlite_version(*)
5298
+ SQL (0.8ms)  SELECT name
5299
+ FROM sqlite_master
5300
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
5301
+ 
5302
+ SQL (3.8ms) DROP TABLE "users"
5303
+ SQL (2.6ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "first_name" varchar(255), "last_name" varchar(255), "email" varchar(255), "username" varchar(255), "role" varchar(255)) 
5304
+
5305
+
5306
+ Processing Stock1Controller#index (for 0.0.0.0 at 2009-11-04 15:51:43) [GET]
5307
+ Redirected to http://test.host/
5308
+ Filter chain halted as [#<Proc:0x024fc69c@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:22>] rendered_or_redirected.
5309
+ Completed in 2ms (DB: 8) | 302 Found [http://test.host/stock1]
5310
+
5311
+
5312
+ Processing Stock1Controller#index (for 0.0.0.0 at 2009-11-04 15:51:43) [GET]
5313
+ Completed in 14ms (View: 1, DB: 0) | 200 OK [http://test.host/stock1]
5314
+
5315
+
5316
+ Processing Stock1Controller#index (for 0.0.0.0 at 2009-11-04 15:51:43) [GET]
5317
+ Redirected to http://test.host/
5318
+ Filter chain halted as [#<Proc:0x024fc69c@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:22>] rendered_or_redirected.
5319
+ Completed in 3ms (DB: 0) | 302 Found [http://test.host/stock1]
5320
+
5321
+
5322
+ Processing Stock1Controller#show (for 0.0.0.0 at 2009-11-04 15:51:43) [GET]
5323
+ Redirected to http://test.host/
5324
+ Filter chain halted as [#<Proc:0x024fc69c@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:22>] rendered_or_redirected.
5325
+ Completed in 2ms (DB: 0) | 302 Found [http://test.host/stock1]
5326
+
5327
+
5328
+ Processing Stock2Controller#show (for 0.0.0.0 at 2009-11-04 15:51:43) [GET]
5329
+ Redirected to http://test.host/
5330
+ Filter chain halted as [#<Proc:0x024fc69c@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:22>] rendered_or_redirected.
5331
+ Completed in 2ms (DB: 0) | 302 Found [http://test.host/stock2/show]
5332
+
5333
+
5334
+ Processing Stock2Controller#show (for 0.0.0.0 at 2009-11-04 15:51:43) [GET]
5335
+ Completed in 15ms (View: 1, DB: 0) | 200 OK [http://test.host/stock2/show]
5336
+
5337
+
5338
+ Processing Stock2Controller#index (for 0.0.0.0 at 2009-11-04 15:51:44) [GET]
5339
+ Completed in 2ms (View: 1, DB: 0) | 200 OK [http://test.host/stock2]
5340
+
5341
+
5342
+ Processing Stock3Controller#show (for 0.0.0.0 at 2009-11-04 15:51:44) [GET]
5343
+ Redirected to http://test.host/
5344
+ Filter chain halted as [#<Proc:0x024fc69c@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:22>] rendered_or_redirected.
5345
+ Completed in 1ms (DB: 0) | 302 Found [http://test.host/stock3/show]
5346
+
5347
+
5348
+ Processing Stock3Controller#show (for 0.0.0.0 at 2009-11-04 15:51:44) [GET]
5349
+ Completed in 14ms (View: 1, DB: 0) | 200 OK [http://test.host/stock3/show]
5350
+
5351
+
5352
+ Processing Stock3Controller#index (for 0.0.0.0 at 2009-11-04 15:51:44) [GET]
5353
+ Completed in 2ms (View: 1, DB: 0) | 200 OK [http://test.host/stock3]
5354
+
5355
+
5356
+ Processing Stock4Controller#index (for 0.0.0.0 at 2009-11-04 15:51:44) [GET]
5357
+ Redirected to http://test.host/
5358
+ Filter chain halted as [#<Proc:0x024fc69c@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:22>] rendered_or_redirected.
5359
+ Completed in 2ms (DB: 0) | 302 Found [http://test.host/stock4]
5360
+
5361
+
5362
+ Processing Stock4Controller#show (for 0.0.0.0 at 2009-11-04 15:51:44) [GET]
5363
+ Completed in 13ms (View: 1, DB: 0) | 200 OK [http://test.host/stock4/show]
5364
+
5365
+
5366
+ Processing Stock5Controller#index (for 0.0.0.0 at 2009-11-04 15:51:44) [GET]
5367
+ Redirected to http://test.host/
5368
+ Filter chain halted as [#<Proc:0x024fc3b8@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:32>] rendered_or_redirected.
5369
+ Completed in 1ms (DB: 0) | 302 Found [http://test.host/stock5]
5370
+
5371
+
5372
+ Processing StockController1#index (for 0.0.0.0 at 2009-11-04 15:51:44) [GET]
5373
+ Redirected to http://test.host/
5374
+ Filter chain halted as [#<Proc:0x024fc69c@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:22>] rendered_or_redirected.
5375
+ Completed in 1ms (DB: 0) | 302 Found [http://test.host/stock_controller1]
5376
+
5377
+
5378
+ Processing StockController2#index (for 0.0.0.0 at 2009-11-04 15:51:44) [GET]
5379
+ Redirected to http://test.host/signup
5380
+ Filter chain halted as [#<Proc:0x024fc69c@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:22>] rendered_or_redirected.
5381
+ Completed in 1ms (DB: 0) | 302 Found [http://test.host/stock_controller2]
5382
+
5383
+
5384
+ Processing StockController3#index (for 0.0.0.0 at 2009-11-04 15:51:44) [GET]
5385
+ Redirected to http://test.host/
5386
+ Filter chain halted as [#<Proc:0x024fc3b8@/Users/wes/Projects/zuul/lib/zuul/restrict_access.rb:32>] rendered_or_redirected.
5387
+ Completed in 1ms (DB: 0) | 302 Found [http://test.host/stock_controller3]
5204
5388
  WARNING: Can't mass-assign these protected attributes: role
data/zuul.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{zuul}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Wes Gibbs"]
12
- s.date = %q{2009-11-01}
12
+ s.date = %q{2009-11-04}
13
13
  s.description = %q{A simple authorization solution for Rails apps.}
14
14
  s.email = %q{wes@hashrocket.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zuul
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wes Gibbs
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-01 00:00:00 -04:00
12
+ date: 2009-11-04 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency