feat: add content report governance
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user