feat: 更新删除评论逻辑,增加对目标内容所有者的权限检查;添加编辑者角色常量

This commit is contained in:
2025-09-13 23:46:07 +08:00
parent 8be05cd9c2
commit 78cc596544
2 changed files with 11 additions and 2 deletions

View File

@ -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
}