Skip to content

Commit

Permalink
Merge pull request #245 from bcgov/fix/edx-1904
Browse files Browse the repository at this point in the history
EDX-1904: ensured that finding a Primary EDX Activation Code will exp…
  • Loading branch information
trev-dev authored Oct 17, 2023
2 parents f751181 + 9a0c5fd commit 09a652b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public interface EdxActivationCodeRepository extends JpaRepository<EdxActivation

List<EdxActivationCodeEntity> findEdxActivationCodeEntitiesByValidationCode(UUID userActivationValidationCode);

Optional<EdxActivationCodeEntity> findEdxActivationCodeEntitiesBySchoolIDAndIsPrimaryTrue(UUID schoolID);
Optional<EdxActivationCodeEntity> findEdxActivationCodeEntitiesBySchoolIDAndIsPrimaryTrueAndDistrictIDIsNull(UUID schoolID);

Optional<EdxActivationCodeEntity> findEdxActivationCodeEntitiesByDistrictIDAndIsPrimaryTrue(UUID districtID);
Optional<EdxActivationCodeEntity> findEdxActivationCodeEntitiesByDistrictIDAndIsPrimaryTrueAndSchoolIDIsNull(UUID districtID);

List<EdxActivationCodeEntity> findEdxActivationCodeEntitiesByEdxUserId(UUID edxUserId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public void createPrimaryActivationCode(CreateSchoolSagaData sagaData) {
EdxPrimaryActivationCode edxPrimaryActivationCode = new EdxPrimaryActivationCode();
School school = sagaData.getSchool();
edxPrimaryActivationCode.setSchoolID(UUID.fromString(school.getSchoolId()));
edxPrimaryActivationCode.setDistrictID(UUID.fromString(school.getDistrictId()));
RequestUtil.setAuditColumnsForCreate(edxPrimaryActivationCode);

service.generateOrRegeneratePrimaryEdxActivationCode(SCHOOL, school.getSchoolId(), edxPrimaryActivationCode);
Expand All @@ -82,8 +81,7 @@ public void sendPrimaryActivationCodeNotification(CreateSchoolSagaData sagaData)
School school = sagaData.getSchool();
UUID schoolId = UUID.fromString(school.getSchoolId());

Optional<EdxActivationCodeEntity> edxActivationCodeEntity
= edxActivationCodeRepository.findEdxActivationCodeEntitiesBySchoolIDAndIsPrimaryTrue(schoolId);
Optional<EdxActivationCodeEntity> edxActivationCodeEntity = edxActivationCodeRepository.findEdxActivationCodeEntitiesBySchoolIDAndIsPrimaryTrueAndDistrictIDIsNull(schoolId);

EmailNotification emailNotification = EmailNotification.builder()
.fromEmail(emailProperties.getEdxSchoolUserActivationInviteEmailFrom())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,9 +854,9 @@ public EdxActivationCodeEntity generateOrRegeneratePrimaryEdxActivationCode(Inst
private Optional<EdxActivationCodeEntity> findPrimaryEdxActivationCodeForInstitute(InstituteTypeCode instituteType, String contactIdentifier) {
switch (instituteType) {
case SCHOOL:
return getEdxActivationCodeRepository().findEdxActivationCodeEntitiesBySchoolIDAndIsPrimaryTrue(UUID.fromString(contactIdentifier));
return getEdxActivationCodeRepository().findEdxActivationCodeEntitiesBySchoolIDAndIsPrimaryTrueAndDistrictIDIsNull(UUID.fromString(contactIdentifier));
case DISTRICT:
return getEdxActivationCodeRepository().findEdxActivationCodeEntitiesByDistrictIDAndIsPrimaryTrue(UUID.fromString(contactIdentifier));
return getEdxActivationCodeRepository().findEdxActivationCodeEntitiesByDistrictIDAndIsPrimaryTrueAndSchoolIDIsNull(UUID.fromString(contactIdentifier));
default:
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ void testCreatePrimaryCode_GivenAnInitialUserAndSchool_sagaShouldCreatePrimarySc
JsonUtil.getJsonObjectFromString(CreateSchoolSagaData.class, newEvent.getEventPayload());

UUID schooId = UUID.fromString(newData.getSchool().getSchoolId());
Optional<EdxActivationCodeEntity> codeOptional =
edxActivationCodeRepository.findEdxActivationCodeEntitiesBySchoolIDAndIsPrimaryTrue(schooId);
Optional<EdxActivationCodeEntity> codeOptional = edxActivationCodeRepository.findEdxActivationCodeEntitiesBySchoolIDAndIsPrimaryTrueAndDistrictIDIsNull(schooId);

assertThat(codeOptional).isPresent();
assertThat(newData.getInitialEdxUser()).isPresent();
Expand Down

0 comments on commit 09a652b

Please sign in to comment.