role_authorization 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/role_authorization/roles/role.rb +32 -18
- data/lib/role_authorization/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b82cc6cf70a1dae2b60c08fbbebe3b7eddd8f91
|
4
|
+
data.tar.gz: 76e2bcfe4b15319db70d96923de9f5572a90b6d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 346377c85cd0992b85de06973c5835012e9180e7e185b37c1f6b83d7a1d26a8bda10ee70b5f0133be72a0e2525dc8c400e0a9c6a8ce40595dba7ef0fedae6a8a
|
7
|
+
data.tar.gz: 7f018b62080f8eb3b0d85eb3dfb1fbdd5ca742479fb46a7658fb41a6e5dbfd9aa8d02efe602d1ee9d17e4ed023acc788c8533d8bcdd960a860b70ba2be654bca
|
@@ -16,6 +16,20 @@ module RoleAuthorization
|
|
16
16
|
end
|
17
17
|
|
18
18
|
module InstanceMethods
|
19
|
+
def unserialized_user_ids
|
20
|
+
result = if Rails::VERSION::MAJOR >= 4
|
21
|
+
self.user_ids.unserialized_value
|
22
|
+
else
|
23
|
+
self.user_ids
|
24
|
+
end
|
25
|
+
|
26
|
+
if result.is_a?(Hash)
|
27
|
+
result
|
28
|
+
else
|
29
|
+
Hash.new
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
19
33
|
def scope_with(scope)
|
20
34
|
if scope.blank? || scope.is_a?(Symbol) || scope.is_a?(String) || scope.is_a?(Integer)
|
21
35
|
scope || :all
|
@@ -30,45 +44,45 @@ module RoleAuthorization
|
|
30
44
|
[]
|
31
45
|
else
|
32
46
|
if scope.nil?
|
33
|
-
RoleAuthorization::Roles::Manager.user_klass.where(:id =>
|
47
|
+
RoleAuthorization::Roles::Manager.user_klass.where(:id => unserialized_user_ids.values.flatten.uniq).all
|
34
48
|
else
|
35
|
-
RoleAuthorization::Roles::Manager.user_klass.where(:id =>
|
49
|
+
RoleAuthorization::Roles::Manager.user_klass.where(:id => unserialized_user_ids[scope_with(scope)]).all
|
36
50
|
end
|
37
51
|
end
|
38
52
|
end
|
39
53
|
|
40
54
|
def add_user(user_id, scope = nil)
|
41
|
-
|
42
|
-
|
55
|
+
hash = unserialized_user_ids
|
56
|
+
hash ||= Hash.new
|
43
57
|
|
44
58
|
if scope.nil? || scope.is_a?(Symbol) || scope.is_a?(String) || scope.is_a?(Class)
|
45
|
-
|
46
|
-
|
47
|
-
|
59
|
+
hash[scope_with(scope)] ||= Array.new
|
60
|
+
hash[scope_with(scope)] << user_id
|
61
|
+
hash[scope_with(scope)].uniq!
|
48
62
|
else
|
49
|
-
|
50
|
-
|
51
|
-
|
63
|
+
hash[scope_with(scope)] ||= Array.new
|
64
|
+
hash[scope_with(scope)] << user_id
|
65
|
+
hash[scope_with(scope)].uniq!
|
52
66
|
end
|
53
67
|
|
54
|
-
self.user_ids =
|
68
|
+
self.user_ids = hash
|
55
69
|
|
56
70
|
save
|
57
71
|
end
|
58
72
|
|
59
73
|
def remove_user(user_id, scope = nil)
|
60
|
-
|
61
|
-
|
74
|
+
hash = unserialized_user_ids
|
75
|
+
hash ||= Hash.new
|
62
76
|
|
63
77
|
if scope.nil? || scope.is_a?(Symbol) || scope.is_a?(String) || scope.is_a?(Class)
|
64
|
-
|
65
|
-
|
78
|
+
hash[scope_with(scope)] ||= Array.new
|
79
|
+
hash[scope_with(scope)].delete(user_id)
|
66
80
|
else
|
67
|
-
|
68
|
-
|
81
|
+
hash[scope_with(scope)] ||= Array.new
|
82
|
+
hash[scope_with(scope)].delete(user_id)
|
69
83
|
end
|
70
84
|
|
71
|
-
self.user_ids =
|
85
|
+
self.user_ids = hash
|
72
86
|
|
73
87
|
save
|
74
88
|
end
|