role_core 0.0.27 → 0.0.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -33
- data/lib/role_core/contrib/can_can_can_permission.rb +1 -1
- 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: 39af11ea76fcb0c8a0ff489e44f929ed64fbdd18ae64f5f59f6768a000f8895a
|
4
|
+
data.tar.gz: 4d7b1901033d603da7c7f2b6247f19f120cc18ee1ccf3dbab5045a7b2a385098
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8649c664d4da57eb8665308dd58d2b1795dd619ff6b5e9be9611904b816e66ecbb28482bf25fa857e51a2b964966f655f2e9bddfb55a2c6c36a3506f86b927ab
|
7
|
+
data.tar.gz: d020474094ece60f11a0a8aa350acfa97598eecd492d106799327a10942966d4287fc0ffe4792658143a7d269b7e023e130b6d478723857be273151e95ffd000
|
data/README.md
CHANGED
@@ -98,7 +98,13 @@ RoleCore can be working with CanCanCan, Pundit easily and happily.
|
|
98
98
|
Add this line to your Gemfile:
|
99
99
|
|
100
100
|
```ruby
|
101
|
-
gem
|
101
|
+
gem "role_core"
|
102
|
+
```
|
103
|
+
|
104
|
+
if your Rails < 7 or met `visit_Psych_Nodes_Alias': Unknown alias: redis (Psych::BadAlias)`, add this line:
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
gem "psych", "~> 3.3"
|
102
108
|
```
|
103
109
|
|
104
110
|
Then execute:
|
@@ -138,6 +144,8 @@ $ bin/rails g role_core:model
|
|
138
144
|
Permissions are defined in `config/initializers/role_core.rb`,
|
139
145
|
checking it to know how to define permissions.
|
140
146
|
|
147
|
+
(If you want to define permissions in runtime, check [Dynamic Permissions](https://github.com/rails-engine/role_core#dynamic-permissions))
|
148
|
+
|
141
149
|
In addition, there also includes a directive about how to integrate with CanCanCan.
|
142
150
|
|
143
151
|
#### I18n
|
@@ -325,7 +333,7 @@ Open your User model:
|
|
325
333
|
Add a delegate to User model:
|
326
334
|
|
327
335
|
```ruby
|
328
|
-
|
336
|
+
delegate :computed_permissions, to: :role
|
329
337
|
```
|
330
338
|
|
331
339
|
- For a user who has multiple roles:
|
@@ -380,37 +388,7 @@ You can archive this goal by:
|
|
380
388
|
|
381
389
|
By design, RoleCore is for static permissions, but dynamic permissions is easy to support.
|
382
390
|
|
383
|
-
|
384
|
-
|
385
|
-
Here's an example:
|
386
|
-
|
387
|
-
- Design a model to persisting dynamic permissions, e.g `DynamicPermission(id: bigint, name: string, default: bool)`
|
388
|
-
- Add `dynamic_permissions` column (`text` type) to Role model to persisting dynamic permissions' configuration, and in your model `serialize :dynamic_permissions, Hash`
|
389
|
-
- Generate dynamic permissions set in runtime
|
390
|
-
```ruby
|
391
|
-
# Create a new permission set to containerize dynamic permissions
|
392
|
-
# `"Dynamic"` can be named to other but must be a valid Ruby class name,
|
393
|
-
# that's a hacking for `ActiveModel::Naming`,
|
394
|
-
# and can be used as I18n key, in this case, the key is `role_core/models/dynamic`.
|
395
|
-
dynamic_permission_set_class = PermissionSet.derive "Dynamic"
|
396
|
-
|
397
|
-
# Fetching dynamic permissions
|
398
|
-
dynamic_permissions = DynamicPermission.all
|
399
|
-
|
400
|
-
# Mapping dynamic permissions to permission set
|
401
|
-
dynamic_permission_set_class.draw do
|
402
|
-
dynamic_permissions.each do |p|
|
403
|
-
permission p.name, default: p.default
|
404
|
-
end
|
405
|
-
end
|
406
|
-
```
|
407
|
-
- Create a instance of this dynamic permission set
|
408
|
-
```ruby
|
409
|
-
dynamic_permissions = dynamic_permission_set_class.new(role.dynamic_permissions)
|
410
|
-
```
|
411
|
-
- You can use the `dynamic_permissions` now
|
412
|
-
|
413
|
-
Rails' `serialize` is static so you must do serialize and deserialize manually, you can wrap these logic into model.
|
391
|
+
See [example](test/dummy/app/models/team.rb) in dummy app and relates [view](test/dummy/app/views/teams/_permissions.html.erb) for details.
|
414
392
|
|
415
393
|
## Contributing
|
416
394
|
|
@@ -11,7 +11,7 @@ module RoleCore
|
|
11
11
|
@model_name = options[:model_name]
|
12
12
|
@subject = options[:subject]
|
13
13
|
@action = options[:action] || name
|
14
|
-
@options = options.except(:model, :model_name, :subject, :action)
|
14
|
+
@options = options.except(:model, :model_name, :subject, :action, :_namespace, :_priority, :_callable)
|
15
15
|
@block = block
|
16
16
|
end
|
17
17
|
|
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.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jasl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: options_model
|
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
|
-
rubygems_version: 3.
|
103
|
+
rubygems_version: 3.3.4
|
104
104
|
signing_key:
|
105
105
|
specification_version: 4
|
106
106
|
summary: RoleCore is a Rails engine which could provide essential industry of Role-based
|