foobara 0.4.2 → 0.4.4

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: 979ed0e27280b7f1183c77f8ca34eacaab8b232c719bf9f9ad4964ef309da64c
4
- data.tar.gz: 819ad164acb49337551e91814f5faf3a78a825085c5b723d76fff701d4c1adcd
3
+ metadata.gz: 1bf3d5a0446977b9a62d890956d294cbe24761295f9f8c1c9ad6d4101a280532
4
+ data.tar.gz: 1d680e4acd71324924ffa28f75dc36d8c4f11b648dc1ff1d3c01b647d4e635c5
5
5
  SHA512:
6
- metadata.gz: 488905b81c1b660af40b374cef9f34ebaf5548cae9202afdb2a90680abd78be9673a7b51de2431f1ce836b7815cf82ff1be245757e86da1ea0d4bcb4eed74294
7
- data.tar.gz: 4a1d3377183c75ceea13be7d1501c686c97f9b6b29f76a01e9a9b9fa0e1addd18a0fdbef4bf6879e21f383aa3dc304d6ed2c1f9d1a3ac788be3db41ecc1793eb
6
+ metadata.gz: 7b76877ed83b42e1e625b04a5c3ede92e93627f772568524f3a9cec50868e0b44f8a06dadf4d65b882301866d82708a88827733f9e6da5f6b2f6833f18e0d5b7
7
+ data.tar.gz: d0f8710c28628a270409c5eb10ca4d71d07e8be9cf18b81d3319b12c5399cc6476cfca81c09ad83dcd774fcd11246a270ebf1149438eac89b6d5e0d57c9276ce
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # [0.4.4] - 2026-01-20
2
+
3
+ - Support authenticators that don't have relevant entity classes
4
+ - Fix a bug where we don't look in the dependent domain for a model type to extend
5
+
6
+ # [0.4.3] - 2026-01-19
7
+
8
+ - Allow a request to handle auth mapper methods
9
+
1
10
  # [0.4.2] - 2026-01-15
2
11
 
3
12
  - Fix relaxed lookup bug for a symbol starting with a prefix
@@ -2201,7 +2201,8 @@ RSpec.describe Foobara::CommandConnector do
2201
2201
  command_connector_b.connect(command_class, :auth)
2202
2202
  command_connector_c.connect(command_class, requires_authentication: true)
2203
2203
  command_connector_d.connect(command_class, requires_authentication: true)
2204
- command_connector_e.connect(command_class, requires_authentication: true, authenticator: [authenticator_e])
2204
+ command_connector_e.connect(command_class, requires_authentication: true,
2205
+ authenticator: [authenticator_e])
2205
2206
 
2206
2207
  response = command_connector_a.run(full_command_name:, action:, inputs:)
2207
2208
  expect(response.status).to be(0)
@@ -92,4 +92,27 @@ RSpec.describe Foobara::CommandConnector::Request do
92
92
  end
93
93
  end
94
94
  end
95
+
96
+ context "with an auth-mapped method" do
97
+ let(:command_class) do
98
+ stub_class("SomeCommand", Foobara::Command) do
99
+ def self.requires_authentication = true
100
+ end
101
+ end
102
+
103
+ let(:request) do
104
+ foo_mapper = Foobara::TypeDeclarations::TypedTransformer.subclass(to: :symbol) { :bar }.instance
105
+ # TODO: make a block form of this
106
+ authenticator = Foobara::CommandConnector.to_authenticator(-> { :some_user })
107
+
108
+ described_class.new(authenticator:, auth_mappers: { foo: foo_mapper }).tap do |request|
109
+ request.command_class = command_class
110
+ request.authenticate
111
+ end
112
+ end
113
+
114
+ it "can access the auth-mapped method" do
115
+ expect(request.foo).to eq(:bar)
116
+ end
117
+ end
95
118
  end
@@ -16,10 +16,12 @@ module Foobara
16
16
  :action,
17
17
  :response,
18
18
  :authenticated_user,
19
- :authenticated_credential
19
+ :authenticated_credential,
20
+ :auth_mappers,
21
+ :authenticator
20
22
 
21
23
  def initialize(**opts)
22
- valid_keys = [:inputs, :full_command_name, :action, :serializers]
24
+ valid_keys = [:inputs, :full_command_name, :action, :serializers, :authenticator, :auth_mappers]
23
25
 
24
26
  invalid_keys = opts.keys - valid_keys
25
27
 
@@ -31,6 +33,8 @@ module Foobara
31
33
 
32
34
  self.inputs = opts[:inputs] if opts.key?(:inputs)
33
35
  self.action = opts[:action] if opts.key?(:action)
36
+ self.auth_mappers = opts[:auth_mappers] if opts.key?(:auth_mappers)
37
+ self.authenticator = opts[:authenticator] if opts.key?(:authenticator)
34
38
  self.full_command_name = opts[:full_command_name] if opts.key?(:full_command_name)
35
39
  self.serializers = Util.array(opts[:serializers]) if opts.key?(:serializers)
