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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63ff5664f63f6c6566064499f8a6c5989e3850ad0241d497a42070208d2b86a7
4
- data.tar.gz: 43a6873072604a0b3118e1b7f3836a65ef11453c7636c6410fcf110517193952
3
+ metadata.gz: c3807b5a8e65e935d90be15987889beb281b43544d77e5bbfbad48323fd32d7e
4
+ data.tar.gz: 3cd6a7055bca8202f83c2fab416ed9085bc3c95ee8c91f6448418d485c06d177
5
5
  SHA512:
6
- metadata.gz: 1c707a63d95a06429585cf04ea4396deb3743c3649a554b5d57e01ef87adfa3c002b7df31d1b3692bb32f00311736eaa47b9c24a9751bedfee331f8fdd25cf43
7
- data.tar.gz: c0cca956a8b224b9beec1452285f699b94565e5d2ab271b672952bfb9bfe03e160f3b77e8777eb48e83185a6b79d48d9deb317257f5e1435d9088608fd2dc1c0
6
+ metadata.gz: abef243bca9f77d8d6d0f53e7e05b33aa6df7754eba590a1f4a3183482190ed3818142c83b2f4f726aa41ab318d5506d3b5d3a0f36692b9616186e89b4bfe965
7
+ data.tar.gz: 7b2e615fbc15374a210b1f5725130f52371a59ccc126e7052d7ca939e1fc40dd088a2923f58820659e26de4895b882d258e9018f50d63df96034278f620fe586
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bullet_train-roles (1.19.1)
4
+ bullet_train-roles (1.19.2)
5
5
  active_hash (>= 3.3.1)
6
6
  activesupport
7
7
  cancancan
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.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Roles
4
- VERSION = "1.19.1"
4
+ VERSION = "1.19.2"
5
5
  end
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.each do |role|
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.1
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-19 00:00:00.000000000 Z
11
+ date: 2025-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug