foobara 0.0.90 → 0.0.91

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: 5aef9e716ddfe89cbe85867f6bb5a0af642b3af7e1dab9fb502116380eb4e44e
4
- data.tar.gz: 80f58463fdbc26ee8bdf90cfe56eeca95ecb56dd2d8fb8c4d4014a12d9f98d55
3
+ metadata.gz: afa85ac4f9b3b8a144859108c7d4273fc290449bcf831cc6a3ff6c9445530f10
4
+ data.tar.gz: 918c40b8fd082cc4982d984716b7f7e0fbaac6f2110d445bc248d4985dfa2726
5
5
  SHA512:
6
- metadata.gz: 12a9d4519ac42c3b159b35260e768b67cfafe7811a83d3027ec7f7e278306a48ae5e4185b5416f94b915d1ea4b6dc4f65c1056b7a5c12c229f00d807436b3188
7
- data.tar.gz: 1cb99a0a5e64de8585e578d50845118ffd817abcceafc37d04aeb9b892aebc74c11737560d8adb3656af4ed912dbc27aa3cc762888673114f6018068da1a43cc
6
+ metadata.gz: 2aca63aa3477913c4289896d64b62a53065951da6d7c24982fa7ec8569a97bfc490320ffa002a1f219b97ee205dc2230bd3c5a66def92932da42df133a600ced
7
+ data.tar.gz: 26546b93d55db31c3c88a322dcc1cd472ab2be4392b8410f1a1206a25f060f86b3be2db2628d2cf3897c0b461844acff52bd063a299ab917c0c05c22119cb4ac
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # [0.0.91] - 2025-03-31
2
+
3
+ - Fix bug that was including removed types in command manifest's inputs_types_depended_on
4
+ - Hoist authentication check up into command connector further from transformed command
5
+
1
6
  # [0.0.90] - 2025-03-29
2
7
 
3
8
  - Implement request mutator concept
@@ -180,6 +180,14 @@ module Foobara
180
180
  end.sort.to_h
181
181
  end
182
182
 
183
+ def inputs_types_depended_on
184
+ inputs_type&.types_depended_on || []
185
+ end
186
+
187
+ def result_types_depended_on(remove_sensitive: true)
188
+ result_type&.types_depended_on(remove_sensitive:) || []
189
+ end
190
+
183
191
  def types_depended_on(remove_sensitive: true)
184
192
  # TODO: memoize this
185
193
  # TODO: this should not delegate to command since transformers are in play
@@ -188,29 +196,29 @@ module Foobara
188
196
  type = inputs_type
189
197
 
190
198
  if type != command_class.inputs_type
191
- types |= if type.registered?
192
- # TODO: if we ever change from attributes-only inputs type
193
- # then this will be handy
194
- # :nocov:
195
- [type]
196
- # :nocov:
197
- else
198
- type.types_depended_on(remove_sensitive:)
199
- end
199
+ if type.registered?
200
+ # TODO: if we ever change from attributes-only inputs type
201
+ # then this will be handy
202
+ # :nocov:
203
+ types |= [type]
204
+ # :nocov:
205
+ end
206
+
207
+ types |= type.types_depended_on
200
208
  end
201
209
 
202
210
  type = result_type
203
211
 
204
212
  if type != command_class.result_type
205
- types |= if type.registered?
206
- # TODO: if we ever change from attributes-only inputs type
207
- # then this will be handy
208
- # :nocov:
209
- [type]
210
- # :nocov:
211
- else
212
- type.types_depended_on(remove_sensitive:)
213
- end
213
+ if type.registered?
214
+ # TODO: if we ever change from attributes-only inputs type
215
+ # then this will be handy
216
+ # :nocov:
217
+ types |= [type]
218
+ # :nocov:
219
+ end
220
+
221
+ types |= type.types_depended_on(remove_sensitive:)
214
222
  end
215
223
 
216
224
  possible_errors.each do |possible_error|
@@ -243,8 +251,25 @@ module Foobara
243
251
  response_mutators = self.response_mutators.map { |t| t.foobara_manifest(to_include:) }
