i_am_i_can 4.3.2 → 4.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 519c1026eae5c7971fab21986634e180723d35f6
4
- data.tar.gz: 9cc200adfab71617107fcc41ca4d639f5447d7bb
3
+ metadata.gz: bc8efa706ad5886dd1188273bfed33bf80c80fbf
4
+ data.tar.gz: f1449022f144128db5ed05e85c5d973b08ded6d5
5
5
  SHA512:
6
- metadata.gz: 68319a2d89a43ce758c8fec136284560ef9720f7e7dd1c770969d8e91982bb3cc43fea7737dae965bd9fc8033ad31814fa64f30f9eaba8bc4ef460047c241569
7
- data.tar.gz: ac8315de97eb469c52b0dca44230124a075733afc9c20a75bbe76578b1a3c5bc5fc0c95d2ce48e8ba25601aeb989935aef4b93ade1fe0f25185b8d02b4dd57a2
6
+ metadata.gz: 0f809fa65dc6c707f40bae254e048103dc0ad3614831447228046f79586b188e46f4257221849243f2b6bed41d997f3f0d048b3b5a52df1aa263f007fe2512ed
7
+ data.tar.gz: 9ff64d80f81f29e1e549bc8af7016c8ae64b43d41225aa63c39ba9fc5952678d7978f388fa1ab81173b93d97eb68826c05738483f0c121e005e64732b2976a72
data/i_am_i_can.gemspec CHANGED
@@ -34,4 +34,5 @@ Gem::Specification.new do |spec|
34
34
  spec.add_dependency 'activerecord'
35
35
  spec.add_dependency 'activesupport'
36
36
  spec.add_dependency 'railties'
37
+ spec.add_dependency 'colorize'
37
38
  end
@@ -61,7 +61,7 @@ module IAmICan
61
61
  if config.strict_mode && failed_items.present?
62
62
  raise Error, msg
63
63
  else
64
- Rails.logger.info(msg) unless ENV['ITEST']
64
+ Rails.logger.info(" * #{msg}".green) unless ENV['ITEST']
65
65
  assignment
66
66
  end
67
67
  end
@@ -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: (subject._roles.ids + tmp_role_ids).uniq)
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
- to_be_assigned_names = (instances.map(&:name).map(&:to_sym) + names).uniq
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 |names|
27
- names -= temporary_role_names
28
- temporary_roles.concat(roles = i_am_i_can.role_model.where(name: names))
29
- roles.names
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 |names|
33
- (names & temporary_role_names).each do |n|
34
- temporary_roles.reject! { |i| i.name.to_sym == n }
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, names|
39
- send('_temporary_roles_' + (action == :assign ? 'add' : 'rmv'), names)
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
@@ -1,3 +1,3 @@
1
1
  module IAmICan
2
- VERSION = '4.3.2'
2
+ VERSION = '4.3.3'
3
3
  end
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.2
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: 2018-12-22 00:00:00.000000000 Z
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: