mirror of https://gitee.com/answerdev/answer.git
fix: incorrect answer permission setting
This commit is contained in:
parent
fa00ea3828
commit
d30cae05c7
|
@ -158,7 +158,6 @@ func (ac *AnswerController) Update(ctx *gin.Context) {
|
|||
return
|
||||
}
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
req.IsAdmin = middleware.GetIsAdminFromContext(ctx)
|
||||
|
||||
canList, err := ac.rankService.CheckOperationPermissions(ctx, req.UserID, []string{
|
||||
rank.AnswerEditRank,
|
||||
|
@ -168,11 +167,12 @@ func (ac *AnswerController) Update(ctx *gin.Context) {
|
|||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !canList[0] {
|
||||
req.CanEdit = canList[0]
|
||||
req.NoNeedReview = canList[1]
|
||||
if !req.CanEdit {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
req.NoNeedReview = canList[1]
|
||||
|
||||
_, err = ac.answerService.Update(ctx, req)
|
||||
if err != nil {
|
||||
|
@ -211,7 +211,6 @@ func (ac *AnswerController) AnswerList(ctx *gin.Context) {
|
|||
return
|
||||
}
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
req.IsAdmin = middleware.GetIsAdminFromContext(ctx)
|
||||
|
||||
canList, err := ac.rankService.CheckOperationPermissions(ctx, req.UserID, []string{
|
||||
rank.AnswerEditRank,
|
||||
|
|
|
@ -31,6 +31,8 @@ type AnswerUpdateReq struct {
|
|||
EditSummary string `validate:"omitempty" json:"edit_summary"` // edit_summary
|
||||
IsAdmin bool `json:"-"`
|
||||
NoNeedReview bool `json:"-"`
|
||||
// whether user can edit it
|
||||
CanEdit bool `json:"-"`
|
||||
}
|
||||
|
||||
type AnswerListReq struct {
|
||||
|
|
Loading…
Reference in New Issue