244
252
  request_mutators = self.request_mutators.map { |t| t.foobara_manifest(to_include:) }
245
253
 
254
+ authenticator_manifest = if authenticator
255
+ if authenticator.respond_to?(:foobara_manifest)
256
+ # TODO: test this path
257
+ # :nocov:
258
+ authenticator.foobara_manifest(to_include:)
259
+ # :nocov:
260
+ else
261
+ true
262
+ end
263
+ end
264
+
265
+ inputs_types_depended_on = self.inputs_types_depended_on.map(&:foobara_manifest_reference).sort
266
+ result_types_depended_on = self.result_types_depended_on(remove_sensitive:).map(&:foobara_manifest_reference)
267
+ result_types_depended_on = result_types_depended_on.sort
268
+
246
269
  command_class.foobara_manifest(to_include:, remove_sensitive:).merge(
247
270
  Util.remove_blank(
271
+ inputs_types_depended_on:,
272
+ result_types_depended_on:,
248
273
  types_depended_on: types,
249
274
  inputs_type: inputs_type_for_manifest&.reference_or_declaration_data,
250
275
  result_type: result_type_for_manifest&.reference_or_declaration_data(remove_sensitive:),
@@ -258,7 +283,7 @@ module Foobara
258
283
  response_mutators:,
259
284
  request_mutators:,
260
285
  requires_authentication:,
261
- authenticator: authenticator&.manifest
286
+ authenticator: authenticator_manifest
262
287
  )
263
288
  )
264
289
  end
@@ -394,7 +419,6 @@ module Foobara
394
419
  to: :class
395
420
 
396
421
  def run
397
- authenticate if requires_authentication?
398
422
  apply_allowed_rule
399
423
  apply_pre_commit_transformers
400
424
  run_command
@@ -482,19 +506,6 @@ module Foobara
482
506
  self.command = command_class.new(transformed_inputs)
483
507
  end
484
508
 
485
- def authenticate
486
- command.after_load_records do |command:, **|
487
- self.authenticated_user = instance_eval(&:authenticator)
488
-
489
- unless authenticated_user
490
- self.outcome = Outcome.error(CommandConnector::UnauthenticatedError.new)
491
-
492
- command.state_machine.error!
493
- command.halt!
494
- end
495
- end
496
- end
497
-
498
509
  def apply_allowed_rule
499
510
  rule = allowed_rule
500
511
 
@@ -338,6 +338,10 @@ module Foobara
338
338
  # TODO: feels like a smell
339
339
  request.command_connector = self
340
340
 
341
+ if command.respond_to?(:requires_authentication?) && command.requires_authentication?
342
+ authenticate(request)
343
+ end
344
+
341
345
  if command
342
346
  command.run
343
347
  # :nocov:
@@ -349,6 +353,23 @@ module Foobara
349
353
  build_response(request)
350
354
  end
351
355
 
356
+ def authenticate(request)
357
+ request_command = request.command
358
+
359
+ request_command.after_load_records do |command:, **|
360
+ authenticated_user = request.instance_eval(&authenticator)
361
+
362
+ request_command.authenticated_user = authenticated_user
363
+
364
+ unless authenticated_user
365
+ request_command.outcome = Outcome.error(CommandConnector::UnauthenticatedError.new)
366
+
367
+ command.state_machine.error!
368
+ command.halt!
369
+ end
370
+ end
371
+ end
372
+
352
373
  def build_request_and_command(...)
353
374
  request = build_request(...)
354
375
 
@@ -3,6 +3,10 @@ module Foobara
3
3
  class Command < BaseManifest
4
4
  self.category_symbol = :command
5
5
 
6
+ def requires_authentication?
7
+ !!self[:requires_authentication]
8
+ end
9
+
6
10
  def command_manifest
7
11
  relevant_manifest
8
12
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.90
4
+ version: 0.0.91
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-30 00:00:00.000000000 Z
10
+ date: 2025-03-31 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bigdecimal