update answer

This commit is contained in:
aichy126 2023-03-07 17:56:51 +08:00 committed by LinkinStars
parent f85304f2b9
commit b00cfbf775
2 changed files with 20 additions and 0 deletions

View File

@ -136,6 +136,24 @@ func (ac *AnswerController) Add(ctx *gin.Context) {
handler.HandleResponse(ctx, nil, nil)
return
}
canList, err := ac.rankService.CheckOperationPermissions(ctx, req.UserID, []string{
permission.AnswerEdit,
permission.AnswerDelete,
})
if err != nil {
handler.HandleResponse(ctx, err, nil)
return
}
objectOwner := ac.rankService.CheckOperationObjectOwner(ctx, req.UserID, info.ID)
req.CanEdit = canList[0] || objectOwner
req.CanDelete = canList[1] || objectOwner
if !can {
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
return
}
info.MemberActions = permission.GetAnswerPermission(ctx, req.UserID, info.UserID, req.CanEdit, req.CanDelete)
handler.HandleResponse(ctx, nil, gin.H{
"info": info,
"question": questionInfo,

View File

@ -24,6 +24,8 @@ type AnswerAddReq struct {
Content string `validate:"required,notblank,gte=6,lte=65535" json:"content"`
HTML string `json:"-"`
UserID string `json:"-"`
CanEdit bool `json:"-"`
CanDelete bool `json:"-"`
}
func (req *AnswerAddReq) Check() (errFields []*validator.FormErrorField, err error) {