authorize_when 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest +7 -0
- data/README.textile +56 -0
- data/Rakefile +15 -0
- data/authorize_when.gemspec +30 -0
- data/init.rb +2 -0
- data/lib/authorize_when.rb +48 -0
- data/lib/authorize_when/forbidden_exception.rb +22 -0
- metadata +81 -0
data/Manifest
ADDED
data/README.textile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
h1. AuthorizeWhen
|
2
|
+
|
3
|
+
Super simple authorization system for Rails. *AuthorizeWhen* provides a small DSL to write authorization rules in your controllers.
|
4
|
+
Each rule can be declared using the @authorize@ method and consists of a @block@ that must evaluate to @true@ otherwise a @ForbiddenException@ will be thrown.
|
5
|
+
|
6
|
+
h2. Use It
|
7
|
+
|
8
|
+
<pre>
|
9
|
+
class VideosController
|
10
|
+
authorize :when_not => [:show, :index] { current_user.has_role? :administrator }
|
11
|
+
end
|
12
|
+
</pre>
|
13
|
+
|
14
|
+
|
15
|
+
h2. Installation
|
16
|
+
|
17
|
+
h3. As a gem:
|
18
|
+
|
19
|
+
Add this line to your @environment.rb@:
|
20
|
+
|
21
|
+
<pre>
|
22
|
+
config.gem "authorize_when"
|
23
|
+
</pre>
|
24
|
+
|
25
|
+
and then do
|
26
|
+
|
27
|
+
<pre>
|
28
|
+
rake gems:install
|
29
|
+
</pre>
|
30
|
+
|
31
|
+
or just
|
32
|
+
|
33
|
+
<pre>
|
34
|
+
gem install authorize_when
|
35
|
+
</pre>
|
36
|
+
|
37
|
+
|
38
|
+
h3. As a plugin
|
39
|
+
|
40
|
+
<pre>
|
41
|
+
script/plugin install git://github.com/mcasimir/authorize_when.git
|
42
|
+
</pre>
|
43
|
+
|
44
|
+
|
45
|
+
h2. Project Details
|
46
|
+
|
47
|
+
h3. Roadmap
|
48
|
+
* Add a @forbid@ instance method that raise @ForbiddenException@
|
49
|
+
* Add an _"authorize with schema"_ feature that allows to group and reuse authorization rules
|
50
|
+
* Provide a customizable default way to recover from @ForbiddenException@, eg. redirect to /404
|
51
|
+
* Rescue from every exception in authorize block reraising a new @ForbiddenException@
|
52
|
+
|
53
|
+
h3. Copyright
|
54
|
+
|
55
|
+
Copyright © 2010 Maurizio Casimirri, released under the LGPL license.
|
56
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('authorize_when', '0.1.0') do |p|
|
6
|
+
p.description = "Super simple authorization system for Rails"
|
7
|
+
p.url = "http://github.com/mcasimir/authorize_when"
|
8
|
+
p.author = "Maurizio Casimirri"
|
9
|
+
p.email = "maurizio.cas@gmail.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
15
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{authorize_when}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Maurizio Casimirri"]
|
9
|
+
s.date = %q{2010-07-18}
|
10
|
+
s.description = %q{Super simple authorization system for Rails}
|
11
|
+
s.email = %q{maurizio.cas@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["README.textile", "lib/authorize_when.rb", "lib/authorize_when/forbidden_exception.rb"]
|
13
|
+
s.files = ["README.textile", "Rakefile", "authorize_when.gemspec", "init.rb", "lib/authorize_when.rb", "lib/authorize_when/forbidden_exception.rb", "Manifest"]
|
14
|
+
s.homepage = %q{http://github.com/mcasimir/authorize_when}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Authorize_when", "--main", "README.textile"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{authorize_when}
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{Super simple authorization system for Rails}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Author:: Maurizio Casimirri (mailto:maurizio.cas@gmail.com)
|
2
|
+
# Copyright:: Copyright (c) 2010 Maurizio Casimirri
|
3
|
+
|
4
|
+
# This library is free software; you can redistribute it and/or
|
5
|
+
# modify it under the terms of the GNU Lesser General Public
|
6
|
+
# License as published by the Free Software Foundation; either
|
7
|
+
# version 2.1 of the License, or (at your option) any later version.
|
8
|
+
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
|
+
|
18
|
+
module AuthorizeWhen
|
19
|
+
|
20
|
+
|
21
|
+
def self.included(base)
|
22
|
+
base.extend ClassMethods
|
23
|
+
end
|
24
|
+
|
25
|
+
module ClassMethods
|
26
|
+
def authorize(options = {}, &block)
|
27
|
+
|
28
|
+
filter_options = {}
|
29
|
+
filter_options[:only] = options[:when]
|
30
|
+
filter_options[:except] = options[:when_not]
|
31
|
+
|
32
|
+
self.send(:before_filter, filter_options) do |controller|
|
33
|
+
if !controller.instance_eval(&block)
|
34
|
+
raise AuthorizeWhen::ForbiddenException
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end # ~ authorize
|
39
|
+
end # ~ ClassMethods
|
40
|
+
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
class ActionController::Base
|
46
|
+
include AuthorizeWhen
|
47
|
+
end
|
48
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Author:: Maurizio Casimirri (mailto:maurizio.cas@gmail.com)
|
2
|
+
# Copyright:: Copyright (c) 2010 Maurizio Casimirri
|
3
|
+
|
4
|
+
# This library is free software; you can redistribute it and/or
|
5
|
+
# modify it under the terms of the GNU Lesser General Public
|
6
|
+
# License as published by the Free Software Foundation; either
|
7
|
+
# version 2.1 of the License, or (at your option) any later version.
|
8
|
+
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
|
+
|
18
|
+
module AuthorizeWhen
|
19
|
+
class ForbiddenException < Exception
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: authorize_when
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Maurizio Casimirri
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-07-18 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Super simple authorization system for Rails
|
23
|
+
email: maurizio.cas@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README.textile
|
30
|
+
- lib/authorize_when.rb
|
31
|
+
- lib/authorize_when/forbidden_exception.rb
|
32
|
+
files:
|
33
|
+
- README.textile
|
34
|
+
- Rakefile
|
35
|
+
- authorize_when.gemspec
|
36
|
+
- init.rb
|
37
|
+
- lib/authorize_when.rb
|
38
|
+
- lib/authorize_when/forbidden_exception.rb
|
39
|
+
- Manifest
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/mcasimir/authorize_when
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --line-numbers
|
47
|
+
- --inline-source
|
48
|
+
- --title
|
49
|
+
- Authorize_when
|
50
|
+
- --main
|
51
|
+
- README.textile
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 11
|
69
|
+
segments:
|
70
|
+
- 1
|
71
|
+
- 2
|
72
|
+
version: "1.2"
|
73
|
+
requirements: []
|
74
|
+
|
75
|
+
rubyforge_project: authorize_when
|
76
|
+
rubygems_version: 1.3.7
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Super simple authorization system for Rails
|
80
|
+
test_files: []
|
81
|
+
|