ez-permissions 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/app/models/ez/permissions/model.rb +3 -3
- data/lib/ez/permissions/api/authorize.rb +2 -2
- data/lib/ez/permissions/api/models.rb +4 -4
- data/lib/ez/permissions/api/permissions.rb +2 -2
- data/lib/ez/permissions/dsl.rb +1 -1
- data/lib/ez/permissions/resource.rb +1 -1
- data/lib/ez/permissions/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: f220c1b6b47d2c4ec04c717591243c0256a5870f5802005a38a4c451104ea574
|
4
|
+
data.tar.gz: 68dba463fa3ece4365ee47c3443ea859aac01b010b001c67a6419e61e910efdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23f50653976ef276868f2c4bb0bcce1fd71582b424da461345138cb04bcc25c8cd75cdda2b5b66a2474536f3474535f5fa7780f5ae3618d4407b3e020f3dc14a
|
7
|
+
data.tar.gz: ba64376d6c05184036cdb550ed39229485105af12f95f78132756893131bbf4a9fa7eeb2c67d865659c2ea10ad1fee53be01397652ddf0f237cd7ab51a689c82
|
data/README.md
CHANGED
@@ -72,8 +72,8 @@ Ez::Permissions::DSL.define do |setup|
|
|
72
72
|
setup.add :permissions, actions: %i[crud my_custom_action]
|
73
73
|
|
74
74
|
# Actions option are not required. In such case you add all crud actions by default
|
75
|
-
setup.add :users
|
76
|
-
setup.add :projects
|
75
|
+
setup.add :users, group: :accounts # You can group resources
|
76
|
+
setup.add :projects # Resource without a group will get "others" group
|
77
77
|
end
|
78
78
|
```
|
79
79
|
|
@@ -7,16 +7,16 @@ module Ez
|
|
7
7
|
def self.included(base)
|
8
8
|
base.has_many :assigned_roles,
|
9
9
|
class_name: 'Ez::Permissions::ModelRole',
|
10
|
-
as:
|
10
|
+
as: :model
|
11
11
|
|
12
12
|
base.has_many :roles,
|
13
13
|
-> { distinct },
|
14
|
-
through:
|
14
|
+
through: :assigned_roles,
|
15
15
|
class_name: 'Ez::Permissions::Role'
|
16
16
|
|
17
17
|
base.has_many :permissions,
|
18
18
|
-> { distinct },
|
19
|
-
through:
|
19
|
+
through: :roles,
|
20
20
|
class_name: 'Ez::Permissions::Permission'
|
21
21
|
end
|
22
22
|
# rubocop:enable Metrics/MethodLength
|
@@ -53,9 +53,9 @@ module Ez
|
|
53
53
|
permission_ids = Ez::Permissions::PermissionRole.where(role_id: role_ids).pluck(:permission_id)
|
54
54
|
|
55
55
|
Ez::Permissions::Permission.where(
|
56
|
-
id:
|
56
|
+
id: permission_ids,
|
57
57
|
resource: resource,
|
58
|
-
action:
|
58
|
+
action: actions.map(&:to_s)
|
59
59
|
)
|
60
60
|
end
|
61
61
|
|
@@ -8,8 +8,8 @@ module Ez
|
|
8
8
|
role = Ez::Permissions::API.get_role!(role_name)
|
9
9
|
|
10
10
|
Ez::Permissions::ModelRole.find_or_create_by!(
|
11
|
-
role:
|
12
|
-
model:
|
11
|
+
role: role,
|
12
|
+
model: model,
|
13
13
|
scoped: scoped
|
14
14
|
)
|
15
15
|
end
|
@@ -30,8 +30,8 @@ module Ez
|
|
30
30
|
|
31
31
|
def model_role(role, model, scoped)
|
32
32
|
Ez::Permissions::ModelRole.find_by(
|
33
|
-
role:
|
34
|
-
model:
|
33
|
+
role: role,
|
34
|
+
model: model,
|
35
35
|
scoped: scoped
|
36
36
|
)
|
37
37
|
end
|
@@ -28,7 +28,7 @@ module Ez
|
|
28
28
|
permission = get_permission!(action, resource)
|
29
29
|
|
30
30
|
Ez::Permissions::PermissionRole.find_by(
|
31
|
-
role:
|
31
|
+
role: role,
|
32
32
|
permission: permission
|
33
33
|
)&.delete
|
34
34
|
end
|
@@ -37,7 +37,7 @@ module Ez
|
|
37
37
|
|
38
38
|
def grant_single_permission(role, permission)
|
39
39
|
Ez::Permissions::PermissionRole.find_or_create_by!(
|
40
|
-
role:
|
40
|
+
role: role,
|
41
41
|
permission: permission
|
42
42
|
)
|
43
43
|
end
|
data/lib/ez/permissions/dsl.rb
CHANGED