role_based_authorization 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
= RoleBasedAuthorization
|
2
2
|
|
3
3
|
|
4
|
-
This library provide a very simple authorization system. It should work fine with
|
5
|
-
|
6
|
-
has been done in this regard. There are a lot of similar plugin/gems and probably
|
7
|
-
this is not better than any others (see http://steffenbartsch.com/blog/2008/08/rails-authorization-plugins/ for a nice review).
|
4
|
+
This library provide a very simple authorization system. It should work fine with most of the authentication plugins (and gems) out there, even though little testing has been done in this regard. There are a lot of similar plugin/gems and probably this is not better than any others (see http://steffenbartsch.com/blog/2008/08/rails-authorization-plugins/ for a nice review). I already used it in several small projects and it worked great
|
5
|
+
for my needs.
|
8
6
|
|
9
7
|
Installation:
|
10
8
|
* install the role_based_authorization by issuing:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.11
|
@@ -111,7 +111,7 @@ module RoleBasedAuthorization
|
|
111
111
|
|
112
112
|
# Returns true if one of the rules defined for this controller matches
|
113
113
|
# the given options
|
114
|
-
def
|
114
|
+
def exists_rule_matching_options? user, controllers, actions, ids
|
115
115
|
rules = self.class.role_auth_rules
|
116
116
|
AUTHORIZATION_LOGGER.debug("current set of rules: %s" % [rules.inspect])
|
117
117
|
|
@@ -168,7 +168,7 @@ module RoleBasedAuthorization
|
|
168
168
|
action,
|
169
169
|
ids.inspect])
|
170
170
|
|
171
|
-
if
|
171
|
+
if exists_rule_matching_options?( user, [controller,'application'], [:all,action] , ids )
|
172
172
|
AUTHORIZATION_LOGGER.info('returning true (access granted)')
|
173
173
|
return true
|
174
174
|
else
|
@@ -197,7 +197,7 @@ module RoleBasedAuthorization
|
|
197
197
|
# if_authorized?( edit_item_path ) { |opts| link_to('yyy', opts) }
|
198
198
|
|
199
199
|
def if_authorized? opts, &block
|
200
|
-
cleanup_url_regexp = %r{(
|
200
|
+
cleanup_url_regexp = %r{(#{ActionController::Base.relative_url_root})?}
|
201
201
|
|
202
202
|
url_options = nil
|
203
203
|
if opts.class == String
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{role_based_authorization}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.11"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Roberto Esposito"]
|
12
|
-
s.date = %q{2010-02-
|
12
|
+
s.date = %q{2010-02-17}
|
13
13
|
s.description = %q{Provides a simple DSL for specifying the authorization logic of your application. Install the gem, add a role attribute to your user model and your almost ready to go.}
|
14
14
|
s.email = %q{boborbt@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -10,8 +10,11 @@ class DummyUser
|
|
10
10
|
def role=(new_role) @role = new_role end
|
11
11
|
end
|
12
12
|
|
13
|
-
class
|
14
|
-
include RoleBasedAuthorization
|
13
|
+
class ApplicationController < ActionController::Base
|
14
|
+
include RoleBasedAuthorization
|
15
|
+
end
|
16
|
+
|
17
|
+
class DummyController < ApplicationController
|
15
18
|
|
16
19
|
def initialize() return @user = DummyUser.new end
|
17
20
|
def logged_in?() return true end
|
@@ -101,9 +104,32 @@ class RoleBasedAuthorizationTest < ActiveSupport::TestCase
|
|
101
104
|
|
102
105
|
|
103
106
|
test "helper method should work" do
|
107
|
+
got_inside = false
|
104
108
|
@controller.if_authorized?(:action => 'very_low_security') {
|
105
|
-
|
109
|
+
got_inside = true
|
106
110
|
}
|
111
|
+
|
112
|
+
assert got_inside
|
113
|
+
end
|
114
|
+
|
115
|
+
test "helper_method should work with paths" do
|
116
|
+
got_inside = false
|
117
|
+
@controller.if_authorized?( '/dummy/very_low_security' ) do
|
118
|
+
got_inside = true
|
119
|
+
end
|
120
|
+
|
121
|
+
assert got_inside
|
122
|
+
end
|
123
|
+
|
124
|
+
test "helper_method should work with resource paths even when prefixed with the ActionController::Base.relative_url_root" do
|
125
|
+
ActionController::Base.relative_url_root = '/appname'
|
126
|
+
|
127
|
+
got_inside = false
|
128
|
+
@controller.if_authorized?( '/appname/dummy/very_low_security' ) do
|
129
|
+
got_inside = true
|
130
|
+
end
|
131
|
+
|
132
|
+
assert got_inside
|
107
133
|
end
|
108
134
|
|
109
135
|
|
data/test/test_helper.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'active_support'
|
3
|
+
require 'action_controller'
|
3
4
|
require 'active_support/test_case'
|
5
|
+
require 'test/unit'
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
+
RAILS_ROOT='.'
|
8
|
+
AUTH_LOG_DIR = File.join(RAILS_ROOT,'log')
|
9
|
+
Dir.mkdir(AUTH_LOG_DIR) unless File.directory?(AUTH_LOG_DIR)
|
7
10
|
|
8
|
-
|
9
|
-
|
11
|
+
ActionController::Routing::Routes.draw do |map|
|
12
|
+
map.dummy_low_action '/dummy/very_low_security', :controller => :dummy, :action => :very_low_security
|
13
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: role_based_authorization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Esposito
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-17 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|