action-guard 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +69 -4
- data/VERSION +1 -1
- data/action-guard.gemspec +75 -0
- metadata +6 -6
- data/action_guard.gemspec +0 -24
data/README.md
CHANGED
@@ -12,26 +12,91 @@ following design principles in mind:
|
|
12
12
|
'fullpath' to the authorization which is then matched against a set of
|
13
13
|
authorisation rules.
|
14
14
|
|
15
|
+
# Documentation
|
16
|
+
|
17
|
+
Documentation is work in progress. PLease this besides this readme, you
|
18
|
+
can read the
|
19
|
+
[specs](https://github.com/rwestgeest/action-guard/tree/master/spec)
|
20
|
+
and find the rdoc here:
|
21
|
+
|
22
|
+
http://rubydoc.info/gems/action-guard
|
23
|
+
|
15
24
|
# Installing
|
16
25
|
|
26
|
+
gem install action-guard
|
27
|
+
|
28
|
+
or put action-guard in your Gemfile and
|
17
29
|
|
30
|
+
bundle install
|
18
31
|
|
19
|
-
#
|
32
|
+
# Getting started
|
20
33
|
|
21
|
-
Assuming a Rails application you specify an initializer with the
|
22
|
-
following content
|
34
|
+
Assuming a Rails application, you specify an initializer with the
|
35
|
+
following content:
|
23
36
|
|
37
|
+
ActionGuard.load_from_file(File.join(Rails.root, 'config', 'authorization.rules'))
|
24
38
|
|
39
|
+
and a file called authorization.rules in the config directory with
|
40
|
+
something like:
|
25
41
|
|
26
42
|
role :god , 0
|
27
43
|
role :admin, 1
|
28
44
|
role :worker, 2
|
29
45
|
|
30
46
|
allow '/'
|
31
|
-
allow '/tracking', :
|
47
|
+
allow '/tracking', :only_by => :admin
|
32
48
|
allow '/maintenance', :at_least => :worker
|
33
49
|
allow '/maintenance/[0-9]*/edit', :at_least => :admin
|
34
50
|
allow '/maintenance/[0-9]*$', :at_least => :admin
|
35
51
|
|
52
|
+
and some model with a string typed attribute called 'role', in an
|
53
|
+
account or user model e.g.:
|
54
|
+
|
55
|
+
class Account
|
56
|
+
attr_reader :role
|
57
|
+
end
|
58
|
+
|
59
|
+
then in your (Application) controller you can
|
60
|
+
|
61
|
+
class ApplicationController < ActionController::Base
|
62
|
+
prepend_before_filter :authorize_action
|
63
|
+
|
64
|
+
protected
|
65
|
+
def authorized?(fullpath)
|
66
|
+
ActionGuard.authorized?(current_account, fullpath)
|
67
|
+
end
|
68
|
+
helper_method :authorized?
|
69
|
+
|
70
|
+
private
|
71
|
+
def authorize_action
|
72
|
+
unless authorized?(request.fullpath)
|
73
|
+
flash[:alert] = I18n.t("not_authorized")
|
74
|
+
sign_out current_account if current_account
|
75
|
+
redirect_to new_account_session_path
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
(In the example above, the path helpers, sign_out and current_account
|
81
|
+
methods are from [Devise]i(https://github.com/plataformatec/devise))
|
82
|
+
|
83
|
+
This is in essence all you need to get actionguard working. You could
|
84
|
+
also hide non authorized linkes by adding an authorized_link_to method
|
85
|
+
like so:
|
86
|
+
|
87
|
+
def authorized_link_to(what, path, options = {})
|
88
|
+
if (authorized?(path))
|
89
|
+
link_to(what, path, options)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
or overwrite link_to
|
94
|
+
|
95
|
+
# Issues - bugs
|
96
|
+
|
97
|
+
If you find any issues in the code please let me know through:
|
98
|
+
|
99
|
+
https://github.com/rwestgeest/action-guard/issues
|
36
100
|
|
101
|
+
also consult that list for known issues in ActionGuard
|
37
102
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{action-guard}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Rob Westgeest"]
|
12
|
+
s.date = %q{2011-06-27}
|
13
|
+
s.description = %q{authorisation module of actions based on url-paths for usage in Rails and possibly other ruby based web frameworks}
|
14
|
+
s.email = %q{rob.westgeest@qwan.it}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.md"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".gitignore",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"action-guard.gemspec",
|
29
|
+
"lib/action-guard.rb",
|
30
|
+
"lib/action-guard/base.rb",
|
31
|
+
"lib/action-guard/role.rb",
|
32
|
+
"lib/action-guard/rules.rb",
|
33
|
+
"lib/action-guard/syntax.rb",
|
34
|
+
"lib/action-guard/version.rb",
|
35
|
+
"script/authorization.rules",
|
36
|
+
"script/console",
|
37
|
+
"spec/action-guard_spec.rb",
|
38
|
+
"spec/spec_helper.rb"
|
39
|
+
]
|
40
|
+
s.homepage = %q{http://github.com/rwestgeest/action-guard}
|
41
|
+
s.licenses = ["MIT"]
|
42
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
43
|
+
s.require_paths = ["lib"]
|
44
|
+
s.rubygems_version = %q{1.3.7}
|
45
|
+
s.summary = %q{Action guard-0.0.2}
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.5.0"])
|
53
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
55
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<ZenTest>, [">= 4.2.0"])
|
57
|
+
s.add_development_dependency(%q<rspec>, ["> 2.5.0"])
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<rspec>, ["~> 2.5.0"])
|
60
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
61
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
62
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
63
|
+
s.add_dependency(%q<ZenTest>, [">= 4.2.0"])
|
64
|
+
s.add_dependency(%q<rspec>, ["> 2.5.0"])
|
65
|
+
end
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<rspec>, ["~> 2.5.0"])
|
68
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
69
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
70
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
71
|
+
s.add_dependency(%q<ZenTest>, [">= 4.2.0"])
|
72
|
+
s.add_dependency(%q<rspec>, ["> 2.5.0"])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action-guard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Rob Westgeest
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06-
|
18
|
+
date: 2011-06-27 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -130,7 +130,7 @@ files:
|
|
130
130
|
- README.md
|
131
131
|
- Rakefile
|
132
132
|
- VERSION
|
133
|
-
-
|
133
|
+
- action-guard.gemspec
|
134
134
|
- lib/action-guard.rb
|
135
135
|
- lib/action-guard/base.rb
|
136
136
|
- lib/action-guard/role.rb
|
@@ -174,6 +174,6 @@ rubyforge_project:
|
|
174
174
|
rubygems_version: 1.3.7
|
175
175
|
signing_key:
|
176
176
|
specification_version: 3
|
177
|
-
summary: Action guard-0.0.
|
177
|
+
summary: Action guard-0.0.2
|
178
178
|
test_files: []
|
179
179
|
|
data/action_guard.gemspec
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
3
|
-
require "action_guard/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "action_guard"
|
7
|
-
s.version = ActionGuard::Version::STRING
|
8
|
-
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Rob Westgeest"]
|
10
|
-
s.email = "rob.westgeest@gmail.com"
|
11
|
-
s.homepage = "http://github.com/actionguard"
|
12
|
-
s.summary = "actionguard-#{ActionGuard::Version::STRING}"
|
13
|
-
s.description = "authorisation of actions based on url-paths"
|
14
|
-
|
15
|
-
s.rubygems_version = "1.3.7"
|
16
|
-
s.rubyforge_project = "actionguard"
|
17
|
-
|
18
|
-
s.files = `git ls-files`.split("\n")
|
19
|
-
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
20
|
-
s.extra_rdoc_files = [ "README.md" ]
|
21
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
22
|
-
s.require_path = "lib"
|
23
|
-
end
|
24
|
-
|