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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 514c8e8c18bb9bf6d8bd0268cca374d477b2c276a3caf69b0ef58222b5b14b33
|
|
4
|
+
data.tar.gz: 8e9f2307f6fd2d6a99e78df4604f838c319a61487e0d1549df1712eaf683b639
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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(
|
|
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
|
|
150
|
-
#
|
|
151
|
-
#
|
|
152
|
-
#
|
|
153
|
-
#
|
|
154
|
-
|
|
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
|
data/lib/standard_id/version.rb
CHANGED