From dab36e1ac0a25876c5866cb84315d5754ab0093a Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Sat, 23 Mar 2024 08:31:57 +0800 Subject: [PATCH 01/12] add endpoint --- .../java/teammates/common/util/Const.java | 1 + .../java/teammates/sqllogic/api/Logic.java | 7 +++++++ .../sqllogic/core/AccountRequestsLogic.java | 7 +++++++ .../storage/sqlapi/AccountRequestsDb.java | 14 ++++++++++++++ .../ui/constants/ResourceEndpoints.java | 1 + .../teammates/ui/webapi/ActionFactory.java | 1 + .../GetAllPendingAccountRequestsAction.java | 19 +++++++++++++++++++ 7 files changed, 50 insertions(+) create mode 100644 src/main/java/teammates/ui/webapi/GetAllPendingAccountRequestsAction.java diff --git a/src/main/java/teammates/common/util/Const.java b/src/main/java/teammates/common/util/Const.java index b24d0ded648..b4616858d3d 100644 --- a/src/main/java/teammates/common/util/Const.java +++ b/src/main/java/teammates/common/util/Const.java @@ -332,6 +332,7 @@ public static class ResourceURIs { public static final String ACCOUNT = URI_PREFIX + "/account"; public static final String ACCOUNT_RESET = URI_PREFIX + "/account/reset"; public static final String ACCOUNT_REQUEST = URI_PREFIX + "/account/request"; + public static final String ACCOUNT_REQUESTS_PENDING = URI_PREFIX + "/account/requests/pending"; public static final String ACCOUNT_REQUEST_RESET = ACCOUNT_REQUEST + "/reset"; public static final String ACCOUNTS = URI_PREFIX + "/accounts"; public static final String RESPONSE_COMMENT = URI_PREFIX + "/responsecomment"; diff --git a/src/main/java/teammates/sqllogic/api/Logic.java b/src/main/java/teammates/sqllogic/api/Logic.java index 3ffa0458042..3a20c76de48 100644 --- a/src/main/java/teammates/sqllogic/api/Logic.java +++ b/src/main/java/teammates/sqllogic/api/Logic.java @@ -149,6 +149,13 @@ public void deleteAccountRequest(String email, String institute) { accountRequestLogic.deleteAccountRequest(email, institute); } + /** + * Gets all pending account requests. + */ + public List getAllPendingAccountRequests() { + return accountRequestLogic.getAllPendingAccountRequests(); + } + /** * Gets an account. */ diff --git a/src/main/java/teammates/sqllogic/core/AccountRequestsLogic.java b/src/main/java/teammates/sqllogic/core/AccountRequestsLogic.java index 5766fa6c224..e0c22a2a2ac 100644 --- a/src/main/java/teammates/sqllogic/core/AccountRequestsLogic.java +++ b/src/main/java/teammates/sqllogic/core/AccountRequestsLogic.java @@ -88,6 +88,13 @@ public AccountRequest getAccountRequestByRegistrationKey(String regkey) { return accountRequestDb.getAccountRequestByRegistrationKey(regkey); } + /** + * Gets all pending account requests. + */ + public List getAllPendingAccountRequests() { + return accountRequestDb.getAllPendingAccountRequests(); + } + /** * Creates/resets the account request with the given email and institute such that it is not registered. */ diff --git a/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java b/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java index 068ed3ed253..f5554cf7a6b 100644 --- a/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java +++ b/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.UUID; +import teammates.common.datatransfer.AccountRequestStatus; import teammates.common.exception.EntityDoesNotExistException; import teammates.common.exception.InvalidParametersException; import teammates.common.exception.SearchServiceException; @@ -68,6 +69,19 @@ public AccountRequest getAccountRequest(String email, String institute) { return query.getResultStream().findFirst().orElse(null); } + /** + * Get all Account Requests with {@code status} of 'pending'. + */ + public List getAllPendingAccountRequests() { + CriteriaBuilder cb = HibernateUtil.getCriteriaBuilder(); + CriteriaQuery cr = cb.createQuery(AccountRequest.class); + Root root = cr.from(AccountRequest.class); + cr.select(root).where(cb.equal(root.get("status"), AccountRequestStatus.PENDING)); + + TypedQuery query = HibernateUtil.createQuery(cr); + return query.getResultList(); + } + /** * Get AccountRequest by {@code registrationKey} from database. */ diff --git a/src/main/java/teammates/ui/constants/ResourceEndpoints.java b/src/main/java/teammates/ui/constants/ResourceEndpoints.java index 2401fad8efe..c4f9286e578 100644 --- a/src/main/java/teammates/ui/constants/ResourceEndpoints.java +++ b/src/main/java/teammates/ui/constants/ResourceEndpoints.java @@ -15,6 +15,7 @@ public enum ResourceEndpoints { ACCOUNT(ResourceURIs.ACCOUNT), ACCOUNT_RESET(ResourceURIs.ACCOUNT_RESET), ACCOUNT_REQUEST(ResourceURIs.ACCOUNT_REQUEST), + ACCOUNT_REQUESTS_PENDING(ResourceURIs.ACCOUNT_REQUESTS_PENDING), ACCOUNT_REQUEST_RESET(ResourceURIs.ACCOUNT_REQUEST_RESET), ACCOUNTS(ResourceURIs.ACCOUNTS), RESPONSE_COMMENT(ResourceURIs.RESPONSE_COMMENT), diff --git a/src/main/java/teammates/ui/webapi/ActionFactory.java b/src/main/java/teammates/ui/webapi/ActionFactory.java index 38c4b00b753..e53fea65e9e 100644 --- a/src/main/java/teammates/ui/webapi/ActionFactory.java +++ b/src/main/java/teammates/ui/webapi/ActionFactory.java @@ -50,6 +50,7 @@ public final class ActionFactory { map(ResourceURIs.ACCOUNT_REQUEST, GET, GetAccountRequestAction.class); map(ResourceURIs.ACCOUNT_REQUEST, POST, CreateAccountRequestAction.class); map(ResourceURIs.ACCOUNT_REQUEST, DELETE, DeleteAccountRequestAction.class); + map(ResourceURIs.ACCOUNT_REQUESTS_PENDING, GET, GetAllPendingAccountRequestsAction.class); map(ResourceURIs.ACCOUNT_REQUEST_RESET, PUT, ResetAccountRequestAction.class); map(ResourceURIs.ACCOUNTS, GET, GetAccountsAction.class); map(ResourceURIs.COURSE, GET, GetCourseAction.class); diff --git a/src/main/java/teammates/ui/webapi/GetAllPendingAccountRequestsAction.java b/src/main/java/teammates/ui/webapi/GetAllPendingAccountRequestsAction.java new file mode 100644 index 00000000000..49e33d6989c --- /dev/null +++ b/src/main/java/teammates/ui/webapi/GetAllPendingAccountRequestsAction.java @@ -0,0 +1,19 @@ +package teammates.ui.webapi; + +import java.util.List; + +import teammates.storage.sqlentity.AccountRequest; +import teammates.ui.output.AccountRequestData; +import teammates.ui.output.AccountRequestsData; + +public class GetAllPendingAccountRequestsAction extends AdminOnlyAction { + @Override + public JsonResult execute() { + List accountRequests = sqlLogic.getAllPendingAccountRequests(); + List accountRequestDatas = accountRequests.stream().map(ar -> new AccountRequestData(ar)).toList(); + + AccountRequestsData output = new AccountRequestsData(); + output.setAccountRequests(accountRequestDatas); + return new JsonResult(output); + } +} From 76e97c0eeb0f2e6622eb1359a286572615713b2c Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Sat, 23 Mar 2024 08:45:22 +0800 Subject: [PATCH 02/12] remove 'all' in class and method names --- src/main/java/teammates/sqllogic/api/Logic.java | 4 ++-- .../java/teammates/sqllogic/core/AccountRequestsLogic.java | 4 ++-- src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java | 2 +- src/main/java/teammates/ui/webapi/ActionFactory.java | 2 +- ...questsAction.java => GetPendingAccountRequestsAction.java} | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) rename src/main/java/teammates/ui/webapi/{GetAllPendingAccountRequestsAction.java => GetPendingAccountRequestsAction.java} (77%) diff --git a/src/main/java/teammates/sqllogic/api/Logic.java b/src/main/java/teammates/sqllogic/api/Logic.java index 3a20c76de48..a6f785e442e 100644 --- a/src/main/java/teammates/sqllogic/api/Logic.java +++ b/src/main/java/teammates/sqllogic/api/Logic.java @@ -152,8 +152,8 @@ public void deleteAccountRequest(String email, String institute) { /** * Gets all pending account requests. */ - public List getAllPendingAccountRequests() { - return accountRequestLogic.getAllPendingAccountRequests(); + public List getPendingAccountRequests() { + return accountRequestLogic.getPendingAccountRequests(); } /** diff --git a/src/main/java/teammates/sqllogic/core/AccountRequestsLogic.java b/src/main/java/teammates/sqllogic/core/AccountRequestsLogic.java index e0c22a2a2ac..6c0f34efb1a 100644 --- a/src/main/java/teammates/sqllogic/core/AccountRequestsLogic.java +++ b/src/main/java/teammates/sqllogic/core/AccountRequestsLogic.java @@ -91,8 +91,8 @@ public AccountRequest getAccountRequestByRegistrationKey(String regkey) { /** * Gets all pending account requests. */ - public List getAllPendingAccountRequests() { - return accountRequestDb.getAllPendingAccountRequests(); + public List getPendingAccountRequests() { + return accountRequestDb.getPendingAccountRequests(); } /** diff --git a/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java b/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java index f5554cf7a6b..e3ced48d6af 100644 --- a/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java +++ b/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java @@ -72,7 +72,7 @@ public AccountRequest getAccountRequest(String email, String institute) { /** * Get all Account Requests with {@code status} of 'pending'. */ - public List getAllPendingAccountRequests() { + public List getPendingAccountRequests() { CriteriaBuilder cb = HibernateUtil.getCriteriaBuilder(); CriteriaQuery cr = cb.createQuery(AccountRequest.class); Root root = cr.from(AccountRequest.class); diff --git a/src/main/java/teammates/ui/webapi/ActionFactory.java b/src/main/java/teammates/ui/webapi/ActionFactory.java index e53fea65e9e..ee121bf99b0 100644 --- a/src/main/java/teammates/ui/webapi/ActionFactory.java +++ b/src/main/java/teammates/ui/webapi/ActionFactory.java @@ -50,7 +50,7 @@ public final class ActionFactory { map(ResourceURIs.ACCOUNT_REQUEST, GET, GetAccountRequestAction.class); map(ResourceURIs.ACCOUNT_REQUEST, POST, CreateAccountRequestAction.class); map(ResourceURIs.ACCOUNT_REQUEST, DELETE, DeleteAccountRequestAction.class); - map(ResourceURIs.ACCOUNT_REQUESTS_PENDING, GET, GetAllPendingAccountRequestsAction.class); + map(ResourceURIs.ACCOUNT_REQUESTS_PENDING, GET, GetPendingAccountRequestsAction.class); map(ResourceURIs.ACCOUNT_REQUEST_RESET, PUT, ResetAccountRequestAction.class); map(ResourceURIs.ACCOUNTS, GET, GetAccountsAction.class); map(ResourceURIs.COURSE, GET, GetCourseAction.class); diff --git a/src/main/java/teammates/ui/webapi/GetAllPendingAccountRequestsAction.java b/src/main/java/teammates/ui/webapi/GetPendingAccountRequestsAction.java similarity index 77% rename from src/main/java/teammates/ui/webapi/GetAllPendingAccountRequestsAction.java rename to src/main/java/teammates/ui/webapi/GetPendingAccountRequestsAction.java index 49e33d6989c..0b7ca3147fa 100644 --- a/src/main/java/teammates/ui/webapi/GetAllPendingAccountRequestsAction.java +++ b/src/main/java/teammates/ui/webapi/GetPendingAccountRequestsAction.java @@ -6,10 +6,10 @@ import teammates.ui.output.AccountRequestData; import teammates.ui.output.AccountRequestsData; -public class GetAllPendingAccountRequestsAction extends AdminOnlyAction { +public class GetPendingAccountRequestsAction extends AdminOnlyAction { @Override public JsonResult execute() { - List accountRequests = sqlLogic.getAllPendingAccountRequests(); + List accountRequests = sqlLogic.getPendingAccountRequests(); List accountRequestDatas = accountRequests.stream().map(ar -> new AccountRequestData(ar)).toList(); AccountRequestsData output = new AccountRequestsData(); From ff961a2b355682b9ce4a3502c709a4e33ca11907 Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Sat, 23 Mar 2024 08:50:21 +0800 Subject: [PATCH 03/12] fix checkstyle --- .../ui/webapi/GetPendingAccountRequestsAction.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/teammates/ui/webapi/GetPendingAccountRequestsAction.java b/src/main/java/teammates/ui/webapi/GetPendingAccountRequestsAction.java index 0b7ca3147fa..0c270caf07a 100644 --- a/src/main/java/teammates/ui/webapi/GetPendingAccountRequestsAction.java +++ b/src/main/java/teammates/ui/webapi/GetPendingAccountRequestsAction.java @@ -6,11 +6,17 @@ import teammates.ui.output.AccountRequestData; import teammates.ui.output.AccountRequestsData; +/** + * Action: Gets pending account requests. + */ public class GetPendingAccountRequestsAction extends AdminOnlyAction { @Override public JsonResult execute() { List accountRequests = sqlLogic.getPendingAccountRequests(); - List accountRequestDatas = accountRequests.stream().map(ar -> new AccountRequestData(ar)).toList(); + List accountRequestDatas = accountRequests + .stream() + .map(ar -> new AccountRequestData(ar)) + .toList(); AccountRequestsData output = new AccountRequestsData(); output.setAccountRequests(accountRequestDatas); From 887fb2358fe10e7f20611f35ec8cb45efe89b438 Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Sat, 23 Mar 2024 09:19:27 +0800 Subject: [PATCH 04/12] add it test --- .../GetPendingAccountRequestsActionIT.java | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/it/java/teammates/it/ui/webapi/GetPendingAccountRequestsActionIT.java diff --git a/src/it/java/teammates/it/ui/webapi/GetPendingAccountRequestsActionIT.java b/src/it/java/teammates/it/ui/webapi/GetPendingAccountRequestsActionIT.java new file mode 100644 index 00000000000..5c4c37dccac --- /dev/null +++ b/src/it/java/teammates/it/ui/webapi/GetPendingAccountRequestsActionIT.java @@ -0,0 +1,90 @@ +package teammates.it.ui.webapi; + +import java.util.List; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import teammates.common.datatransfer.AccountRequestStatus; +import teammates.common.exception.EntityAlreadyExistsException; +import teammates.common.exception.InvalidParametersException; +import teammates.common.util.Const; +import teammates.common.util.HibernateUtil; +import teammates.storage.sqlentity.AccountRequest; +import teammates.storage.sqlentity.Course; +import teammates.ui.output.AccountRequestData; +import teammates.ui.output.AccountRequestsData; +import teammates.ui.webapi.GetPendingAccountRequestsAction; +import teammates.ui.webapi.JsonResult; + +/** + * SUT: {@link GetPendingAccountRequestsAction}. + */ +public class GetPendingAccountRequestsActionIT extends BaseActionIT { + + @Override + @BeforeMethod + protected void setUp() throws Exception { + super.setUp(); + persistDataBundle(typicalBundle); + HibernateUtil.flushSession(); + } + + @Override + protected String getActionUri() { + return Const.ResourceURIs.ACCOUNT_REQUESTS_PENDING; + } + + @Override + protected String getRequestMethod() { + return GET; + } + + @Override + @Test + public void testExecute() { + ______TS("No pending account requests initially"); + + GetPendingAccountRequestsAction action = getAction(); + JsonResult result = getJsonResult(action); + AccountRequestsData data = (AccountRequestsData) result.getOutput(); + List arData = data.getAccountRequests(); + + assertEquals(0, arData.size()); + + ______TS("Get 2 pending account requests, ignore 1 approved account request"); + AccountRequest accountRequest1_approved = typicalBundle.accountRequests.get("instructor2"); + accountRequest1_approved.setStatus(AccountRequestStatus.APPROVED); + + AccountRequest accountRequest1 = typicalBundle.accountRequests.get("instructor1"); + AccountRequest accountRequest2 = typicalBundle.accountRequests.get("instructor1OfCourse2"); + accountRequest1.setStatus(AccountRequestStatus.PENDING); + accountRequest2.setStatus(AccountRequestStatus.PENDING); + + action = getAction(); + result = getJsonResult(action); + data = (AccountRequestsData) result.getOutput(); + arData = data.getAccountRequests(); + + assertEquals(2, arData.size()); + + // account request 1 + assertEquals(arData.get(0).getEmail(), accountRequest1.getEmail()); + assertEquals(arData.get(0).getInstitute(), accountRequest1.getInstitute()); + assertEquals(arData.get(0).getName(), accountRequest1.getName()); + assertEquals(arData.get(0).getRegistrationKey(), accountRequest1.getRegistrationKey()); + + // account request 2 + assertEquals(arData.get(1).getEmail(), accountRequest2.getEmail()); + assertEquals(arData.get(1).getInstitute(), accountRequest2.getInstitute()); + assertEquals(arData.get(1).getName(), accountRequest2.getName()); + assertEquals(arData.get(1).getRegistrationKey(), accountRequest2.getRegistrationKey()); + } + + @Override + @Test + public void testAccessControl() throws InvalidParametersException, EntityAlreadyExistsException { + Course course = typicalBundle.courses.get("course1"); + verifyOnlyAdminCanAccess(course); + } +} From c6d2bb3675b3358ecdd618d53e259d632ddc4452 Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Sat, 23 Mar 2024 09:22:33 +0800 Subject: [PATCH 05/12] fix checkstyle --- .../it/ui/webapi/GetPendingAccountRequestsActionIT.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/it/java/teammates/it/ui/webapi/GetPendingAccountRequestsActionIT.java b/src/it/java/teammates/it/ui/webapi/GetPendingAccountRequestsActionIT.java index 5c4c37dccac..5b8e8253a7e 100644 --- a/src/it/java/teammates/it/ui/webapi/GetPendingAccountRequestsActionIT.java +++ b/src/it/java/teammates/it/ui/webapi/GetPendingAccountRequestsActionIT.java @@ -49,12 +49,12 @@ public void testExecute() { JsonResult result = getJsonResult(action); AccountRequestsData data = (AccountRequestsData) result.getOutput(); List arData = data.getAccountRequests(); - + assertEquals(0, arData.size()); ______TS("Get 2 pending account requests, ignore 1 approved account request"); - AccountRequest accountRequest1_approved = typicalBundle.accountRequests.get("instructor2"); - accountRequest1_approved.setStatus(AccountRequestStatus.APPROVED); + AccountRequest approvedAccountRequest1 = typicalBundle.accountRequests.get("instructor2"); + approvedAccountRequest1.setStatus(AccountRequestStatus.APPROVED); AccountRequest accountRequest1 = typicalBundle.accountRequests.get("instructor1"); AccountRequest accountRequest2 = typicalBundle.accountRequests.get("instructor1OfCourse2"); @@ -68,7 +68,7 @@ public void testExecute() { assertEquals(2, arData.size()); - // account request 1 + // account request 1 assertEquals(arData.get(0).getEmail(), accountRequest1.getEmail()); assertEquals(arData.get(0).getInstitute(), accountRequest1.getInstitute()); assertEquals(arData.get(0).getName(), accountRequest1.getName()); From 039020003415de8f8403067858990eb8394f95fc Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Sat, 23 Mar 2024 09:32:32 +0800 Subject: [PATCH 06/12] fix checkstyle --- .../teammates/ui/webapi/GetPendingAccountRequestsAction.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/teammates/ui/webapi/GetPendingAccountRequestsAction.java b/src/main/java/teammates/ui/webapi/GetPendingAccountRequestsAction.java index 0c270caf07a..a6e33a73457 100644 --- a/src/main/java/teammates/ui/webapi/GetPendingAccountRequestsAction.java +++ b/src/main/java/teammates/ui/webapi/GetPendingAccountRequestsAction.java @@ -1,6 +1,7 @@ package teammates.ui.webapi; import java.util.List; +import java.util.stream.Collectors; import teammates.storage.sqlentity.AccountRequest; import teammates.ui.output.AccountRequestData; @@ -16,7 +17,7 @@ public JsonResult execute() { List accountRequestDatas = accountRequests .stream() .map(ar -> new AccountRequestData(ar)) - .toList(); + .collect(Collectors.toList()); AccountRequestsData output = new AccountRequestsData(); output.setAccountRequests(accountRequestDatas); From e03cd5445027cec2e6b4e7cc242fd30bc2921805 Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Sat, 23 Mar 2024 18:22:01 +0800 Subject: [PATCH 07/12] fix failing test --- .../java/teammates/ui/webapi/GetActionClassesActionTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/teammates/ui/webapi/GetActionClassesActionTest.java b/src/test/java/teammates/ui/webapi/GetActionClassesActionTest.java index 2c989868edc..91b6865d789 100644 --- a/src/test/java/teammates/ui/webapi/GetActionClassesActionTest.java +++ b/src/test/java/teammates/ui/webapi/GetActionClassesActionTest.java @@ -86,6 +86,7 @@ protected void testExecute() { CreateAccountRequestAction.class, GetAccountRequestAction.class, DeleteAccountRequestAction.class, + GetPendingAccountRequestsAction.class, GetAccountAction.class, GetAccountsAction.class, FeedbackSessionPublishedRemindersAction.class, From 7dfbecdd4de1e2619614858e00bd9a17ac568385 Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Sun, 24 Mar 2024 18:45:34 +0800 Subject: [PATCH 08/12] update endpoint url --- ...tsActionIT.java => GetAccountRequestsActionIT.java} | 10 +++++----- src/main/java/teammates/common/util/Const.java | 3 ++- .../java/teammates/ui/constants/ResourceEndpoints.java | 2 +- src/main/java/teammates/ui/webapi/ActionFactory.java | 2 +- ...questsAction.java => GetAccountRequestsAction.java} | 10 ++++++++-- .../ui/webapi/GetActionClassesActionTest.java | 2 +- 6 files changed, 18 insertions(+), 11 deletions(-) rename src/it/java/teammates/it/ui/webapi/{GetPendingAccountRequestsActionIT.java => GetAccountRequestsActionIT.java} (90%) rename src/main/java/teammates/ui/webapi/{GetPendingAccountRequestsAction.java => GetAccountRequestsAction.java} (62%) diff --git a/src/it/java/teammates/it/ui/webapi/GetPendingAccountRequestsActionIT.java b/src/it/java/teammates/it/ui/webapi/GetAccountRequestsActionIT.java similarity index 90% rename from src/it/java/teammates/it/ui/webapi/GetPendingAccountRequestsActionIT.java rename to src/it/java/teammates/it/ui/webapi/GetAccountRequestsActionIT.java index 5b8e8253a7e..a2dcaa6cebf 100644 --- a/src/it/java/teammates/it/ui/webapi/GetPendingAccountRequestsActionIT.java +++ b/src/it/java/teammates/it/ui/webapi/GetAccountRequestsActionIT.java @@ -14,13 +14,13 @@ import teammates.storage.sqlentity.Course; import teammates.ui.output.AccountRequestData; import teammates.ui.output.AccountRequestsData; -import teammates.ui.webapi.GetPendingAccountRequestsAction; +import teammates.ui.webapi.GetAccountRequestsAction; import teammates.ui.webapi.JsonResult; /** - * SUT: {@link GetPendingAccountRequestsAction}. + * SUT: {@link GetAccountRequestsAction}. */ -public class GetPendingAccountRequestsActionIT extends BaseActionIT { +public class GetAccountRequestsActionIT extends BaseActionIT { @Override @BeforeMethod @@ -32,7 +32,7 @@ protected void setUp() throws Exception { @Override protected String getActionUri() { - return Const.ResourceURIs.ACCOUNT_REQUESTS_PENDING; + return Const.ResourceURIs.ACCOUNT_REQUESTS; } @Override @@ -45,7 +45,7 @@ protected String getRequestMethod() { public void testExecute() { ______TS("No pending account requests initially"); - GetPendingAccountRequestsAction action = getAction(); + GetAccountRequestsAction action = getAction(); JsonResult result = getJsonResult(action); AccountRequestsData data = (AccountRequestsData) result.getOutput(); List arData = data.getAccountRequests(); diff --git a/src/main/java/teammates/common/util/Const.java b/src/main/java/teammates/common/util/Const.java index b4616858d3d..923556ef747 100644 --- a/src/main/java/teammates/common/util/Const.java +++ b/src/main/java/teammates/common/util/Const.java @@ -122,6 +122,7 @@ public static class ParamsNames { public static final String INSTRUCTOR_INSTITUTION = "instructorinstitution"; public static final String IS_CREATING_ACCOUNT = "iscreatingaccount"; public static final String IS_INSTRUCTOR = "isinstructor"; + public static final String ACCOUNT_REQUEST_STATUS = "accountrequeststatus"; public static final String FEEDBACK_SESSION_NAME = "fsname"; public static final String FEEDBACK_SESSION_STARTTIME = "starttime"; @@ -332,7 +333,7 @@ public static class ResourceURIs { public static final String ACCOUNT = URI_PREFIX + "/account"; public static final String ACCOUNT_RESET = URI_PREFIX + "/account/reset"; public static final String ACCOUNT_REQUEST = URI_PREFIX + "/account/request"; - public static final String ACCOUNT_REQUESTS_PENDING = URI_PREFIX + "/account/requests/pending"; + public static final String ACCOUNT_REQUESTS = URI_PREFIX + "/account/requests"; public static final String ACCOUNT_REQUEST_RESET = ACCOUNT_REQUEST + "/reset"; public static final String ACCOUNTS = URI_PREFIX + "/accounts"; public static final String RESPONSE_COMMENT = URI_PREFIX + "/responsecomment"; diff --git a/src/main/java/teammates/ui/constants/ResourceEndpoints.java b/src/main/java/teammates/ui/constants/ResourceEndpoints.java index c4f9286e578..8e288eb6264 100644 --- a/src/main/java/teammates/ui/constants/ResourceEndpoints.java +++ b/src/main/java/teammates/ui/constants/ResourceEndpoints.java @@ -15,7 +15,7 @@ public enum ResourceEndpoints { ACCOUNT(ResourceURIs.ACCOUNT), ACCOUNT_RESET(ResourceURIs.ACCOUNT_RESET), ACCOUNT_REQUEST(ResourceURIs.ACCOUNT_REQUEST), - ACCOUNT_REQUESTS_PENDING(ResourceURIs.ACCOUNT_REQUESTS_PENDING), + ACCOUNT_REQUESTS(ResourceURIs.ACCOUNT_REQUESTS), ACCOUNT_REQUEST_RESET(ResourceURIs.ACCOUNT_REQUEST_RESET), ACCOUNTS(ResourceURIs.ACCOUNTS), RESPONSE_COMMENT(ResourceURIs.RESPONSE_COMMENT), diff --git a/src/main/java/teammates/ui/webapi/ActionFactory.java b/src/main/java/teammates/ui/webapi/ActionFactory.java index ee121bf99b0..72d16ad9973 100644 --- a/src/main/java/teammates/ui/webapi/ActionFactory.java +++ b/src/main/java/teammates/ui/webapi/ActionFactory.java @@ -50,7 +50,7 @@ public final class ActionFactory { map(ResourceURIs.ACCOUNT_REQUEST, GET, GetAccountRequestAction.class); map(ResourceURIs.ACCOUNT_REQUEST, POST, CreateAccountRequestAction.class); map(ResourceURIs.ACCOUNT_REQUEST, DELETE, DeleteAccountRequestAction.class); - map(ResourceURIs.ACCOUNT_REQUESTS_PENDING, GET, GetPendingAccountRequestsAction.class); + map(ResourceURIs.ACCOUNT_REQUESTS, GET, GetAccountRequestsAction.class); map(ResourceURIs.ACCOUNT_REQUEST_RESET, PUT, ResetAccountRequestAction.class); map(ResourceURIs.ACCOUNTS, GET, GetAccountsAction.class); map(ResourceURIs.COURSE, GET, GetCourseAction.class); diff --git a/src/main/java/teammates/ui/webapi/GetPendingAccountRequestsAction.java b/src/main/java/teammates/ui/webapi/GetAccountRequestsAction.java similarity index 62% rename from src/main/java/teammates/ui/webapi/GetPendingAccountRequestsAction.java rename to src/main/java/teammates/ui/webapi/GetAccountRequestsAction.java index a6e33a73457..ebfb74938ea 100644 --- a/src/main/java/teammates/ui/webapi/GetPendingAccountRequestsAction.java +++ b/src/main/java/teammates/ui/webapi/GetAccountRequestsAction.java @@ -3,6 +3,7 @@ import java.util.List; import java.util.stream.Collectors; +import teammates.common.util.Const; import teammates.storage.sqlentity.AccountRequest; import teammates.ui.output.AccountRequestData; import teammates.ui.output.AccountRequestsData; @@ -10,9 +11,14 @@ /** * Action: Gets pending account requests. */ -public class GetPendingAccountRequestsAction extends AdminOnlyAction { +public class GetAccountRequestsAction extends AdminOnlyAction { @Override - public JsonResult execute() { + public JsonResult execute() throws InvalidHttpParameterException { + String accountRequestStatus = getNonNullRequestParamValue(Const.ParamsNames.ACCOUNT_REQUEST_STATUS); + if (!accountRequestStatus.equals("pending")) { + throw new InvalidHttpParameterException("Only 'pending' is allowed for account request status."); + } + List accountRequests = sqlLogic.getPendingAccountRequests(); List accountRequestDatas = accountRequests .stream() diff --git a/src/test/java/teammates/ui/webapi/GetActionClassesActionTest.java b/src/test/java/teammates/ui/webapi/GetActionClassesActionTest.java index 91b6865d789..752a74d9101 100644 --- a/src/test/java/teammates/ui/webapi/GetActionClassesActionTest.java +++ b/src/test/java/teammates/ui/webapi/GetActionClassesActionTest.java @@ -86,7 +86,7 @@ protected void testExecute() { CreateAccountRequestAction.class, GetAccountRequestAction.class, DeleteAccountRequestAction.class, - GetPendingAccountRequestsAction.class, + GetAccountRequestsAction.class, GetAccountAction.class, GetAccountsAction.class, FeedbackSessionPublishedRemindersAction.class, From b4452540863543bbe1172d11e8de0c9d819ef477 Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Sun, 24 Mar 2024 18:55:47 +0800 Subject: [PATCH 09/12] update it tests --- .../it/ui/webapi/GetAccountRequestsActionIT.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/it/java/teammates/it/ui/webapi/GetAccountRequestsActionIT.java b/src/it/java/teammates/it/ui/webapi/GetAccountRequestsActionIT.java index a2dcaa6cebf..1c81a2e9235 100644 --- a/src/it/java/teammates/it/ui/webapi/GetAccountRequestsActionIT.java +++ b/src/it/java/teammates/it/ui/webapi/GetAccountRequestsActionIT.java @@ -21,6 +21,7 @@ * SUT: {@link GetAccountRequestsAction}. */ public class GetAccountRequestsActionIT extends BaseActionIT { + private final String[] validParams = {Const.ParamsNames.ACCOUNT_REQUEST_STATUS, "pending"}; @Override @BeforeMethod @@ -43,9 +44,14 @@ protected String getRequestMethod() { @Override @Test public void testExecute() { + ______TS("accountrequeststatus param is null"); + + verifyHttpParameterFailure(); + verifyHttpParameterFailure(Const.ParamsNames.ACCOUNT_REQUEST_STATUS, "pendin"); + ______TS("No pending account requests initially"); - GetAccountRequestsAction action = getAction(); + GetAccountRequestsAction action = getAction(this.validParams); JsonResult result = getJsonResult(action); AccountRequestsData data = (AccountRequestsData) result.getOutput(); List arData = data.getAccountRequests(); @@ -61,7 +67,7 @@ public void testExecute() { accountRequest1.setStatus(AccountRequestStatus.PENDING); accountRequest2.setStatus(AccountRequestStatus.PENDING); - action = getAction(); + action = getAction(this.validParams); result = getJsonResult(action); data = (AccountRequestsData) result.getOutput(); arData = data.getAccountRequests(); From 3dc9c474276c93b62851be88f0f86acaaa3bb8fb Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Sun, 24 Mar 2024 21:52:30 +0800 Subject: [PATCH 10/12] fix linting --- .../java/teammates/ui/webapi/GetAccountRequestsAction.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/teammates/ui/webapi/GetAccountRequestsAction.java b/src/main/java/teammates/ui/webapi/GetAccountRequestsAction.java index ebfb74938ea..0283afc66e0 100644 --- a/src/main/java/teammates/ui/webapi/GetAccountRequestsAction.java +++ b/src/main/java/teammates/ui/webapi/GetAccountRequestsAction.java @@ -13,9 +13,9 @@ */ public class GetAccountRequestsAction extends AdminOnlyAction { @Override - public JsonResult execute() throws InvalidHttpParameterException { + public JsonResult execute() { String accountRequestStatus = getNonNullRequestParamValue(Const.ParamsNames.ACCOUNT_REQUEST_STATUS); - if (!accountRequestStatus.equals("pending")) { + if (!"pending".equals(accountRequestStatus)) { throw new InvalidHttpParameterException("Only 'pending' is allowed for account request status."); } From 5d5adaa7be1c0bd5aed7a4dc39732f269923be3e Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Sun, 24 Mar 2024 23:53:25 +0800 Subject: [PATCH 11/12] update param name --- src/main/java/teammates/common/util/Const.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/teammates/common/util/Const.java b/src/main/java/teammates/common/util/Const.java index 923556ef747..34b5a369479 100644 --- a/src/main/java/teammates/common/util/Const.java +++ b/src/main/java/teammates/common/util/Const.java @@ -122,7 +122,7 @@ public static class ParamsNames { public static final String INSTRUCTOR_INSTITUTION = "instructorinstitution"; public static final String IS_CREATING_ACCOUNT = "iscreatingaccount"; public static final String IS_INSTRUCTOR = "isinstructor"; - public static final String ACCOUNT_REQUEST_STATUS = "accountrequeststatus"; + public static final String ACCOUNT_REQUEST_STATUS = "status"; public static final String FEEDBACK_SESSION_NAME = "fsname"; public static final String FEEDBACK_SESSION_STARTTIME = "starttime"; From 69073e7cb3a7a8c5c62f79b132cbaf15587a8744 Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Mon, 25 Mar 2024 09:21:58 +0800 Subject: [PATCH 12/12] update request param condition --- .../ui/webapi/GetAccountRequestsActionIT.java | 17 +++++++++++++++-- .../ui/webapi/GetAccountRequestsAction.java | 4 +++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/it/java/teammates/it/ui/webapi/GetAccountRequestsActionIT.java b/src/it/java/teammates/it/ui/webapi/GetAccountRequestsActionIT.java index 1c81a2e9235..565fda387a5 100644 --- a/src/it/java/teammates/it/ui/webapi/GetAccountRequestsActionIT.java +++ b/src/it/java/teammates/it/ui/webapi/GetAccountRequestsActionIT.java @@ -21,7 +21,7 @@ * SUT: {@link GetAccountRequestsAction}. */ public class GetAccountRequestsActionIT extends BaseActionIT { - private final String[] validParams = {Const.ParamsNames.ACCOUNT_REQUEST_STATUS, "pending"}; + private final String[] validParams = { Const.ParamsNames.ACCOUNT_REQUEST_STATUS, "pending" }; @Override @BeforeMethod @@ -58,11 +58,24 @@ public void testExecute() { assertEquals(0, arData.size()); + ______TS("1 pending account request, case insensitive match for status request param"); + + AccountRequest accountRequest1 = typicalBundle.accountRequests.get("instructor1"); + accountRequest1.setStatus(AccountRequestStatus.PENDING); + + String[] params = { Const.ParamsNames.ACCOUNT_REQUEST_STATUS, "PendinG" }; + action = getAction(params); + result = getJsonResult(action); + data = (AccountRequestsData) result.getOutput(); + arData = data.getAccountRequests(); + + assertEquals(1, arData.size()); + ______TS("Get 2 pending account requests, ignore 1 approved account request"); AccountRequest approvedAccountRequest1 = typicalBundle.accountRequests.get("instructor2"); approvedAccountRequest1.setStatus(AccountRequestStatus.APPROVED); - AccountRequest accountRequest1 = typicalBundle.accountRequests.get("instructor1"); + accountRequest1 = typicalBundle.accountRequests.get("instructor1"); AccountRequest accountRequest2 = typicalBundle.accountRequests.get("instructor1OfCourse2"); accountRequest1.setStatus(AccountRequestStatus.PENDING); accountRequest2.setStatus(AccountRequestStatus.PENDING); diff --git a/src/main/java/teammates/ui/webapi/GetAccountRequestsAction.java b/src/main/java/teammates/ui/webapi/GetAccountRequestsAction.java index 0283afc66e0..7cac4331b98 100644 --- a/src/main/java/teammates/ui/webapi/GetAccountRequestsAction.java +++ b/src/main/java/teammates/ui/webapi/GetAccountRequestsAction.java @@ -3,6 +3,7 @@ import java.util.List; import java.util.stream.Collectors; +import teammates.common.datatransfer.AccountRequestStatus; import teammates.common.util.Const; import teammates.storage.sqlentity.AccountRequest; import teammates.ui.output.AccountRequestData; @@ -15,7 +16,8 @@ public class GetAccountRequestsAction extends AdminOnlyAction { @Override public JsonResult execute() { String accountRequestStatus = getNonNullRequestParamValue(Const.ParamsNames.ACCOUNT_REQUEST_STATUS); - if (!"pending".equals(accountRequestStatus)) { + String pending = AccountRequestStatus.PENDING.name(); // 'PENDING' + if (!pending.equalsIgnoreCase(accountRequestStatus)) { throw new InvalidHttpParameterException("Only 'pending' is allowed for account request status."); }