role_core 0.0.19 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -0
- data/lib/role_core/contrib/can_can_can_permission.rb +4 -3
- data/lib/role_core/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9edb95eb240054cb26913657fe3c3b6b1d723a02bf34bc1503435598e9299d99
|
4
|
+
data.tar.gz: 02666f872e3cdee62288e3e567ac157b30a88240f8e620c4e4777b2332da6b57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e87f6dc580136e18fc8fc95e527cd0cd3cc53d707e29531131253f405f5c62a789f86b396708011307a4e3bb3f7346a426b6a3beb78383461c105c6213fed6af
|
7
|
+
data.tar.gz: c1b1037ba4e4e192a0a46ea149157f141166ceed57ea42062f18ca0b448775ec0f71f6dcfb6dc69cac91d2ae46e641e3d6851d4aab96882c15905c9db894ab11
|
data/README.md
CHANGED
@@ -285,6 +285,33 @@ user.can? { |permissions| permissions.project.read? }
|
|
285
285
|
|
286
286
|
_Keep in mind: fetching `roles` will made a SQL query, you may need eager loading to avoid N+1 problem in some cases._
|
287
287
|
|
288
|
+
### Integrate with Pundit
|
289
|
+
|
290
|
+
Just call permissions' method (see `checking permission` above) in Pundit's policy.
|
291
|
+
|
292
|
+
e.g:
|
293
|
+
|
294
|
+
```ruby
|
295
|
+
class PostPolicy
|
296
|
+
attr_reader :user, :post
|
297
|
+
|
298
|
+
def initialize(user, post)
|
299
|
+
@user = user
|
300
|
+
@post = post
|
301
|
+
end
|
302
|
+
|
303
|
+
def update?
|
304
|
+
user.permissions.post.update?
|
305
|
+
end
|
306
|
+
|
307
|
+
def update_my_own?
|
308
|
+
return true if user.permissions.post.update?
|
309
|
+
return unless user.permissions.post.update_my_own?
|
310
|
+
post.author == user
|
311
|
+
end
|
312
|
+
end
|
313
|
+
```
|
314
|
+
|
288
315
|
### Integrate with CanCanCan
|
289
316
|
|
290
317
|
Open `config/initializers/role_core.rb`, uncomment CanCanCan integration codes and follows samples to define permissions for CanCanCan
|
@@ -8,7 +8,7 @@ module RoleCore
|
|
8
8
|
super
|
9
9
|
return unless _callable
|
10
10
|
|
11
|
-
@
|
11
|
+
@model_name = options[:model_name]
|
12
12
|
@action = options[:action] || name
|
13
13
|
@options = options.except(:model, :model_name, :action)
|
14
14
|
@block = block
|
@@ -17,10 +17,11 @@ module RoleCore
|
|
17
17
|
def call(context, *args)
|
18
18
|
return unless callable
|
19
19
|
|
20
|
+
model = @model_name.constantize
|
20
21
|
if block_attached?
|
21
|
-
context.can @action,
|
22
|
+
context.can @action, model, &@block.curry[*args]
|
22
23
|
else
|
23
|
-
context.can @action,
|
24
|
+
context.can @action, model, @options
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
data/lib/role_core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: role_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jasl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
version: '0'
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.7.
|
98
|
+
rubygems_version: 2.7.7
|
99
99
|
signing_key:
|
100
100
|
specification_version: 4
|
101
101
|
summary: RoleCore is a Rails engine which could provide essential industry of Role-based
|