mdarby-restful_acl 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/MIT-LICENSE +20 -0
- data/README +3 -0
- data/Rakefile +22 -0
- data/init.rb +1 -0
- data/lib/restful_acl.rb +54 -0
- data/lib/restful_acl_helper.rb +43 -0
- data/tasks/restful_acl_tasks.rake +4 -0
- data/uninstall.rb +1 -0
- metadata +61 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Matt Darby
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
RESTful_ACL is a simple Access Control Layer for Ruby on Rails. It restricts access on a fine-grained level to any RESTful MVC stack. While the ACL structure and engine are provided by this plugin, the implementation is fully up to the user. Every application is different and everyone likes to setup their User / Account / Role resources differently; this plugin will allow you to do your thing and keep that thing locked down.
|
2
|
+
|
3
|
+
Please see the wiki (http://github.com/mdarby/restful_acl/wikis/) for more information.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the restful_acl plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Generate documentation for the restful_acl plugin.'
|
16
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
18
|
+
rdoc.title = 'RestfulAcl'
|
19
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
+
rdoc.rdoc_files.include('README')
|
21
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/rails/init"
|
data/lib/restful_acl.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
module RestfulAcl
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
base.send :include, ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
|
10
|
+
def has_permission?
|
11
|
+
return true if current_user.respond_to?("is_admin?") && current_user.is_admin? # Admins rule.
|
12
|
+
|
13
|
+
begin
|
14
|
+
# Load the Model based on the controller name
|
15
|
+
klass = self.controller_name.classify.constantize
|
16
|
+
|
17
|
+
# Load the object requested if the param[:id] exists
|
18
|
+
object = klass.find(params[:id]) unless params[:id].blank?
|
19
|
+
|
20
|
+
# Let's let the Model decide what is acceptable
|
21
|
+
permission_denied unless case params[:action]
|
22
|
+
when "index" then klass.is_readable_by(current_user)
|
23
|
+
when "show" then klass.is_readable_by(current_user, object)
|
24
|
+
when "edit", "update" then object.is_updatable_by(current_user)
|
25
|
+
when "new", "create" then klass.is_creatable_by(current_user)
|
26
|
+
when "destroy" then object.is_deletable_by(current_user)
|
27
|
+
else klass.is_readable_by(current_user)
|
28
|
+
end
|
29
|
+
|
30
|
+
rescue
|
31
|
+
# Failsafe: If any funny business is going on, log and redirect
|
32
|
+
routing_error
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def permission_denied
|
40
|
+
logger.info("[ACL] Permission denied to %s at %s for %s" %
|
41
|
+
[(logged_in? ? current_user.login : 'guest'), Time.now, request.request_uri])
|
42
|
+
|
43
|
+
redirect_to denied_url
|
44
|
+
end
|
45
|
+
|
46
|
+
def routing_error
|
47
|
+
logger.info("[ACL] Routing error by %s at %s for %s" %
|
48
|
+
[(logged_in? ? current_user.login : 'guest'), Time.now, request.request_uri])
|
49
|
+
|
50
|
+
redirect_to error_url
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module RestfulAclHelper
|
2
|
+
|
3
|
+
def creatable
|
4
|
+
return true if admin_enabled
|
5
|
+
|
6
|
+
klass.is_creatable_by(current_user)
|
7
|
+
end
|
8
|
+
alias_method :createable, :creatable
|
9
|
+
|
10
|
+
|
11
|
+
def updatable(object)
|
12
|
+
return true if admin_enabled
|
13
|
+
|
14
|
+
object.is_updatable_by(current_user)
|
15
|
+
end
|
16
|
+
alias_method :updateable, :updatable
|
17
|
+
|
18
|
+
|
19
|
+
def deletable(object)
|
20
|
+
return true if admin_enabled
|
21
|
+
|
22
|
+
object.is_deletable_by(current_user)
|
23
|
+
end
|
24
|
+
alias_method :deleteable, :deletable
|
25
|
+
|
26
|
+
|
27
|
+
def readable(object = nil)
|
28
|
+
return true if admin_enabled
|
29
|
+
|
30
|
+
klass.is_readable_by(current_user, object)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def admin_enabled
|
36
|
+
current_user.respond_to?("is_admin?") && current_user.is_admin?
|
37
|
+
end
|
38
|
+
|
39
|
+
def klass
|
40
|
+
params[:controller].classify.constantize
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mdarby-restful_acl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "1.0"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Darby
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-12-14 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A Rails gem that provides fine grained access control to RESTful resources in a Rails 2.0+ project.
|
17
|
+
email: matt@matt-darby.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- MIT-LICENSE
|
26
|
+
- README
|
27
|
+
- Rakefile
|
28
|
+
- init.rb
|
29
|
+
- lib/restful_acl.rb
|
30
|
+
- lib/restful_acl_helper.rb
|
31
|
+
- rails/init.rb
|
32
|
+
- tasks/restful_acl_tasks.rake
|
33
|
+
- uninstall.rb
|
34
|
+
has_rdoc: false
|
35
|
+
homepage: http://github.com/mdarby/restful_acl/tree/master
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.2.0
|
57
|
+
signing_key:
|
58
|
+
specification_version: 2
|
59
|
+
summary: Object-level access control
|
60
|
+
test_files: []
|
61
|
+
|