bravo_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/lib/bravo_guard/model.rb +19 -2
- data/lib/bravo_guard/version.rb +1 -1
- metadata +4 -4
data/lib/bravo_guard/model.rb
CHANGED
@@ -44,9 +44,10 @@ module BravoGuard::Model::InstanceMethods
|
|
44
44
|
# nodoc
|
45
45
|
def allows?(actor, *permissions)
|
46
46
|
begin
|
47
|
-
permission = permissions.join('_')
|
48
|
-
method_name = [:allows, permission_name(permission)].join('_') + '?'
|
49
47
|
self.actor = actor
|
48
|
+
permission = permission_name(permissions.join('_'))
|
49
|
+
method_name = [:allows, permission].join('_') + '?'
|
50
|
+
check_anon_permission! permission
|
50
51
|
send method_name
|
51
52
|
rescue BravoGuard::PermissionDenied
|
52
53
|
return false
|
@@ -59,6 +60,22 @@ module BravoGuard::Model::InstanceMethods
|
|
59
60
|
|
60
61
|
|
61
62
|
|
63
|
+
# anything in here will not be auto-rejected for anons, instead, the permission
|
64
|
+
# method will be called as usual so you can still check object state etc
|
65
|
+
def anon_permissions
|
66
|
+
[]
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
# nodoc
|
71
|
+
def check_anon_permission!(permission)
|
72
|
+
is_anon = actor.nil? || (actor.respond_to?(:anon) && actor.anon?)
|
73
|
+
return if anon_permissions.include?(permission.intern)
|
74
|
+
return unless is_anon
|
75
|
+
no!
|
76
|
+
end
|
77
|
+
|
78
|
+
|
62
79
|
# shorthand for 'return false'. allows?() will catch this and return false
|
63
80
|
def no!
|
64
81
|
raise BravoGuard::PermissionDenied
|
data/lib/bravo_guard/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bravo_guard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-27 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|
@@ -70,7 +70,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
70
|
version: '0'
|
71
71
|
segments:
|
72
72
|
- 0
|
73
|
-
hash:
|
73
|
+
hash: 920269711
|
74
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
75
|
none: false
|
76
76
|
requirements:
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
version: '0'
|
80
80
|
segments:
|
81
81
|
- 0
|
82
|
-
hash:
|
82
|
+
hash: 920269711
|
83
83
|
requirements: []
|
84
84
|
rubyforge_project:
|
85
85
|
rubygems_version: 1.8.10
|