role_authorization 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/role_authorization/roles/role.rb +15 -19
- data/lib/role_authorization/user.rb +15 -15
- data/lib/role_authorization/version.rb +1 -1
- metadata +2 -2
@@ -12,33 +12,29 @@ module RoleAuthorization
|
|
12
12
|
|
13
13
|
module InstanceMethods
|
14
14
|
def scope_with(scope)
|
15
|
-
if scope.is_a?(Symbol) || scope.is_a?(String) || scope.is_a?(Integer)
|
16
|
-
scope
|
15
|
+
if scope.blank? || scope.is_a?(Symbol) || scope.is_a?(String) || scope.is_a?(Integer)
|
16
|
+
scope || :all
|
17
17
|
else
|
18
18
|
scope.id
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
def users(scope = nil)
|
23
|
-
|
24
|
-
RoleAuthorization::Roles::Manager.user_klass.where(:id => user_ids[scope_with(scope)]).all
|
25
|
-
else
|
26
|
-
RoleAuthorization::Roles::Manager.user_klass.where(:id => user_ids).all
|
27
|
-
end
|
23
|
+
RoleAuthorization::Roles::Manager.user_klass.where(:id => user_ids[scope_with(scope)]).all
|
28
24
|
end
|
29
25
|
|
30
26
|
def add_user(user_id, scope = nil)
|
31
27
|
unserialized_user_ids = self.user_ids
|
28
|
+
unserialized_user_ids ||= Hash.new
|
32
29
|
|
33
30
|
if scope.nil? || scope.is_a?(Symbol) || scope.is_a?(String) || scope.is_a?(Class)
|
34
|
-
unserialized_user_ids ||= Array.new
|
35
|
-
unserialized_user_ids << user_id
|
36
|
-
unserialized_user_ids.uniq!
|
31
|
+
unserialized_user_ids[scope_with(scope)] ||= Array.new
|
32
|
+
unserialized_user_ids[scope_with(scope)] << user_id
|
33
|
+
unserialized_user_ids[scope_with(scope)].uniq!
|
37
34
|
else
|
38
|
-
unserialized_user_ids ||=
|
39
|
-
unserialized_user_ids[scope
|
40
|
-
unserialized_user_ids[scope.
|
41
|
-
unserialized_user_ids[scope.id].uniq!
|
35
|
+
unserialized_user_ids[scope_with(scope)] ||= Array.new
|
36
|
+
unserialized_user_ids[scope_with(scope)] << user_id
|
37
|
+
unserialized_user_ids[scope_with(scope)].uniq!
|
42
38
|
end
|
43
39
|
|
44
40
|
self.user_ids = unserialized_user_ids
|
@@ -48,14 +44,14 @@ module RoleAuthorization
|
|
48
44
|
|
49
45
|
def remove_user(user_id, scope = nil)
|
50
46
|
unserialized_user_ids = self.user_ids
|
47
|
+
unserialized_user_ids ||= Hash.new
|
51
48
|
|
52
49
|
if scope.nil? || scope.is_a?(Symbol) || scope.is_a?(String) || scope.is_a?(Class)
|
53
|
-
unserialized_user_ids ||= Array.new
|
54
|
-
unserialized_user_ids.delete(user_id)
|
50
|
+
unserialized_user_ids[scope_with(scope)] ||= Array.new
|
51
|
+
unserialized_user_ids[scope_with(scope)].delete(user_id)
|
55
52
|
else
|
56
|
-
unserialized_user_ids ||=
|
57
|
-
unserialized_user_ids[scope
|
58
|
-
unserialized_user_ids[scope.id].delete(user_id)
|
53
|
+
unserialized_user_ids[scope_with(scope)] ||= Array.new
|
54
|
+
unserialized_user_ids[scope_with(scope)].delete(user_id)
|
59
55
|
end
|
60
56
|
|
61
57
|
self.user_ids = unserialized_user_ids
|
@@ -82,20 +82,20 @@ module RoleAuthorization
|
|
82
82
|
def enroll(role_name, scope = nil)
|
83
83
|
return true if has_role?(role_name.to_sym, scope)
|
84
84
|
|
85
|
-
|
85
|
+
scope_key, scope_id = scope_with(scope)
|
86
86
|
self.serialized_roles ||= Hash.new
|
87
87
|
|
88
|
-
if
|
88
|
+
if scope_key.nil?
|
89
89
|
self.serialized_roles[:global] ||= Array.new
|
90
90
|
self.serialized_roles[:global] << role_name.to_sym
|
91
91
|
else
|
92
92
|
if scope_id.nil?
|
93
|
-
self.serialized_roles[
|
94
|
-
self.serialized_roles[
|
93
|
+
self.serialized_roles[scope_key] ||= Array.new
|
94
|
+
self.serialized_roles[scope_key] << role_name.to_sym
|
95
95
|
else
|
96
|
-
self.serialized_roles[
|
97
|
-
self.serialized_roles[
|
98
|
-
self.serialized_roles[
|
96
|
+
self.serialized_roles[scope_key] ||= Hash.new
|
97
|
+
self.serialized_roles[scope_key][scope_id] ||= Array.new
|
98
|
+
self.serialized_roles[scope_key][scope_id] << role_name.to_sym
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
@@ -110,20 +110,20 @@ module RoleAuthorization
|
|
110
110
|
def withdraw(role_name, scope = nil)
|
111
111
|
return true unless has_role?(role_name.to_sym, scope)
|
112
112
|
|
113
|
-
|
113
|
+
scope_key, scope_id = scope_with(scope)
|
114
114
|
serialized_roles ||= Hash.new
|
115
115
|
|
116
|
-
if
|
116
|
+
if scope_key.nil?
|
117
117
|
self.serialized_roles[:global] ||= Array.new
|
118
118
|
self.serialized_roles[:global].delete(role_name.to_sym)
|
119
119
|
else
|
120
|
-
if
|
121
|
-
self.serialized_roles[
|
122
|
-
self.serialized_roles[
|
120
|
+
if scope_key_id.nil?
|
121
|
+
self.serialized_roles[scope_key] ||= Array.new
|
122
|
+
self.serialized_roles[scope_key].delete(role_name.to_sym)
|
123
123
|
else
|
124
|
-
self.serialized_roles[
|
125
|
-
self.serialized_roles[
|
126
|
-
self.serialized_roles[
|
124
|
+
self.serialized_roles[scope_key] ||= Hash.new
|
125
|
+
self.serialized_roles[scope_key][scope_key_id] ||= Array.new
|
126
|
+
self.serialized_roles[scope_key][scope_key_id].delete(role_name.to_sym)
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: role_authorization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- John 'asceth' Long
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-21 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|