standard_id 0.5.1 → 0.5.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: b1c16f53717e8c9b0d2bcf1095f2387c99b9bfeb9b1327d1b101e2ea140d3eaf
4
- data.tar.gz: 59d779aa3fe5a74f639f826505f9d21a845964b6edaedd085397d435241d5fa4
3
+ metadata.gz: 514c8e8c18bb9bf6d8bd0268cca374d477b2c276a3caf69b0ef58222b5b14b33
4
+ data.tar.gz: 8e9f2307f6fd2d6a99e78df4604f838c319a61487e0d1549df1712eaf683b639
5
5
  SHA512:
6
- metadata.gz: 4cef892853b6d5d87fe83919582b122e41d525cd20a938cd40444252a6cbf3470bca8aba08b8a6e7a04ed5b5eadc237410a2f03a475ad8b10941531dd7cbde8f
7
- data.tar.gz: 7d1c980a1be28688515573053cd91c28afd03119a8d8db41d72be8859d4472f8a3ccf50c5d005376ba8f5a91a2f5bb9f0fd27fd3ed75611682c68a8600db94fa
6
+ metadata.gz: 21fcdb6b8caaf652bdbe6cb86c52e7cf66480b5aae7bf9fab210dad86b9cb12626920190cd1743c138d8b3fc1608c2f921a3c18b79f0cdfe20407530fbcee596
7
+ data.tar.gz: 30dfa2dae9df664b4ff7bfdb972cbc3970bf8ac81fb185e8f6aca0676b4647903f20e60d0eaf5d531b3e3a1e4fcbaf923b1e05ee7f9f8fd6ca93461b0567e999
@@ -9,6 +9,19 @@ module StandardId
9
9
  # Safe to include even when the Sentry gem is not installed -- the
10
10
  # callback is a no-op if `Sentry` is not defined.
11
11
  #
12
+ # Extra fields can be added via the `sentry_context` config option:
13
+ #
14
+ # StandardId.configure do |c|
15
+ # c.sentry_context = ->(account, session) {
16
+ # { email: account.email, username: account.try(:display_name) }
17
+ # }
18
+ # end
19
+ #
20
+ # The lambda must return a Hash (nil and non-Hash returns are ignored).
21
+ # Base keys (id, session_id) always take precedence and cannot be
22
+ # overridden by the lambda. Exceptions raised by the lambda are not
23
+ # caught — they will propagate to surface misconfiguration immediately.
24
+ #
12
25
  # @example
13
26
  # class ApplicationController < ActionController::Base
14
27
  # include StandardId::WebAuthentication
@@ -27,12 +40,20 @@ module StandardId
27
40
  return unless defined?(Sentry)
28
41
  return unless respond_to?(:current_account, true) && current_account.present?
29
42
 
30
- context = { id: current_account.id }
31
- if respond_to?(:current_session, true) && current_session.present? && current_session.respond_to?(:id)
32
- context[:session_id] = current_session.id
43
+ session_value = current_session.presence if respond_to?(:current_session, true)
44
+
45
+ base = { id: current_account.id }
46
+ base[:session_id] = session_value.id if session_value&.respond_to?(:id)
47
+
48
+ extra = StandardId.config.sentry_context
49
+ if extra.respond_to?(:call)
50
+ result = extra.call(current_account, session_value)
51
+ # Merge lambda result underneath base keys so id/session_id cannot
52
+ # be accidentally overridden by the host app's lambda.
53
+ base = result.merge(base) if result.is_a?(Hash)
33
54
  end
34
55
 
35
- Sentry.set_user(context)
56
+ Sentry.set_user(base)
36
57
  end
37
58
  end
38
59
  end
@@ -146,12 +146,19 @@ module StandardId
146
146
  # framework: for known frameworks)
147
147
  def skip_authorization_callback(controller, callback, framework)
148
148
  if (class_method = CLASS_METHOD_SKIP[framework])
149
- # Engine API controllers inherit from ActionController::API, not the
150
- # host app's ApplicationController, so they won't include ActionPolicy.
151
- # A controller without ActionPolicy can never have verify_authorized in
152
- # its callback chain, so skipping the call is safe — not a silent failure.
153
- # This mirrors the `raise: false` intent of the other branches.
154
- controller.public_send(class_method) if controller.respond_to?(class_method)
149
+ # Engine controllers may inherit the skip class method (e.g.
150
+ # skip_verify_authorized from ActionPolicy) via the host app's
151
+ # ApplicationController without having called verify_authorized
152
+ # themselves. Rails raises ArgumentError when trying to skip a
153
+ # callback that was never registered. We match on the message to
154
+ # avoid masking unrelated ArgumentErrors.
155
+ begin
156
+ controller.public_send(class_method) if controller.respond_to?(class_method)
157
+ rescue ArgumentError => e
158
+ raise unless e.message.include?(":#{callback} has not been defined")
159
+
160
+ Rails.logger.debug { "[StandardId] Skipped #{class_method} on #{controller.name}: #{e.message}" }
161
+ end
155
162
  elsif AFTER_ACTION_FRAMEWORKS.include?(framework)
156
163
  controller.skip_after_action callback, raise: false
157
164
  else
@@ -18,6 +18,9 @@ StandardConfig.schema.draw do
18
18
  field :use_inertia, type: :boolean, default: false
19
19
  field :inertia_component_namespace, type: :string, default: "standard_id"
20
20
  field :alias_current_user, type: :boolean, default: false
21
+ # Callable (lambda/proc) that returns a Hash of extra Sentry user context fields.
22
+ # Receives (account, session) where session may be nil. Non-callable values are ignored.
23
+ field :sentry_context, type: :any, default: nil
21
24
  end
22
25
 
23
26
  scope :events do
@@ -1,3 +1,3 @@
1
1
  module StandardId
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaryl Sim