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

General: Allow users to login with their email address #9181

Merged
merged 5 commits into from
Aug 11, 2024

Conversation

krusche
Copy link
Member

@krusche krusche commented Aug 3, 2024

Checklist

General

Server

  • Important: I implemented the changes with a very good performance and prevented too many (unnecessary) database calls.
  • I strictly followed the server coding and design guidelines.
  • I documented the Java code using JavaDoc style.

Motivation and Context

  • Improve usability during login
  • Sync data during login to reflect changes
  • Note: This PR right now only adds the required server changes, client changes will be added in a follow-up PR (in particular changing the warning for TUM users), also server tests will be added in a follow-up

Steps for Testing

  1. Log in with your username, primary email and a few secondary email addresses of TUM
  2. Make sure the login works, but does not work with any wrong data

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Performance Review

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced user authentication by allowing login via both usernames and email addresses.
    • Introduced new methods for user retrieval based on email and user groups.
    • Added email validation functionality.
  • Bug Fixes

    • Improved handling of user identification to prevent duplicate entries in the database.
  • Refactor

    • Updated method names and parameters to align terminology from "username" to "login" and improved code clarity.
    • Optimized user detail saving process to enhance database efficiency.
  • Tests

    • Updated integration tests to reflect changes in method names and improve accuracy in user identification.

@github-actions github-actions bot added tests server Pull requests that update Java code. (Added Automatically!) labels Aug 3, 2024
@krusche krusche added this to the 7.5.0 milestone Aug 4, 2024
@krusche krusche marked this pull request as ready for review August 11, 2024 08:06
@krusche krusche requested a review from a team as a code owner August 11, 2024 08:06
Copy link

coderabbitai bot commented Aug 11, 2024

Walkthrough

The recent changes enhance user authentication processes by allowing identification through both login names and email addresses. Key updates include introducing a regex pattern for email validation, refining user retrieval methods in repositories, and standardizing terminology from "username" to "login." These modifications prioritize clarity, flexibility, and extensibility in user management, improving how user data is handled across the application.

Changes

Files Change Summary
src/main/java/de/tum/in/www1/artemis/config/Constants.java Added SIMPLE_EMAIL_REGEX for email validation; renamed TUM_LDAP_EMAIL to TUM_LDAP_MAIN_EMAIL; added TUM_LDAP_EMAILS for multiple email handling.
src/main/java/de/tum/in/www1/artemis/repository/UserRepository.java Removed findOneWithAuthoritiesByLogin; added findOneWithGroupsAndAuthoritiesByEmailAndIsInternal for comprehensive user retrieval.
src/main/java/de/tum/in/www1/artemis/security/DomainUserDetailsService.java Modified loadUserByUsername to accept loginOrEmail, enhancing flexibility for user authentication.
src/main/java/de/tum/in/www1/artemis/security/SecurityUtils.java Introduced isEmail method for validating email addresses.
src/main/java/de/tum/in/www1/artemis/service/connectors/ldap/LdapAuthenticationProvider.java Enhanced getOrCreateUser to differentiate between login and email inputs, improving user identification and preventing duplicates.
src/main/java/de/tum/in/www1/artemis/service/connectors/lti/LtiService.java Renamed parameter username to login in createNewUserFromLaunchRequest, aligning with internal logic.
src/main/java/de/tum/in/www1/artemis/service/ldap/LdapUserDto.java Renamed username field to login and updated email handling constants for clarity.
src/main/java/de/tum/in/www1/artemis/service/ldap/LdapUserService.java Renamed methods: findByUsername to findByLogin and findByEmail to findByMainEmail; added findByAnyEmail.
src/main/java/de/tum/in/www1/artemis/service/user/UserService.java Updated method parameters from "username" to "login" and "email" to "anyEmail" in various methods for consistency.
src/test/java/de/tum/in/www1/artemis/authentication/LdapAuthenticationIntegrationTest.java Renamed constants and variables from "USERNAME" to "LOGIN" for consistency in tests.
src/test/java/de/tum/in/www1/artemis/exam/ExamRegistrationIntegrationTest.java Updated test methods to use new user retrieval functions based on login and any email.
src/test/java/de/tum/in/www1/artemis/localvcci/LocalVCIntegrationTest.java Modified method calls in tests to replace findByUsername with findByLogin.
src/test/java/de/tum/in/www1/artemis/service/CourseServiceTest.java Updated mock method calls to reflect changes in user identification methods related to login and any email.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LdapAuthenticationProvider
    participant UserRepository

    User->>LdapAuthenticationProvider: Login/Email input
    LdapAuthenticationProvider->>User: Validate input type (login or email)
    alt Email
        LdapAuthenticationProvider->>UserRepository: findOneWithGroupsAndAuthoritiesByEmail
    else Login
        LdapAuthenticationProvider->>UserRepository: findOneWithGroupsAndAuthoritiesByLogin
    end
    UserRepository-->>LdapAuthenticationProvider: User details
    LdapAuthenticationProvider-->>User: Authentication result
Loading

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

Copy link

⚠️ Unable to deploy to test servers ⚠️

The docker build needs to run through before deploying.

@github-actions github-actions bot added the deployment-error Added by deployment workflows if an error occured label Aug 11, 2024
@JohannesStoehr JohannesStoehr added deploy:artemis-test1 and removed deployment-error Added by deployment workflows if an error occured labels Aug 11, 2024
@JohannesStoehr JohannesStoehr temporarily deployed to artemis-test1.artemis.cit.tum.de August 11, 2024 08:15 — with GitHub Actions Inactive
Copy link
Contributor

@JohannesStoehr JohannesStoehr left a comment

Choose a reason for hiding this comment

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

Login works for me, but we need to make a small adjustment to the UI:
Bildschirmfoto 2024-08-11 um 10 18 40

Additonaly left one inline comment:

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 11, 2024
@krusche
Copy link
Member Author

krusche commented Aug 11, 2024

Login works for me, but we need to make a small adjustment to the UI: Bildschirmfoto 2024-08-11 um 10 18 40

Additonaly left one inline comment:

This will be done in a follow-up PR.

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

Copy link
Contributor

@az108 az108 left a comment

Choose a reason for hiding this comment

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

Tested on TS1 again with my different tum emails after redeployment right now and works as expected. Code also looks good to me after the small changes now 👍

Copy link
Contributor

@pzdr7 pzdr7 left a comment

Choose a reason for hiding this comment

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

Tested on TS1.

  • Sign in with login ✅
  • Sign in with primary email ✅
  • Sign in with secondary emails (tried mytum and matlab.rbg) ✅

Test user

  • Sign in with email ✅
  • Sign in with login ✅

UI changes will be done in a follow-up -> we should change "Username" accordingly in that follow-up as well

image

Copy link
Contributor

@JohannesStoehr JohannesStoehr left a comment

Choose a reason for hiding this comment

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

Tested on TS1 and looked at the code 👍

Copy link
Member

@julian-christl julian-christl left a comment

Choose a reason for hiding this comment

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

Looks good.

  • Client changes are out of scope
  • As mentioned, I'd suggest searching for username and email in one go. @krusche prefers to do this in a follow-up as complications with the current implementation would only arise through a rare edge-case
  • Two comments (one code improvement, one TODO), both can be resolved in a follow-up if you want.

@krusche krusche merged commit 5011de0 into develop Aug 11, 2024
34 of 37 checks passed
@krusche krusche deleted the feature/enable-login-via-email branch August 11, 2024 20:47
@krusche krusche mentioned this pull request Sep 2, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review ready to merge server Pull requests that update Java code. (Added Automatically!) tests
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants