This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a commit to branch test
in repository https://gitbox.apache.org/repos/asf/answer.git
The following commit(s) were added to refs/heads/test by this push:
new 9ea13af8 feat(revision): enhance revision management with object
status handling
9ea13af8 is described below
commit 9ea13af8606976a447e6f3b416c325627ee4fa79
Author: LinkinStars <[email protected]>
AuthorDate: Tue Jan 27 17:38:47 2026 +0800
feat(revision): enhance revision management with object status handling
---
internal/controller/revision_controller.go | 2 ++
internal/router/answer_api_router.go | 4 +---
internal/schema/revision_schema.go | 2 ++
internal/schema/simple_obj_info_schema.go | 3 +++
internal/service/content/revision_service.go | 17 +++++++++++++++++
internal/service/object_info/object_info.go | 12 +++++++-----
6 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/internal/controller/revision_controller.go
b/internal/controller/revision_controller.go
index 13bee19c..57574375 100644
--- a/internal/controller/revision_controller.go
+++ b/internal/controller/revision_controller.go
@@ -69,6 +69,8 @@ func (rc *RevisionController) GetRevisionList(ctx
*gin.Context) {
objectID = uid.DeShortID(objectID)
req := &schema.GetRevisionListReq{
ObjectID: objectID,
+ IsAdmin: middleware.GetUserIsAdminModerator(ctx),
+ UserID: middleware.GetLoginUserIDFromContext(ctx),
}
resp, err := rc.revisionListService.GetRevisionList(ctx, req)
diff --git a/internal/router/answer_api_router.go
b/internal/router/answer_api_router.go
index fc53ec45..c642b2a1 100644
--- a/internal/router/answer_api_router.go
+++ b/internal/router/answer_api_router.go
@@ -188,9 +188,6 @@ func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r
*gin.RouterGroup) {
r.GET("/personal/comment/page",
a.commentController.GetCommentPersonalWithPage)
r.GET("/comment", a.commentController.GetComment)
- // revision
- r.GET("/revisions", a.revisionController.GetRevisionList)
-
// tag
r.GET("/tags/page", a.tagController.GetTagWithPage)
r.GET("/tags/following", a.tagController.GetFollowingTags)
@@ -224,6 +221,7 @@ func (a *AnswerAPIRouter)
RegisterAuthUserWithAnyStatusAnswerAPIRouter(r *gin.Ro
func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) {
// revisions
+ r.GET("/revisions", a.revisionController.GetRevisionList)
r.GET("/revisions/unreviewed",
a.revisionController.GetUnreviewedRevisionList)
r.PUT("/revisions/audit", a.revisionController.RevisionAudit)
r.GET("/revisions/edit/check",
a.revisionController.CheckCanUpdateRevision)
diff --git a/internal/schema/revision_schema.go
b/internal/schema/revision_schema.go
index 6f3246e5..dad067f4 100644
--- a/internal/schema/revision_schema.go
+++ b/internal/schema/revision_schema.go
@@ -45,6 +45,8 @@ type AddRevisionDTO struct {
type GetRevisionListReq struct {
// object id
ObjectID string `validate:"required" comment:"object_id"
form:"object_id"`
+ IsAdmin bool `json:"-"`
+ UserID string `json:"-"`
}
const RevisionAuditApprove = "approve"
diff --git a/internal/schema/simple_obj_info_schema.go
b/internal/schema/simple_obj_info_schema.go
index a9bcf3b1..21a03ae2 100644
--- a/internal/schema/simple_obj_info_schema.go
+++ b/internal/schema/simple_obj_info_schema.go
@@ -35,6 +35,7 @@ type SimpleObjectInfo struct {
CommentID string `json:"comment_id"`
CommentStatus int `json:"comment_status"`
TagID string `json:"tag_id"`
+ TagStatus int `json:"tag_status"`
ObjectType string `json:"object_type"`
Title string `json:"title"`
Content string `json:"content"`
@@ -49,6 +50,8 @@ func (s *SimpleObjectInfo) IsDeleted() bool {
return s.AnswerStatus == entity.AnswerStatusDeleted
case constant.CommentObjectType:
return s.CommentStatus == entity.CommentStatusDeleted
+ case constant.TagObjectType:
+ return s.TagStatus == entity.TagStatusDeleted
}
return false
}
diff --git a/internal/service/content/revision_service.go
b/internal/service/content/revision_service.go
index 13ec65b7..66e6181f 100644
--- a/internal/service/content/revision_service.go
+++ b/internal/service/content/revision_service.go
@@ -388,6 +388,23 @@ func (rs *RevisionService) GetRevisionList(ctx
context.Context, req *schema.GetR
)
resp = []schema.GetRevisionResp{}
+ objInfo, infoErr := rs.objectInfoService.GetInfo(ctx, req.ObjectID)
+ if infoErr != nil {
+ return nil, infoErr
+ }
+ if !req.IsAdmin && objInfo.IsDeleted() && objInfo.ObjectCreatorUserID
!= req.UserID {
+ switch objInfo.ObjectType {
+ case constant.QuestionObjectType:
+ return nil, errors.NotFound(reason.QuestionNotFound)
+ case constant.AnswerObjectType:
+ return nil, errors.NotFound(reason.AnswerNotFound)
+ case constant.TagObjectType:
+ return nil, errors.NotFound(reason.TagNotFound)
+ default:
+ return nil, errors.NotFound(reason.ObjectNotFound)
+ }
+ }
+
_ = copier.Copy(&rev, req)
revs, err = rs.revisionRepo.GetRevisionList(ctx, &rev)
diff --git a/internal/service/object_info/object_info.go
b/internal/service/object_info/object_info.go
index 5ef438ff..6380b880 100644
--- a/internal/service/object_info/object_info.go
+++ b/internal/service/object_info/object_info.go
@@ -277,11 +277,13 @@ func (os *ObjService) GetInfo(ctx context.Context,
objectID string) (objInfo *sc
break
}
objInfo = &schema.SimpleObjectInfo{
- ObjectID: tagInfo.ID,
- TagID: tagInfo.ID,
- ObjectType: objectType,
- Title: tagInfo.SlugName,
- Content: tagInfo.ParsedText, // todo trim
+ ObjectID: tagInfo.ID,
+ ObjectCreatorUserID: tagInfo.UserID,
+ TagID: tagInfo.ID,
+ TagStatus: tagInfo.Status,
+ ObjectType: objectType,
+ Title: tagInfo.SlugName,
+ Content: tagInfo.ParsedText, // todo trim
}
}
if objInfo == nil {