Skip to content
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

Also log user when legacy sign in methods are used #5995

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

jorg-vr
Copy link
Contributor

@jorg-vr jorg-vr commented Dec 10, 2024

This pull request adds the user to events.

In order to decide if we can get rid of the legacy sign in methods I wanted to see which accounts have been unused for more then 2 years and are picked up again. (Also to verify what the impact would be if we had given them a new account instead).

See https://dodona.be/en/events/?event_type=other

@jorg-vr jorg-vr added the chore Repository/build/dependency maintenance label Dec 10, 2024
@jorg-vr jorg-vr self-assigned this Dec 10, 2024
@jorg-vr jorg-vr requested a review from bmesuere as a code owner December 10, 2024 12:17
Copy link
Contributor

coderabbitai bot commented Dec 10, 2024

Walkthrough

The changes in this pull request enhance the logging functionality within the Auth::OmniauthCallbacksController class, specifically in the find_identity_by_uid method. The modifications ensure that when creating Event instances during user sign-ins for Office365 and Smartschool with legacy identifiers, the associated user object is included. This provides additional context for logged events without altering other methods or the overall control flow.

Changes

File Path Change Summary
app/controllers/auth/omniauth_callbacks_controller.rb Updated find_identity_by_uid method to include user object in Event creation for logging.

Possibly related PRs

  • Log usage of legacy identities #5893: The changes in this PR also modify the find_identity_by_uid method in the Auth::OmniauthCallbacksController class to enhance logging for legacy sign-in methods, directly relating to the logging functionality improvements in the main PR.

Suggested reviewers

  • bmesuere

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
app/controllers/auth/omniauth_callbacks_controller.rb (1)

254-254: LGTM: Event logging for Smartschool legacy sign-in is well implemented.

The event logging is correctly placed to capture Smartschool users signing in with legacy identifiers, and properly includes the user information for tracking purposes.

Consider extracting the event logging into a private method to reduce code duplication:

  def find_identity_by_uid
    # ... existing code ...

    if provider.class.sym == :office365 && auth_email.present?
      # ... existing identity lookup code ...
      return nil if identity.nil?

-     Event.new(event_type: :other, message: 'Office365 user signed in with legacy identifier', user: identity.user).save!
+     log_legacy_signin!(identity, 'Office365')

      # 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?
      # ... existing identity lookup code ...
      return nil if identity.nil?

-     Event.new(event_type: :other, message: 'Smartschool user signed in with legacy identifier', user: identity.user).save!
+     log_legacy_signin!(identity, 'Smartschool')

      # Update the identifier to the new uid
      identity.update(identifier: auth_uid, identifier_based_on_username: false)
    end
    identity
  end

+ private
+
+ def log_legacy_signin!(identity, provider_name)
+   Event.new(
+     event_type: :other,
+     message: "#{provider_name} user signed in with legacy identifier",
+     user: identity.user
+   ).save!
+ end
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7909495 and 80a20c0.

📒 Files selected for processing (1)
  • app/controllers/auth/omniauth_callbacks_controller.rb (2 hunks)
🔇 Additional comments (1)
app/controllers/auth/omniauth_callbacks_controller.rb (1)

238-238: LGTM: Event logging for Office365 legacy sign-in is well implemented.

The event logging is correctly placed to capture Office365 users signing in with legacy identifiers, and properly includes the user information for tracking purposes.

@jorg-vr jorg-vr merged commit d28dffe into main Dec 10, 2024
16 checks passed
@jorg-vr jorg-vr deleted the chore/improve-sign-in-logging branch December 10, 2024 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Repository/build/dependency maintenance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants