diff --git a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMail.java b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMail.java index a780e3d6883225dd238b908366be172535a96a65..ed84924b41b56f16d30afaf3cf5c259d52ca8c8e 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMail.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMail.java @@ -10,11 +10,9 @@ import javax.validation.constraints.Size; import com.fasterxml.jackson.annotation.JsonIgnore; -import de.itvsh.goofy.common.LinkedResource; import de.itvsh.goofy.common.binaryfile.FileId; import de.itvsh.goofy.common.command.CommandBody; import de.itvsh.goofy.common.user.UserId; -import de.itvsh.goofy.common.user.UserProfileController; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; @@ -42,7 +40,7 @@ public class PostfachMail implements CommandBody { private String vorgangId; private ZonedDateTime createdAt; - @LinkedResource(controllerClass = UserProfileController.class) + @JsonIgnore private UserId createdBy; private ZonedDateTime sentAt; diff --git a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailModelAssembler.java b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailModelAssembler.java index a323d38ae2e7194e2edfcf8f33fa3b656d9322dd..74734a95188d2896e2a6bd3f4dcc013f77f17278 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailModelAssembler.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailModelAssembler.java @@ -15,6 +15,7 @@ import org.springframework.stereotype.Component; import de.itvsh.goofy.common.ModelBuilder; import de.itvsh.goofy.common.binaryfile.BinaryFileController; import de.itvsh.goofy.common.command.CommandController.CommandByRelationController; +import de.itvsh.goofy.common.user.UserProfileController; import de.itvsh.goofy.postfach.PostfachMailController.PostfachMailCommandController; @Component @@ -24,10 +25,15 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac public static final String REL_RESEND_POSTFACH_MAIL = "resendPostfachMail"; public static final String REL_ATTACHMENTS = "attachments"; static final String REL_UPLOAD_ATTACHMENT = "uploadAttachment"; + static final String REL_CREATED_BY = "createdBy"; private static final Predicate<PostfachMail> SENT_FAILED = postfachMail -> BooleanUtils.isFalse(postfachMail.getSentSuccessful()); private static final Predicate<PostfachMail> HAS_ATTACHMENTS = nachricht -> !nachricht.getAttachments().isEmpty(); + static final String SYSTEM_USER_IDENTIFIER = "system"; + private static final Predicate<PostfachMail> SENT_BY_CLIENT_USER = postfachNachricht -> !postfachNachricht.getCreatedBy().toString() + .startsWith(SYSTEM_USER_IDENTIFIER); + public CollectionModel<EntityModel<PostfachMail>> toCollectionModel(Stream<PostfachMail> entities, String vorgangId, long vorgangVersion, Optional<String> postfachId) { CollectionModel<EntityModel<PostfachMail>> model = CollectionModel.of(entities.map(this::toModel).toList(), @@ -49,6 +55,8 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac .ifMatch(HAS_ATTACHMENTS) .addLink(linkTo(methodOn(PostfachMailController.class).findAttachments(PostfachNachrichtId.from(postfachMail.getId()))) .withRel(REL_ATTACHMENTS)) + .ifMatch(SENT_BY_CLIENT_USER) + .addLink(linkTo(UserProfileController.class).slash(postfachMail.getCreatedBy()).withRel(REL_CREATED_BY)) .buildModel(); } diff --git a/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailModelAssemblerTest.java b/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailModelAssemblerTest.java index b3b6db94568ed1eb142301e319d90736495d0709..8faa7b4cf65a9aebc068bcd67922978c6a53056e 100644 --- a/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailModelAssemblerTest.java +++ b/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailModelAssemblerTest.java @@ -1,8 +1,7 @@ package de.itvsh.goofy.postfach; -import static org.assertj.core.api.Assertions.*; - import java.util.Optional; +import java.util.UUID; import java.util.stream.Stream; import org.junit.jupiter.api.DisplayName; @@ -14,6 +13,9 @@ import org.springframework.hateoas.EntityModel; import org.springframework.hateoas.IanaLinkRelations; import org.springframework.hateoas.Link; +import static org.assertj.core.api.Assertions.*; + +import de.itvsh.goofy.common.user.UserId; import de.itvsh.goofy.vorgang.VorgangHeaderTestFactory; class PostfachMailModelAssemblerTest { @@ -78,6 +80,30 @@ class PostfachMailModelAssemblerTest { } } + @DisplayName("created by link") + @Nested + class TestCreatedByLink { + + @Test + void shouldBePresent() { + var link = modelAssembler.toModel(PostfachMailTestFactory.create()).getLink(PostfachMailModelAssembler.REL_CREATED_BY); + + assertThat(link).isPresent().get().extracting(Link::getHref) + .isEqualTo("/api/userProfiles/" + PostfachMailTestFactory.CREATED_BY); + } + + @DisplayName("should not be present if the value of createdBy starts with 'system'") + @Test + void shouldNOTBePresentOnSystemUser() { + var link = modelAssembler + .toModel(PostfachMailTestFactory.createBuilder() + .createdBy(UserId.from(PostfachMailModelAssembler.SYSTEM_USER_IDENTIFIER + UUID.randomUUID().toString())).build()) + .getLink(PostfachMailModelAssembler.REL_CREATED_BY); + + assertThat(link).isNotPresent(); + } + } + } @Nested