36
40
  end
@@ -59,15 +63,6 @@ module Foobara
59
63
  end
60
64
  end
61
65
 
62
- def authenticator
63
- command_class.authenticator
64
- end
65
-
66
- def auth_mappers
67
- # TODO: make this consistent?
68
- command_connector.auth_map
69
- end
70
-
71
66
  def auth_mapped_method?(method_name)
72
67
  auth_mappers&.key?(method_name)
73
68
  end
@@ -88,6 +83,20 @@ module Foobara
88
83
  end
89
84
  end
90
85
 
86
+ def method_missing(method_name, ...)
87
+ if auth_mapped_method?(method_name)
88
+ auth_mapped_value_for(method_name)
89
+ else
90
+ # :nocov:
91
+ super
92
+ # :nocov:
93
+ end
94
+ end
95
+
96
+ def respond_to_missing?(method_name, private = false)
97
+ auth_mapped_method?(method_name) || super
98
+ end
99
+
91
100
  def serializer
92
101
  return @serializer if defined?(@serializer)
93
102
 
@@ -141,8 +150,12 @@ module Foobara
141
150
  # TODO: move this to entity_plumbing
142
151
  def relevant_entity_classes
143
152
  if command_class.is_a?(::Class) && command_class < TransformedCommand
144
- entity_classes = authenticator&.relevant_entity_classes(self)
145
- [*entity_classes, *relevant_entity_classes_from_inputs_transformer]
153
+ if authenticator.respond_to?(:relevant_entity_classes)
154
+ entity_classes = authenticator.relevant_entity_classes(self)
155
+ [*entity_classes, *relevant_entity_classes_from_inputs_transformer]
156
+ else
157
+ relevant_entity_classes_from_inputs_transformer
158
+ end
146
159
  end || EMPTY_ARRAY
147
160
  end
148
161
 
@@ -206,6 +206,7 @@ module Foobara
206
206
 
207
207
  self.authenticator = authenticator
208
208
  self.command_registry = CommandRegistry.new(authenticator:)
209
+
209
210
  self.capture_unknown_error = capture_unknown_error
210
211
  self.name = name
211
212
 
@@ -556,7 +557,7 @@ module Foobara
556
557
 
557
558
  def build_request(...)
558
559
  self.class::Request.new(...).tap do |request|
559
- # TODO: feels like a smell
560
+ # TODO: feels like a smell? Can we deprecate this somehow? Request no longer calls command_connector it seems...
560
561
  request.command_connector = self
561
562
  end
562
563
  end
@@ -566,6 +567,14 @@ module Foobara
566
567
  command_class = determine_command_class(request)
567
568
  request.command_class = command_class
568
569
 
570
+ if command_class.respond_to?(:requires_authentication) && command_class.requires_authentication
571
+ request.authenticator ||= command_class.authenticator || authenticator
572
+
573
+ if auth_map
574
+ request.auth_mappers ||= auth_map
575
+ end
576
+ end
577
+
569
578
  return build_response(request) unless command_class
570
579
 
571
580
  begin
@@ -540,7 +540,7 @@ module Foobara
540
540
  Value::Transformer.create(transform: transformer)
541
541
  else
542
542
  # :nocov:
543
- raise "Not sure how to apply #{inputs_transformer}"
543
+ raise "Not sure how to apply #{transformer}"
544
544
  # :nocov:
545
545
  end
546
546
  end
@@ -16,8 +16,12 @@ module Foobara
16
16
 
17
17
  def declaration_to_type(strict_type_declaration)
18
18
  # TODO: cache this on a #base_type= helper
19
- strict_type_declaration.type ||
20
- lookup_type(strict_type_declaration[:type], mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE)
19
+ type = strict_type_declaration.type
20
+ return type if type
21
+
22
+ type_symbol = strict_type_declaration[:type]
23
+
24
+ lookup_type(type_symbol, mode: Namespace::LookupMode::ABSOLUTE)
21
25
  end
22
26
  end
23
27
  end
@@ -9,7 +9,14 @@ module Foobara
9
9
 
10
10
  klass.to(to) if to
11
11
  klass.from(from) if from
12
- klass.define_method(:transform, &map_proc) if map_proc
12
+
13
+ if map_proc
14
+ if map_proc.arity.zero?
15
+ klass.define_method(:transform) { |_ignored| map_proc.call }
16
+ else
17
+ klass.define_method(:transform, &map_proc)
18
+ end
19
+ end
13
20
 
14
21
  klass
15
22
  end
@@ -11,6 +11,7 @@ module Foobara
11
11
 
12
12
  start = result.nil?
13
13
  result ||= Set.new
14
+
14
15
  return if result.include?(self)
15
16
 
16
17
  result << self
data/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Foobara
2
2
  module Version
3
- VERSION = "0.4.2".freeze
3
+ VERSION = "0.4.4".freeze
4
4
  MINIMUM_RUBY_VERSION = ">= 3.4.0".freeze
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi