feat: add content report governance

This commit is contained in:
2026-01-16 11:36:04 +08:00
parent 3af3c854c9
commit 609ca7b980
18 changed files with 2480 additions and 101 deletions

View File

@@ -0,0 +1,47 @@
package v1
import (
dto "quyun/v2/app/http/super/v1/dto"
"quyun/v2/app/requests"
"quyun/v2/app/services"
"quyun/v2/database/models"
"github.com/gofiber/fiber/v3"
)
// @provider
type contentReports struct{}
// List content reports
//
// @Router /super/v1/content-reports [get]
// @Summary List content reports
// @Description List content report records across tenants
// @Tags Content
// @Accept json
// @Produce json
// @Param page query int false "Page number"
// @Param limit query int false "Page size"
// @Success 200 {object} requests.Pager{items=[]dto.SuperContentReportItem}
// @Bind filter query
func (c *contentReports) List(ctx fiber.Ctx, filter *dto.SuperContentReportListFilter) (*requests.Pager, error) {
return services.Super.ListContentReports(ctx, filter)
}
// Process content report
//
// @Router /super/v1/content-reports/:id<int>/process [post]
// @Summary Process content report
// @Description Process a content report record
// @Tags Content
// @Accept json
// @Produce json
// @Param id path int64 true "Report ID"
// @Param form body dto.SuperContentReportProcessForm true "Process form"
// @Success 200 {string} string "Processed"
// @Bind user local key(__ctx_user)
// @Bind id path
// @Bind form body
func (c *contentReports) Process(ctx fiber.Ctx, user *models.User, id int64, form *dto.SuperContentReportProcessForm) error {
return services.Super.ProcessContentReport(ctx, user.ID, id, form)
}

View File

@@ -0,0 +1,100 @@
package dto
import "quyun/v2/app/requests"
// SuperContentReportListFilter 超管内容举报列表过滤条件。
type SuperContentReportListFilter struct {
requests.Pagination
// ID 举报ID精确匹配。
ID *int64 `query:"id"`
// TenantID 租户ID精确匹配。
TenantID *int64 `query:"tenant_id"`
// TenantCode 租户编码,模糊匹配。
TenantCode *string `query:"tenant_code"`
// TenantName 租户名称,模糊匹配。
TenantName *string `query:"tenant_name"`
// ContentID 内容ID精确匹配。
ContentID *int64 `query:"content_id"`
// ContentTitle 内容标题关键字,模糊匹配。
ContentTitle *string `query:"content_title"`
// ReporterID 举报人用户ID精确匹配。
ReporterID *int64 `query:"reporter_id"`
// ReporterName 举报人用户名/昵称,模糊匹配。
ReporterName *string `query:"reporter_name"`
// HandledBy 处理人用户ID精确匹配。
HandledBy *int64 `query:"handled_by"`
// HandledByName 处理人用户名/昵称,模糊匹配。
HandledByName *string `query:"handled_by_name"`
// Reason 举报原因关键字,模糊匹配。
Reason *string `query:"reason"`
// Keyword 举报描述关键字,模糊匹配。
Keyword *string `query:"keyword"`
// Status 处理状态pending/approved/rejected/all
Status *string `query:"status"`
// CreatedAtFrom 举报时间起始RFC3339
CreatedAtFrom *string `query:"created_at_from"`
// CreatedAtTo 举报时间结束RFC3339
CreatedAtTo *string `query:"created_at_to"`
// HandledAtFrom 处理时间起始RFC3339
HandledAtFrom *string `query:"handled_at_from"`
// HandledAtTo 处理时间结束RFC3339
HandledAtTo *string `query:"handled_at_to"`
// Asc 升序字段id/created_at/handled_at/status
Asc *string `query:"asc"`
// Desc 降序字段id/created_at/handled_at/status
Desc *string `query:"desc"`
}
// SuperContentReportItem 超管内容举报列表项。
type SuperContentReportItem struct {
// ID 举报ID。
ID int64 `json:"id"`
// TenantID 租户ID。
TenantID int64 `json:"tenant_id"`
// TenantCode 租户编码。
TenantCode string `json:"tenant_code"`
// TenantName 租户名称。
TenantName string `json:"tenant_name"`
// ContentID 内容ID。
ContentID int64 `json:"content_id"`
// ContentTitle 内容标题。
ContentTitle string `json:"content_title"`
// ContentStatus 内容状态。
ContentStatus string `json:"content_status"`
// ContentOwnerID 内容作者用户ID。
ContentOwnerID int64 `json:"content_owner_id"`
// ContentOwnerName 内容作者用户名/昵称。
ContentOwnerName string `json:"content_owner_name"`
// ReporterID 举报人用户ID。
ReporterID int64 `json:"reporter_id"`
// ReporterName 举报人用户名/昵称。
ReporterName string `json:"reporter_name"`
// Reason 举报原因。
Reason string `json:"reason"`
// Detail 举报描述。
Detail string `json:"detail"`
// Status 处理状态。
Status string `json:"status"`
// HandledBy 处理人用户ID。
HandledBy int64 `json:"handled_by"`
// HandledByName 处理人用户名/昵称。
HandledByName string `json:"handled_by_name"`
// HandledAction 处理动作block/unpublish/ignore
HandledAction string `json:"handled_action"`
// HandledReason 处理说明。
HandledReason string `json:"handled_reason"`
// CreatedAt 举报时间RFC3339
CreatedAt string `json:"created_at"`
// HandledAt 处理时间RFC3339
HandledAt string `json:"handled_at"`
}
// SuperContentReportProcessForm 超管内容举报处理表单。
type SuperContentReportProcessForm struct {
// Action 处理动作approve/reject
Action string `json:"action"`
// ContentAction 内容处置动作block/unpublish/ignore仅在 approve 时生效。
ContentAction string `json:"content_action"`
// Reason 处理说明(可选,用于审计记录)。
Reason string `json:"reason"`
}

