Skip to content

Conversation

@Luoq1-Xu
Copy link

Fixes #13119

Cause
Previously, admins could not approve an account request if any account with the same email existed, including student accounts. This was due to the UpdateAccountRequestAction class calling the getAccountsForEmailWithTransactionmethod from sqlLogic, which gets all accounts (regardless of if those were student-only or instructor accounts) linked to a particular email. This was too restrictive, as only instructor accounts in the same institute should block approval.

Outline of Solution

  • The approval logic now only prevents approval if there is an existing instructor account with the same email in the same institute as the account request.
  • Introduced a new method isInstructorWithEmailInInstitute(email, institute) into the Logic class, which searches for instructors with the given email and verifies if it belongs to any course under the specified institute.
  • Admins can now approve instructor account requests even if a student account with the same email exists, as long as there is no conflicting instructor account in the same institute.

Luoq1-Xu added 8 commits July 13, 2025 20:12
Previously, admin could not approve an account request if any account
with the same email existed, including student accounts. This was too
restrictive, as only instructor accounts in the same institute should
block approval.

This commit updates the approval logic to only prevent approval if there
is an existing instructor account with the same email in the same
institute as the account request. The check now uses
`logic.isInstructorWithEmailInInstitute(email, institute)`, which
searches for instructors with the given email and verifies if any belong
to a course under the specified institute.

This allows admins to approve instructor account requests even if a
student account with the same email exists, as long as there is no
conflicting instructor account in the same institute.
- Add getInstructorsForEmail method in InstructorsDb to retrieve all
instructors with a specific email address.
- Add corresponding forwarding method in Logic.
- Refactor InstructorsLogic.isExistingInstructorWithEmailInInstitute to
use getInstructorsForEmail instead of searchInstructorsInWholeSystem,
reducing dependency on search service.
- Update error message in UpdateAccountRequestAction to clarify
duplicate instructor account condition.
- Update UpdateAccountRequestActionIT test
- Fix checkstyle errors
- Update the error message in UpdateAccountRequestAction and related
tests to be more descriptive, mentioning that an instructor account
with the same email under the same institute already exists.
Adding a trivial comment to trigger a new CI workflow run. This is to
re-verify the failing integration test (Job ID: 46799151757).
@damithc damithc requested a review from Copilot July 31, 2025 13:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where admins couldn't create instructor accounts when a student account already existed with the same email address. The solution refines the validation logic to only prevent instructor account creation when there's an existing instructor account with the same email in the same institute, rather than blocking for any account type.

  • Replaced broad email conflict check with institute-specific instructor validation
  • Added new methods to check for existing instructors by email within a specific institute
  • Updated error messaging to be more specific about the conflict type

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
UpdateAccountRequestAction.java Updated approval logic to check for instructor conflicts only within the same institute
InstructorsDb.java Added database layer method to retrieve instructors by email
InstructorsLogic.java Added business logic to check for existing instructors by email in a specific institute
Logic.java Added public API method for instructor existence validation
UpdateAccountRequestActionIT.java Updated integration tests to verify the new behavior and error messages

Comment on lines 447 to 448
if (instructor.getEmail().equals(email)
&& institute.equals(coursesLogic.getCourseInstitute(instructor.getCourseId()))) {
Copy link

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

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

The email comparison instructor.getEmail().equals(email) is redundant since getInstructorsForEmail(email) already filters by email. This condition will always be true and should be removed.

Suggested change
if (instructor.getEmail().equals(email)
&& institute.equals(coursesLogic.getCourseInstitute(instructor.getCourseId()))) {
if (institute.equals(coursesLogic.getCourseInstitute(instructor.getCourseId()))) {

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please take a look at this copilot suggestion.


/**
* Checks if there is an existing instructor with the given email
* in any course under that belongs to the specified institute.
Copy link

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

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

Grammar error in the comment: 'under that belongs to' should be 'that belongs to'.

Suggested change
* in any course under that belongs to the specified institute.
* in any course that belongs to the specified institute.

Copilot uses AI. Check for mistakes.

/**
* Returns the typical course attributes.
* This is a placeholder method because getTypicalCourse is not compatible, using the newer sql
Copy link

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

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

Grammar error in the comment: 'using the newer sql' should be 'as it uses the newer SQL'.

Suggested change
* This is a placeholder method because getTypicalCourse is not compatible, using the newer sql
* This is a placeholder method because getTypicalCourse is not compatible, as it uses the newer SQL

Copilot uses AI. Check for mistakes.
@damithc damithc requested review from DhiraPT and mingyang143 July 31, 2025 13:39
Copy link
Contributor

@DhiraPT DhiraPT left a comment

Choose a reason for hiding this comment

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

Thank you for the PR. The code changes look correct, minimal, and aligned with architecture and business rules. However, the PR currently lacks an integration test that specifically reproduces the original bug (student → instructor email reuse) to prove the fix. Adding that test is critical to ensure the fix addresses issue #13119 and to prevent regressions. Please add this test to UpdateAccountRequestActionIT.

* Checks if there is an existing instructor with the given email
* in any course under that belongs to the specified institute.
*/
public boolean isExistingInstructorWithEmailInInstitute(String email, String institute) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps you could standardize isExistingInstructorWithEmailInInstitute and isInstructorWithEmailInInstitute to existsInstructorWithEmailInInstitute.

Comment on lines 447 to 448
if (instructor.getEmail().equals(email)
&& institute.equals(coursesLogic.getCourseInstitute(instructor.getCourseId()))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please take a look at this copilot suggestion.

- standardized isExistingInstructorWithEmailInInstitute and
isInstructorWithEmailInInstitute to existsInstructorWithEmailInInstitute
for better clarity
- fixed a few grammatical issues in comments
@Luoq1-Xu
Copy link
Author

Hi @DhiraPT, thanks for getting back! I have made the changes and added the relevant integration test to UpdateAccountRequestActionIT.

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.

Admin: Unable to create an instructor account if the same email was used for a student account

2 participants