implement wildcard for contacts emailAddress search

This commit is contained in:
Michael Hoennig 2024-12-12 16:00:03 +01:00
parent ee0e59bd55
commit 025ebac846
3 changed files with 6 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import io.micrometer.core.annotation.Timed;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@ -28,8 +29,8 @@ public interface HsOfficeContactRbacRepository extends Repository<HsOfficeContac
@Timed("app.office.contacts.repo.findContactByEmailAddressImpl.rbac")
List<HsOfficeContactRbacEntity> findContactByEmailAddressImpl(final String emailAddressExpression);
default List<HsOfficeContactRbacEntity> findContactByEmailAddress(final String emailAddress) {
return findContactByEmailAddressImpl("$.** ? (@ == \"" + emailAddress + "\")");
default List<HsOfficeContactRbacEntity> findContactByEmailAddress(@NotNull final String emailAddress) {
return findContactByEmailAddressImpl("$.** ? (@ like_regex \"" + emailAddress.replace("%", ".*") + "\")");
}
@Timed("app.office.contacts.repo.save.rbac")

View File

@ -18,7 +18,7 @@ get:
required: false
schema:
type: string
description: Beginning of email-address to filter the results.
description: Beginning of email-address to filter the results, use '%' as wildcard.
responses:
"200":
description: OK

View File

@ -188,12 +188,12 @@ class HsOfficeContactRbacRepositoryIntegrationTest extends ContextBasedTestWithC
class FindByEmailAddress {
@Test
public void globalAdmin_withoutAssumedRole_canViewAllContacts() {
public void globalAdmin_withoutAssumedRole_canFindContactsByEmailAddress() {
// given
context("superuser-alex@hostsharing.net", null);
// when
final var result = contactRepo.findContactByEmailAddress("contact-admin@secondcontact.example.com");
final var result = contactRepo.findContactByEmailAddress("%@secondcontact.example.com");
// then
exactlyTheseContactsAreReturned(result, "second contact");