View File

@@ -31,6 +31,13 @@ func Provide(opts ...opt.Option) error {
}); err != nil {
return err
}
if err := container.Container.Provide(func() (*contentReports, error) {
obj := &contentReports{}
return obj, nil
}); err != nil {
return err
}
if err := container.Container.Provide(func() (*contents, error) {
obj := &contents{}
@@ -98,6 +105,7 @@ func Provide(opts ...opt.Option) error {
assets *assets,
auditLogs *auditLogs,
comments *comments,
contentReports *contentReports,
contents *contents,
coupons *coupons,
creatorApplications *creatorApplications,
@@ -117,6 +125,7 @@ func Provide(opts ...opt.Option) error {
assets: assets,
auditLogs: auditLogs,
comments: comments,
contentReports: contentReports,
contents: contents,
coupons: coupons,
creatorApplications: creatorApplications,

View File

@@ -28,6 +28,7 @@ type Routes struct {
assets *assets
auditLogs *auditLogs
comments *comments
contentReports *contentReports
contents *contents
coupons *coupons
creatorApplications *creatorApplications
@@ -94,6 +95,19 @@ func (r *Routes) Register(router fiber.Router) {
PathParam[int64]("id"),
Body[dto.SuperCommentDeleteForm]("form"),
))
// Register routes for controller: contentReports
r.log.Debugf("Registering route: Get /super/v1/content-reports -> contentReports.List")
router.Get("/super/v1/content-reports"[len(r.Path()):], DataFunc1(
r.contentReports.List,
Query[dto.SuperContentReportListFilter]("filter"),
))
r.log.Debugf("Registering route: Post /super/v1/content-reports/:id<int>/process -> contentReports.Process")
router.Post("/super/v1/content-reports/:id<int>/process"[len(r.Path()):], Func3(
r.contentReports.Process,
Local[*models.User]("__ctx_user"),
PathParam[int64]("id"),
Body[dto.SuperContentReportProcessForm]("form"),
))
// Register routes for controller: contents
r.log.Debugf("Registering route: Get /super/v1/contents -> contents.List")
router.Get("/super/v1/contents"[len(r.Path()):], DataFunc1(

View File

@@ -2611,6 +2611,474 @@ func (s *super) DeleteComment(ctx context.Context, operatorID, id int64, form *s
return nil
}
func (s *super) ListContentReports(ctx context.Context, filter *super_dto.SuperContentReportListFilter) (*requests.Pager, error) {
if filter == nil {
filter = &super_dto.SuperContentReportListFilter{}
}
tbl, q := models.ContentReportQuery.QueryContext(ctx)
if filter.ID != nil && *filter.ID > 0 {
q = q.Where(tbl.ID.Eq(*filter.ID))
}
if filter.TenantID != nil && *filter.TenantID > 0 {
q = q.Where(tbl.TenantID.Eq(*filter.TenantID))
}
if filter.ContentID != nil && *filter.ContentID > 0 {
q = q.Where(tbl.ContentID.Eq(*filter.ContentID))
}
if filter.ReporterID != nil && *filter.ReporterID > 0 {
q = q.Where(tbl.ReporterID.Eq(*filter.ReporterID))
}
if filter.HandledBy != nil && *filter.HandledBy > 0 {
q = q.Where(tbl.HandledBy.Eq(*filter.HandledBy))
}
if filter.Reason != nil && strings.TrimSpace(*filter.Reason) != "" {
keyword := "%" + strings.TrimSpace(*filter.Reason) + "%"
q = q.Where(tbl.Reason.Like(keyword))
}
if filter.Keyword != nil && strings.TrimSpace(*filter.Keyword) != "" {
keyword := "%" + strings.TrimSpace(*filter.Keyword) + "%"
q = q.Where(field.Or(tbl.Detail.Like(keyword), tbl.Reason.Like(keyword)))
}
status := ""
if filter.Status != nil {
status = strings.TrimSpace(*filter.Status)
}
if status != "" && status != "all" {
q = q.Where(tbl.Status.Eq(status))
}
tenantIDs, tenantFilter, err := s.lookupTenantIDs(ctx, filter.TenantCode, filter.TenantName)
if err != nil {
return nil, err
}
if tenantFilter {
if len(tenantIDs) == 0 {
q = q.Where(tbl.ID.Eq(-1))
} else {
q = q.Where(tbl.TenantID.In(tenantIDs...))
}
}
reporterIDs, reporterFilter, err := s.lookupUserIDs(ctx, filter.ReporterName)
if err != nil {
return nil, err
}
if reporterFilter {
if len(reporterIDs) == 0 {
q = q.Where(tbl.ID.Eq(-1))
} else {
q = q.Where(tbl.ReporterID.In(reporterIDs...))
}
}
handledIDs, handledFilter, err := s.lookupUserIDs(ctx, filter.HandledByName)
if err != nil {
return nil, err
}
if handledFilter {
if len(handledIDs) == 0 {
q = q.Where(tbl.ID.Eq(-1))
} else {
q = q.Where(tbl.HandledBy.In(handledIDs...))
}
}
if filter.ContentTitle != nil && strings.TrimSpace(*filter.ContentTitle) != "" {
contentTbl, contentQuery := models.ContentQuery.QueryContext(ctx)
contentQuery = contentQuery.Unscoped()
keyword := "%" + strings.TrimSpace(*filter.ContentTitle) + "%"
contentQuery = contentQuery.Where(field.Or(
contentTbl.Title.Like(keyword),
contentTbl.Description.Like(keyword),
contentTbl.Summary.Like(keyword),
))
if filter.TenantID != nil && *filter.TenantID > 0 {
contentQuery = contentQuery.Where(contentTbl.TenantID.Eq(*filter.TenantID))
}
if tenantFilter {
if len(tenantIDs) == 0 {
q = q.Where(tbl.ID.Eq(-1))
} else {
contentQuery = contentQuery.Where(contentTbl.TenantID.In(tenantIDs...))
}
}
contentIDs, err := contentQuery.Select(contentTbl.ID).Find()
if err != nil {
return nil, errorx.ErrDatabaseError.WithCause(err)
}
ids := make([]int64, 0, len(contentIDs))
for _, content := range contentIDs {
ids = append(ids, content.ID)
}
if len(ids) == 0 {
q = q.Where(tbl.ID.Eq(-1))
} else {
q = q.Where(tbl.ContentID.In(ids...))
}
}
if filter.CreatedAtFrom != nil {
from, err := s.parseFilterTime(filter.CreatedAtFrom)
if err != nil {
return nil, err
}
if from != nil {
q = q.Where(tbl.CreatedAt.Gte(*from))
}
}
if filter.CreatedAtTo != nil {
to, err := s.parseFilterTime(filter.CreatedAtTo)
if err != nil {
return nil, err
}
if to != nil {
q = q.Where(tbl.CreatedAt.Lte(*to))
}
}
if filter.HandledAtFrom != nil {
from, err := s.parseFilterTime(filter.HandledAtFrom)
if err != nil {
return nil, err
}
if from != nil {
q = q.Where(tbl.HandledAt.Gte(*from))
}
}
if filter.HandledAtTo != nil {
to, err := s.parseFilterTime(filter.HandledAtTo)
if err != nil {
return nil, err
}
if to != nil {
q = q.Where(tbl.HandledAt.Lte(*to))
}
}
orderApplied := false
if filter.Desc != nil && strings.TrimSpace(*filter.Desc) != "" {
switch strings.TrimSpace(*filter.Desc) {
case "id":
q = q.Order(tbl.ID.Desc())
case "created_at":
q = q.Order(tbl.CreatedAt.Desc())
case "handled_at":
q = q.Order(tbl.HandledAt.Desc())
case "status":
q = q.Order(tbl.Status.Desc())
}
orderApplied = true
} else if filter.Asc != nil && strings.TrimSpace(*filter.Asc) != "" {
switch strings.TrimSpace(*filter.Asc) {
case "id":
q = q.Order(tbl.ID)
case "created_at":
q = q.Order(tbl.CreatedAt)
case "handled_at":
q = q.Order(tbl.HandledAt)
case "status":
q = q.Order(tbl.Status)
}
orderApplied = true
}
if !orderApplied {
q = q.Order(tbl.CreatedAt.Desc())
}
filter.Pagination.Format()
total, err := q.Count()
if err != nil {
return nil, errorx.ErrDatabaseError.WithCause(err)
}
list, err := q.Offset(int(filter.Pagination.Offset())).Limit(int(filter.Pagination.Limit)).Find()
if err != nil {
return nil, errorx.ErrDatabaseError.WithCause(err)
}
if len(list) == 0 {
return &requests.Pager{
Pagination: filter.Pagination,
Total: total,
Items: []super_dto.SuperContentReportItem{},
}, nil
}
tenantSet := make(map[int64]struct{})
contentSet := make(map[int64]struct{})
userSet := make(map[int64]struct{})
for _, report := range list {
tenantSet[report.TenantID] = struct{}{}
contentSet[report.ContentID] = struct{}{}
if report.ReporterID > 0 {
userSet[report.ReporterID] = struct{}{}
}
if report.HandledBy > 0 {
userSet[report.HandledBy] = struct{}{}
}
}
tenantIDs = make([]int64, 0, len(tenantSet))
for id := range tenantSet {
tenantIDs = append(tenantIDs, id)
}
contentIDs := make([]int64, 0, len(contentSet))
for id := range contentSet {
contentIDs = append(contentIDs, id)
}
tenantMap := make(map[int64]*models.Tenant, len(tenantIDs))
if len(tenantIDs) > 0 {
tenantTbl, tenantQuery := models.TenantQuery.QueryContext(ctx)
tenants, err := tenantQuery.Where(tenantTbl.ID.In(tenantIDs...)).Find()
if err != nil {
return nil, errorx.ErrDatabaseError.WithCause(err)
}
for _, tenant := range tenants {
tenantMap[tenant.ID] = tenant
}
}
contentMap := make(map[int64]*models.Content, len(contentIDs))
if len(contentIDs) > 0 {
contentTbl, contentQuery := models.ContentQuery.QueryContext(ctx)
contentQuery = contentQuery.Unscoped()
contents, err := contentQuery.Where(contentTbl.ID.In(contentIDs...)).Find()
if err != nil {
return nil, errorx.ErrDatabaseError.WithCause(err)
}
for _, content := range contents {
contentMap[content.ID] = content
if content.UserID > 0 {
userSet[content.UserID] = struct{}{}
}
}
}
userIDs := make([]int64, 0, len(userSet))
for id := range userSet {
userIDs = append(userIDs, id)
}
userMap := make(map[int64]*models.User, len(userIDs))
if len(userIDs) > 0 {
userTbl, userQuery := models.UserQuery.QueryContext(ctx)
users, err := userQuery.Where(userTbl.ID.In(userIDs...)).Find()
if err != nil {
return nil, errorx.ErrDatabaseError.WithCause(err)
}
for _, user := range users {
userMap[user.ID] = user
}
}
items := make([]super_dto.SuperContentReportItem, 0, len(list))
for _, report := range list {
tenant := tenantMap[report.TenantID]
content := contentMap[report.ContentID]
reporter := userMap[report.ReporterID]
handler := userMap[report.HandledBy]
reporterName := ""
if reporter != nil {
if reporter.Username != "" {
reporterName = reporter.Username
} else {
reporterName = reporter.Nickname
}
}
if reporterName == "" && report.ReporterID > 0 {
reporterName = "ID:" + strconv.FormatInt(report.ReporterID, 10)
}
handlerName := ""
if handler != nil {
if handler.Username != "" {
handlerName = handler.Username
} else {
handlerName = handler.Nickname
}
}
if handlerName == "" && report.HandledBy > 0 {
handlerName = "ID:" + strconv.FormatInt(report.HandledBy, 10)
}
ownerID := int64(0)
ownerName := ""
if content != nil {
ownerID = content.UserID
if owner := userMap[content.UserID]; owner != nil {
if owner.Username != "" {
ownerName = owner.Username
} else {
ownerName = owner.Nickname
}
}
if ownerName == "" && content.UserID > 0 {
ownerName = "ID:" + strconv.FormatInt(content.UserID, 10)
}
}
item := super_dto.SuperContentReportItem{
ID: report.ID,
TenantID: report.TenantID,
ContentID: report.ContentID,
ContentTitle: "",
ContentStatus: "",
ContentOwnerID: ownerID,
ContentOwnerName: ownerName,
ReporterID: report.ReporterID,
ReporterName: reporterName,
Reason: report.Reason,
Detail: report.Detail,
Status: report.Status,
HandledBy: report.HandledBy,
HandledByName: handlerName,
HandledAction: report.HandledAction,
HandledReason: report.HandledReason,
CreatedAt: s.formatTime(report.CreatedAt),
HandledAt: s.formatTime(report.HandledAt),
}
if tenant != nil {
item.TenantCode = tenant.Code
item.TenantName = tenant.Name
}
if content != nil {
item.ContentTitle = content.Title
item.ContentStatus = string(content.Status)
}
items = append(items, item)
}
return &requests.Pager{
Pagination: filter.Pagination,
Total: total,
Items: items,
}, nil
}
func (s *super) ProcessContentReport(ctx context.Context, operatorID, id int64, form *super_dto.SuperContentReportProcessForm) error {
if operatorID == 0 {
return errorx.ErrUnauthorized.WithMsg("缺少操作者信息")
}
if form == nil {
return errorx.ErrBadRequest.WithMsg("处理参数不能为空")
}
action := strings.ToLower(strings.TrimSpace(form.Action))
if action != "approve" && action != "reject" {
return errorx.ErrBadRequest.WithMsg("处理动作非法")
}
contentAction := strings.ToLower(strings.TrimSpace(form.ContentAction))
if action == "approve" {
if contentAction == "" {
contentAction = "ignore"
}
switch contentAction {
case "block", "unpublish", "ignore":
default:
return errorx.ErrBadRequest.WithMsg("内容处置动作非法")
}
} else {
contentAction = "ignore"
}
tbl, q := models.ContentReportQuery.QueryContext(ctx)
report, err := q.Where(tbl.ID.Eq(id)).First()
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return errorx.ErrRecordNotFound
}
return errorx.ErrDatabaseError.WithCause(err)
}
if strings.TrimSpace(report.Status) != "" && report.Status != "pending" {
return errorx.ErrStatusConflict.WithMsg("举报已处理")
}
contentTbl, contentQuery := models.ContentQuery.QueryContext(ctx)
contentQuery = contentQuery.Unscoped()
content, err := contentQuery.Where(contentTbl.ID.Eq(report.ContentID)).First()
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return errorx.ErrDatabaseError.WithCause(err)
}
if errors.Is(err, gorm.ErrRecordNotFound) {
content = nil
}
status := "approved"
if action == "reject" {
status = "rejected"
}
handledReason := strings.TrimSpace(form.Reason)
handledAt := time.Now()
err = models.Q.Transaction(func(tx *models.Query) error {
reportTbl, reportQuery := tx.ContentReport.QueryContext(ctx)
_, err := reportQuery.Where(reportTbl.ID.Eq(report.ID)).UpdateSimple(
reportTbl.Status.Value(status),
reportTbl.HandledBy.Value(operatorID),
reportTbl.HandledAction.Value(contentAction),
reportTbl.HandledReason.Value(handledReason),
reportTbl.HandledAt.Value(handledAt),
)
if err != nil {
return errorx.ErrDatabaseError.WithCause(err)
}
if action == "approve" && content != nil {
var nextStatus consts.ContentStatus
switch contentAction {
case "block":
nextStatus = consts.ContentStatusBlocked
case "unpublish":
nextStatus = consts.ContentStatusUnpublished
}
if nextStatus != "" && content.Status != nextStatus {
contentTbl, contentQuery := tx.Content.QueryContext(ctx)
_, err := contentQuery.Where(contentTbl.ID.Eq(content.ID)).UpdateSimple(
contentTbl.Status.Value(nextStatus),
)
if err != nil {
return errorx.ErrDatabaseError.WithCause(err)
}
}
}
return nil
})
if err != nil {
return err
}
if action == "approve" && content != nil {
title := "内容举报成立"
actionLabel := "不处理内容"
switch contentAction {
case "block":
actionLabel = "封禁内容"
case "unpublish":
actionLabel = "下架内容"
}
detail := "内容《" + content.Title + "》举报成立,处理结果:" + actionLabel
if handledReason != "" {
detail += "。说明:" + handledReason
}
_ = Notification.Send(ctx, content.TenantID, content.UserID, string(consts.NotificationTypeAudit), title, detail)
}
if Audit != nil {
detail := "处理内容举报:" + action + " / " + contentAction
if handledReason != "" {
detail += " / " + handledReason
}
Audit.Log(ctx, report.TenantID, operatorID, "process_content_report", cast.ToString(report.ID), detail)
}
return nil
}
func (s *super) UpdateContentStatus(ctx context.Context, tenantID, contentID int64, form *super_dto.SuperTenantContentStatusUpdateForm) error {
tbl, q := models.ContentQuery.QueryContext(ctx)
_, err := q.Where(tbl.ID.Eq(contentID), tbl.TenantID.Eq(tenantID)).Update(tbl.Status, consts.ContentStatus(form.Status))

View File

@@ -287,6 +287,113 @@ func (s *SuperTestSuite) Test_CommentGovernance() {
})
}
func (s *SuperTestSuite) Test_ContentReportGovernance() {
Convey("Content Report Governance", s.T(), func() {
ctx := s.T().Context()
database.Truncate(ctx, s.DB, models.TableNameContentReport, models.TableNameContent, models.TableNameTenant, models.TableNameUser)
owner := &models.User{Username: "owner_report"}
reporter := &models.User{Username: "reporter"}
admin := &models.User{Username: "admin_report"}
models.UserQuery.WithContext(ctx).Create(owner, reporter, admin)
tenant := &models.Tenant{UserID: owner.ID, Code: "t-report", Name: "Report Tenant", Status: consts.TenantStatusVerified}
models.TenantQuery.WithContext(ctx).Create(tenant)
content := &models.Content{
TenantID: tenant.ID,
UserID: owner.ID,
Title: "Report Content",
Description: "Report Desc",
Status: consts.ContentStatusPublished,
}
models.ContentQuery.WithContext(ctx).Create(content)
Convey("should list reports", func() {
report := &models.ContentReport{
TenantID: tenant.ID,
ContentID: content.ID,
ReporterID: reporter.ID,
Reason: "spam",
Detail: "内容涉嫌违规",
Status: "pending",
}
models.ContentReportQuery.WithContext(ctx).Create(report)
filter := &super_dto.SuperContentReportListFilter{
Pagination: requests.Pagination{Page: 1, Limit: 10},
}
res, err := Super.ListContentReports(ctx, filter)
So(err, ShouldBeNil)
So(res.Total, ShouldEqual, 1)
items := res.Items.([]super_dto.SuperContentReportItem)
So(items[0].ContentTitle, ShouldEqual, "Report Content")
So(items[0].ReporterName, ShouldEqual, reporter.Username)
So(items[0].Status, ShouldEqual, "pending")
})
Convey("should process report and block content", func() {
report := &models.ContentReport{
TenantID: tenant.ID,
ContentID: content.ID,
ReporterID: reporter.ID,
Reason: "abuse",
Detail: "严重违规",
Status: "pending",
}
models.ContentReportQuery.WithContext(ctx).Create(report)
err := Super.ProcessContentReport(ctx, admin.ID, report.ID, &super_dto.SuperContentReportProcessForm{
Action: "approve",
ContentAction: "block",
Reason: "违规属实",
})
So(err, ShouldBeNil)
reloaded, err := models.ContentReportQuery.WithContext(ctx).Where(models.ContentReportQuery.ID.Eq(report.ID)).First()
So(err, ShouldBeNil)
So(reloaded.Status, ShouldEqual, "approved")
So(reloaded.HandledBy, ShouldEqual, admin.ID)
So(reloaded.HandledAction, ShouldEqual, "block")
So(reloaded.HandledReason, ShouldEqual, "违规属实")
So(reloaded.HandledAt.IsZero(), ShouldBeFalse)
contentReload, err := models.ContentQuery.WithContext(ctx).Where(models.ContentQuery.ID.Eq(content.ID)).First()
So(err, ShouldBeNil)
So(contentReload.Status, ShouldEqual, consts.ContentStatusBlocked)
})
Convey("should reject report without content action", func() {
report := &models.ContentReport{
TenantID: tenant.ID,
ContentID: content.ID,
ReporterID: reporter.ID,
Reason: "other",
Detail: "误报",
Status: "pending",
}
models.ContentReportQuery.WithContext(ctx).Create(report)
err := Super.ProcessContentReport(ctx, admin.ID, report.ID, &super_dto.SuperContentReportProcessForm{
Action: "reject",
Reason: "证据不足",
})
So(err, ShouldBeNil)
reloaded, err := models.ContentReportQuery.WithContext(ctx).Where(models.ContentReportQuery.ID.Eq(report.ID)).First()
So(err, ShouldBeNil)
So(reloaded.Status, ShouldEqual, "rejected")
So(reloaded.HandledBy, ShouldEqual, admin.ID)
So(reloaded.HandledAction, ShouldEqual, "ignore")
So(reloaded.HandledReason, ShouldEqual, "证据不足")
contentReload, err := models.ContentQuery.WithContext(ctx).Where(models.ContentQuery.ID.Eq(content.ID)).First()
So(err, ShouldBeNil)
So(contentReload.Status, ShouldEqual, consts.ContentStatusPublished)
})
})
}
func (s *SuperTestSuite) Test_FinanceAnomalies() {
Convey("Finance Anomalies", s.T(), func() {
ctx := s.T().Context()