role_core 0.0.27 → 0.0.29
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/README.md +11 -33
- data/lib/role_core/concerns/models/role.rb +1 -1
- 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: c7fe4d1e27ca682fe3bb59dce5e6eefba062053ff7cad056ea5245a09da51d68
|
4
|
+
data.tar.gz: 830ea09acdfe5cc6a1cd652e39215c64eac62053d001b40885af93794a12a090
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57341db8d74b769b4502ef08ac08031516f026f5d1854f8137dbc24b6f4be8553cdd6dc9472e57274d80d8a2fdafc6d971bc5e6df4f21f13fc83f1359df61547
|
7
|
+
data.tar.gz: 68dcaee1798f9522c1e67045cdd2fb853d36c309f1b8157cba9017f5da0c8d50a6e042567e3884ae12ad011e17d6e4ebca6ddddf12dbb72cc3306f1e8c5df2a0
|
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.29
|
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: 2024-03-12 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.5.6
|
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
|