From 6de9607e48ecd10b38c87d1b1f42aaa2379d9440 Mon Sep 17 00:00:00 2001 From: DS Date: Thu, 11 Apr 2024 19:40:57 +0800 Subject: [PATCH] [#11878] Update DeleteAccountRequest to reference by ID (#12997) * Update to delete by id * fix lint * fix lint * fix frontend lint --- .../java/teammates/e2e/cases/AdminHomePageE2ETest.java | 3 ++- .../java/teammates/e2e/cases/AdminSearchPageE2ETest.java | 2 +- .../it/sqllogic/core/AccountRequestsLogicIT.java | 4 ++-- .../it/ui/webapi/CreateAccountRequestActionIT.java | 2 +- .../it/ui/webapi/UpdateAccountRequestActionIT.java | 2 +- src/main/java/teammates/sqllogic/api/Logic.java | 6 +++--- .../teammates/sqllogic/core/AccountRequestsLogic.java | 8 ++++---- .../java/teammates/sqllogic/core/DataBundleLogic.java | 2 +- .../teammates/ui/webapi/DeleteAccountRequestAction.java | 9 +++++---- src/test/java/teammates/test/AbstractBackDoor.java | 5 ++--- .../account-request-table.component.ts | 2 +- src/web/services/account.service.spec.ts | 5 ++--- src/web/services/account.service.ts | 5 ++--- 13 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/e2e/java/teammates/e2e/cases/AdminHomePageE2ETest.java b/src/e2e/java/teammates/e2e/cases/AdminHomePageE2ETest.java index 56953689329..820acf5bb9b 100644 --- a/src/e2e/java/teammates/e2e/cases/AdminHomePageE2ETest.java +++ b/src/e2e/java/teammates/e2e/cases/AdminHomePageE2ETest.java @@ -48,7 +48,8 @@ public void testAll() { "\"invalidemail\" is not acceptable to TEAMMATES as a/an email because it is not in the correct format.")); assertNotNull(BACKDOOR.getAccountRequest(email, institute)); - BACKDOOR.deleteAccountRequest(email, institute); + // TODO: delete account request after get + // BACKDOOR.deleteAccountRequest(email, institute); } } diff --git a/src/e2e/java/teammates/e2e/cases/AdminSearchPageE2ETest.java b/src/e2e/java/teammates/e2e/cases/AdminSearchPageE2ETest.java index b5ce80693f0..09071e74770 100644 --- a/src/e2e/java/teammates/e2e/cases/AdminSearchPageE2ETest.java +++ b/src/e2e/java/teammates/e2e/cases/AdminSearchPageE2ETest.java @@ -193,7 +193,7 @@ private String getExpectedInstructorManageAccountLink(InstructorAttributes instr @AfterClass public void classTeardown() { for (AccountRequest request : sqlTestData.accountRequests.values()) { - BACKDOOR.deleteAccountRequest(request.getEmail(), request.getInstitute()); + BACKDOOR.deleteAccountRequest(request.getId()); } } diff --git a/src/it/java/teammates/it/sqllogic/core/AccountRequestsLogicIT.java b/src/it/java/teammates/it/sqllogic/core/AccountRequestsLogicIT.java index 566c967a7e7..4156e4f1ca9 100644 --- a/src/it/java/teammates/it/sqllogic/core/AccountRequestsLogicIT.java +++ b/src/it/java/teammates/it/sqllogic/core/AccountRequestsLogicIT.java @@ -67,9 +67,9 @@ public void testResetAccountRequest() ______TS("success: test delete account request"); - accountRequestsLogic.deleteAccountRequest(email, institute); + accountRequestsLogic.deleteAccountRequest(toReset.getId()); - assertNull(accountRequestsLogic.getAccountRequest(email, institute)); + assertNull(accountRequestsLogic.getAccountRequest(toReset.getId())); ______TS("failure: reset account request that does not exist"); diff --git a/src/it/java/teammates/it/ui/webapi/CreateAccountRequestActionIT.java b/src/it/java/teammates/it/ui/webapi/CreateAccountRequestActionIT.java index 85449452b5f..a4a680c4839 100644 --- a/src/it/java/teammates/it/ui/webapi/CreateAccountRequestActionIT.java +++ b/src/it/java/teammates/it/ui/webapi/CreateAccountRequestActionIT.java @@ -230,7 +230,7 @@ protected void tearDown() { HibernateUtil.beginTransaction(); List accountRequests = logic.getPendingAccountRequests(); for (AccountRequest ar : accountRequests) { - logic.deleteAccountRequest(ar.getEmail(), ar.getInstitute()); + logic.deleteAccountRequest(ar.getId()); } accountRequests = logic.getPendingAccountRequests(); HibernateUtil.commitTransaction(); diff --git a/src/it/java/teammates/it/ui/webapi/UpdateAccountRequestActionIT.java b/src/it/java/teammates/it/ui/webapi/UpdateAccountRequestActionIT.java index 45ad945c673..3d038daa8a3 100644 --- a/src/it/java/teammates/it/ui/webapi/UpdateAccountRequestActionIT.java +++ b/src/it/java/teammates/it/ui/webapi/UpdateAccountRequestActionIT.java @@ -227,7 +227,7 @@ protected void tearDown() { HibernateUtil.beginTransaction(); List accountRequests = logic.getAllAccountRequests(); for (AccountRequest ar : accountRequests) { - logic.deleteAccountRequest(ar.getEmail(), ar.getInstitute()); + logic.deleteAccountRequest(ar.getId()); } HibernateUtil.commitTransaction(); } diff --git a/src/main/java/teammates/sqllogic/api/Logic.java b/src/main/java/teammates/sqllogic/api/Logic.java index c840ef2834c..72712057143 100644 --- a/src/main/java/teammates/sqllogic/api/Logic.java +++ b/src/main/java/teammates/sqllogic/api/Logic.java @@ -177,7 +177,7 @@ public AccountRequest resetAccountRequest(String email, String institute) } /** - * Deletes account request by email and institute. + * Deletes account request by id. * *
    *
  • Fails silently if no such account request.
  • @@ -186,8 +186,8 @@ public AccountRequest resetAccountRequest(String email, String institute) *

    Preconditions:

    * All parameters are non-null. */ - public void deleteAccountRequest(String email, String institute) { - accountRequestLogic.deleteAccountRequest(email, institute); + public void deleteAccountRequest(UUID id) { + accountRequestLogic.deleteAccountRequest(id); } /** diff --git a/src/main/java/teammates/sqllogic/core/AccountRequestsLogic.java b/src/main/java/teammates/sqllogic/core/AccountRequestsLogic.java index 31956cd0101..cff14372bf1 100644 --- a/src/main/java/teammates/sqllogic/core/AccountRequestsLogic.java +++ b/src/main/java/teammates/sqllogic/core/AccountRequestsLogic.java @@ -159,13 +159,13 @@ public AccountRequest resetAccountRequest(String email, String institute) } /** - * Deletes account request associated with the {@code email} and {@code institute}. + * Deletes account request associated with the {@code id}. * - *

    Fails silently if no account requests with the given email and institute to delete can be found.

    + *

    Fails silently if no account requests with the given id to delete can be found.

    * */ - public void deleteAccountRequest(String email, String institute) { - AccountRequest toDelete = accountRequestDb.getAccountRequest(email, institute); + public void deleteAccountRequest(UUID id) { + AccountRequest toDelete = accountRequestDb.getAccountRequest(id); accountRequestDb.deleteAccountRequest(toDelete); } diff --git a/src/main/java/teammates/sqllogic/core/DataBundleLogic.java b/src/main/java/teammates/sqllogic/core/DataBundleLogic.java index 8ab165d31b7..0c7c9f66311 100644 --- a/src/main/java/teammates/sqllogic/core/DataBundleLogic.java +++ b/src/main/java/teammates/sqllogic/core/DataBundleLogic.java @@ -351,7 +351,7 @@ public void removeDataBundle(SqlDataBundle dataBundle) throws InvalidParametersE accountsLogic.deleteAccount(account.getGoogleId()); }); dataBundle.accountRequests.values().forEach(accountRequest -> { - accountRequestsLogic.deleteAccountRequest(accountRequest.getEmail(), accountRequest.getInstitute()); + accountRequestsLogic.deleteAccountRequest(accountRequest.getId()); }); } diff --git a/src/main/java/teammates/ui/webapi/DeleteAccountRequestAction.java b/src/main/java/teammates/ui/webapi/DeleteAccountRequestAction.java index fa12bc67d81..ad157b1e5a3 100644 --- a/src/main/java/teammates/ui/webapi/DeleteAccountRequestAction.java +++ b/src/main/java/teammates/ui/webapi/DeleteAccountRequestAction.java @@ -1,5 +1,7 @@ package teammates.ui.webapi; +import java.util.UUID; + import teammates.common.util.Const; import teammates.storage.sqlentity.AccountRequest; @@ -10,17 +12,16 @@ class DeleteAccountRequestAction extends AdminOnlyAction { @Override public JsonResult execute() throws InvalidOperationException { - String email = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_EMAIL); - String institute = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_INSTITUTION); + UUID id = getUuidRequestParamValue(Const.ParamsNames.ACCOUNT_REQUEST_ID); - AccountRequest toDelete = sqlLogic.getAccountRequest(email, institute); + AccountRequest toDelete = sqlLogic.getAccountRequest(id); if (toDelete != null && toDelete.getRegisteredAt() != null) { // instructor is already registered and cannot be deleted throw new InvalidOperationException("Account request of a registered instructor cannot be deleted."); } - sqlLogic.deleteAccountRequest(email, institute); + sqlLogic.deleteAccountRequest(id); return new JsonResult("Account request successfully deleted."); } diff --git a/src/test/java/teammates/test/AbstractBackDoor.java b/src/test/java/teammates/test/AbstractBackDoor.java index 16c62c5e3ed..99c1d3dc1a2 100644 --- a/src/test/java/teammates/test/AbstractBackDoor.java +++ b/src/test/java/teammates/test/AbstractBackDoor.java @@ -868,10 +868,9 @@ public String getRegKeyForAccountRequest(String email, String institute) { /** * Deletes an account request from the database. */ - public void deleteAccountRequest(String email, String institute) { + public void deleteAccountRequest(UUID id) { Map params = new HashMap<>(); - params.put(Const.ParamsNames.INSTRUCTOR_EMAIL, email); - params.put(Const.ParamsNames.INSTRUCTOR_INSTITUTION, institute); + params.put(Const.ParamsNames.ACCOUNT_REQUEST_ID, id.toString()); executeDeleteRequest(Const.ResourceURIs.ACCOUNT_REQUEST, params); } diff --git a/src/web/app/components/account-requests-table/account-request-table.component.ts b/src/web/app/components/account-requests-table/account-request-table.component.ts index a9177960752..eab1fc95d7a 100755 --- a/src/web/app/components/account-requests-table/account-request-table.component.ts +++ b/src/web/app/components/account-requests-table/account-request-table.component.ts @@ -129,7 +129,7 @@ export class AccountRequestTableComponent { `Delete account request for ${accountRequest.name}?`, SimpleModalType.DANGER, modalContent); modalRef.result.then(() => { - this.accountService.deleteAccountRequest(accountRequest.email, accountRequest.instituteAndCountry) + this.accountService.deleteAccountRequest(accountRequest.id) .subscribe({ next: (resp: MessageOutput) => { this.statusMessageService.showSuccessToast(resp.message); diff --git a/src/web/services/account.service.spec.ts b/src/web/services/account.service.spec.ts index 82a2e6a5985..d463b982020 100644 --- a/src/web/services/account.service.spec.ts +++ b/src/web/services/account.service.spec.ts @@ -84,10 +84,9 @@ describe('AccountService', () => { }); it('should execute DELETE on account request endpoint', () => { - service.deleteAccountRequest('testEmail', 'testInstitution'); + service.deleteAccountRequest('testId'); const paramMap: Record = { - instructoremail: 'testEmail', - instructorinstitution: 'testInstitution', + id: 'testId', }; expect(spyHttpRequestService.delete).toHaveBeenCalledWith(ResourceEndpoints.ACCOUNT_REQUEST, paramMap); }); diff --git a/src/web/services/account.service.ts b/src/web/services/account.service.ts index 6f7a1f8bc5f..a99397a1a64 100644 --- a/src/web/services/account.service.ts +++ b/src/web/services/account.service.ts @@ -58,10 +58,9 @@ export class AccountService { /** * Deletes an account request by calling API. */ - deleteAccountRequest(email: string, institute: string): Observable { + deleteAccountRequest(id: string): Observable { const paramMap: Record = { - instructoremail: email, - instructorinstitution: institute, + id, }; return this.httpRequestService.delete(ResourceEndpoints.ACCOUNT_REQUEST, paramMap); }