role_core 0.0.16 → 0.0.17
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/lib/generators/role_core/config/templates/role_core.en.yml +1 -0
- data/lib/generators/role_core/config/templates/role_core.rb +7 -0
- data/lib/role_core/contrib/can_can_can_permission.rb +4 -1
- data/lib/role_core/permission.rb +3 -2
- data/lib/role_core/version.rb +1 -1
- data/lib/tasks/role_core_tasks.rake +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32110dc81e77039a694a09ff4d761751dd78e2308542672a42376d4c0660f75b
|
4
|
+
data.tar.gz: 8e6c5a01c34352ae9bff7a700cfb9c2d493b0c48e256168e32d8b517277bf1d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e275a6b77ed0b93c1930a4efe6e0f694e03d05c64642b2506d17a9ccc000df490dce2f9c3abc5ba941aee2702ee859214cc9436b5269a31e35b6d11885013fe
|
7
|
+
data.tar.gz: f44c84d5c76c63c860853b6d1d0aaa55be911ced977a153dce45c3b37116069fd86657b87f5bb682986f85effd6ae5428c15f9c7b47d8748e9e3f9b8a66d6e7f
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# YOU NEED TO RESTART APP AFTER CHANGING THIS FILE
|
4
|
+
|
3
5
|
# Uncomment below if you want to integrate with CanCanCan
|
4
6
|
#
|
5
7
|
# require "role_core/contrib/can_can_can_permission"
|
@@ -67,4 +69,9 @@ RoleCore.permission_set_class.draw do
|
|
67
69
|
#
|
68
70
|
# permission :read_public, action: :read, is_public: true
|
69
71
|
#
|
72
|
+
# For some reason, you won't interpret the permission to CanCanCan,
|
73
|
+
# you can set `_callable: false` to `permission` or `group`
|
74
|
+
#
|
75
|
+
# permission :read, _callable: false
|
76
|
+
#
|
70
77
|
end.finalize! # Call `finalize!` to freezing the definition, that's optional.
|
@@ -4,8 +4,9 @@ module RoleCore
|
|
4
4
|
class CanCanCanPermission < RoleCore::Permission
|
5
5
|
attr_reader :action, :options
|
6
6
|
|
7
|
-
def initialize(name, _namespace: [], _priority: 0, **options, &block)
|
7
|
+
def initialize(name, _namespace: [], _priority: 0, _callable: true, **options, &block)
|
8
8
|
super
|
9
|
+
return unless _callable
|
9
10
|
|
10
11
|
@model = options[:model] || options.fetch(:model_name).constantize
|
11
12
|
@action = options[:action] || name
|
@@ -14,6 +15,8 @@ module RoleCore
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def call(context, *args)
|
18
|
+
return unless callable
|
19
|
+
|
17
20
|
if block_attached?
|
18
21
|
context.can @action, @model, &@block.curry[*args]
|
19
22
|
else
|
data/lib/role_core/permission.rb
CHANGED
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
module RoleCore
|
4
4
|
class Permission
|
5
|
-
attr_reader :name, :namespace, :priority
|
5
|
+
attr_reader :name, :namespace, :priority, :callable
|
6
6
|
|
7
|
-
def initialize(name, _namespace: [], _priority: 0, **options, &block)
|
7
|
+
def initialize(name, _namespace: [], _priority: 0, _callable: false, **options, &block)
|
8
8
|
@name = name
|
9
9
|
@namespace = _namespace
|
10
10
|
@priority = _priority
|
11
|
+
@callable = _callable
|
11
12
|
end
|
12
13
|
|
13
14
|
def call(context, *)
|
data/lib/role_core/version.rb
CHANGED