diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacRepository.java index 8f304ce8..51c3990e 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacRepository.java @@ -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 findContactByEmailAddressImpl(final String emailAddressExpression); - default List findContactByEmailAddress(final String emailAddress) { - return findContactByEmailAddressImpl("$.** ? (@ == \"" + emailAddress + "\")"); + default List findContactByEmailAddress(@NotNull final String emailAddress) { + return findContactByEmailAddressImpl("$.** ? (@ like_regex \"" + emailAddress.replace("%", ".*") + "\")"); } @Timed("app.office.contacts.repo.save.rbac") diff --git a/src/main/resources/api-definition/hs-office/hs-office-contacts.yaml b/src/main/resources/api-definition/hs-office/hs-office-contacts.yaml index 4694660b..0dff9a63 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-contacts.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-contacts.yaml @@ -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 diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacRepositoryIntegrationTest.java index 379c8137..5b59f3b6 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacRepositoryIntegrationTest.java @@ -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");