mirror of https://github.com/halo-dev/halo
feat: add API for recycle users own posts
parent
2c849d8361
commit
cd90771bb7
|
@ -50,4 +50,6 @@ public interface PostService {
|
|||
Mono<Post> revertToSpecifiedSnapshot(String postName, String snapshotName);
|
||||
|
||||
Mono<ContentWrapper> deleteContent(String postName, String snapshotName);
|
||||
|
||||
Mono<Post> recycleBy(String postName, String username);
|
||||
}
|
||||
|
|
|
@ -379,6 +379,15 @@ public class PostServiceImpl extends AbstractContentService implements PostServi
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Post> recycleBy(String postName, String username) {
|
||||
return getByUsername(postName, username)
|
||||
.flatMap(post -> updatePostWithRetry(post, record -> {
|
||||
record.getSpec().setDeleted(true);
|
||||
return record;
|
||||
}));
|
||||
}
|
||||
|
||||
private Mono<Post> updatePostWithRetry(Post post, UnaryOperator<Post> func) {
|
||||
return client.update(func.apply(post))
|
||||
.onErrorResume(OptimisticLockingFailureException.class,
|
||||
|
|
|
@ -124,13 +124,27 @@ public class UcPostEndpoint implements CustomEndpoint {
|
|||
.operationId("UnpublishMyPost")
|
||||
.description("Unpublish my post.")
|
||||
.parameter(namePathParam)
|
||||
.response(responseBuilder().implementation(Post.class)))
|
||||
.response(responseBuilder().implementation(Post.class))
|
||||
)
|
||||
.DELETE("/{name}/recycle", this::recycleMyPost, builder -> builder.tag(tag)
|
||||
.operationId("RecycleMyPost")
|
||||
.description("Move my post to recycle bin.")
|
||||
.parameter(namePathParam)
|
||||
.response(responseBuilder().implementation(Post.class))
|
||||
)
|
||||
.build(),
|
||||
builder -> {
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
private Mono<ServerResponse> recycleMyPost(ServerRequest request) {
|
||||
final var name = request.pathVariable("name");
|
||||
return getCurrentUser()
|
||||
.flatMap(username -> postService.recycleBy(name, username))
|
||||
.flatMap(post -> ServerResponse.ok().bodyValue(post));
|
||||
}
|
||||
|
||||
private Mono<ServerResponse> getMyPostDraft(ServerRequest request) {
|
||||
var name = request.pathVariable("name");
|
||||
var patched = request.queryParam("patched").map(Boolean::valueOf).orElse(false);
|
||||
|
|
|
@ -39,7 +39,8 @@ metadata:
|
|||
# Currently, yaml definition does not support i18n, please see https://github.com/halo-dev/halo/issues/3573
|
||||
rbac.authorization.halo.run/display-name: "Post Author"
|
||||
rbac.authorization.halo.run/dependencies: |
|
||||
[ "role-template-post-contributor", "role-template-post-publisher", "role-template-post-attachment-manager" ]
|
||||
[ "role-template-post-contributor", "role-template-post-publisher", "role-template-recycle-my-post",
|
||||
"role-template-post-attachment-manager" ]
|
||||
rules: [ ]
|
||||
|
||||
---
|
||||
|
@ -98,6 +99,23 @@ rules:
|
|||
resources: [ "posts/publish", "posts/unpublish" ]
|
||||
verbs: [ "update" ]
|
||||
|
||||
---
|
||||
apiVersion: v1alpha1
|
||||
kind: Role
|
||||
metadata:
|
||||
name: role-template-recycle-my-post
|
||||
labels:
|
||||
halo.run/role-template: "true"
|
||||
annotations:
|
||||
rbac.authorization.halo.run/module: "Posts Management"
|
||||
rbac.authorization.halo.run/display-name: "Recycle My Post"
|
||||
rbac.authorization.halo.run/ui-permissions: |
|
||||
[ "uc:posts:recycle" ]
|
||||
rules:
|
||||
- apiGroups: [ "uc.api.content.halo.run" ]
|
||||
resources: [ "posts/recycle" ]
|
||||
verbs: [ "delete" ]
|
||||
|
||||
---
|
||||
apiVersion: v1alpha1
|
||||
kind: Role
|
||||
|
|
Loading…
Reference in New Issue