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

[#11878] Update ResetAccountRequest to reference by ID #13002

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ public void testResetAccountRequest()

toReset.setRegisteredAt(Instant.now());
toReset = accountRequestsDb.getAccountRequest(email, institute);
UUID id = toReset.getId();

assertNotNull(toReset);
assertNotNull(toReset.getRegisteredAt());

______TS("success: reset account request that already exists");

AccountRequest resetted = accountRequestsLogic.resetAccountRequest(email, institute);
AccountRequest resetted = accountRequestsLogic.resetAccountRequest(id);

assertNull(resetted.getRegisteredAt());

Expand All @@ -74,6 +75,6 @@ public void testResetAccountRequest()
______TS("failure: reset account request that does not exist");

assertThrows(EntityDoesNotExistException.class,
() -> accountRequestsLogic.resetAccountRequest(name, institute));
() -> accountRequestsLogic.resetAccountRequest(id));
}
}
8 changes: 4 additions & 4 deletions src/main/java/teammates/sqllogic/api/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ public AccountRequest updateAccountRequestWithTransaction(AccountRequest account
}

/**
* Creates/Resets the account request with the given email and institute
* Creates/Resets the account request with the given id
* such that it is not registered.
*
* @return account request that is unregistered with the
* email and institute.
* id.
*/
public AccountRequest resetAccountRequest(String email, String institute)
public AccountRequest resetAccountRequest(UUID id)
throws EntityDoesNotExistException, InvalidParametersException {
return accountRequestLogic.resetAccountRequest(email, institute);
return accountRequestLogic.resetAccountRequest(id);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ public List<AccountRequest> getAllAccountRequests() {
}

/**
* Creates/resets the account request with the given email and institute such that it is not registered.
* Creates/resets the account request with the given id such that it is not registered.
*/
public AccountRequest resetAccountRequest(String email, String institute)
public AccountRequest resetAccountRequest(UUID id)
throws EntityDoesNotExistException, InvalidParametersException {
AccountRequest accountRequest = accountRequestDb.getAccountRequest(email, institute);
AccountRequest accountRequest = accountRequestDb.getAccountRequest(id);

if (accountRequest == null) {
throw new EntityDoesNotExistException("Failed to reset since AccountRequest with "
+ "the given email and institute cannot be found.");
+ "the given id cannot be found.");
}
accountRequest.setRegisteredAt(null);

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/teammates/ui/webapi/ResetAccountRequestAction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package teammates.ui.webapi;

import java.util.UUID;

import org.apache.http.HttpStatus;

import teammates.common.exception.EntityDoesNotExistException;
Expand All @@ -19,21 +21,19 @@ class ResetAccountRequestAction extends AdminOnlyAction {

@Override
public JsonResult execute() throws InvalidOperationException {
String instructorEmail = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_EMAIL);
String institute = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_INSTITUTION);
UUID id = getUuidRequestParamValue(Const.ParamsNames.ACCOUNT_REQUEST_ID);

AccountRequest accountRequest = sqlLogic.getAccountRequest(instructorEmail, institute);
AccountRequest accountRequest = sqlLogic.getAccountRequest(id);

if (accountRequest == null) {
throw new EntityNotFoundException("Account request for instructor with email: " + instructorEmail
+ " and institute: " + institute + " does not exist.");
throw new EntityNotFoundException("Account request with id: " + id.toString() + " does not exist.");
}
if (accountRequest.getRegisteredAt() == null) {
throw new InvalidOperationException("Unable to reset account request as instructor is still unregistered.");
}

try {
accountRequest = sqlLogic.resetAccountRequest(instructorEmail, institute);
accountRequest = sqlLogic.resetAccountRequest(id);
} catch (InvalidParametersException | EntityDoesNotExistException ue) {
// InvalidParametersException and EntityDoesNotExistException should not be thrown as
// validity of params has been verified when fetching entity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class AccountRequestTableComponent {
`Reset account request for <strong>${accountRequest.name}</strong>?`, SimpleModalType.WARNING, modalContent);

modalRef.result.then(() => {
this.accountService.resetAccountRequest(accountRequest.email, accountRequest.instituteAndCountry)
this.accountService.resetAccountRequest(accountRequest.id)
.subscribe({
next: () => {
this.statusMessageService
Expand Down
5 changes: 2 additions & 3 deletions src/web/services/account.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ describe('AccountService', () => {
});

it('should execute PUT on account request reset endpoint', () => {
service.resetAccountRequest('testEmail', 'testInstitution');
service.resetAccountRequest('testId');
const paramMap: Record<string, string> = {
instructoremail: 'testEmail',
instructorinstitution: 'testInstitution',
id: 'testId',
};
expect(spyHttpRequestService.put).toHaveBeenCalledWith(ResourceEndpoints.ACCOUNT_REQUEST_RESET, paramMap);
});
Expand Down
5 changes: 2 additions & 3 deletions src/web/services/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ export class AccountService {
/**
* Resets an account request by calling API.
*/
resetAccountRequest(email: string, institute: string): Observable<JoinLink> {
resetAccountRequest(id: string): Observable<JoinLink> {
const paramMap: Record<string, string> = {
instructoremail: email,
instructorinstitution: institute,
id,
};
return this.httpRequestService.put(ResourceEndpoints.ACCOUNT_REQUEST_RESET, paramMap);
}
Expand Down
Loading