can_play 0.3.0 → 0.3.1

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: 118e6008d49cde4499d3473b9dff67015058ac8f
4
- data.tar.gz: 63d21c9f2b80bea055281b7b7eaa2c7f13937d66
3
+ metadata.gz: 16441a20427ca9e3570f0e3a3cda976916eea535
4
+ data.tar.gz: 23b9fd796b805e68ab8022ba381920e6b76d1f02
5
5
  SHA512:
6
- metadata.gz: a9a0ca283d060284017e0ef76c5b5c8eaea02e08fbc3da71595eb7768e4bd52b1d9c5261d4e5a24d60803c04f1652060f3bafe4e75bbbeb816807f605cf348a6
7
- data.tar.gz: 044b3026d16fe494b15c90e0a04c1b7f005a9bbd924d45d6e5da41cd8f65049c1cb465a2532c6f50f8bb01995a8596a51661ad84a519bcb2a9dad7d6d7470f4a
6
+ metadata.gz: 1275d49864ffd120b58b98a39035f8573defc82ea5b0579e7e01e158c9260f5ba9bce86037838cc881356c75f7d49b2d2566e9a160242cb509dbb6cdd7ad3fec
7
+ data.tar.gz: 59e3db805478f280d33fd85606dd1cc3e3fe2de01094a3c4157ae5ea0bbdd4200e162235ac08672b9694821dd2e5c6187fae40541252c0b031a55448883ad78d
@@ -3,30 +3,36 @@ class Ability
3
3
  attr_accessor :user
4
4
 
5
5
  def initialize(user)
6
- self.user = user||CanPlay::Config.user_class_name.constantize.new
7
- CanPlay::Config.super_roles.each do |role_name|
8
- can(:manage, :all) if user.send(CanPlay::Config.role_judge_method, role_name)
9
- end
10
- CanPlay::Config.role_class_name.constantize.all.each do |role|
11
- next unless user.send(CanPlay::Config.role_judge_method, role)
12
- role.send(CanPlay::Config.role_resources_relation_name).each do |role_resource|
13
- resource = CanPlay.find_by_name_and_code(role_resource.resource_name, CanPlay.override_code)
14
- next unless resource
15
- if resource[:type] == 'collection'
16
- if resource[:behavior]
17
- block = resource[:behavior]
18
- can(resource[:verb], resource[:object]) if block.call(user)
19
- else
20
- can resource[:verb], resource[:object]
21
- end
22
- elsif resource[:type] == 'member'
23
- if resource[:behavior]
24
- block = resource[:behavior]
25
- can resource[:verb], resource[:object] do |object|
26
- block.call(user, object)
6
+ CanPlay::Config.tap do |i|
7
+ self.user = user||i.user_class_name.constantize.new
8
+ if i.super_roles.is_a?(Array)
9
+ i.super_roles.each do |role_name|
10
+ can(:manage, :all) if user.send(i.role_judge_method, role_name)
11
+ end
12
+ elsif i.super_roles.is_a?(Proc)
13
+ can(:manage, :all) if i.super_roles.call(user)
14
+ end
15
+ i.role_class_name.constantize.all.each do |role|
16
+ next unless user.send(i.role_judge_method, role)
17
+ role.send(i.role_resources_relation_name).each do |role_resource|
18
+ resource = CanPlay.find_by_name_and_code(role_resource.resource_name, CanPlay.override_code)
19
+ next unless resource
20
+ if resource[:type] == 'collection'
21
+ if resource[:behavior]
22
+ block = resource[:behavior]
23
+ can(resource[:verb], resource[:object]) if block.call(user)
24
+ else
25
+ can resource[:verb], resource[:object]
26
+ end
27
+ elsif resource[:type] == 'member'
28
+ if resource[:behavior]
29
+ block = resource[:behavior]
30
+ can resource[:verb], resource[:object] do |object|
31
+ block.call(user, object)
32
+ end
33
+ else
34
+ can resource[:verb], resource[:object]
27
35
  end
28
- else
29
- can resource[:verb], resource[:object]
30
36
  end
31
37
  end
32
38
  end
@@ -1,3 +1,3 @@
1
1
  module CanPlay
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -14,6 +14,9 @@ CanPlay::Config.setup do |config|
14
14
  # super_roles表示无需分配权限既可拥有所有权限的角色。
15
15
  config.super_roles = ['超级管理员']
16
16
 
17
+ # 也可以传入代码块,若使代码块,则会传入形参user,指代当前用户,代码块返回的结果为true,则当前登录用户的当前角色则有无限权限。。
18
+ #config.super_roles = ->(role) { 1 == user.current_role.try(:id) }
19
+
17
20
  # 判断角色是否符合的方法。
18
21
  config.role_judge_method = 'role_is?'
19
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: can_play
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - happyming9527