-
-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log usage of legacy identities #5893
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,6 +235,8 @@ def find_identity_by_uid | |
identity = Identity.joins(:user).find_by(user: { first_name: auth_hash.info.first_name, last_name: auth_hash.info.last_name }, provider: provider, identifier_based_on_email: true) if identity.nil? | ||
return nil if identity.nil? | ||
|
||
Event.new(event_type: :other, message: 'Office365 user signed in with legacy identifier').save! | ||
|
||
# Update the identifier to the new uid | ||
identity.update(identifier: auth_uid, identifier_based_on_email: false) | ||
elsif provider.class.sym == :smartschool && auth_username.present? | ||
|
@@ -249,6 +251,8 @@ def find_identity_by_uid | |
identity = Identity.joins(:user).find_by(user: { first_name: auth_hash.info.first_name, last_name: auth_hash.info.last_name }, provider: provider, identifier_based_on_username: true) if identity.nil? | ||
return nil if identity.nil? | ||
|
||
Event.new(event_type: :other, message: 'Smartschool user signed in with legacy identifier').save! | ||
|
||
Comment on lines
+254
to
+255
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Extract duplicated legacy provider logging logic. The logging code is duplicated between Office365 and Smartschool providers. This should be extracted into a reusable method. Consider extracting the logging logic: + def log_legacy_identifier_usage(identity, provider_name)
+ Event.create!(
+ event_type: :legacy_provider_usage,
+ message: "User #{identity.user.email} signed in with #{provider_name} legacy identifier",
+ data: {
+ provider: provider_name.downcase,
+ legacy_identifier: identity.identifier,
+ new_identifier: auth_uid,
+ user_id: identity.user_id
+ }
+ )
+ end
def find_identity_by_uid
# ... existing code ...
if provider.class.sym == :office365 && auth_email.present?
# ... existing code ...
return nil if identity.nil?
- Event.new(event_type: :other, message: 'Office365 user signed in with legacy identifier').save!
+ log_legacy_identifier_usage(identity, 'Office365')
# ... existing code ...
elsif provider.class.sym == :smartschool && auth_username.present?
# ... existing code ...
return nil if identity.nil?
- Event.new(event_type: :other, message: 'Smartschool user signed in with legacy identifier').save!
+ log_legacy_identifier_usage(identity, 'Smartschool')
# ... existing code ...
end
identity
end
|
||
# Update the identifier to the new uid | ||
identity.update(identifier: auth_uid, identifier_based_on_username: false) | ||
end | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,7 +11,7 @@ | |||||
# | ||||||
|
||||||
class Event < ApplicationRecord | ||||||
enum :event_type, { rejudge: 0, permission_change: 1, exercise_repository: 2, error: 3 } | ||||||
enum :event_type, { rejudge: 0, permission_change: 1, exercise_repository: 2, error: 3, other: 4 } | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using a more specific event type for legacy provider logging. Using 'other' as the event type for legacy provider usage might make it difficult to track and analyze this specific use case. Consider adding a more descriptive event type like 'legacy_provider_usage' to make the intention clear and facilitate easier querying. Apply this diff: - enum :event_type, { rejudge: 0, permission_change: 1, exercise_repository: 2, error: 3, other: 4 }
+ enum :event_type, { rejudge: 0, permission_change: 1, exercise_repository: 2, error: 3, legacy_provider_usage: 4 } 📝 Committable suggestion
Suggested change
|
||||||
belongs_to :user, optional: true | ||||||
|
||||||
validates :event_type, presence: true | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,6 +175,7 @@ en: | |
permission_change: Change in permission level | ||
exercise_repository: Creation of exercise repository | ||
error: Error | ||
other: Other | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using specific event types instead of "other" for tracking legacy providers. The addition of a generic "other" event type may not align well with the PR's objective of tracking legacy sign-in method usage. To effectively monitor which providers remain unused for a month (as mentioned in PR #5791), consider using specific event types for each legacy provider instead. Replace the generic "other" with specific provider event types: - other: Other
+ legacy_saml_signin: "Legacy SAML Sign-in"
+ legacy_office365_signin: "Legacy Office 365 Sign-in"
+ legacy_smartschool_signin: "Legacy Smartschool Sign-in"
+ legacy_google_signin: "Legacy Google Sign-in"
|
||
export: | ||
statuses: | ||
started: Started | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Enhance logging for Office365 legacy identifier usage.
The current logging implementation could be improved in several ways:
:other
Consider this implementation:
📝 Committable suggestion