sevencan 0.1.6 → 0.1.7
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 +4 -4
- data/README.md +12 -4
- data/lib/seven/abilities.rb +30 -21
- data/lib/seven/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4de7ff55cfab6b3d85dbfd0709662ba247aed6f4
|
4
|
+
data.tar.gz: e284beb2abed20a28ad40b07552d388c68a51039
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47da39039c9052d7eca7ff6fa8b7bb4fbb7f8d53f3a30abc4c58bb074bc28761cbe8ae278529ac17e86ac00021f18f6c1e2cfa802ac34d76dd7cf22a072b3ec2
|
7
|
+
data.tar.gz: 23234e5476b2d13877d4cf8b1da1922b276e4897e6947ea1934abbd3f10ade1c09411428cb9de0d305d1ecc1ebd572e374eff970659fa14f2b94cea6dd176ecd
|
data/README.md
CHANGED
@@ -51,18 +51,22 @@ class MyTopicAbilities
|
|
51
51
|
end
|
52
52
|
|
53
53
|
# if [:admin, :editor].include?(current_user.role)
|
54
|
-
abilities :role, [:admin, :editor] do
|
54
|
+
abilities check: :role, in: [:admin, :editor] do
|
55
55
|
can_manager_topic
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
# current_user.role eqlual :reviewer
|
59
|
+
abilities check: :role, equal: :reviewer do
|
59
60
|
can :review_topic
|
60
61
|
end
|
61
62
|
|
62
|
-
abilities Proc.new { current_user.permissions.include?(:topic_manager) } do
|
63
|
+
abilities pass: Proc.new { current_user.permissions.include?(:topic_manager) } do
|
63
64
|
can_manager_topic
|
64
65
|
end
|
65
66
|
|
67
|
+
abilities pass: :editor_filter do
|
68
|
+
end
|
69
|
+
|
66
70
|
|
67
71
|
def can_manager_topic
|
68
72
|
can :edit_topic, :destroy_topic
|
@@ -71,6 +75,10 @@ class MyTopicAbilities
|
|
71
75
|
def cannot_manager_topic
|
72
76
|
cannot :edit_topic, :destroy_topic
|
73
77
|
end
|
78
|
+
|
79
|
+
def editor_filter
|
80
|
+
current_user.permissions.include?(:topic_editor)
|
81
|
+
end
|
74
82
|
end
|
75
83
|
|
76
84
|
manager.define_rules(Topic, MyTopicAbilities)
|
@@ -300,7 +308,7 @@ end
|
|
300
308
|
```
|
301
309
|
|
302
310
|
|
303
|
-
Manual check,
|
311
|
+
Manual check, not call `ability_check_callback`
|
304
312
|
|
305
313
|
```
|
306
314
|
class TopicController < ApplicationController
|
data/lib/seven/abilities.rb
CHANGED
@@ -50,29 +50,38 @@ module Seven
|
|
50
50
|
attr_reader :rule_procs
|
51
51
|
|
52
52
|
# Params:
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
53
|
+
# options:
|
54
|
+
# {check: :role, equal: 'admin'} current_user.role == 'admin'
|
55
|
+
# {check: :role, in: %w{admin editor}} %w{admin editor}.include?(current_user.role)
|
56
|
+
# {pass: :my_filter} call my_filter method
|
57
|
+
# {pass: Proc.new { ... }} proc.call
|
58
|
+
def abilities(options = nil, &rule_proc)
|
59
|
+
filter = build_seven_abilities_filter(options)
|
60
|
+
@rule_procs ||= []
|
61
|
+
@rule_procs << [filter, rule_proc]
|
62
|
+
end
|
63
|
+
|
64
|
+
def build_seven_abilities_filter(options)
|
65
|
+
return if options.nil?
|
66
|
+
opts = options.symbolize_keys
|
67
|
+
|
68
|
+
if val = opts[:pass]
|
69
|
+
if val.is_a?(Proc)
|
70
|
+
val
|
71
|
+
else
|
72
|
+
Proc.new { send val }
|
73
|
+
end
|
74
|
+
elsif attr = opts[:check]
|
75
|
+
if list = opts[:in]
|
76
|
+
Proc.new { list.include?(current_user.public_send(attr)) }
|
77
|
+
elsif val = opts[:equal]
|
78
|
+
Proc.new { current_user.public_send(attr) == val }
|
79
|
+
else
|
80
|
+
raise Seven::ArgsError, 'Invalid check definition'
|
81
|
+
end
|
69
82
|
else
|
70
|
-
raise Seven::ArgsError,
|
83
|
+
raise Seven::ArgsError, 'Invalid check definition'
|
71
84
|
end
|
72
|
-
|
73
|
-
|
74
|
-
@rule_procs ||= []
|
75
|
-
@rule_procs << [checker, rule_proc]
|
76
85
|
end
|
77
86
|
end
|
78
87
|
end
|
data/lib/seven/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sevencan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jiangzhi.xie
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|