role_core 0.0.15 → 0.0.16
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 +6 -5
- data/lib/generators/role_core/config/templates/role_core.rb +2 -2
- data/lib/role_core/contrib/can_can_can_permission.rb +1 -1
- data/lib/role_core/mapper.rb +6 -1
- data/lib/role_core/permission.rb +4 -3
- data/lib/role_core/permission_set.rb +4 -0
- data/lib/role_core/version.rb +1 -1
- 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: 63f9af3dc716a40099563d28bc8f409c0ae479eef42ece8ddd24fa3a90ab48c9
|
4
|
+
data.tar.gz: 44e757638be123b0877bf868814f712f920b48e5b8f3bb950fc83c1e4f649a62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4151358dfb0e084f9e5c3be912ba6e605610fe80ef1bce0af72c01120df8c8f9061554dc427f00fbcc611bc5050a59c512828b7b0945d128b45eaad0bfdb954f
|
7
|
+
data.tar.gz: 5827598c230b815ef22ba4db1d08f21136495d96419430a5e86c92f48d9790244a8988e0712c80485c8346a01027df2066dfd60032b70e0735a0ecd3dbf3889d
|
@@ -1,8 +1,8 @@
|
|
1
1
|
en:
|
2
2
|
role_core:
|
3
3
|
models: # Defined by `group` place here
|
4
|
-
# project:
|
5
|
-
# task:
|
4
|
+
# project: Projects
|
5
|
+
# project/task: Tasks # A nested group
|
6
6
|
attributes:
|
7
7
|
# global: # Top-level permissions
|
8
8
|
# foo: Foo
|
@@ -11,10 +11,11 @@ en:
|
|
11
11
|
# create: New project
|
12
12
|
# destroy: Destroy project
|
13
13
|
# update: Edit project
|
14
|
-
# read: Read
|
15
|
-
# read_public: Read public
|
16
|
-
# task:
|
14
|
+
# read: Read projects
|
15
|
+
# read_public: Read public projects
|
16
|
+
# project/task:
|
17
17
|
# create: New task
|
18
18
|
# destroy: Destroy task
|
19
19
|
# update: Edit task
|
20
20
|
# update_my_own: Edit my own task
|
21
|
+
# destroy_my_own: Destroy my own task
|
@@ -42,11 +42,11 @@ RoleCore.permission_set_class.draw do
|
|
42
42
|
# can :create, Project
|
43
43
|
# can :destroy, Plan
|
44
44
|
#
|
45
|
-
# You can pass `
|
45
|
+
# You can pass `_priority` argument to `permission`
|
46
46
|
#
|
47
47
|
# group :project, model_name: "Project" do
|
48
48
|
# permission :read_public,
|
49
|
-
# permission :read,
|
49
|
+
# permission :read, _priority: 1
|
50
50
|
# end
|
51
51
|
#
|
52
52
|
# That will made 'read' prior than `read_public`.
|
@@ -4,7 +4,7 @@ module RoleCore
|
|
4
4
|
class CanCanCanPermission < RoleCore::Permission
|
5
5
|
attr_reader :action, :options
|
6
6
|
|
7
|
-
def initialize(name,
|
7
|
+
def initialize(name, _namespace: [], _priority: 0, **options, &block)
|
8
8
|
super
|
9
9
|
|
10
10
|
@model = options[:model] || options.fetch(:model_name).constantize
|
data/lib/role_core/mapper.rb
CHANGED
@@ -4,6 +4,7 @@ module RoleCore
|
|
4
4
|
class Mapper
|
5
5
|
def initialize(set, **constraints) #:nodoc:
|
6
6
|
@constraints = constraints
|
7
|
+
@constraints[:_namespace] ||= []
|
7
8
|
@set = set
|
8
9
|
end
|
9
10
|
|
@@ -16,11 +17,15 @@ module RoleCore
|
|
16
17
|
raise ArgumentError, "`name` can't be blank" if name.blank?
|
17
18
|
raise ArgumentError, "must provide a block" unless block_given?
|
18
19
|
|
20
|
+
constraints[:_namespace] ||= @constraints[:_namespace].dup
|
21
|
+
constraints[:_namespace] << name
|
22
|
+
|
19
23
|
sub_permission_set_class =
|
20
24
|
if @set.nested_classes.has_key?(name)
|
21
25
|
@set.nested_classes[name]
|
22
26
|
else
|
23
|
-
|
27
|
+
klass_name = constraints[:_namespace].map { |n| n.to_s.classify }.join("::")
|
28
|
+
klass = PermissionSet.derive klass_name
|
24
29
|
@set.embeds_one(name, anonymous_class: klass)
|
25
30
|
|
26
31
|
klass
|
data/lib/role_core/permission.rb
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
|
3
3
|
module RoleCore
|
4
4
|
class Permission
|
5
|
-
attr_reader :name, :priority
|
5
|
+
attr_reader :name, :namespace, :priority
|
6
6
|
|
7
|
-
def initialize(name,
|
7
|
+
def initialize(name, _namespace: [], _priority: 0, **options, &block)
|
8
8
|
@name = name
|
9
|
-
@
|
9
|
+
@namespace = _namespace
|
10
|
+
@priority = _priority
|
10
11
|
end
|
11
12
|
|
12
13
|
def call(context, *)
|
data/lib/role_core/version.rb
CHANGED