private Mono<ServerResponse> previewPost(ServerRequest request) {
        final var name = request.pathVariable("name");
        return currentAuthenticatedUserName()
            .flatMap(principal -> client.fetch(Post.class, name))
            .flatMap(post -> {
                String snapshotName = request.queryParam(SNAPSHOT_NAME_PARAM)
                    .orElse(post.getSpec().getHeadSnapshot());
                return convertToPostVo(post, snapshotName);
            })
            .flatMap(post -> canPreview(post.getContributors())
                .doOnNext(canPreview -> {
                    if (!canPreview) {
                        throw new NotFoundException("Post not found.");
                    }
                })
                .thenReturn(post)
            )
            // Check permissions before throwing this exception
            .switchIfEmpty(Mono.error(() -> new NotFoundException("Post not found.")))
            .flatMap(postVo -> {
                String template = postVo.getSpec().getTemplate();
                Map<String, Object> model = ModelMapUtils.postModel(postVo);
                return viewNameResolver.resolveViewNameOrDefault(request, template,
                        DefaultTemplateEnum.POST.getValue())
                    .flatMap(templateName -> ServerResponse.ok().render(templateName, model));
            });
    }
@Test
    @WithMockUser(username = "testuser")
    public void previewPost() {
        Post post = new Post();
        post.setMetadata(new Metadata());
        post.getMetadata().setName("post1");
        post.setSpec(new Post.PostSpec());
        post.getSpec().setOwner("testuser");
        post.getSpec().setHeadSnapshot("snapshot1");
        post.getSpec().setBaseSnapshot("snapshot2");
        post.getSpec().setTemplate("postTemplate");
        when(client.fetch(eq(Post.class), eq("post1"))).thenReturn(Mono.just(post));

        PostVo postVo = PostVo.from(post);
        postVo.setContributors(contributorVos());
        when(postPublicQueryService.convertToVo(eq(post), eq(post.getSpec().getHeadSnapshot())))
            .thenReturn(Mono.just(postVo));

        when(viewNameResolver.resolveViewNameOrDefault(any(ServerRequest.class),
            eq("postTemplate"), eq("post"))).thenReturn(Mono.just("postView"));

        webTestClient.get().uri("/preview/posts/post1")
            .exchange()
            .expectStatus().isOk();

        verify(viewResolver).resolveViewName(any(), any());
        verify(postPublicQueryService).convertToVo(eq(post), eq(post.getSpec().getHeadSnapshot()));
        verify(client).fetch(eq(Post.class), eq("post1"));
    }