Skip to content

Commit

Permalink
Fixes for activation code issue
Browse files Browse the repository at this point in the history
  • Loading branch information
arcshiftsolutions committed Dec 1, 2023
1 parent 7bfdea2 commit 244f2fc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ public EdxUserEntity activateEdxUser(EdxActivateUser edxActivateUser) {
} else {
activationCodes = edxActivationCodeRepository.findEdxActivationCodeByActivationCodeInAndDistrictID(acCodes, edxActivateUser.getDistrictID());
}
validateIncomingActivationCodeTypes(edxActivateUser, activationCodes);
if (!CollectionUtils.isEmpty(activationCodes) && activationCodes.size() == 2) {
EdxActivationCodeEntity userCodeEntity = validateExpiryAndSetEdxUserIdForPersonalActivationCode(edxActivateUser, activationCodes);

Expand All @@ -398,6 +399,16 @@ public EdxUserEntity activateEdxUser(EdxActivateUser edxActivateUser) {
}
}

private void validateIncomingActivationCodeTypes(EdxActivateUser user, List<EdxActivationCodeEntity> activationCodes){
for (val activationCode : activationCodes) {
if((activationCode.getIsPrimary() && !activationCode.getActivationCode().equalsIgnoreCase(user.getPrimaryEdxCode())) ||
(!activationCode.getIsPrimary() && !activationCode.getActivationCode().equalsIgnoreCase(user.getPersonalActivationCode()))){
ApiError error = ApiError.builder().timestamp(LocalDateTime.now()).message("Invalid code provided.").status(BAD_REQUEST).build();
throw new InvalidPayloadException(error);
}
}
}

private EdxActivationCodeEntity validateExpiryAndSetEdxUserIdForPersonalActivationCode(EdxActivateUser edxActivateUser, List<EdxActivationCodeEntity> activationCodes) {
EdxActivationCodeEntity userCodeEntity = null;
for (val activationCode : activationCodes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,25 @@ void testEdxActivateUsers_GivenValidInput_UserIsCreated_WithOkStatusResponse() t
.andExpect(jsonPath("$.edxUserSchools.[0].edxUserSchoolRoles", hasSize(1)))
.andExpect(jsonPath("$.edxUserSchools[0].edxUserSchoolRoles[0].edxUserSchoolRoleID", is(notNullValue())))
.andDo(print()).andExpect(status().isCreated());
}

@Test
void testEdxActivateUsers_GivenValidInput_UserIsCreated_WithBadRequestResponse() throws Exception {
UUID validationCode = UUID.randomUUID();
UUID schoolID = UUID.randomUUID();
this.createActivationCodeTableDataForSchoolUser(this.edxActivationCodeRepository, this.edxPermissionRepository, this.edxRoleRepository, this.edxActivationRoleRepository, true,validationCode, 2, schoolID);
EdxActivateUser edxActivateUser = new EdxActivateUser();
edxActivateUser.setSchoolID(schoolID);
edxActivateUser.setPersonalActivationCode("ABCDE");
edxActivateUser.setPrimaryEdxCode("WXYZ");
edxActivateUser.setDigitalId(UUID.randomUUID().toString());
String activateUserJson = getJsonString(edxActivateUser);
val resultActions = this.mockMvc.perform(post(URL.BASE_URL_USERS + "/activation")
.contentType(MediaType.APPLICATION_JSON)
.content(activateUserJson)
.accept(MediaType.APPLICATION_JSON)
.with(jwt().jwt((jwt) -> jwt.claim("scope", "ACTIVATE_EDX_USER"))));
resultActions.andDo(print()).andExpect(status().isBadRequest());
}

@Test
Expand Down

0 comments on commit 244f2fc

Please sign in to comment.