can_play 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/can_play/ability.rb +4 -1
- data/lib/can_play/version.rb +1 -1
- data/lib/can_play.rb +3 -2
- data/lib/generators/templates/can_play.rb +11 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7eed223e4874c108017e81a8d0502041e3022e81
|
4
|
+
data.tar.gz: 8a490f3b79ac9af3223e67f5b5ba7c6a6a9a0510
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3926d91df4c06593a9d521ffe5274304864a3c4fffb1fd58899ca044fe53e4cb4e2fd47e676637c38109d8a426a1aae3815ebe64055f3cabc2bb2f0b26f61192
|
7
|
+
data.tar.gz: 13d6190e996237505d67a5c4abb74b46cbb963898b287dc9967abb6cef0a488ab505e4c5e00e2ae6e17fe3da94db1a459fa84a1a00046eab12ecac565dab3838
|
data/lib/can_play/ability.rb
CHANGED
@@ -4,9 +4,12 @@ class Ability
|
|
4
4
|
|
5
5
|
def initialize(user)
|
6
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.role?(role_name)
|
9
|
+
end
|
7
10
|
CanPlay::Config.role_class_name.constantize.all.each do |role|
|
8
11
|
next unless user.role?(role.name)
|
9
|
-
role.send(CanPlay::Config.
|
12
|
+
role.send(CanPlay::Config.role_resources_relation_name).each do |role_resource|
|
10
13
|
resource = CanPlay.find_by_name(role_resource.resource_name)
|
11
14
|
next unless resource
|
12
15
|
if resource[:type] == 'collection'
|
data/lib/can_play/version.rb
CHANGED
data/lib/can_play.rb
CHANGED
@@ -74,10 +74,11 @@ module CanPlay
|
|
74
74
|
end
|
75
75
|
|
76
76
|
module Config
|
77
|
-
mattr_accessor :user_class_name, :role_class_name, :
|
77
|
+
mattr_accessor :user_class_name, :role_class_name, :role_resources_relation_name, :super_roles
|
78
78
|
@@user_class_name = 'User'
|
79
79
|
@@role_class_name = 'Role'
|
80
|
-
@@
|
80
|
+
@@role_resources_relation_name = 'role_resources'
|
81
|
+
@@super_roles = []
|
81
82
|
|
82
83
|
def self.setup
|
83
84
|
yield self
|
@@ -1,8 +1,16 @@
|
|
1
|
-
#
|
1
|
+
# 在此可设置重要配置信息。
|
2
2
|
|
3
3
|
CanPlay::Config.setup do |config|
|
4
|
+
|
5
|
+
# role_class_name表示用户表表名。
|
4
6
|
config.user_class_name = 'User'
|
7
|
+
|
8
|
+
# role_class_name表示角色表表名
|
5
9
|
config.role_class_name = 'Role'
|
6
|
-
|
7
|
-
|
10
|
+
|
11
|
+
# super_role_resources_relation_name表示角色和权限中间表在model中的关联名称。
|
12
|
+
config.role_resources_relation_name = 'role_resources'
|
13
|
+
|
14
|
+
# super_roles表示无需分配权限既可拥有所有权限的角色。
|
15
|
+
config.super_roles = ['超级管理员']
|
8
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: can_play
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- happyming9527
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.4.
|
126
|
+
rubygems_version: 2.4.8
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: a permission system.
|