mirror of https://gitee.com/answerdev/answer.git
Merge branch 'feat/0.5.0/timeline_ai' into test
This commit is contained in:
commit
d90f95157a
|
@ -95,6 +95,11 @@ backend:
|
|||
theme:
|
||||
not_found:
|
||||
other: "Theme not found."
|
||||
revision:
|
||||
review_underway:
|
||||
other: "Revision review underway."
|
||||
no_permission:
|
||||
other: "No permission to Revision."
|
||||
user:
|
||||
email_or_password_wrong:
|
||||
other: *email_or_password_wrong
|
||||
|
|
|
@ -55,4 +55,6 @@ const (
|
|||
UploadFileSourceUnsupported = "error.upload.source_unsupported"
|
||||
RecommendTagNotExist = "error.tag.recommend_tag_not_found"
|
||||
RecommendTagEnter = "error.tag.recommend_tag_enter"
|
||||
RevisionReviewUnderway = "error.revision.review_underway"
|
||||
RevisionNoPermission = "error.revision.no_permission"
|
||||
)
|
||||
|
|
|
@ -67,16 +67,18 @@ func (rc *RevisionController) GetUnreviewedRevisionList(ctx *gin.Context) {
|
|||
}
|
||||
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
|
||||
can, err := rc.rankService.CheckOperationPermission(ctx, req.UserID, rank.UnreviewedRevisionListRank, "")
|
||||
canList, err := rc.rankService.CheckOperationPermissions(ctx, req.UserID, []string{
|
||||
rank.QuestionAuditRank,
|
||||
rank.AnswerAuditRank,
|
||||
rank.TagAuditRank,
|
||||
}, "")
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
req.CanReviewQuestion = canList[0]
|
||||
req.CanReviewAnswer = canList[1]
|
||||
req.CanReviewTag = canList[2]
|
||||
|
||||
resp, count, err := rc.revisionListService.GetUnreviewedRevisionList(ctx, req)
|
||||
handler.HandleResponse(ctx, err, gin.H{
|
||||
|
@ -100,15 +102,18 @@ func (rc *RevisionController) RevisionAudit(ctx *gin.Context) {
|
|||
return
|
||||
}
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
can, err := rc.rankService.CheckOperationPermission(ctx, req.UserID, rank.RevisionAuditRank, "")
|
||||
canList, err := rc.rankService.CheckOperationPermissions(ctx, req.UserID, []string{
|
||||
rank.QuestionAuditRank,
|
||||
rank.AnswerAuditRank,
|
||||
rank.TagAuditRank,
|
||||
}, "")
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
return
|
||||
}
|
||||
req.CanReviewQuestion = canList[0]
|
||||
req.CanReviewAnswer = canList[1]
|
||||
req.CanReviewTag = canList[2]
|
||||
|
||||
err = rc.revisionListService.RevisionAudit(ctx, req)
|
||||
handler.HandleResponse(ctx, err, gin.H{})
|
||||
|
|
|
@ -27,7 +27,10 @@ type Revision struct {
|
|||
}
|
||||
|
||||
type RevisionSearch struct {
|
||||
Page int `json:"page" form:"page"` // Query number of pages
|
||||
Page int `json:"page" form:"page"` // Query number of pages
|
||||
CanReviewQuestion bool `json:"-"`
|
||||
CanReviewAnswer bool `json:"-"`
|
||||
CanReviewTag bool `json:"-"`
|
||||
}
|
||||
|
||||
// TableName revision table name
|
||||
|
|
|
@ -176,8 +176,21 @@ func (rr *revisionRepo) SearchUnreviewedList(ctx context.Context, search *entity
|
|||
}
|
||||
PageSize := 1
|
||||
offset := search.Page * PageSize
|
||||
objectType := make([]int, 0)
|
||||
if search.CanReviewAnswer {
|
||||
objectType = append(objectType, constant.ObjectTypeStrMapping[constant.AnswerObjectType])
|
||||
}
|
||||
if search.CanReviewQuestion {
|
||||
objectType = append(objectType, constant.ObjectTypeStrMapping[constant.QuestionObjectType])
|
||||
}
|
||||
if search.CanReviewTag {
|
||||
objectType = append(objectType, constant.ObjectTypeStrMapping[constant.TagObjectType])
|
||||
}
|
||||
|
||||
session := rr.data.DB.Where("")
|
||||
session = session.And("status = ?", entity.RevisionUnreviewedStatus)
|
||||
session = session.In("object_type", objectType)
|
||||
session = session.And("status = ?", entity.RevisionUnreviewedStatus)
|
||||
session = session.OrderBy("created_at desc")
|
||||
session = session.Limit(PageSize, offset)
|
||||
count, err = session.FindAndCount(&rows)
|
||||
|
|
|
@ -31,15 +31,20 @@ const RevisionAuditReject = "reject"
|
|||
|
||||
type RevisionAuditReq struct {
|
||||
// object id
|
||||
ID string `validate:"required" comment:"id" form:"id"`
|
||||
Operation string `validate:"required" comment:"operation" form:"operation"` //approve or reject
|
||||
UserID string `json:"-" ` // user_id
|
||||
// IsAdmin bool `json:"-"`
|
||||
ID string `validate:"required" comment:"id" form:"id"`
|
||||
Operation string `validate:"required" comment:"operation" form:"operation"` //approve or reject
|
||||
UserID string `json:"-"`
|
||||
CanReviewQuestion bool `json:"-"`
|
||||
CanReviewAnswer bool `json:"-"`
|
||||
CanReviewTag bool `json:"-"`
|
||||
}
|
||||
|
||||
type RevisionSearch struct {
|
||||
Page int `json:"page" form:"page"` // Query number of pages
|
||||
UserID string `json:"-"`
|
||||
Page int `json:"page" form:"page"` // Query number of pages
|
||||
CanReviewQuestion bool `json:"-"`
|
||||
CanReviewAnswer bool `json:"-"`
|
||||
CanReviewTag bool `json:"-"`
|
||||
UserID string `json:"-"`
|
||||
}
|
||||
|
||||
type GetUnreviewedRevisionResp struct {
|
||||
|
|
|
@ -846,5 +846,9 @@ func (qs *QuestionService) CheckCanUpdate(ctx context.Context, req *schema.Check
|
|||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if existUnreviewed {
|
||||
err = errors.BadRequest(reason.RevisionReviewUnderway)
|
||||
return existUnreviewed, err
|
||||
}
|
||||
return existUnreviewed, nil
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ const (
|
|||
CommentAddRank = "rank.comment.add"
|
||||
CommentEditRank = "rank.comment.edit"
|
||||
CommentDeleteRank = "rank.comment.delete"
|
||||
CommentVoteUpRank = "rank.comment.vote_up"
|
||||
CommentVoteDownRank = "rank.comment.vote_down"
|
||||
ReportAddRank = "rank.report.add"
|
||||
TagAddRank = "rank.tag.add"
|
||||
TagEditRank = "rank.tag.edit"
|
||||
|
@ -41,8 +43,9 @@ const (
|
|||
TagSynonymRank = "rank.tag.synonym"
|
||||
LinkUrlLimitRank = "rank.link.url_limit"
|
||||
VoteDetailRank = "rank.vote.detail"
|
||||
RevisionAuditRank = "rank.revision.audit"
|
||||
UnreviewedRevisionListRank = "rank.revision.unreviewed_list"
|
||||
AnswerAuditRank = "rank.answer.audit"
|
||||
QuestionAuditRank = "rank.question.audit"
|
||||
TagAuditRank = "rank.tag.audit"
|
||||
)
|
||||
|
||||
type UserRankRepo interface {
|
||||
|
|
|
@ -89,11 +89,23 @@ func (rs *RevisionService) RevisionAudit(ctx context.Context, req *schema.Revisi
|
|||
var saveErr error
|
||||
switch objectType {
|
||||
case constant.QuestionObjectType:
|
||||
saveErr = rs.revisionAuditQuestion(ctx, revisionitem)
|
||||
if !req.CanReviewQuestion {
|
||||
saveErr = errors.BadRequest(reason.RevisionNoPermission)
|
||||
} else {
|
||||
saveErr = rs.revisionAuditQuestion(ctx, revisionitem)
|
||||
}
|
||||
case constant.AnswerObjectType:
|
||||
saveErr = rs.revisionAuditAnswer(ctx, revisionitem)
|
||||
if !req.CanReviewAnswer {
|
||||
saveErr = errors.BadRequest(reason.RevisionNoPermission)
|
||||
} else {
|
||||
saveErr = rs.revisionAuditAnswer(ctx, revisionitem)
|
||||
}
|
||||
case constant.TagObjectType:
|
||||
saveErr = rs.revisionAuditTag(ctx, revisionitem)
|
||||
if !req.CanReviewTag {
|
||||
saveErr = errors.BadRequest(reason.RevisionNoPermission)
|
||||
} else {
|
||||
saveErr = rs.revisionAuditTag(ctx, revisionitem)
|
||||
}
|
||||
}
|
||||
if saveErr != nil {
|
||||
return saveErr
|
||||
|
@ -258,6 +270,18 @@ func (rs *RevisionService) GetUnreviewedRevisionList(ctx context.Context, req *s
|
|||
_ = copier.Copy(revisionitem, revision)
|
||||
rs.parseItem(ctx, revisionitem)
|
||||
item.UnreviewedInfo = revisionitem
|
||||
|
||||
// get user info
|
||||
userInfo, exists, e := rs.userCommon.GetUserBasicInfoByID(ctx, revisionitem.UserID)
|
||||
if e != nil {
|
||||
return resp, 0, e
|
||||
}
|
||||
if exists {
|
||||
var uinfo schema.UserBasicInfo
|
||||
err = copier.Copy(&uinfo, userInfo)
|
||||
item.UnreviewedInfo.UserInfo = uinfo
|
||||
}
|
||||
|
||||
resp = append(resp, item)
|
||||
}
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue