mirror of https://gitee.com/answerdev/answer.git
Merge branch 'feat/0.5.0/timeline_ai' into test
This commit is contained in:
commit
2c32be50b2
|
@ -51,12 +51,17 @@ func (ac *AnswerController) RemoveAnswer(ctx *gin.Context) {
|
|||
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
req.IsAdmin = middleware.GetIsAdminFromContext(ctx)
|
||||
if can, err := ac.rankService.CheckRankPermission(ctx, req.UserID, rank.AnswerDeleteRank, req.ID); err != nil || !can {
|
||||
handler.HandleResponse(ctx, err, errors.Forbidden(reason.RankFailToMeetTheCondition))
|
||||
can, err := ac.rankService.CheckOperationPermission(ctx, req.UserID, rank.AnswerDeleteRank, req.ID)
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
|
||||
err := ac.answerService.RemoveAnswer(ctx, req)
|
||||
err = ac.answerService.RemoveAnswer(ctx, req)
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
}
|
||||
|
||||
|
@ -105,8 +110,13 @@ func (ac *AnswerController) Add(ctx *gin.Context) {
|
|||
}
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
|
||||
if can, err := ac.rankService.CheckRankPermission(ctx, req.UserID, rank.AnswerAddRank, ""); err != nil || !can {
|
||||
handler.HandleResponse(ctx, err, errors.Forbidden(reason.RankFailToMeetTheCondition))
|
||||
can, err := ac.rankService.CheckOperationPermission(ctx, req.UserID, rank.AnswerAddRank, "")
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -149,12 +159,21 @@ func (ac *AnswerController) Update(ctx *gin.Context) {
|
|||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
req.IsAdmin = middleware.GetIsAdminFromContext(ctx)
|
||||
|
||||
if can, err := ac.rankService.CheckRankPermission(ctx, req.UserID, rank.AnswerEditRank, req.ID); err != nil || !can {
|
||||
handler.HandleResponse(ctx, err, errors.Forbidden(reason.RankFailToMeetTheCondition))
|
||||
canList, err := ac.rankService.CheckOperationPermissions(ctx, req.UserID, []string{
|
||||
rank.AnswerEditRank,
|
||||
rank.AnswerEditWithoutReviewRank,
|
||||
}, "")
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !canList[0] {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
req.NoNeedReview = canList[1]
|
||||
|
||||
_, err := ac.answerService.Update(ctx, req)
|
||||
_, err = ac.answerService.Update(ctx, req)
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
|
@ -220,12 +239,17 @@ func (ac *AnswerController) Adopted(ctx *gin.Context) {
|
|||
}
|
||||
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
if can, err := ac.rankService.CheckRankPermission(ctx, req.UserID, rank.AnswerAcceptRank, req.QuestionID); err != nil || !can {
|
||||
handler.HandleResponse(ctx, err, errors.Forbidden(reason.RankFailToMeetTheCondition))
|
||||
can, err := ac.rankService.CheckOperationPermission(ctx, req.UserID, rank.AnswerAcceptRank, req.QuestionID)
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
|
||||
err := ac.answerService.UpdateAdopted(ctx, req)
|
||||
err = ac.answerService.UpdateAdopted(ctx, req)
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
}
|
||||
|
||||
|
|
|
@ -41,8 +41,13 @@ func (cc *CommentController) AddComment(ctx *gin.Context) {
|
|||
}
|
||||
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
if can, err := cc.rankService.CheckRankPermission(ctx, req.UserID, rank.CommentAddRank, ""); err != nil || !can {
|
||||
handler.HandleResponse(ctx, err, errors.Forbidden(reason.RankFailToMeetTheCondition))
|
||||
can, err := cc.rankService.CheckOperationPermission(ctx, req.UserID, rank.CommentAddRank, "")
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -67,12 +72,17 @@ func (cc *CommentController) RemoveComment(ctx *gin.Context) {
|
|||
}
|
||||
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
if can, err := cc.rankService.CheckRankPermission(ctx, req.UserID, rank.CommentDeleteRank, req.CommentID); err != nil || !can {
|
||||
handler.HandleResponse(ctx, err, errors.Forbidden(reason.RankFailToMeetTheCondition))
|
||||
can, err := cc.rankService.CheckOperationPermission(ctx, req.UserID, rank.CommentDeleteRank, req.CommentID)
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
|
||||
err := cc.commentService.RemoveComment(ctx, req)
|
||||
err = cc.commentService.RemoveComment(ctx, req)
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
}
|
||||
|
||||
|
@ -93,12 +103,17 @@ func (cc *CommentController) UpdateComment(ctx *gin.Context) {
|
|||
}
|
||||
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
if can, err := cc.rankService.CheckRankPermission(ctx, req.UserID, rank.CommentEditRank, req.UserID); err != nil || !can {
|
||||
handler.HandleResponse(ctx, err, errors.Forbidden(reason.RankFailToMeetTheCondition))
|
||||
can, err := cc.rankService.CheckOperationPermission(ctx, req.UserID, rank.CommentEditRank, req.UserID)
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
|
||||
err := cc.commentService.UpdateComment(ctx, req)
|
||||
err = cc.commentService.UpdateComment(ctx, req)
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
}
|
||||
|
||||
|
|
|
@ -43,12 +43,17 @@ func (qc *QuestionController) RemoveQuestion(ctx *gin.Context) {
|
|||
}
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
req.IsAdmin = middleware.GetIsAdminFromContext(ctx)
|
||||
if can, err := qc.rankService.CheckRankPermission(ctx, req.UserID, rank.QuestionDeleteRank, req.ID); err != nil || !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), errors.Forbidden(reason.RankFailToMeetTheCondition))
|
||||
can, err := qc.rankService.CheckOperationPermission(ctx, req.UserID, rank.QuestionDeleteRank, req.ID)
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
|
||||
err := qc.questionService.RemoveQuestion(ctx, req)
|
||||
err = qc.questionService.RemoveQuestion(ctx, req)
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
}
|
||||
|
||||
|
@ -190,8 +195,13 @@ func (qc *QuestionController) AddQuestion(ctx *gin.Context) {
|
|||
}
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
|
||||
if can, err := qc.rankService.CheckRankPermission(ctx, req.UserID, rank.QuestionAddRank, ""); err != nil || !can {
|
||||
handler.HandleResponse(ctx, err, errors.Forbidden(reason.RankFailToMeetTheCondition))
|
||||
can, err := qc.rankService.CheckOperationPermission(ctx, req.UserID, rank.QuestionAddRank, "")
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -216,10 +226,19 @@ func (qc *QuestionController) UpdateQuestion(ctx *gin.Context) {
|
|||
}
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
req.IsAdmin = middleware.GetIsAdminFromContext(ctx)
|
||||
if can, err := qc.rankService.CheckRankPermission(ctx, req.UserID, rank.QuestionEditRank, req.ID); err != nil || !can {
|
||||
handler.HandleResponse(ctx, err, errors.Forbidden(reason.RankFailToMeetTheCondition))
|
||||
canList, err := qc.rankService.CheckOperationPermissions(ctx, req.UserID, []string{
|
||||
rank.QuestionEditRank,
|
||||
rank.QuestionEditWithoutReviewRank,
|
||||
}, "")
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !canList[0] {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
req.NoNeedReview = canList[1]
|
||||
|
||||
resp, err := qc.questionService.UpdateQuestion(ctx, req)
|
||||
handler.HandleResponse(ctx, err, resp)
|
||||
|
@ -242,8 +261,13 @@ func (qc *QuestionController) CheckCanUpdateQuestion(ctx *gin.Context) {
|
|||
}
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
req.IsAdmin = middleware.GetIsAdminFromContext(ctx)
|
||||
if can, err := qc.rankService.CheckRankPermission(ctx, req.UserID, rank.QuestionEditRank, req.ID); err != nil || !can {
|
||||
handler.HandleResponse(ctx, err, errors.Forbidden(reason.RankFailToMeetTheCondition))
|
||||
can, err := qc.rankService.CheckOperationPermission(ctx, req.UserID, rank.QuestionEditRank, req.ID)
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -40,12 +40,17 @@ func (rc *ReportController) AddReport(ctx *gin.Context) {
|
|||
}
|
||||
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
if can, err := rc.rankService.CheckRankPermission(ctx, req.UserID, rank.ReportAddRank, ""); err != nil || !can {
|
||||
handler.HandleResponse(ctx, err, errors.Forbidden(reason.RankFailToMeetTheCondition))
|
||||
can, err := rc.rankService.CheckOperationPermission(ctx, req.UserID, rank.ReportAddRank, "")
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
|
||||
err := rc.reportService.AddReport(ctx, req)
|
||||
err = rc.reportService.AddReport(ctx, req)
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"github.com/answerdev/answer/internal/schema"
|
||||
"github.com/answerdev/answer/internal/service"
|
||||
"github.com/answerdev/answer/internal/service/rank"
|
||||
"github.com/answerdev/answer/pkg/converter"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/segmentfault/pacman/errors"
|
||||
)
|
||||
|
@ -62,18 +61,21 @@ func (rc *RevisionController) GetRevisionList(ctx *gin.Context) {
|
|||
// @Success 200 {object} handler.RespBody{data=[]schema.GetRevisionResp}
|
||||
// @Router /answer/api/v1/revisions/unreviewed [get]
|
||||
func (rc *RevisionController) GetUnreviewedRevisionList(ctx *gin.Context) {
|
||||
pageStr := ctx.Query("page")
|
||||
page := converter.StringToInt(pageStr)
|
||||
req := &schema.RevisionSearch{
|
||||
Page: page,
|
||||
req := &schema.RevisionSearch{}
|
||||
if handler.BindAndCheck(ctx, req) {
|
||||
return
|
||||
}
|
||||
userinfo := middleware.GetUserInfoFromContext(ctx)
|
||||
if !userinfo.IsAdmin {
|
||||
userID := middleware.GetLoginUserIDFromContext(ctx)
|
||||
if can, err := rc.rankService.CheckRankPermission(ctx, userID, rank.UnreviewedRevisionListRank, ""); err != nil || !can {
|
||||
handler.HandleResponse(ctx, err, errors.Forbidden(reason.RankFailToMeetTheCondition))
|
||||
return
|
||||
}
|
||||
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
|
||||
can, err := rc.rankService.CheckOperationPermission(ctx, req.UserID, rank.UnreviewedRevisionListRank, "")
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
|
||||
resp, count, err := rc.revisionListService.GetUnreviewedRevisionList(ctx, req)
|
||||
|
@ -98,14 +100,16 @@ func (rc *RevisionController) RevisionAudit(ctx *gin.Context) {
|
|||
return
|
||||
}
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
userinfo := middleware.GetUserInfoFromContext(ctx)
|
||||
if !userinfo.IsAdmin {
|
||||
if can, err := rc.rankService.CheckRankPermission(ctx, req.UserID, rank.RevisionAuditRank, ""); err != nil || !can {
|
||||
handler.HandleResponse(ctx, err, errors.Forbidden(reason.RankFailToMeetTheCondition))
|
||||
return
|
||||
}
|
||||
can, err := rc.rankService.CheckOperationPermission(ctx, req.UserID, rank.RevisionAuditRank, "")
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
|
||||
err := rc.revisionListService.RevisionAudit(ctx, req)
|
||||
err = rc.revisionListService.RevisionAudit(ctx, req)
|
||||
handler.HandleResponse(ctx, err, gin.H{})
|
||||
}
|
||||
|
|
|
@ -63,8 +63,13 @@ func (tc *TagController) RemoveTag(ctx *gin.Context) {
|
|||
}
|
||||
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
if can, err := tc.rankService.CheckRankPermission(ctx, req.UserID, rank.TagDeleteRank, ""); err != nil || !can {
|
||||
handler.HandleResponse(ctx, err, errors.Forbidden(reason.RankFailToMeetTheCondition))
|
||||
can, err := tc.rankService.CheckOperationPermission(ctx, req.UserID, rank.TagDeleteRank, "")
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -88,12 +93,21 @@ func (tc *TagController) UpdateTag(ctx *gin.Context) {
|
|||
}
|
||||
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
if can, err := tc.rankService.CheckRankPermission(ctx, req.UserID, rank.TagEditRank, ""); err != nil || !can {
|
||||
handler.HandleResponse(ctx, err, errors.Forbidden(reason.RankFailToMeetTheCondition))
|
||||
canList, err := tc.rankService.CheckOperationPermissions(ctx, req.UserID, []string{
|
||||
rank.TagEditRank,
|
||||
rank.TagEditWithoutReviewRank,
|
||||
}, "")
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !canList[0] {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
req.NoNeedReview = canList[1]
|
||||
|
||||
err := tc.tagService.UpdateTag(ctx, req)
|
||||
err = tc.tagService.UpdateTag(ctx, req)
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
}
|
||||
|
||||
|
@ -190,11 +204,16 @@ func (tc *TagController) UpdateTagSynonym(ctx *gin.Context) {
|
|||
}
|
||||
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
if can, err := tc.rankService.CheckRankPermission(ctx, req.UserID, rank.TagSynonymRank, ""); err != nil || !can {
|
||||
handler.HandleResponse(ctx, err, errors.Forbidden(reason.RankFailToMeetTheCondition))
|
||||
can, err := tc.rankService.CheckOperationPermission(ctx, req.UserID, rank.TagSynonymRank, "")
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
|
||||
err := tc.tagService.UpdateTagSynonym(ctx, req)
|
||||
err = tc.tagService.UpdateTagSynonym(ctx, req)
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
}
|
||||
|
|
|
@ -22,14 +22,15 @@ type AnswerAddReq struct {
|
|||
}
|
||||
|
||||
type AnswerUpdateReq struct {
|
||||
ID string `json:"id"` // id
|
||||
QuestionID string `json:"question_id" ` // question_id
|
||||
UserID string `json:"-" ` // user_id
|
||||
Title string `json:"title" ` // title
|
||||
Content string `json:"content"` // content
|
||||
HTML string `json:"html" ` // html
|
||||
EditSummary string `validate:"omitempty" json:"edit_summary"` // edit_summary
|
||||
IsAdmin bool `json:"-"`
|
||||
ID string `json:"id"` // id
|
||||
QuestionID string `json:"question_id" ` // question_id
|
||||
UserID string `json:"-" ` // user_id
|
||||
Title string `json:"title" ` // title
|
||||
Content string `json:"content"` // content
|
||||
HTML string `json:"html" ` // html
|
||||
EditSummary string `validate:"omitempty" json:"edit_summary"` // edit_summary
|
||||
IsAdmin bool `json:"-"`
|
||||
NoNeedReview bool `json:"-"`
|
||||
}
|
||||
|
||||
type AnswerList struct {
|
||||
|
|
|
@ -56,8 +56,9 @@ type QuestionUpdate struct {
|
|||
// edit summary
|
||||
EditSummary string `validate:"omitempty" json:"edit_summary"`
|
||||
// user id
|
||||
UserID string `json:"-"`
|
||||
IsAdmin bool `json:"-"`
|
||||
UserID string `json:"-"`
|
||||
IsAdmin bool `json:"-"`
|
||||
NoNeedReview bool `json:"-"`
|
||||
}
|
||||
|
||||
type QuestionBaseInfo struct {
|
||||
|
|
|
@ -38,7 +38,8 @@ type RevisionAuditReq struct {
|
|||
}
|
||||
|
||||
type RevisionSearch struct {
|
||||
Page int `json:"page" form:"page"` // Query number of pages
|
||||
Page int `json:"page" form:"page"` // Query number of pages
|
||||
UserID string `json:"-"`
|
||||
}
|
||||
|
||||
type GetUnreviewedRevisionResp struct {
|
||||
|
|
|
@ -152,8 +152,9 @@ type UpdateTagReq struct {
|
|||
// edit summary
|
||||
EditSummary string `validate:"omitempty" json:"edit_summary"`
|
||||
// user id
|
||||
UserID string `json:"-"`
|
||||
IsAdmin bool `json:"-"`
|
||||
UserID string `json:"-"`
|
||||
IsAdmin bool `json:"-"`
|
||||
NoNeedReview bool `json:"-"`
|
||||
}
|
||||
|
||||
func (r *UpdateTagReq) Check() (errFields []*validator.FormErrorField, err error) {
|
||||
|
|
|
@ -195,6 +195,7 @@ func (as *AnswerService) Insert(ctx context.Context, req *schema.AnswerAddReq) (
|
|||
}
|
||||
|
||||
func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq) (string, error) {
|
||||
//req.NoNeedReview //true 不需要审核
|
||||
var canUpdate bool
|
||||
_, existUnreviewed, err := as.revisionService.ExistUnreviewedByObjectID(ctx, req.ID)
|
||||
if err != nil {
|
||||
|
@ -237,10 +238,13 @@ func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq
|
|||
Log: req.EditSummary,
|
||||
}
|
||||
|
||||
if answerInfo.UserID != req.UserID && !req.IsAdmin {
|
||||
if req.NoNeedReview || req.IsAdmin || answerInfo.UserID == req.UserID {
|
||||
canUpdate = true
|
||||
}
|
||||
|
||||
if !canUpdate {
|
||||
revisionDTO.Status = entity.RevisionUnreviewedStatus
|
||||
} else {
|
||||
canUpdate = true
|
||||
if err = as.answerRepo.UpdateAnswer(ctx, insertData, []string{"original_text", "parsed_text", "update_time"}); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -264,7 +264,7 @@ func (qs *QuestionService) RemoveQuestion(ctx context.Context, req *schema.Remov
|
|||
|
||||
// UpdateQuestion update question
|
||||
func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.QuestionUpdate) (questionInfo any, err error) {
|
||||
var canUpdateQuestion bool
|
||||
var canUpdate bool
|
||||
questionInfo = &schema.QuestionInfo{}
|
||||
|
||||
_, existUnreviewed, err := qs.revisionService.ExistUnreviewedByObjectID(ctx, req.ID)
|
||||
|
@ -345,11 +345,15 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
|
|||
Title: question.Title,
|
||||
Log: req.EditSummary,
|
||||
}
|
||||
|
||||
if req.NoNeedReview || req.IsAdmin || dbinfo.UserID == req.UserID {
|
||||
canUpdate = true
|
||||
}
|
||||
|
||||
// It's not you or the administrator that needs to be reviewed
|
||||
if dbinfo.UserID != req.UserID && !req.IsAdmin {
|
||||
if !canUpdate {
|
||||
revisionDTO.Status = entity.RevisionUnreviewedStatus
|
||||
} else {
|
||||
canUpdateQuestion = true
|
||||
//Direct modification
|
||||
revisionDTO.Status = entity.RevisionReviewPassStatus
|
||||
//update question to db
|
||||
|
@ -377,7 +381,7 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
if canUpdateQuestion {
|
||||
if canUpdate {
|
||||
activity_queue.AddActivity(&schema.ActivityMsg{
|
||||
UserID: req.UserID,
|
||||
ObjectID: question.ID,
|
||||
|
|
|
@ -3,7 +3,6 @@ package rank
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/answerdev/answer/internal/base/constant"
|
||||
"github.com/answerdev/answer/internal/base/pager"
|
||||
"github.com/answerdev/answer/internal/base/reason"
|
||||
"github.com/answerdev/answer/internal/entity"
|
||||
|
@ -18,29 +17,32 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
QuestionAddRank = "rank.question.add"
|
||||
QuestionEditRank = "rank.question.edit"
|
||||
QuestionDeleteRank = "rank.question.delete"
|
||||
QuestionVoteUpRank = "rank.question.vote_up"
|
||||
QuestionVoteDownRank = "rank.question.vote_down"
|
||||
AnswerAddRank = "rank.answer.add"
|
||||
AnswerEditRank = "rank.answer.edit"
|
||||
AnswerDeleteRank = "rank.answer.delete"
|
||||
AnswerAcceptRank = "rank.answer.accept"
|
||||
AnswerVoteUpRank = "rank.answer.vote_up"
|
||||
AnswerVoteDownRank = "rank.answer.vote_down"
|
||||
CommentAddRank = "rank.comment.add"
|
||||
CommentEditRank = "rank.comment.edit"
|
||||
CommentDeleteRank = "rank.comment.delete"
|
||||
ReportAddRank = "rank.report.add"
|
||||
TagAddRank = "rank.tag.add"
|
||||
TagEditRank = "rank.tag.edit"
|
||||
TagDeleteRank = "rank.tag.delete"
|
||||
TagSynonymRank = "rank.tag.synonym"
|
||||
LinkUrlLimitRank = "rank.link.url_limit"
|
||||
VoteDetailRank = "rank.vote.detail"
|
||||
RevisionAuditRank = "rank.revision.audit"
|
||||
UnreviewedRevisionListRank = "rank.revision.unreviewed_list"
|
||||
QuestionAddRank = "rank.question.add"
|
||||
QuestionEditRank = "rank.question.edit"
|
||||
QuestionEditWithoutReviewRank = "rank.question.edit_without_review"
|
||||
QuestionDeleteRank = "rank.question.delete"
|
||||
QuestionVoteUpRank = "rank.question.vote_up"
|
||||
QuestionVoteDownRank = "rank.question.vote_down"
|
||||
AnswerAddRank = "rank.answer.add"
|
||||
AnswerEditRank = "rank.answer.edit"
|
||||
AnswerEditWithoutReviewRank = "rank.answer.edit_without_review"
|
||||
AnswerDeleteRank = "rank.answer.delete"
|
||||
AnswerAcceptRank = "rank.answer.accept"
|
||||
AnswerVoteUpRank = "rank.answer.vote_up"
|
||||
AnswerVoteDownRank = "rank.answer.vote_down"
|
||||
CommentAddRank = "rank.comment.add"
|
||||
CommentEditRank = "rank.comment.edit"
|
||||
CommentDeleteRank = "rank.comment.delete"
|
||||
ReportAddRank = "rank.report.add"
|
||||
TagAddRank = "rank.tag.add"
|
||||
TagEditRank = "rank.tag.edit"
|
||||
TagEditWithoutReviewRank = "rank.tag.edit_without_review"
|
||||
TagDeleteRank = "rank.tag.delete"
|
||||
TagSynonymRank = "rank.tag.synonym"
|
||||
LinkUrlLimitRank = "rank.link.url_limit"
|
||||
VoteDetailRank = "rank.vote.detail"
|
||||
RevisionAuditRank = "rank.revision.audit"
|
||||
UnreviewedRevisionListRank = "rank.revision.unreviewed_list"
|
||||
)
|
||||
|
||||
type UserRankRepo interface {
|
||||
|
@ -70,8 +72,8 @@ func NewRankService(
|
|||
}
|
||||
}
|
||||
|
||||
// CheckRankPermission check whether the user reputation meets the permission
|
||||
func (rs *RankService) CheckRankPermission(ctx context.Context, userID string, action string, objectID string) (
|
||||
// CheckOperationPermission verify that the user has operation
|
||||
func (rs *RankService) CheckOperationPermission(ctx context.Context, userID string, action string, objectID string) (
|
||||
can bool, err error) {
|
||||
if len(userID) == 0 {
|
||||
return false, nil
|
||||
|
@ -93,24 +95,74 @@ func (rs *RankService) CheckRankPermission(ctx context.Context, userID string, a
|
|||
if len(objectID) > 0 {
|
||||
objectInfo, err := rs.objectInfoService.GetInfo(ctx, objectID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
log.Error(err)
|
||||
}
|
||||
// if the user is this object creator, the user can operate this object.
|
||||
// but if this object is tag, only users who have reached the rank level can operate.
|
||||
if objectInfo.ObjectCreatorUserID == userID && objectInfo.ObjectType != constant.TagObjectType {
|
||||
if objectInfo != nil &&
|
||||
objectInfo.ObjectCreatorUserID == userID {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
return rs.checkUserRank(ctx, userInfo.ID, userInfo.Rank, action)
|
||||
}
|
||||
|
||||
// CheckOperationPermissions verify that the user has operation
|
||||
func (rs *RankService) CheckOperationPermissions(ctx context.Context, userID string, actions []string, objectID string) (
|
||||
can []bool, err error) {
|
||||
can = make([]bool, len(actions))
|
||||
if len(userID) == 0 {
|
||||
return can, nil
|
||||
}
|
||||
|
||||
// get the rank of the current user
|
||||
userInfo, exist, err := rs.userCommon.GetUserBasicInfoByID(ctx, userID)
|
||||
if err != nil {
|
||||
return can, err
|
||||
}
|
||||
if !exist {
|
||||
return can, nil
|
||||
}
|
||||
|
||||
objectOwner := false
|
||||
if len(objectID) > 0 {
|
||||
objectInfo, err := rs.objectInfoService.GetInfo(ctx, objectID)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
// if the user is this object creator, the user can operate this object.
|
||||
if objectInfo != nil &&
|
||||
objectInfo.ObjectCreatorUserID == userID {
|
||||
objectOwner = true
|
||||
}
|
||||
}
|
||||
|
||||
for idx, action := range actions {
|
||||
if userInfo.IsAdmin || objectOwner {
|
||||
can[idx] = true
|
||||
continue
|
||||
}
|
||||
meetRank, err := rs.checkUserRank(ctx, userInfo.ID, userInfo.Rank, action)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
can[idx] = meetRank
|
||||
}
|
||||
return can, nil
|
||||
}
|
||||
|
||||
// CheckRankPermission verify that the user meets the prestige criteria
|
||||
func (rs *RankService) checkUserRank(ctx context.Context, userID string, userRank int, action string) (
|
||||
can bool, err error) {
|
||||
// get the amount of rank required for the current operation
|
||||
requireRank, err := rs.configRepo.GetInt(action)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
currentUserRank := userInfo.Rank
|
||||
currentUserRank := userRank
|
||||
if currentUserRank < requireRank {
|
||||
log.Debugf("user %s want to do action %s, but rank %d < %d",
|
||||
userInfo.DisplayName, action, currentUserRank, requireRank)
|
||||
userID, action, currentUserRank, requireRank)
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
|
|
|
@ -627,9 +627,7 @@ func (ts *TagCommonService) UpdateTag(ctx context.Context, req *schema.UpdateTag
|
|||
Log: req.EditSummary,
|
||||
}
|
||||
|
||||
if !req.IsAdmin {
|
||||
revisionDTO.Status = entity.RevisionUnreviewedStatus
|
||||
} else {
|
||||
if req.IsAdmin || req.NoNeedReview {
|
||||
canUpdate = true
|
||||
err = ts.tagRepo.UpdateTag(ctx, tagInfo)
|
||||
if err != nil {
|
||||
|
@ -651,6 +649,8 @@ func (ts *TagCommonService) UpdateTag(ctx context.Context, req *schema.UpdateTag
|
|||
}
|
||||
}
|
||||
revisionDTO.Status = entity.RevisionReviewPassStatus
|
||||
} else {
|
||||
revisionDTO.Status = entity.RevisionUnreviewedStatus
|
||||
}
|
||||
|
||||
tagInfoJson, _ := json.Marshal(tagInfo)
|
||||
|
|
Loading…
Reference in New Issue