From 025ebac84625a1a54244343edfe7f612a0e1f4a2 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 12 Dec 2024 16:00:03 +0100 Subject: [PATCH] implement wildcard for contacts emailAddress search --- .../hs/office/contact/HsOfficeContactRbacRepository.java | 5 +++-- .../api-definition/hs-office/hs-office-contacts.yaml | 2 +- .../HsOfficeContactRbacRepositoryIntegrationTest.java | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) 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");