i_am_i_can 4.3.2 → 4.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc8efa706ad5886dd1188273bfed33bf80c80fbf
|
4
|
+
data.tar.gz: f1449022f144128db5ed05e85c5d973b08ded6d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f809fa65dc6c707f40bae254e048103dc0ad3614831447228046f79586b188e46f4257221849243f2b6bed41d997f3f0d048b3b5a52df1aa263f007fe2512ed
|
7
|
+
data.tar.gz: 9ff64d80f81f29e1e549bc8af7016c8ae64b43d41225aa63c39ba9fc5952678d7978f388fa1ab81173b93d97eb68826c05738483f0c121e005e64732b2976a72
|
data/i_am_i_can.gemspec
CHANGED
data/lib/i_am_i_can/resource.rb
CHANGED
@@ -6,29 +6,12 @@ module IAmICan
|
|
6
6
|
# Book.that_allow(User.all, to: :read)
|
7
7
|
# Book.that_allow(User.last, to: :write)
|
8
8
|
scope :that_allow, -> (subject, to:) do
|
9
|
+
stored_ids = subject.try(:new_record?) ? [ ] : subject._roles.ids
|
9
10
|
tmp_role_ids = Array(subject).flat_map(&:temporary_roles).map(&:id).uniq
|
10
|
-
allowed_ids = subject.i_am_i_can.role_model.where(id: (
|
11
|
+
allowed_ids = subject.i_am_i_can.role_model.where(id: (stored_ids + tmp_role_ids).uniq)
|
11
12
|
._permissions.where(action: to, obj_type: self.name).pluck(:obj_id).uniq
|
12
13
|
where(id: allowed_ids)
|
13
14
|
end
|
14
15
|
end
|
15
|
-
|
16
|
-
class_methods do
|
17
|
-
# def that_allow(subject)
|
18
|
-
# ThatAllow.new(self, subject)
|
19
|
-
# end
|
20
|
-
end
|
21
16
|
end
|
22
|
-
|
23
|
-
# class ThatAllow
|
24
|
-
# attr_accessor :records, :subject
|
25
|
-
#
|
26
|
-
# def initialize(records, subject)
|
27
|
-
# self.records = records
|
28
|
-
# self.subject = subject
|
29
|
-
# end
|
30
|
-
#
|
31
|
-
# def to(action)
|
32
|
-
# end
|
33
|
-
# end
|
34
17
|
end
|
@@ -40,8 +40,7 @@ module IAmICan
|
|
40
40
|
assignment = _stored_roles_exec(action, instances, name: names)
|
41
41
|
_set_roles_expire(exp, assignment.map(&:id)) if exp
|
42
42
|
else
|
43
|
-
|
44
|
-
assignment = _temporary_roles_exec(action, to_be_assigned_names)
|
43
|
+
assignment = _temporary_roles_exec(action, instances, name: names)
|
45
44
|
end
|
46
45
|
|
47
46
|
ResultOf.role assignment, i_am_i_can, given: [instances, names]
|
@@ -23,20 +23,23 @@ module IAmICan
|
|
23
23
|
#
|
24
24
|
alias_method "#{name.to_s.singularize}_names", :temporary_role_names if name
|
25
25
|
|
26
|
-
define_method :_temporary_roles_add do |
|
27
|
-
|
28
|
-
temporary_roles.concat(roles
|
29
|
-
roles.
|
26
|
+
define_method :_temporary_roles_add do |instances = nil, name: nil|
|
27
|
+
roles = instances.present? ? instances : i_am_i_can.role_model.where(name: name - temporary_role_names)
|
28
|
+
temporary_roles.concat(roles)
|
29
|
+
roles.map(&:name).map(&:to_sym)
|
30
30
|
end
|
31
31
|
|
32
|
-
define_method :_temporary_roles_rmv do |
|
33
|
-
|
34
|
-
temporary_roles
|
32
|
+
define_method :_temporary_roles_rmv do |instances = nil, name: nil|
|
33
|
+
if instances.present?
|
34
|
+
self.temporary_roles -= instances
|
35
|
+
instances.map(&:name).map(&:to_sym)
|
36
|
+
else
|
37
|
+
(name & temporary_role_names).each { |n| self.temporary_roles.reject! { |i| i.name.to_sym == n } }
|
35
38
|
end
|
36
39
|
end
|
37
40
|
|
38
|
-
define_method :_temporary_roles_exec do |action = :assign,
|
39
|
-
send('_temporary_roles_' + (action == :assign ? 'add' : 'rmv'),
|
41
|
+
define_method :_temporary_roles_exec do |action = :assign, instances = nil, name: nil|
|
42
|
+
send('_temporary_roles_' + (action == :assign ? 'add' : 'rmv'), instances, name: name)
|
40
43
|
end
|
41
44
|
end
|
42
45
|
end
|
data/lib/i_am_i_can/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i_am_i_can
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.3.
|
4
|
+
version: 4.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhandao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: colorize
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
167
181
|
description: "(RBAC like) Concise and Natural DSL for `Subject - Role(Role Group)
|
168
182
|
- Permission - Resource` Management."
|
169
183
|
email:
|