bullet_train-roles 0.1.6 → 0.1.9
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/.circleci/config.yml +127 -49
- data/Gemfile.lock +7 -6
- data/README.md +3 -2
- data/lib/bullet_train/roles/engine.rb +17 -0
- data/lib/bullet_train/roles/version.rb +1 -1
- data/lib/bullet_train/roles.rb +2 -0
- data/lib/models/role.rb +23 -13
- data/lib/roles/permit.rb +41 -23
- data/lib/roles/support.rb +1 -1
- data/lib/roles/user.rb +9 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22f9bcc3e444766f5813562e0506db8f9b921f141ce2ce77eb3d30156418c80f
|
4
|
+
data.tar.gz: 7db6d4154b2bd4e58e7d35455635b55b84f6e66424e1f4e9b26a82e908865dbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ece8c36a0ae647489604813e15646ec1096d62f3980d032892ceefd21b8bf7a5f82430ad6a58219edf287994ee0019a7dc00dbe2939782ac7e24b1ff0b77188
|
7
|
+
data.tar.gz: 0a386a84154f7d192019ab68d5be0094b3fcd6827dd53f29bf629fa0ed15a8ff8546bbd2fb382b9a4e3b30e13d922de0b7e2d819c08c03fb4662516f193df0af
|
data/.circleci/config.yml
CHANGED
@@ -1,86 +1,124 @@
|
|
1
1
|
version: 2.1
|
2
2
|
orbs:
|
3
3
|
ruby: circleci/ruby@0.1.2
|
4
|
-
|
4
|
+
browser-tools: circleci/browser-tools@1.1
|
5
5
|
aliases:
|
6
6
|
- &restore_bundler_cache
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
name: Restore Bundler cache
|
8
|
+
keys:
|
9
|
+
- gem-cache-v1-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
|
10
|
+
- gem-cache-v1-{{ .Branch }}-
|
11
|
+
- gem-cache-v1-
|
12
12
|
- &restore_yarn_cache
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
name: Restore Yarn cache
|
14
|
+
keys:
|
15
|
+
- yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}
|
16
|
+
- yarn-packages-v1-{{ .Branch }}-
|
17
|
+
- yarn-packages-
|
18
18
|
- &save_bundle_cache
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
name: Save Bundle cache
|
20
|
+
key: gem-cache-v1-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
|
21
|
+
paths:
|
22
|
+
- vendor/bundle
|
23
23
|
- &save_yarn_cache
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
name: Save Yarn cache
|
25
|
+
key: yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}
|
26
|
+
paths:
|
27
|
+
- node_modules
|
28
|
+
- &ruby_node_browsers_docker_image
|
29
|
+
- image: cimg/ruby:3.1.2-browsers
|
30
|
+
environment:
|
31
|
+
PGHOST: localhost
|
32
|
+
PGUSER: untitled_application
|
33
|
+
RAILS_ENV: test
|
34
|
+
- &postgres_docker_image
|
35
|
+
- image: circleci/postgres
|
36
|
+
environment:
|
37
|
+
POSTGRES_HOST_AUTH_METHOD: trust
|
38
|
+
POSTGRES_DB: untitled_application_test
|
39
|
+
POSTGRES_USER: untitled_application
|
40
|
+
- &wait_for_docker
|
41
|
+
# We run this because the DB might not be available for a while due to a race condition.
|
42
|
+
run: dockerize -wait tcp://localhost:5432 -timeout 1m
|
29
43
|
jobs:
|
30
|
-
'
|
44
|
+
'Local Minitest':
|
45
|
+
docker:
|
46
|
+
- <<: *ruby_node_browsers_docker_image
|
47
|
+
- <<: *postgres_docker_image
|
48
|
+
- image: circleci/redis
|
49
|
+
executor: ruby/default
|
50
|
+
steps:
|
51
|
+
- browser-tools/install-browser-tools
|
52
|
+
- checkout
|
53
|
+
|
54
|
+
# Install dependencies
|
55
|
+
- run: "bundle install"
|
56
|
+
- run: "bundle clean --force"
|
57
|
+
- run: "yarn install"
|
58
|
+
- *wait_for_docker
|
59
|
+
- run:
|
60
|
+
name: Run unit tests
|
61
|
+
command: bundle exec rails test
|
62
|
+
|
63
|
+
'Local Standard Ruby':
|
31
64
|
docker:
|
32
|
-
|
33
|
-
- image: circleci/ruby:3.0.2-node-browsers
|
65
|
+
- <<: *ruby_node_browsers_docker_image
|
34
66
|
steps:
|
35
67
|
- checkout
|
36
68
|
|
37
|
-
#
|
38
|
-
|
39
|
-
- restore_cache: *
|
69
|
+
# TODO Figure out how to make these work for `tmp/starter`
|
70
|
+
# # Restore dependency caches
|
71
|
+
# - restore_cache: *restore_bundler_cache
|
72
|
+
# - restore_cache: *restore_yarn_cache
|
40
73
|
|
41
74
|
# Install dependencies
|
42
75
|
- ruby/bundle-install
|
43
76
|
- run: bundle clean --force
|
44
77
|
- run: yarn install
|
45
78
|
|
46
|
-
# Save dependency caches
|
47
|
-
# We only do this as part of this job, because it's time consuming and we don't want it to slow down test runners.
|
48
|
-
- save_cache: *save_bundle_cache
|
49
|
-
- save_cache: *save_yarn_cache
|
79
|
+
# # Save dependency caches
|
80
|
+
# # We only do this as part of this job, because it's time consuming and we don't want it to slow down test runners.
|
81
|
+
# - save_cache: *save_bundle_cache
|
82
|
+
# - save_cache: *save_yarn_cache
|
50
83
|
|
51
84
|
- run:
|
52
85
|
name: Check Standard Ruby
|
53
86
|
command: bundle exec standardrb
|
54
87
|
|
55
|
-
'Minitest':
|
88
|
+
'Starter Repo Minitest':
|
56
89
|
docker:
|
57
|
-
-
|
58
|
-
|
59
|
-
|
60
|
-
PGUSER: bullet_train
|
61
|
-
RAILS_ENV: test
|
62
|
-
- image: circleci/postgres
|
63
|
-
environment:
|
64
|
-
POSTGRES_HOST_AUTH_METHOD: trust
|
65
|
-
POSTGRES_DB: bullet_train_test
|
66
|
-
POSTGRES_USER: bullet_train
|
90
|
+
- <<: *ruby_node_browsers_docker_image
|
91
|
+
- <<: *postgres_docker_image
|
92
|
+
- image: circleci/redis
|
67
93
|
executor: ruby/default
|
68
94
|
parallelism: 16
|
69
95
|
steps:
|
96
|
+
- browser-tools/install-browser-tools
|
70
97
|
- checkout
|
71
|
-
-
|
72
|
-
|
98
|
+
- run: "git clone https://github.com/bullet-train-co/bullet_train.git tmp/starter"
|
99
|
+
|
100
|
+
- run:
|
101
|
+
name: Link starter repository to the Ruby gem being tested.
|
102
|
+
command: "grep -v 'gem \"bullet_train-roles\"' tmp/starter/Gemfile > tmp/starter/Gemfile.tmp && mv tmp/starter/Gemfile.tmp tmp/starter/Gemfile && echo 'gem \"bullet_train-roles\", path: \"../..\"' >> tmp/starter/Gemfile"
|
103
|
+
|
104
|
+
# TODO Figure out how to make these work for `tmp/starter`
|
105
|
+
# - restore_cache: *restore_bundler_cache
|
106
|
+
# - restore_cache: *restore_yarn_cache
|
73
107
|
|
74
108
|
# Install dependencies
|
75
|
-
-
|
76
|
-
- run: bundle clean --force
|
109
|
+
- run: "cd tmp/starter && bundle install"
|
110
|
+
- run: "cd tmp/starter && bundle clean --force"
|
111
|
+
- run: "cd tmp/starter && bundle exec rake bt:link"
|
112
|
+
- run: "cd tmp/starter && yarn install"
|
113
|
+
- run: "cd tmp/starter && yarn build"
|
114
|
+
- run: "cd tmp/starter && yarn build:css"
|
77
115
|
|
78
|
-
|
79
|
-
- run: dockerize -wait tcp://localhost:5432 -timeout 1m
|
116
|
+
- *wait_for_docker
|
80
117
|
|
81
118
|
- run:
|
82
119
|
name: Run tests with Knapsack Pro
|
83
120
|
command: |
|
121
|
+
cd tmp/starter
|
84
122
|
export RAILS_ENV=test
|
85
123
|
bundle exec rails "knapsack_pro:queue:minitest[--verbose]"
|
86
124
|
environment:
|
@@ -102,9 +140,49 @@ jobs:
|
|
102
140
|
# - store_test_results:
|
103
141
|
# path: test/reports
|
104
142
|
|
143
|
+
'Starter Repo Minitest for Super Scaffolding':
|
144
|
+
docker:
|
145
|
+
- <<: *ruby_node_browsers_docker_image
|
146
|
+
- <<: *postgres_docker_image
|
147
|
+
- image: circleci/redis
|
148
|
+
executor: ruby/default
|
149
|
+
steps:
|
150
|
+
- browser-tools/install-browser-tools
|
151
|
+
- checkout
|
152
|
+
- run: "git clone https://github.com/bullet-train-co/bullet_train.git tmp/starter"
|
153
|
+
|
154
|
+
- run:
|
155
|
+
name: Link starter repository to the Ruby gem being tested.
|
156
|
+
command: "grep -v 'gem \"bullet_train-roles\"' tmp/starter/Gemfile > tmp/starter/Gemfile.tmp && mv tmp/starter/Gemfile.tmp tmp/starter/Gemfile && echo 'gem \"bullet_train-roles\", path: \"../..\"' >> tmp/starter/Gemfile"
|
157
|
+
|
158
|
+
# TODO Figure out how to make these work for `tmp/starter`
|
159
|
+
# # Restore dependency caches
|
160
|
+
# - restore_cache: *restore_bundler_cache
|
161
|
+
# - restore_cache: *restore_yarn_cache
|
162
|
+
|
163
|
+
# Install dependencies
|
164
|
+
- run: "cd tmp/starter && bundle install"
|
165
|
+
- run: "cd tmp/starter && bundle clean --force"
|
166
|
+
- run: "cd tmp/starter && bundle exec rake bt:link"
|
167
|
+
- run: "cd tmp/starter && yarn install"
|
168
|
+
- run: "cd tmp/starter && yarn build"
|
169
|
+
- run: "cd tmp/starter && yarn build:css"
|
170
|
+
|
171
|
+
- *wait_for_docker
|
172
|
+
|
173
|
+
- run:
|
174
|
+
name: 'Setup Super Scaffolding System Test'
|
175
|
+
command: "cd tmp/starter && bundle exec test/bin/setup-super-scaffolding-system-test"
|
176
|
+
- run:
|
177
|
+
name: 'Run Super Scaffolding Test'
|
178
|
+
command: "cd tmp/starter && bundle exec rails test test/system/super_scaffolding_test.rb"
|
179
|
+
|
105
180
|
workflows:
|
106
181
|
version: 2
|
107
182
|
build:
|
108
183
|
jobs:
|
109
|
-
- '
|
110
|
-
- '
|
184
|
+
- 'Local Minitest'
|
185
|
+
- 'Local Standard Ruby'
|
186
|
+
- 'Starter Repo Minitest'
|
187
|
+
# TODO Get this passing.
|
188
|
+
# - 'Starter Repo Minitest for Super Scaffolding'
|
data/Gemfile.lock
CHANGED
@@ -9,7 +9,7 @@ GIT
|
|
9
9
|
PATH
|
10
10
|
remote: .
|
11
11
|
specs:
|
12
|
-
bullet_train-roles (0.1.
|
12
|
+
bullet_train-roles (0.1.9)
|
13
13
|
active_hash
|
14
14
|
activesupport
|
15
15
|
cancancan
|
@@ -79,7 +79,7 @@ GEM
|
|
79
79
|
ast (2.4.2)
|
80
80
|
builder (3.2.4)
|
81
81
|
byebug (11.1.3)
|
82
|
-
cancancan (3.
|
82
|
+
cancancan (3.4.0)
|
83
83
|
concurrent-ruby (1.1.9)
|
84
84
|
crass (1.0.6)
|
85
85
|
erubi (1.10.0)
|
@@ -102,11 +102,11 @@ GEM
|
|
102
102
|
marcel (1.0.2)
|
103
103
|
method_source (1.0.0)
|
104
104
|
mini_mime (1.1.2)
|
105
|
+
mini_portile2 (2.6.1)
|
105
106
|
minitest (5.15.0)
|
106
107
|
nio4r (2.5.8)
|
107
|
-
nokogiri (1.12.5
|
108
|
-
|
109
|
-
nokogiri (1.12.5-x86_64-darwin)
|
108
|
+
nokogiri (1.12.5)
|
109
|
+
mini_portile2 (~> 2.6.1)
|
110
110
|
racc (~> 1.4)
|
111
111
|
parallel (1.21.0)
|
112
112
|
parser (3.0.3.2)
|
@@ -176,6 +176,7 @@ GEM
|
|
176
176
|
PLATFORMS
|
177
177
|
arm64-darwin-20
|
178
178
|
arm64-darwin-21
|
179
|
+
ruby
|
179
180
|
x86_64-darwin-21
|
180
181
|
|
181
182
|
DEPENDENCIES
|
@@ -191,4 +192,4 @@ DEPENDENCIES
|
|
191
192
|
standard (~> 1.5.0)
|
192
193
|
|
193
194
|
BUNDLED WITH
|
194
|
-
2.3.
|
195
|
+
2.3.13
|
data/README.md
CHANGED
@@ -68,7 +68,7 @@ editor:
|
|
68
68
|
manageable_roles:
|
69
69
|
- editor
|
70
70
|
models:
|
71
|
-
Project:
|
71
|
+
Project: crud
|
72
72
|
|
73
73
|
billing:
|
74
74
|
manageable_roles:
|
@@ -98,7 +98,8 @@ The following things are true given the example configuration above:
|
|
98
98
|
- By default, users on a team are read-only participants.
|
99
99
|
- Users with the `editor` role:
|
100
100
|
- can give other users the `editor` role.
|
101
|
-
- can
|
101
|
+
- can perform crud actions on project (create, read, update and destroy).
|
102
|
+
- cannot perform any custom controller actions the projects controller responds to
|
102
103
|
- Users with the `billing` role:
|
103
104
|
- can give other users the `billing` role.
|
104
105
|
- can create and update billing subscriptions.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module BulletTrain
|
2
|
+
module Roles
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
config.eager_load_paths << Role.full_path
|
5
|
+
|
6
|
+
initializer "bullet_train-roles.config" do |app|
|
7
|
+
role_reloader = ActiveSupport::FileUpdateChecker.new([Role.full_path]) do
|
8
|
+
Role.reload(true)
|
9
|
+
end
|
10
|
+
|
11
|
+
ActiveSupport::Reloader.to_prepare do
|
12
|
+
role_reloader.execute_if_updated
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/bullet_train/roles.rb
CHANGED
data/lib/models/role.rb
CHANGED
@@ -89,9 +89,9 @@ class Role < ActiveYaml::Base
|
|
89
89
|
!default?
|
90
90
|
end
|
91
91
|
|
92
|
-
def ability_generator(user, through, parent)
|
92
|
+
def ability_generator(user, through, parent, intermediary)
|
93
93
|
models.each do |model_name, _|
|
94
|
-
ag = AbilityGenerator.new(self, model_name, user, through, parent)
|
94
|
+
ag = AbilityGenerator.new(self, model_name, user, through, parent, intermediary)
|
95
95
|
yield(ag)
|
96
96
|
end
|
97
97
|
end
|
@@ -125,7 +125,7 @@ class Role < ActiveYaml::Base
|
|
125
125
|
class AbilityGenerator
|
126
126
|
attr_reader :model
|
127
127
|
|
128
|
-
def initialize(role, model_name, user, through, parent_name)
|
128
|
+
def initialize(role, model_name, user, through, parent_name, intermediary = nil)
|
129
129
|
begin
|
130
130
|
@model = model_name.constantize
|
131
131
|
rescue NameError
|
@@ -137,6 +137,8 @@ class Role < ActiveYaml::Base
|
|
137
137
|
@through = through
|
138
138
|
@parent = user.send(through).reflect_on_association(parent_name)&.klass
|
139
139
|
@parent_ids = user.parent_ids_for(@role, @through, parent_name) if @parent
|
140
|
+
@intermediary = intermediary
|
141
|
+
@intermediary_class = @model.reflect_on_association(intermediary)&.class_name&.constantize if @intermediary.present?
|
140
142
|
end
|
141
143
|
|
142
144
|
def valid?
|
@@ -145,9 +147,16 @@ class Role < ActiveYaml::Base
|
|
145
147
|
|
146
148
|
def actions
|
147
149
|
return @actions if @actions
|
148
|
-
actions = (@ability_data["actions"] if @ability_data.is_a?(Hash)) || @ability_data
|
149
|
-
|
150
|
-
|
150
|
+
@actions = (@ability_data["actions"] if @ability_data.is_a?(Hash)) || @ability_data
|
151
|
+
# crud is a special value that we substitute for the 4 crud actions
|
152
|
+
# This is instead of :manage which covers all 4 actions _and_ any extra actions the controller may respond to
|
153
|
+
@actions = crud_actions if @actions.to_s.downcase == "crud"
|
154
|
+
@actions = [actions] unless actions.is_a?(Array)
|
155
|
+
@actions.map!(&:to_sym)
|
156
|
+
end
|
157
|
+
|
158
|
+
def crud_actions
|
159
|
+
[:create, :read, :update, :destroy]
|
151
160
|
end
|
152
161
|
|
153
162
|
def possible_parent_associations
|
@@ -167,17 +176,18 @@ class Role < ActiveYaml::Base
|
|
167
176
|
if @model == @parent
|
168
177
|
return @condition = {id: @parent_ids}
|
169
178
|
end
|
170
|
-
parent_association = possible_parent_associations.find { |association| @model.
|
179
|
+
parent_association = possible_parent_associations.find { |association| @model.reflect_on_association(association) || @intermediary_class&.reflect_on_association(association) }
|
171
180
|
return nil unless parent_association.present?
|
172
|
-
# If possible, use the team_id attribute because it saves us having to join all the way back to the
|
181
|
+
# If possible, use the team_id attribute because it saves us having to join all the way back to the source parent model
|
173
182
|
# In some scenarios this may be quicker, or if the parent model is in a different database shard, it may not even
|
174
183
|
# be possible to do the join
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
184
|
+
parent_with_id = "#{parent_association}_id"
|
185
|
+
@condition = if @model.column_names.include?(parent_with_id)
|
186
|
+
{parent_with_id.to_sym => @parent_ids}
|
187
|
+
elsif @intermediary.present? && @model.reflect_on_association(@intermediary)
|
188
|
+
{@intermediary.to_sym => {parent_with_id.to_sym => @parent_ids}}
|
179
189
|
else
|
180
|
-
|
190
|
+
{parent_association => {id: @parent_ids}}
|
181
191
|
end
|
182
192
|
end
|
183
193
|
end
|
data/lib/roles/permit.rb
CHANGED
@@ -2,48 +2,66 @@
|
|
2
2
|
|
3
3
|
module Roles
|
4
4
|
module Permit
|
5
|
-
def permit(user, through:, parent:, debug: false)
|
6
|
-
# Without this, you need to restart the server each time you make changes to the config/models/role.yml file
|
7
|
-
Role.reload(true) if Rails.env.development?
|
8
|
-
|
5
|
+
def permit(user, through:, parent:, debug: false, intermediary: nil, cache_key: nil)
|
9
6
|
# When changing permissions during development, you may also want to do this on each request:
|
10
7
|
# User.update_all ability_cache: nil if Rails.env.development?
|
11
|
-
|
8
|
+
permissions = if cache_key
|
9
|
+
Rails.cache.fetch(cache_key) do
|
10
|
+
build_permissions(user, through, parent, intermediary)
|
11
|
+
end
|
12
|
+
else
|
13
|
+
build_permissions(user, through, parent, intermediary)
|
14
|
+
end
|
15
|
+
|
16
|
+
permissions.each do |permission|
|
17
|
+
can(permission.actions, permission.model.constantize, permission.condition) unless permission.is_debug
|
18
|
+
end
|
19
|
+
|
20
|
+
if debug
|
21
|
+
puts "###########################"
|
22
|
+
puts "Auto generated `ability.rb` content:"
|
23
|
+
permissions.map do |permission|
|
24
|
+
if permission.is_debug
|
25
|
+
puts permission.info
|
26
|
+
else
|
27
|
+
puts "can #{permission.actions}, #{permission.model}, #{permission.condition}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
puts "############################"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_permissions(user, through, parent, intermediary)
|
12
35
|
added_roles = Set.new
|
36
|
+
permissions = []
|
13
37
|
user.send(through).map(&:roles).flatten.uniq.each do |role|
|
14
38
|
unless added_roles.include?(role)
|
15
|
-
|
16
|
-
|
39
|
+
permissions << OpenStruct.new(is_debug: true, info: "########### ROLE: #{role.key}")
|
40
|
+
permissions += add_abilities_for(role, user, through, parent, intermediary)
|
17
41
|
added_roles << role
|
18
42
|
end
|
19
43
|
|
20
44
|
role.included_roles.each do |included_role|
|
21
45
|
unless added_roles.include?(included_role)
|
22
|
-
|
23
|
-
|
46
|
+
permissions << OpenStruct.new(is_debug: true, info: "############# INCLUDED ROLE: #{included_role.key}")
|
47
|
+
permissions += add_abilities_for(included_role, user, through, parent, intermediary)
|
24
48
|
end
|
25
49
|
end
|
26
50
|
end
|
27
51
|
|
28
|
-
|
29
|
-
puts "###########################"
|
30
|
-
puts "Auto generated `ability.rb` content:"
|
31
|
-
puts output
|
32
|
-
puts "############################"
|
33
|
-
end
|
52
|
+
permissions
|
34
53
|
end
|
35
54
|
|
36
|
-
def add_abilities_for(role, user, through, parent)
|
37
|
-
|
38
|
-
role.ability_generator(user, through, parent) do |ag|
|
39
|
-
if ag.valid?
|
40
|
-
|
41
|
-
can(ag.actions, ag.model, ag.condition)
|
55
|
+
def add_abilities_for(role, user, through, parent, intermediary)
|
56
|
+
permissions = []
|
57
|
+
role.ability_generator(user, through, parent, intermediary) do |ag|
|
58
|
+
permissions << if ag.valid?
|
59
|
+
OpenStruct.new(is_debug: false, actions: ag.actions, model: ag.model.to_s, condition: ag.condition)
|
42
60
|
else
|
43
|
-
|
61
|
+
OpenStruct.new(is_debug: true, info: "# #{ag.model} does not respond to #{parent} so we're not going to add an ability for the #{through} context")
|
44
62
|
end
|
45
63
|
end
|
46
|
-
|
64
|
+
permissions
|
47
65
|
end
|
48
66
|
end
|
49
67
|
end
|
data/lib/roles/support.rb
CHANGED
data/lib/roles/user.rb
CHANGED
@@ -10,16 +10,23 @@ module Roles
|
|
10
10
|
def parent_ids_for(role, through, parent)
|
11
11
|
parent_id_column = "#{parent}_id"
|
12
12
|
key = "#{role.key}_#{through}_#{parent_id_column}s"
|
13
|
+
|
14
|
+
@_parent_ids_for_cache ||= {}
|
15
|
+
return @_parent_ids_for_cache[key] if @_parent_ids_for_cache[key]
|
16
|
+
|
13
17
|
# TODO Maybe we should make ability caching a default feature of the gem?
|
14
18
|
# If we do that, we would just make it check whether `ability_cache` exists.
|
15
19
|
# return ability_cache[key] if ability_cache && ability_cache[key]
|
16
20
|
role = nil if role.default?
|
17
|
-
|
21
|
+
@_parent_ids_for_cache[key] = send(through).with_role(role).distinct.pluck(parent_id_column)
|
18
22
|
# TODO Maybe we should make ability caching a default feature of the gem?
|
19
23
|
# current_cache = ability_cache || {}
|
20
24
|
# current_cache[key] = value
|
21
25
|
# update_column :ability_cache, current_cache
|
22
|
-
|
26
|
+
end
|
27
|
+
|
28
|
+
def invalidate_ability_cache
|
29
|
+
update_column :ability_cache, {}
|
23
30
|
end
|
24
31
|
end
|
25
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet_train-roles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Prabin Poudel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-08-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: byebug
|
@@ -185,6 +185,7 @@ files:
|
|
185
185
|
- bin/setup
|
186
186
|
- bullet_train-roles.gemspec
|
187
187
|
- lib/bullet_train/roles.rb
|
188
|
+
- lib/bullet_train/roles/engine.rb
|
188
189
|
- lib/bullet_train/roles/version.rb
|
189
190
|
- lib/generators/bullet_train/roles/install/USAGE
|
190
191
|
- lib/generators/bullet_train/roles/install/install_generator.rb
|
@@ -215,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
215
216
|
- !ruby/object:Gem::Version
|
216
217
|
version: '0'
|
217
218
|
requirements: []
|
218
|
-
rubygems_version: 3.3.
|
219
|
+
rubygems_version: 3.3.7
|
219
220
|
signing_key:
|
220
221
|
specification_version: 4
|
221
222
|
summary: Yaml-backed ApplicationHash for CanCan Roles
|