Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: consultant email search #694

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
import de.caritas.cob.userservice.api.service.SessionDataService;
import de.caritas.cob.userservice.api.service.archive.SessionArchiveService;
import de.caritas.cob.userservice.api.service.archive.SessionDeleteService;
import de.caritas.cob.userservice.api.service.helper.EmailUrlDecoder;
import de.caritas.cob.userservice.api.service.session.SessionFilter;
import de.caritas.cob.userservice.api.service.session.SessionService;
import de.caritas.cob.userservice.api.service.user.UserAccountService;
Expand All @@ -115,6 +116,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.commons.validator.routines.EmailValidator;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -766,7 +768,7 @@ public ResponseEntity<List<ConsultantResponseDTO>> getConsultants(@RequestParam
@Override
public ResponseEntity<ConsultantSearchResultDTO> searchConsultants(
String query, Integer page, Integer perPage, String field, String order) {
var decodedInfix = URLDecoder.decode(query, StandardCharsets.UTF_8).trim();
var decodedInfix = determineDecodedInfix(query).trim();
var isAscending = order.equalsIgnoreCase("asc");
var mappedField = consultantDtoMapper.mappedFieldOf(field);
var resultMap =
Expand All @@ -793,6 +795,14 @@ public ResponseEntity<ConsultantSearchResultDTO> searchConsultants(
return ResponseEntity.ok(result);
}

private String determineDecodedInfix(String query) {
if (EmailValidator.getInstance().isValid(query)) {
return EmailUrlDecoder.decodeEmailQuery(query);
} else {
return URLDecoder.decode(query, StandardCharsets.UTF_8).trim();
}
}

private void removeAgenciesWithoutAccessRight(
ConsultantAdminResponseDTO response, Collection<Long> agenciesToFilterConsultants) {
List<AgencyAdminResponseDTO> agencies = response.getEmbedded().getAgencies();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public static String decodeEmailQuery(String query) {
strings.stream()
.map(part -> URLDecoder.decode(part, StandardCharsets.UTF_8).trim())
.collect(Collectors.toList());
return Joiner.on(PLUS).join(decodedList);
return Joiner.on(PLUS).join(decodedList).trim();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,21 @@

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

class EmailUrlDecoderTest {

@Test
public void decodeEmailQuery_Should_notChangeProperEmail() {
assertThat(EmailUrlDecoder.decodeEmailQuery("[email protected]"))
.isEqualTo("[email protected]");
assertThat(EmailUrlDecoder.decodeEmailQuery("testmail%40virtual-identity.com"))
.isEqualTo("[email protected]");
assertThat(EmailUrlDecoder.decodeEmailQuery("test.mail%40virtual-identity.com"))
.isEqualTo("[email protected]");
}

@Test
public void decodeEmailQuery_Should_decodeProperlyMailsWithPlus() {
assertThat(EmailUrlDecoder.decodeEmailQuery("testmail%2Bext%40gmail.com"))
.isEqualTo("[email protected]");
assertThat(EmailUrlDecoder.decodeEmailQuery("testmail%2Bext%40virtual-identity.com"))
.isEqualTo("[email protected]");
assertThat(
EmailUrlDecoder.decodeEmailQuery(
"test.user.ext%2Btenant14.02.v2%40virtual-identity.com"))
.isEqualTo("[email protected]");
@ParameterizedTest
@CsvSource({
"testmail%2Bext%40gmail.com,[email protected]",
"testmail%2Bext%40virtual-identity.com,[email protected]",
"test.user.ext%2Btenant14.02.v2%40virtual-identity.com,[email protected]",
"[email protected],[email protected]",
"testmail%40virtual-identity.com,[email protected]",
"test.mail%40virtual-identity.com,[email protected]",
})
void decodeEmailQuery_Should_decodeProperlyMailsWithPlus(String input, String expectedOutput) {
assertThat(EmailUrlDecoder.decodeEmailQuery(input)).isEqualTo(expectedOutput);
}
}
Loading