-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create account request rejection endpoint
- Loading branch information
Showing
6 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/teammates/ui/request/AccountRequestRejectionRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package teammates.ui.request; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import teammates.common.datatransfer.AccountRequestStatus; | ||
import teammates.common.util.SanitizationHelper; | ||
|
||
/** | ||
* The request reasonBody for rejecting an account request. | ||
*/ | ||
public class AccountRequestRejectionRequest extends BasicRequest { | ||
@Nullable | ||
private String reasonTitle; | ||
|
||
@Nullable | ||
private String reasonBody; | ||
|
||
public AccountRequestRejectionRequest(String reasonTitle, String reasonBody) { | ||
this.reasonTitle = SanitizationHelper.sanitizeTitle(reasonTitle); | ||
this.reasonBody = SanitizationHelper.sanitizeForRichText(reasonBody); | ||
} | ||
|
||
@Override | ||
public void validate() throws InvalidHttpRequestBodyException { | ||
// No validation | ||
} | ||
|
||
public String getReasonTitle() { | ||
return this.reasonTitle; | ||
} | ||
|
||
public String getReasonBody() { | ||
return this.reasonBody; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/teammates/ui/webapi/RejectAccountRequestAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package teammates.ui.webapi; | ||
|
||
import java.util.UUID; | ||
|
||
import teammates.common.datatransfer.AccountRequestStatus; | ||
import teammates.common.exception.EntityDoesNotExistException; | ||
import teammates.common.exception.InvalidParametersException; | ||
import teammates.common.util.Const; | ||
import teammates.storage.sqlentity.AccountRequest; | ||
import teammates.ui.output.AccountRequestData; | ||
import teammates.ui.request.AccountRequestRejectionRequest; | ||
import teammates.ui.request.InvalidHttpRequestBodyException; | ||
|
||
/** | ||
* Rejects an account request. | ||
*/ | ||
public class RejectAccountRequestAction extends AdminOnlyAction { | ||
|
||
@Override | ||
public JsonResult execute() throws InvalidOperationException, InvalidHttpRequestBodyException { | ||
String id = getNonNullRequestParamValue(Const.ParamsNames.ACCOUNT_REQUEST_ID); | ||
UUID accountRequestId; | ||
|
||
try { | ||
accountRequestId = UUID.fromString(id); | ||
} catch (IllegalArgumentException e) { | ||
throw new InvalidHttpParameterException(e.getMessage(), e); | ||
} | ||
|
||
AccountRequest accountRequest = sqlLogic.getAccountRequest(accountRequestId); | ||
|
||
if (accountRequest == null) { | ||
String errorMessage = String.format(Const.ACCOUNT_REQUEST_NOT_FOUND, accountRequestId.toString()); | ||
throw new EntityNotFoundException(errorMessage); | ||
} | ||
|
||
AccountRequestRejectionRequest accountRequestRejectionRequest = | ||
getAndValidateRequestBody(AccountRequestRejectionRequest.class); | ||
|
||
try { | ||
accountRequest.setStatus(AccountRequestStatus.REJECTED); | ||
accountRequest = sqlLogic.updateAccountRequest(accountRequest); | ||
} catch (InvalidParametersException e) { | ||
throw new InvalidHttpRequestBodyException(e); | ||
} catch (EntityDoesNotExistException e) { | ||
throw new EntityNotFoundException(e); | ||
} | ||
|
||
if (accountRequestRejectionRequest.getReasonBody() != null) { | ||
// TODO: generate rejection email from reason title and reason body | ||
} | ||
|
||
return new JsonResult(new AccountRequestData(accountRequest)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters