bullet_train-roles 1.19.1 → 1.19.2
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/Gemfile.lock +1 -1
- data/README.md +6 -0
- data/lib/bullet_train/roles/version.rb +1 -1
- data/lib/roles/permit.rb +8 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3807b5a8e65e935d90be15987889beb281b43544d77e5bbfbad48323fd32d7e
|
4
|
+
data.tar.gz: 3cd6a7055bca8202f83c2fab416ed9085bc3c95ee8c91f6448418d485c06d177
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abef243bca9f77d8d6d0f53e7e05b33aa6df7754eba590a1f4a3183482190ed3818142c83b2f4f726aa41ab318d5506d3b5d3a0f36692b9616186e89b4bfe965
|
7
|
+
data.tar.gz: 7b2e615fbc15374a210b1f5725130f52371a59ccc126e7052d7ca939e1fc40dd088a2923f58820659e26de4895b882d258e9018f50d63df96034278f620fe586
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -165,6 +165,12 @@ To access the array of all roles available for a particular model, use the `assi
|
|
165
165
|
<% end %>
|
166
166
|
```
|
167
167
|
|
168
|
+
You may want to restrict the roles considered at runtime too. To do this you can use the `included_roles` keyword of `permit`:
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
permit user, through: :memberships, parent: :team, included_roles: Membership.assignable_roles
|
172
|
+
```
|
173
|
+
|
168
174
|
## Checking user permissions
|
169
175
|
|
170
176
|
Generally the CanCanCan helper method (`account_load_and_authorize_resource`) at the top of each controller will handle checking user permissions and will only load resources appropriate for the current user.
|
data/lib/roles/permit.rb
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
module Roles
|
4
4
|
module Permit
|
5
|
-
def permit(user, through:, parent:, debug: false, intermediary: nil, rails_cache_key: nil)
|
5
|
+
def permit(user, through:, parent:, debug: false, intermediary: nil, rails_cache_key: nil, included_roles: [])
|
6
6
|
# When changing permissions during development, you may also want to do this on each request:
|
7
7
|
# User.update_all ability_cache: nil if Rails.env.development?
|
8
8
|
permissions = if rails_cache_key
|
9
9
|
Rails.cache.fetch(rails_cache_key) do
|
10
|
-
build_permissions(user, through, parent, intermediary)
|
10
|
+
build_permissions(user, through, parent, intermediary, included_roles)
|
11
11
|
end
|
12
12
|
else
|
13
|
-
build_permissions(user, through, parent, intermediary)
|
13
|
+
build_permissions(user, through, parent, intermediary, included_roles)
|
14
14
|
end
|
15
15
|
|
16
16
|
begin
|
@@ -47,10 +47,13 @@ module Roles
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def build_permissions(user, through, parent, intermediary)
|
50
|
+
def build_permissions(user, through, parent, intermediary, included_roles)
|
51
51
|
added_roles = Set.new
|
52
52
|
permissions = []
|
53
|
-
user.send(through).map(&:roles).flatten.uniq
|
53
|
+
user_roles = user.send(through).map(&:roles).flatten.uniq
|
54
|
+
user_roles &= included_roles if included_roles.any?
|
55
|
+
|
56
|
+
user_roles.each do |role|
|
54
57
|
unless added_roles.include?(role)
|
55
58
|
permissions << {is_debug: true, info: "########### ROLE: #{role.key}"}
|
56
59
|
permissions += add_abilities_for(role, user, through, parent, intermediary)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet_train-roles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.19.
|
4
|
+
version: 1.19.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Prabin Poudel
|
8
8
|
- Andrew Culver
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|