mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 11:06:23 +00:00
feat: 更新删除评论逻辑,增加对目标内容所有者的权限检查;添加编辑者角色常量
This commit is contained in:
@ -95,7 +95,15 @@ func (cs *CommentService) DeleteComment(ctx context.Context, commentID string) e
|
||||
return errs.New(errs.ErrNotFound.Code, "comment not found", err)
|
||||
}
|
||||
|
||||
if comment.UserID != currentUser.ID {
|
||||
isTargetOwner := false
|
||||
if comment.TargetType == constant.TargetTypePost {
|
||||
post, err := repo.Post.GetPostByID(strconv.Itoa(int(comment.TargetID)))
|
||||
if err == nil && post.UserID == currentUser.ID {
|
||||
isTargetOwner = true
|
||||
}
|
||||
}
|
||||
|
||||
if comment.UserID != currentUser.ID || isTargetOwner {
|
||||
return errs.ErrForbidden
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user