mirror of https://gitee.com/answerdev/answer.git
update revision audit
This commit is contained in:
parent
d1f4793394
commit
b5b1a10df4
|
@ -164,7 +164,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
|
|||
searchService := service.NewSearchService(searchParser, searchRepo)
|
||||
searchController := controller.NewSearchController(searchService)
|
||||
serviceRevisionService := service.NewRevisionService(revisionRepo, userCommon, questionCommon, answerService, objService)
|
||||
revisionController := controller.NewRevisionController(serviceRevisionService)
|
||||
revisionController := controller.NewRevisionController(serviceRevisionService, rankService)
|
||||
rankController := controller.NewRankController(rankService)
|
||||
commonRepo := common.NewCommonRepo(dataData, uniqueIDRepo)
|
||||
reportHandle := report_handle_backyard.NewReportHandle(questionCommon, commentRepo, configRepo)
|
||||
|
|
58
docs/docs.go
58
docs/docs.go
|
@ -3069,8 +3069,49 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/answer/api/v1/revisions/audit": {
|
||||
"put": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "revision audit operation:approve or reject",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Revision"
|
||||
],
|
||||
"summary": "revision audit",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "audit",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.RevisionAuditReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/handler.RespBody"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/answer/api/v1/revisions/unreviewed": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "get unreviewed revision list",
|
||||
"produces": [
|
||||
"application/json"
|
||||
|
@ -6013,6 +6054,23 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"schema.RevisionAuditReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"operation"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"description": "object id",
|
||||
"type": "string"
|
||||
},
|
||||
"operation": {
|
||||
"description": "approve or reject",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema.SearchListResp": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
@ -3057,8 +3057,49 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/answer/api/v1/revisions/audit": {
|
||||
"put": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "revision audit operation:approve or reject",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Revision"
|
||||
],
|
||||
"summary": "revision audit",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "audit",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.RevisionAuditReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/handler.RespBody"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/answer/api/v1/revisions/unreviewed": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "get unreviewed revision list",
|
||||
"produces": [
|
||||
"application/json"
|
||||
|
@ -6001,6 +6042,23 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"schema.RevisionAuditReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"operation"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"description": "object id",
|
||||
"type": "string"
|
||||
},
|
||||
"operation": {
|
||||
"description": "approve or reject",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema.SearchListResp": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
@ -1069,6 +1069,18 @@ definitions:
|
|||
- flagged_type
|
||||
- id
|
||||
type: object
|
||||
schema.RevisionAuditReq:
|
||||
properties:
|
||||
id:
|
||||
description: object id
|
||||
type: string
|
||||
operation:
|
||||
description: approve or reject
|
||||
type: string
|
||||
required:
|
||||
- id
|
||||
- operation
|
||||
type: object
|
||||
schema.SearchListResp:
|
||||
properties:
|
||||
count:
|
||||
|
@ -3494,6 +3506,28 @@ paths:
|
|||
summary: get revision list
|
||||
tags:
|
||||
- Revision
|
||||
/answer/api/v1/revisions/audit:
|
||||
put:
|
||||
description: revision audit operation:approve or reject
|
||||
parameters:
|
||||
- description: audit
|
||||
in: body
|
||||
name: data
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/schema.RevisionAuditReq'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/handler.RespBody'
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: revision audit
|
||||
tags:
|
||||
- Revision
|
||||
/answer/api/v1/revisions/unreviewed:
|
||||
get:
|
||||
description: get unreviewed revision list
|
||||
|
@ -3517,6 +3551,8 @@ paths:
|
|||
$ref: '#/definitions/schema.GetRevisionResp'
|
||||
type: array
|
||||
type: object
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: get unreviewed revision list
|
||||
tags:
|
||||
- Revision
|
||||
|
|
|
@ -57,6 +57,7 @@ func (rc *RevisionController) GetRevisionList(ctx *gin.Context) {
|
|||
// @Description get unreviewed revision list
|
||||
// @Tags Revision
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param page query string true "page id"
|
||||
// @Success 200 {object} handler.RespBody{data=[]schema.GetRevisionResp}
|
||||
// @Router /answer/api/v1/revisions/unreviewed [get]
|
||||
|
@ -69,7 +70,7 @@ func (rc *RevisionController) GetUnreviewedRevisionList(ctx *gin.Context) {
|
|||
userinfo := middleware.GetUserInfoFromContext(ctx)
|
||||
if !userinfo.IsAdmin {
|
||||
userID := middleware.GetLoginUserIDFromContext(ctx)
|
||||
if can, err := rc.rankService.CheckRankPermission(ctx, userID, rank.QuestionEditRank); err != nil || !can {
|
||||
if can, err := rc.rankService.CheckRankPermission(ctx, userID, rank.UnreviewedRevisionListRank); err != nil || !can {
|
||||
handler.HandleResponse(ctx, err, errors.Forbidden(reason.RankFailToMeetTheCondition))
|
||||
return
|
||||
}
|
||||
|
@ -81,3 +82,30 @@ func (rc *RevisionController) GetUnreviewedRevisionList(ctx *gin.Context) {
|
|||
"count": count,
|
||||
})
|
||||
}
|
||||
|
||||
// RevisionAudit godoc
|
||||
// @Summary revision audit
|
||||
// @Description revision audit operation:approve or reject
|
||||
// @Tags Revision
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param data body schema.RevisionAuditReq true "audit"
|
||||
// @Success 200 {object} handler.RespBody{}
|
||||
// @Router /answer/api/v1/revisions/audit [put]
|
||||
func (rc *RevisionController) RevisionAudit(ctx *gin.Context) {
|
||||
req := &schema.RevisionAuditReq{}
|
||||
if handler.BindAndCheck(ctx, req) {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
err := rc.revisionListService.RevisionAudit(ctx, req)
|
||||
handler.HandleResponse(ctx, err, gin.H{})
|
||||
}
|
||||
|
|
|
@ -79,6 +79,21 @@ func (rr *revisionRepo) UpdateObjectRevisionId(ctx context.Context, revision *en
|
|||
return nil
|
||||
}
|
||||
|
||||
// UpdateStatus update revision status
|
||||
func (rr *revisionRepo) UpdateStatus(ctx context.Context, id string, status int) (err error) {
|
||||
if id == "" {
|
||||
return nil
|
||||
}
|
||||
var data entity.Revision
|
||||
data.ID = id
|
||||
data.Status = status
|
||||
_, err = rr.data.DB.Where("id =?", id).Cols("status").Update(&data)
|
||||
if err != nil {
|
||||
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetRevision get revision one
|
||||
func (rr *revisionRepo) GetRevision(ctx context.Context, id string) (
|
||||
revision *entity.Revision, exist bool, err error,
|
||||
|
|
|
@ -140,9 +140,14 @@ func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {
|
|||
//siteinfo
|
||||
r.GET("/siteinfo", a.siteinfoController.GetSiteInfo)
|
||||
r.GET("/siteinfo/legal", a.siteinfoController.GetSiteLegalInfo)
|
||||
|
||||
}
|
||||
|
||||
func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) {
|
||||
//revisions
|
||||
r.GET("/revisions/unreviewed", a.revisionController.GetUnreviewedRevisionList)
|
||||
r.PUT("/revisions/audit", a.revisionController.RevisionAudit)
|
||||
|
||||
// comment
|
||||
r.POST("/comment", a.commentController.AddComment)
|
||||
r.DELETE("/comment", a.commentController.RemoveComment)
|
||||
|
@ -209,9 +214,6 @@ func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) {
|
|||
r.GET("/activity/timeline", a.activityController.GetObjectTimeline)
|
||||
r.GET("/activity/timeline/detail", a.activityController.GetObjectTimelineDetail)
|
||||
|
||||
//revisions
|
||||
r.GET("/revisions/unreviewed", a.revisionController.GetUnreviewedRevisionList)
|
||||
|
||||
}
|
||||
|
||||
func (a *AnswerAPIRouter) RegisterAnswerCmsAPIRouter(r *gin.RouterGroup) {
|
||||
|
|
|
@ -26,6 +26,17 @@ type GetRevisionListReq struct {
|
|||
ObjectID string `validate:"required" comment:"object_id" form:"object_id"`
|
||||
}
|
||||
|
||||
const RevisionAuditApprove = "approve"
|
||||
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:"-"`
|
||||
}
|
||||
|
||||
type RevisionSearch struct {
|
||||
Page int `json:"page" form:"page"` // Query number of pages
|
||||
}
|
||||
|
|
|
@ -17,27 +17,29 @@ 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"
|
||||
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"
|
||||
)
|
||||
|
||||
type UserRankRepo interface {
|
||||
|
|
|
@ -16,4 +16,5 @@ type RevisionRepo interface {
|
|||
UpdateObjectRevisionId(ctx context.Context, revision *entity.Revision, session *xorm.Session) (err error)
|
||||
ExistUnreviewedByObjectID(ctx context.Context, objectID string) (revision *entity.Revision, exist bool, err error)
|
||||
SearchUnreviewedList(ctx context.Context, search *entity.RevisionSearch) ([]*entity.Revision, int64, error)
|
||||
UpdateStatus(ctx context.Context, id string, status int) (err error)
|
||||
}
|
||||
|
|
|
@ -38,6 +38,25 @@ func NewRevisionService(
|
|||
objectInfoService: objectInfoService,
|
||||
}
|
||||
}
|
||||
func (rs *RevisionService) RevisionAudit(ctx context.Context, req *schema.RevisionAuditReq) (err error) {
|
||||
revisioninfo, exist, err := rs.revisionRepo.GetRevisionByID(ctx, req.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if !exist {
|
||||
return
|
||||
}
|
||||
if revisioninfo.Status != entity.RevisionUnreviewedStatus {
|
||||
return
|
||||
}
|
||||
if req.Operation == schema.RevisionAuditReject {
|
||||
revisioninfo.Status = entity.RevisionReviewRejectStatus
|
||||
err = rs.revisionRepo.UpdateStatus(ctx, req.ID, entity.RevisionReviewRejectStatus)
|
||||
return
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SearchUnreviewedList get unreviewed list
|
||||
func (rs *RevisionService) GetUnreviewedRevisionList(ctx context.Context, req *schema.RevisionSearch) (resp []*schema.GetUnreviewedRevisionResp, count int64, err error) {
|
||||
|
|
Loading…
Reference in New Issue