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

fix for google sign in issue #1600

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

GMayank0310
Copy link
Contributor

@GMayank0310 GMayank0310 commented Nov 20, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced account deletion process to include removal of associated email confirmation records.
    • Improved trusted device management with checks for existing devices and email confirmation handling.
  • Bug Fixes

    • Updated error handling for adding trusted devices to improve user feedback.
  • Tests

    • Expanded tests for account deletion and trusted device addition to ensure proper handling of email confirmations and duplicate entries.

Copy link

coderabbitai bot commented Nov 20, 2024

Walkthrough

The changes involve modifications to the AccountProcessor class in kairon/shared/account/processor.py, enhancing account deletion and trusted device management functionalities. Key updates include the deletion of associated UserEmailConfirmation records during account deletion, validation checks for trusted device settings, and improved error handling in device management methods. Additionally, the test suite in tests/unit_test/api/api_processor_test.py has been updated to reflect these changes, ensuring that email confirmation handling and duplicate entry checks are properly tested.

Changes

File Path Change Summary
kairon/shared/account/processor.py - Updated delete_account to remove associated UserEmailConfirmation records.
- Modified get_location_and_add_trusted_device to check validate_trusted_device setting and handle exceptions.
- Adjusted add_trusted_device to prevent duplicate entries and generate confirmation links.
- Enhanced confirm_add_trusted_device for better error handling.
tests/unit_test/api/api_processor_test.py - Imported UserEmailConfirmation for email confirmation handling.
- Updated tests for delete_account to include the email parameter and check for UserEmailConfirmation removal.
- Expanded tests to ensure duplicate entry exceptions are raised for account and user additions.
tests/integration_test/services_test.py - Imported UserEmailConfirmation for email confirmation handling.
- Modified _password_reset function to create and save a UserEmailConfirmation instance during tests.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AccountProcessor
    participant UserEmailConfirmation

    User->>AccountProcessor: delete_account(account_id, email)
    AccountProcessor->>UserEmailConfirmation: delete associated record
    AccountProcessor-->>User: confirm deletion
Loading

🐰 "In the meadow, we hop with glee,
Deleting accounts, as swift as can be!
With emails gone, and devices in check,
Our code's now tidy, what the heck!
Hooray for changes, let's dance and play,
For a brighter, better coding day! 🥳"


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d8d5432 and 012e949.

📒 Files selected for processing (1)
  • tests/integration_test/services_test.py (2 hunks)
🔇 Additional comments (2)
tests/integration_test/services_test.py (2)

30-30: LGTM!

The import statement is properly placed and organized with related imports.


28595-28595: Verify the necessity of UserEmailConfirmation in password reset test

The addition of UserEmailConfirmation record in a password reset test scenario needs verification. While this might be related to the Google sign-in fix, please confirm if this is the correct location for this setup.

Let's check the relationship between password reset and email confirmation:


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 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

@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: 1

🧹 Outside diff range and nitpick comments (2)
tests/unit_test/api/api_processor_test.py (2)

483-484: Refactor repeated initialization of UserEmailConfirmation

The code initializing and saving UserEmailConfirmation with the account email is repeated across multiple test methods (test_delete_account_for_account_bots, test_delete_account_for_account, test_delete_account_for_user, test_delete_account_again_add). Consider refactoring this into a helper function to reduce code duplication and enhance maintainability.

Also applies to: 546-547, 572-573, 610-611


500-501: Refactor repeated assertions for UserEmailConfirmation deletion

The assertions checking for the non-existence of UserEmailConfirmation after account deletion are repeated in several tests. Refactoring these into a helper function can improve readability and maintainability.

Also applies to: 534-535, 561-562, 599-600, 624-625

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6d9901a and d8d5432.

📒 Files selected for processing (2)
  • kairon/shared/account/processor.py (1 hunks)
  • tests/unit_test/api/api_processor_test.py (9 hunks)
🔇 Additional comments (8)
tests/unit_test/api/api_processor_test.py (8)

31-32: Import UserEmailConfirmation for account deletion tests

The addition of UserEmailConfirmation to the import statement is appropriate, as it is used in subsequent tests to verify the deletion of email confirmations when an account is deleted.


500-501: Verify UserEmailConfirmation is deleted after account deletion

The test correctly asserts that the UserEmailConfirmation object no longer exists after the account is deleted, ensuring data integrity.


534-535: Ensure deletion of UserEmailConfirmation with shared account

Verifying that UserEmailConfirmation is deleted when a shared account is removed confirms consistent cleanup across different account types.


559-560: Proper exception handling when deleting a non-existent account

The test appropriately checks that attempting to delete an already deleted account raises an AppException with the message "Account does not exist!".


561-562: Confirm UserEmailConfirmation removal after account deletion

Asserting the non-existence of UserEmailConfirmation ensures that email confirmation records are properly cleaned up.


599-600: Validate UserEmailConfirmation is removed when deleting multiple users

The test verifies that UserEmailConfirmation objects for all users are deleted when the account is removed, ensuring complete data cleanup.


624-625: Check for deletion of UserEmailConfirmation after re-adding account

After recreating an account with the same email, confirming that old UserEmailConfirmation objects are not present maintains data consistency.


483-484: Handle potential None value for email

Ensure that the email retrieved from account.get('email') is not None before saving UserEmailConfirmation to prevent possible exceptions.

Comment on lines +1231 to +1232
UserEmailConfirmation.objects().get(email=email).delete()

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling and fix indentation for UserEmailConfirmation deletion

The deletion of UserEmailConfirmation records needs improvement:

  1. Add error handling for cases where the record doesn't exist
  2. Consider moving this operation earlier in the method for better cleanup order
  3. Fix the indentation to match the method's scope

Apply this diff to implement the suggested changes:

-        UserEmailConfirmation.objects().get(email=email).delete()
+        try:
+            UserEmailConfirmation.objects().get(email=email).delete()
+        except DoesNotExist:
+            logging.warning(f"No email confirmation record found for {email}")

Also, consider moving this block right after the account validation and before bot deletion for better cleanup order.

Committable suggestion skipped: line range outside the PR's diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant