permissive 0.2.7.alpha → 0.2.8.alpha
Sign up to get free protection for your applications and to get access to all the features.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.8.alpha
|
@@ -49,7 +49,6 @@ module Permissive
|
|
49
49
|
permission.save!
|
50
50
|
end
|
51
51
|
permission
|
52
|
-
# raise 'set'
|
53
52
|
end
|
54
53
|
|
55
54
|
def can?(*args)
|
@@ -83,8 +82,9 @@ module Permissive
|
|
83
82
|
def bits_for(scope, permissions)
|
84
83
|
on = Permissive::PermissionDefinition.normalize_scope(proxy_owner.class, scope)
|
85
84
|
permissions.flatten.map do |permission|
|
86
|
-
|
87
|
-
|
85
|
+
permission = permission.to_s.underscore.gsub('/', '_').to_sym
|
86
|
+
proxy_owner.class.permissions[on].try(:permissions).try(:[], permission) || proxy_owner.class.permissions[:global].try(:permissions).try(:[], permission)# || raise(Permissive::InvalidPermissionError.new("#{proxy_owner.class.name} does not have a#{'n' if permission.to_s[0, 1].downcase =~ /[aeiou]/} #{permission} permission#{" on #{on}" if on}"))
|
87
|
+
end.compact
|
88
88
|
end
|
89
89
|
private :bits_for
|
90
90
|
end
|
@@ -117,7 +117,8 @@ module Permissive
|
|
117
117
|
scope = :global
|
118
118
|
end
|
119
119
|
permissions = permissions.split('_and_')
|
120
|
-
if permissions.all? {|permission| self.class.permissions[scope].permissions.has_key?(permission.downcase.to_sym)
|
120
|
+
if permissions.all? {|permission| self.class.permissions[scope].permissions.has_key?(permission.downcase.to_sym) ||
|
121
|
+
self.class.permissions[:global].permissions.has_key?(permission.downcase.to_sym) }
|
121
122
|
if revoke
|
122
123
|
class_eval <<-end_eval
|
123
124
|
def #{method}(scope = nil)
|
@@ -3,8 +3,8 @@ module Permissive
|
|
3
3
|
class Permission < ActiveRecord::Base
|
4
4
|
belongs_to :permitted_object, :polymorphic => true
|
5
5
|
belongs_to :scoped_object, :polymorphic => true
|
6
|
-
named_scope :granted, lambda {
|
7
|
-
{:conditions => permissions.map{|bit| "(mask & #{bit}) > 0"}.join(' AND ')}
|
6
|
+
named_scope :granted, lambda {|*permissions|
|
7
|
+
{:conditions => permissions.flatten.map{|bit| "(mask & #{bit}) > 0"}.join(' AND ')}
|
8
8
|
}
|
9
9
|
named_scope :on, lambda {|scoped_object|
|
10
10
|
case scoped_object
|
@@ -13,7 +13,6 @@ module Permissive
|
|
13
13
|
when Class
|
14
14
|
{:conditions => {:scoped_object_id => nil, :scoped_object_type => scoped_object.name}}
|
15
15
|
when String, Symbol
|
16
|
-
scope =
|
17
16
|
{:conditions => {:scoped_object_id => nil, :scoped_object_type => scoped_object.to_s.classify}}
|
18
17
|
else
|
19
18
|
{:conditions => {:scoped_object_id => nil, :scoped_object_type => nil}}
|
@@ -23,7 +23,7 @@ module Permissive
|
|
23
23
|
model_module.pop
|
24
24
|
model_module = model_module.join('::')
|
25
25
|
if (model_module.blank? ? Object : Object.const_get(model_module)).const_defined?(attempted_scope)
|
26
|
-
[model_module, attempted_scope].join('::')
|
26
|
+
[model_module, attempted_scope].reject(&:blank?).join('::')
|
27
27
|
else
|
28
28
|
scope.to_s.classify
|
29
29
|
end
|
@@ -149,4 +149,4 @@ module Permissive
|
|
149
149
|
@roles ||= {}
|
150
150
|
end
|
151
151
|
end
|
152
|
-
end
|
152
|
+
end
|
@@ -27,13 +27,13 @@ describe Permissive, "scoped permissions" do
|
|
27
27
|
@user.can?(:manage_games, :on => @organization).should be_true
|
28
28
|
end
|
29
29
|
|
30
|
-
it "should not respond to generic permissions on scoped permissions" do
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
30
|
+
# it "should not respond to generic permissions on scoped permissions" do
|
31
|
+
# @user.can!(:manage_games, :on => @organization)
|
32
|
+
# lambda {
|
33
|
+
# @user.can?(:manage_games).should be_false
|
34
|
+
# }.should raise_error(Permissive::InvalidPermissionError)
|
35
|
+
# @user.can?(:manage_games, :on => @organization).should be_true
|
36
|
+
# end
|
37
37
|
|
38
38
|
it "should revoke the correct permissions through the `revoke' method" do
|
39
39
|
@user.can!(:manage_games, :control_rides, :on => @organization)
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
8
|
+
- 8
|
9
9
|
- alpha
|
10
|
-
version: 0.2.
|
10
|
+
version: 0.2.8.alpha
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Flip Sasser
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-05-21 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|