feat: abuse report queue with public submission and admin review (#185)

Visitors can report shares or users from the share page more-menu; the
public endpoint is IP rate-limited and captcha-gated via the new
abuse_captcha setting (default on). Admins review the queue at
/admin/abuse with resolve/dismiss transitions and an optional reversible
share block that expires the link rather than deleting it. Submissions
emit report_abuse activity events.

Authored By: TDvorak <info@tdvorak.dev>

Generated with [Devin](https://devin.ai)

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
pull/3587/head
Tomáš Dvořák 2 weeks ago committed by GitHub
parent 60138e322c
commit 4018d04a5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -112,6 +112,8 @@ type Dep interface {
VasClient() inventory.VasClient
// ActivityClient Get a singleton inventory.ActivityClient instance for the audit event store.
ActivityClient() inventory.ActivityClient
// AbuseReportClient Get a singleton inventory.AbuseReportClient instance for the abuse review queue.
AbuseReportClient() inventory.AbuseReportClient
// TaskClient Get a singleton inventory.TaskClient instance for access DB task store.
TaskClient() inventory.TaskClient
// ForkWithLogger create a shallow copy of dependency with a new correlated logger, used as per-request dep.
@ -171,6 +173,7 @@ type dependency struct {
aclClient inventory.AclClient
vasClient inventory.VasClient
activityClient inventory.ActivityClient
abuseReportClient inventory.AbuseReportClient
settingProvider setting.Provider
userClient inventory.UserClient
groupClient inventory.GroupClient
@ -858,6 +861,15 @@ func (d *dependency) ActivityClient() inventory.ActivityClient {
return d.activityClient
}
func (d *dependency) AbuseReportClient() inventory.AbuseReportClient {
if d.abuseReportClient != nil {
return d.abuseReportClient
}
d.abuseReportClient = inventory.NewAbuseReportClient(d.DBClient())
return d.abuseReportClient
}
func (d *dependency) TaskClient() inventory.TaskClient {
if d.taskClient != nil {
return d.taskClient

@ -0,0 +1,219 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/cloudreve/Cloudreve/v4/ent/abusereport"
)
// AbuseReport is the model entity for the AbuseReport schema.
type AbuseReport struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
// DeletedAt holds the value of the "deleted_at" field.
DeletedAt *time.Time `json:"deleted_at,omitempty"`
// ReporterID holds the value of the "reporter_id" field.
ReporterID int `json:"reporter_id,omitempty"`
// ReporterEmail holds the value of the "reporter_email" field.
ReporterEmail string `json:"reporter_email,omitempty"`
// TargetType holds the value of the "target_type" field.
TargetType string `json:"target_type,omitempty"`
// TargetID holds the value of the "target_id" field.
TargetID int `json:"target_id,omitempty"`
// Reason holds the value of the "reason" field.
Reason int `json:"reason,omitempty"`
// Description holds the value of the "description" field.
Description string `json:"description,omitempty"`
// Status holds the value of the "status" field.
Status string `json:"status,omitempty"`
// AdminNote holds the value of the "admin_note" field.
AdminNote string `json:"admin_note,omitempty"`
selectValues sql.SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func (*AbuseReport) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case abusereport.FieldID, abusereport.FieldReporterID, abusereport.FieldTargetID, abusereport.FieldReason:
values[i] = new(sql.NullInt64)
case abusereport.FieldReporterEmail, abusereport.FieldTargetType, abusereport.FieldDescription, abusereport.FieldStatus, abusereport.FieldAdminNote:
values[i] = new(sql.NullString)
case abusereport.FieldCreatedAt, abusereport.FieldUpdatedAt, abusereport.FieldDeletedAt:
values[i] = new(sql.NullTime)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the AbuseReport fields.
func (ar *AbuseReport) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case abusereport.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
ar.ID = int(value.Int64)
case abusereport.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
ar.CreatedAt = value.Time
}
case abusereport.FieldUpdatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
} else if value.Valid {
ar.UpdatedAt = value.Time
}
case abusereport.FieldDeletedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
} else if value.Valid {
ar.DeletedAt = new(time.Time)
*ar.DeletedAt = value.Time
}
case abusereport.FieldReporterID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field reporter_id", values[i])
} else if value.Valid {
ar.ReporterID = int(value.Int64)
}
case abusereport.FieldReporterEmail:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field reporter_email", values[i])
} else if value.Valid {
ar.ReporterEmail = value.String
}
case abusereport.FieldTargetType:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field target_type", values[i])
} else if value.Valid {
ar.TargetType = value.String
}
case abusereport.FieldTargetID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field target_id", values[i])
} else if value.Valid {
ar.TargetID = int(value.Int64)
}
case abusereport.FieldReason:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field reason", values[i])
} else if value.Valid {
ar.Reason = int(value.Int64)
}
case abusereport.FieldDescription:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field description", values[i])
} else if value.Valid {
ar.Description = value.String
}
case abusereport.FieldStatus:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field status", values[i])
} else if value.Valid {
ar.Status = value.String
}
case abusereport.FieldAdminNote:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field admin_note", values[i])
} else if value.Valid {
ar.AdminNote = value.String
}
default:
ar.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the AbuseReport.
// This includes values selected through modifiers, order, etc.
func (ar *AbuseReport) Value(name string) (ent.Value, error) {
return ar.selectValues.Get(name)
}
// Update returns a builder for updating this AbuseReport.
// Note that you need to call AbuseReport.Unwrap() before calling this method if this AbuseReport
// was returned from a transaction, and the transaction was committed or rolled back.
func (ar *AbuseReport) Update() *AbuseReportUpdateOne {
return NewAbuseReportClient(ar.config).UpdateOne(ar)
}
// Unwrap unwraps the AbuseReport entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (ar *AbuseReport) Unwrap() *AbuseReport {
_tx, ok := ar.config.driver.(*txDriver)
if !ok {
panic("ent: AbuseReport is not a transactional entity")
}
ar.config.driver = _tx.drv
return ar
}
// String implements the fmt.Stringer.
func (ar *AbuseReport) String() string {
var builder strings.Builder
builder.WriteString("AbuseReport(")
builder.WriteString(fmt.Sprintf("id=%v, ", ar.ID))
builder.WriteString("created_at=")
builder.WriteString(ar.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(ar.UpdatedAt.Format(time.ANSIC))
builder.WriteString(", ")
if v := ar.DeletedAt; v != nil {
builder.WriteString("deleted_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteString(", ")
builder.WriteString("reporter_id=")
builder.WriteString(fmt.Sprintf("%v", ar.ReporterID))
builder.WriteString(", ")
builder.WriteString("reporter_email=")
builder.WriteString(ar.ReporterEmail)
builder.WriteString(", ")
builder.WriteString("target_type=")
builder.WriteString(ar.TargetType)
builder.WriteString(", ")
builder.WriteString("target_id=")
builder.WriteString(fmt.Sprintf("%v", ar.TargetID))
builder.WriteString(", ")
builder.WriteString("reason=")
builder.WriteString(fmt.Sprintf("%v", ar.Reason))
builder.WriteString(", ")
builder.WriteString("description=")
builder.WriteString(ar.Description)
builder.WriteString(", ")
builder.WriteString("status=")
builder.WriteString(ar.Status)
builder.WriteString(", ")
builder.WriteString("admin_note=")
builder.WriteString(ar.AdminNote)
builder.WriteByte(')')
return builder.String()
}
// AbuseReports is a parsable slice of AbuseReport.
type AbuseReports []*AbuseReport

@ -0,0 +1,148 @@
// Code generated by ent, DO NOT EDIT.
package abusereport
import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
const (
// Label holds the string label denoting the abusereport type in the database.
Label = "abuse_report"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at"
// FieldDeletedAt holds the string denoting the deleted_at field in the database.
FieldDeletedAt = "deleted_at"
// FieldReporterID holds the string denoting the reporter_id field in the database.
FieldReporterID = "reporter_id"
// FieldReporterEmail holds the string denoting the reporter_email field in the database.
FieldReporterEmail = "reporter_email"
// FieldTargetType holds the string denoting the target_type field in the database.
FieldTargetType = "target_type"
// FieldTargetID holds the string denoting the target_id field in the database.
FieldTargetID = "target_id"
// FieldReason holds the string denoting the reason field in the database.
FieldReason = "reason"
// FieldDescription holds the string denoting the description field in the database.
FieldDescription = "description"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// FieldAdminNote holds the string denoting the admin_note field in the database.
FieldAdminNote = "admin_note"
// Table holds the table name of the abusereport in the database.
Table = "abuse_reports"
)
// Columns holds all SQL columns for abusereport fields.
var Columns = []string{
FieldID,
FieldCreatedAt,
FieldUpdatedAt,
FieldDeletedAt,
FieldReporterID,
FieldReporterEmail,
FieldTargetType,
FieldTargetID,
FieldReason,
FieldDescription,
FieldStatus,
FieldAdminNote,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
// Note that the variables below are initialized by the runtime
// package on the initialization of the application. Therefore,
// it should be imported in the main as follows:
//
// import _ "github.com/cloudreve/Cloudreve/v4/ent/runtime"
var (
Hooks [1]ent.Hook
Interceptors [1]ent.Interceptor
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt func() time.Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
UpdateDefaultUpdatedAt func() time.Time
// DefaultStatus holds the default value on creation for the "status" field.
DefaultStatus string
)
// OrderOption defines the ordering options for the AbuseReport queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByUpdatedAt orders the results by the updated_at field.
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
}
// ByDeletedAt orders the results by the deleted_at field.
func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDeletedAt, opts...).ToFunc()
}
// ByReporterID orders the results by the reporter_id field.
func ByReporterID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldReporterID, opts...).ToFunc()
}
// ByReporterEmail orders the results by the reporter_email field.
func ByReporterEmail(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldReporterEmail, opts...).ToFunc()
}
// ByTargetType orders the results by the target_type field.
func ByTargetType(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldTargetType, opts...).ToFunc()
}
// ByTargetID orders the results by the target_id field.
func ByTargetID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldTargetID, opts...).ToFunc()
}
// ByReason orders the results by the reason field.
func ByReason(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldReason, opts...).ToFunc()
}
// ByDescription orders the results by the description field.
func ByDescription(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDescription, opts...).ToFunc()
}
// ByStatus orders the results by the status field.
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStatus, opts...).ToFunc()
}
// ByAdminNote orders the results by the admin_note field.
func ByAdminNote(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldAdminNote, opts...).ToFunc()
}

@ -0,0 +1,740 @@
// Code generated by ent, DO NOT EDIT.
package abusereport
import (
"time"
"entgo.io/ent/dialect/sql"
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
)
// ID filters vertices based on their ID field.
func ID(id int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLTE(FieldID, id))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldCreatedAt, v))
}
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
func UpdatedAt(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldUpdatedAt, v))
}
// DeletedAt applies equality check predicate on the "deleted_at" field. It's identical to DeletedAtEQ.
func DeletedAt(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldDeletedAt, v))
}
// ReporterID applies equality check predicate on the "reporter_id" field. It's identical to ReporterIDEQ.
func ReporterID(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldReporterID, v))
}
// ReporterEmail applies equality check predicate on the "reporter_email" field. It's identical to ReporterEmailEQ.
func ReporterEmail(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldReporterEmail, v))
}
// TargetType applies equality check predicate on the "target_type" field. It's identical to TargetTypeEQ.
func TargetType(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldTargetType, v))
}
// TargetID applies equality check predicate on the "target_id" field. It's identical to TargetIDEQ.
func TargetID(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldTargetID, v))
}
// Reason applies equality check predicate on the "reason" field. It's identical to ReasonEQ.
func Reason(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldReason, v))
}
// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ.
func Description(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldDescription, v))
}
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
func Status(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldStatus, v))
}
// AdminNote applies equality check predicate on the "admin_note" field. It's identical to AdminNoteEQ.
func AdminNote(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldAdminNote, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLTE(FieldCreatedAt, v))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func UpdatedAtEQ(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldUpdatedAt, v))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func UpdatedAtNEQ(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNEQ(FieldUpdatedAt, v))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func UpdatedAtIn(vs ...time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldIn(FieldUpdatedAt, vs...))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func UpdatedAtNotIn(vs ...time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNotIn(FieldUpdatedAt, vs...))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func UpdatedAtGT(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGT(FieldUpdatedAt, v))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func UpdatedAtGTE(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGTE(FieldUpdatedAt, v))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func UpdatedAtLT(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLT(FieldUpdatedAt, v))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func UpdatedAtLTE(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLTE(FieldUpdatedAt, v))
}
// DeletedAtEQ applies the EQ predicate on the "deleted_at" field.
func DeletedAtEQ(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldDeletedAt, v))
}
// DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field.
func DeletedAtNEQ(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNEQ(FieldDeletedAt, v))
}
// DeletedAtIn applies the In predicate on the "deleted_at" field.
func DeletedAtIn(vs ...time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldIn(FieldDeletedAt, vs...))
}
// DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field.
func DeletedAtNotIn(vs ...time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNotIn(FieldDeletedAt, vs...))
}
// DeletedAtGT applies the GT predicate on the "deleted_at" field.
func DeletedAtGT(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGT(FieldDeletedAt, v))
}
// DeletedAtGTE applies the GTE predicate on the "deleted_at" field.
func DeletedAtGTE(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGTE(FieldDeletedAt, v))
}
// DeletedAtLT applies the LT predicate on the "deleted_at" field.
func DeletedAtLT(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLT(FieldDeletedAt, v))
}
// DeletedAtLTE applies the LTE predicate on the "deleted_at" field.
func DeletedAtLTE(v time.Time) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLTE(FieldDeletedAt, v))
}
// DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field.
func DeletedAtIsNil() predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldIsNull(FieldDeletedAt))
}
// DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field.
func DeletedAtNotNil() predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNotNull(FieldDeletedAt))
}
// ReporterIDEQ applies the EQ predicate on the "reporter_id" field.
func ReporterIDEQ(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldReporterID, v))
}
// ReporterIDNEQ applies the NEQ predicate on the "reporter_id" field.
func ReporterIDNEQ(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNEQ(FieldReporterID, v))
}
// ReporterIDIn applies the In predicate on the "reporter_id" field.
func ReporterIDIn(vs ...int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldIn(FieldReporterID, vs...))
}
// ReporterIDNotIn applies the NotIn predicate on the "reporter_id" field.
func ReporterIDNotIn(vs ...int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNotIn(FieldReporterID, vs...))
}
// ReporterIDGT applies the GT predicate on the "reporter_id" field.
func ReporterIDGT(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGT(FieldReporterID, v))
}
// ReporterIDGTE applies the GTE predicate on the "reporter_id" field.
func ReporterIDGTE(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGTE(FieldReporterID, v))
}
// ReporterIDLT applies the LT predicate on the "reporter_id" field.
func ReporterIDLT(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLT(FieldReporterID, v))
}
// ReporterIDLTE applies the LTE predicate on the "reporter_id" field.
func ReporterIDLTE(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLTE(FieldReporterID, v))
}
// ReporterIDIsNil applies the IsNil predicate on the "reporter_id" field.
func ReporterIDIsNil() predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldIsNull(FieldReporterID))
}
// ReporterIDNotNil applies the NotNil predicate on the "reporter_id" field.
func ReporterIDNotNil() predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNotNull(FieldReporterID))
}
// ReporterEmailEQ applies the EQ predicate on the "reporter_email" field.
func ReporterEmailEQ(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldReporterEmail, v))
}
// ReporterEmailNEQ applies the NEQ predicate on the "reporter_email" field.
func ReporterEmailNEQ(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNEQ(FieldReporterEmail, v))
}
// ReporterEmailIn applies the In predicate on the "reporter_email" field.
func ReporterEmailIn(vs ...string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldIn(FieldReporterEmail, vs...))
}
// ReporterEmailNotIn applies the NotIn predicate on the "reporter_email" field.
func ReporterEmailNotIn(vs ...string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNotIn(FieldReporterEmail, vs...))
}
// ReporterEmailGT applies the GT predicate on the "reporter_email" field.
func ReporterEmailGT(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGT(FieldReporterEmail, v))
}
// ReporterEmailGTE applies the GTE predicate on the "reporter_email" field.
func ReporterEmailGTE(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGTE(FieldReporterEmail, v))
}
// ReporterEmailLT applies the LT predicate on the "reporter_email" field.
func ReporterEmailLT(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLT(FieldReporterEmail, v))
}
// ReporterEmailLTE applies the LTE predicate on the "reporter_email" field.
func ReporterEmailLTE(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLTE(FieldReporterEmail, v))
}
// ReporterEmailContains applies the Contains predicate on the "reporter_email" field.
func ReporterEmailContains(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldContains(FieldReporterEmail, v))
}
// ReporterEmailHasPrefix applies the HasPrefix predicate on the "reporter_email" field.
func ReporterEmailHasPrefix(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldHasPrefix(FieldReporterEmail, v))
}
// ReporterEmailHasSuffix applies the HasSuffix predicate on the "reporter_email" field.
func ReporterEmailHasSuffix(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldHasSuffix(FieldReporterEmail, v))
}
// ReporterEmailIsNil applies the IsNil predicate on the "reporter_email" field.
func ReporterEmailIsNil() predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldIsNull(FieldReporterEmail))
}
// ReporterEmailNotNil applies the NotNil predicate on the "reporter_email" field.
func ReporterEmailNotNil() predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNotNull(FieldReporterEmail))
}
// ReporterEmailEqualFold applies the EqualFold predicate on the "reporter_email" field.
func ReporterEmailEqualFold(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEqualFold(FieldReporterEmail, v))
}
// ReporterEmailContainsFold applies the ContainsFold predicate on the "reporter_email" field.
func ReporterEmailContainsFold(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldContainsFold(FieldReporterEmail, v))
}
// TargetTypeEQ applies the EQ predicate on the "target_type" field.
func TargetTypeEQ(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldTargetType, v))
}
// TargetTypeNEQ applies the NEQ predicate on the "target_type" field.
func TargetTypeNEQ(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNEQ(FieldTargetType, v))
}
// TargetTypeIn applies the In predicate on the "target_type" field.
func TargetTypeIn(vs ...string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldIn(FieldTargetType, vs...))
}
// TargetTypeNotIn applies the NotIn predicate on the "target_type" field.
func TargetTypeNotIn(vs ...string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNotIn(FieldTargetType, vs...))
}
// TargetTypeGT applies the GT predicate on the "target_type" field.
func TargetTypeGT(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGT(FieldTargetType, v))
}
// TargetTypeGTE applies the GTE predicate on the "target_type" field.
func TargetTypeGTE(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGTE(FieldTargetType, v))
}
// TargetTypeLT applies the LT predicate on the "target_type" field.
func TargetTypeLT(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLT(FieldTargetType, v))
}
// TargetTypeLTE applies the LTE predicate on the "target_type" field.
func TargetTypeLTE(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLTE(FieldTargetType, v))
}
// TargetTypeContains applies the Contains predicate on the "target_type" field.
func TargetTypeContains(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldContains(FieldTargetType, v))
}
// TargetTypeHasPrefix applies the HasPrefix predicate on the "target_type" field.
func TargetTypeHasPrefix(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldHasPrefix(FieldTargetType, v))
}
// TargetTypeHasSuffix applies the HasSuffix predicate on the "target_type" field.
func TargetTypeHasSuffix(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldHasSuffix(FieldTargetType, v))
}
// TargetTypeEqualFold applies the EqualFold predicate on the "target_type" field.
func TargetTypeEqualFold(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEqualFold(FieldTargetType, v))
}
// TargetTypeContainsFold applies the ContainsFold predicate on the "target_type" field.
func TargetTypeContainsFold(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldContainsFold(FieldTargetType, v))
}
// TargetIDEQ applies the EQ predicate on the "target_id" field.
func TargetIDEQ(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldTargetID, v))
}
// TargetIDNEQ applies the NEQ predicate on the "target_id" field.
func TargetIDNEQ(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNEQ(FieldTargetID, v))
}
// TargetIDIn applies the In predicate on the "target_id" field.
func TargetIDIn(vs ...int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldIn(FieldTargetID, vs...))
}
// TargetIDNotIn applies the NotIn predicate on the "target_id" field.
func TargetIDNotIn(vs ...int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNotIn(FieldTargetID, vs...))
}
// TargetIDGT applies the GT predicate on the "target_id" field.
func TargetIDGT(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGT(FieldTargetID, v))
}
// TargetIDGTE applies the GTE predicate on the "target_id" field.
func TargetIDGTE(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGTE(FieldTargetID, v))
}
// TargetIDLT applies the LT predicate on the "target_id" field.
func TargetIDLT(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLT(FieldTargetID, v))
}
// TargetIDLTE applies the LTE predicate on the "target_id" field.
func TargetIDLTE(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLTE(FieldTargetID, v))
}
// ReasonEQ applies the EQ predicate on the "reason" field.
func ReasonEQ(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldReason, v))
}
// ReasonNEQ applies the NEQ predicate on the "reason" field.
func ReasonNEQ(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNEQ(FieldReason, v))
}
// ReasonIn applies the In predicate on the "reason" field.
func ReasonIn(vs ...int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldIn(FieldReason, vs...))
}
// ReasonNotIn applies the NotIn predicate on the "reason" field.
func ReasonNotIn(vs ...int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNotIn(FieldReason, vs...))
}
// ReasonGT applies the GT predicate on the "reason" field.
func ReasonGT(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGT(FieldReason, v))
}
// ReasonGTE applies the GTE predicate on the "reason" field.
func ReasonGTE(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGTE(FieldReason, v))
}
// ReasonLT applies the LT predicate on the "reason" field.
func ReasonLT(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLT(FieldReason, v))
}
// ReasonLTE applies the LTE predicate on the "reason" field.
func ReasonLTE(v int) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLTE(FieldReason, v))
}
// DescriptionEQ applies the EQ predicate on the "description" field.
func DescriptionEQ(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldDescription, v))
}
// DescriptionNEQ applies the NEQ predicate on the "description" field.
func DescriptionNEQ(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNEQ(FieldDescription, v))
}
// DescriptionIn applies the In predicate on the "description" field.
func DescriptionIn(vs ...string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldIn(FieldDescription, vs...))
}
// DescriptionNotIn applies the NotIn predicate on the "description" field.
func DescriptionNotIn(vs ...string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNotIn(FieldDescription, vs...))
}
// DescriptionGT applies the GT predicate on the "description" field.
func DescriptionGT(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGT(FieldDescription, v))
}
// DescriptionGTE applies the GTE predicate on the "description" field.
func DescriptionGTE(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGTE(FieldDescription, v))
}
// DescriptionLT applies the LT predicate on the "description" field.
func DescriptionLT(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLT(FieldDescription, v))
}
// DescriptionLTE applies the LTE predicate on the "description" field.
func DescriptionLTE(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLTE(FieldDescription, v))
}
// DescriptionContains applies the Contains predicate on the "description" field.
func DescriptionContains(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldContains(FieldDescription, v))
}
// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field.
func DescriptionHasPrefix(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldHasPrefix(FieldDescription, v))
}
// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field.
func DescriptionHasSuffix(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldHasSuffix(FieldDescription, v))
}
// DescriptionIsNil applies the IsNil predicate on the "description" field.
func DescriptionIsNil() predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldIsNull(FieldDescription))
}
// DescriptionNotNil applies the NotNil predicate on the "description" field.
func DescriptionNotNil() predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNotNull(FieldDescription))
}
// DescriptionEqualFold applies the EqualFold predicate on the "description" field.
func DescriptionEqualFold(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEqualFold(FieldDescription, v))
}
// DescriptionContainsFold applies the ContainsFold predicate on the "description" field.
func DescriptionContainsFold(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldContainsFold(FieldDescription, v))
}
// StatusEQ applies the EQ predicate on the "status" field.
func StatusEQ(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldStatus, v))
}
// StatusNEQ applies the NEQ predicate on the "status" field.
func StatusNEQ(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNEQ(FieldStatus, v))
}
// StatusIn applies the In predicate on the "status" field.
func StatusIn(vs ...string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldIn(FieldStatus, vs...))
}
// StatusNotIn applies the NotIn predicate on the "status" field.
func StatusNotIn(vs ...string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNotIn(FieldStatus, vs...))
}
// StatusGT applies the GT predicate on the "status" field.
func StatusGT(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGT(FieldStatus, v))
}
// StatusGTE applies the GTE predicate on the "status" field.
func StatusGTE(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGTE(FieldStatus, v))
}
// StatusLT applies the LT predicate on the "status" field.
func StatusLT(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLT(FieldStatus, v))
}
// StatusLTE applies the LTE predicate on the "status" field.
func StatusLTE(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLTE(FieldStatus, v))
}
// StatusContains applies the Contains predicate on the "status" field.
func StatusContains(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldContains(FieldStatus, v))
}
// StatusHasPrefix applies the HasPrefix predicate on the "status" field.
func StatusHasPrefix(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldHasPrefix(FieldStatus, v))
}
// StatusHasSuffix applies the HasSuffix predicate on the "status" field.
func StatusHasSuffix(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldHasSuffix(FieldStatus, v))
}
// StatusEqualFold applies the EqualFold predicate on the "status" field.
func StatusEqualFold(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEqualFold(FieldStatus, v))
}
// StatusContainsFold applies the ContainsFold predicate on the "status" field.
func StatusContainsFold(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldContainsFold(FieldStatus, v))
}
// AdminNoteEQ applies the EQ predicate on the "admin_note" field.
func AdminNoteEQ(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEQ(FieldAdminNote, v))
}
// AdminNoteNEQ applies the NEQ predicate on the "admin_note" field.
func AdminNoteNEQ(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNEQ(FieldAdminNote, v))
}
// AdminNoteIn applies the In predicate on the "admin_note" field.
func AdminNoteIn(vs ...string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldIn(FieldAdminNote, vs...))
}
// AdminNoteNotIn applies the NotIn predicate on the "admin_note" field.
func AdminNoteNotIn(vs ...string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNotIn(FieldAdminNote, vs...))
}
// AdminNoteGT applies the GT predicate on the "admin_note" field.
func AdminNoteGT(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGT(FieldAdminNote, v))
}
// AdminNoteGTE applies the GTE predicate on the "admin_note" field.
func AdminNoteGTE(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldGTE(FieldAdminNote, v))
}
// AdminNoteLT applies the LT predicate on the "admin_note" field.
func AdminNoteLT(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLT(FieldAdminNote, v))
}
// AdminNoteLTE applies the LTE predicate on the "admin_note" field.
func AdminNoteLTE(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldLTE(FieldAdminNote, v))
}
// AdminNoteContains applies the Contains predicate on the "admin_note" field.
func AdminNoteContains(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldContains(FieldAdminNote, v))
}
// AdminNoteHasPrefix applies the HasPrefix predicate on the "admin_note" field.
func AdminNoteHasPrefix(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldHasPrefix(FieldAdminNote, v))
}
// AdminNoteHasSuffix applies the HasSuffix predicate on the "admin_note" field.
func AdminNoteHasSuffix(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldHasSuffix(FieldAdminNote, v))
}
// AdminNoteIsNil applies the IsNil predicate on the "admin_note" field.
func AdminNoteIsNil() predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldIsNull(FieldAdminNote))
}
// AdminNoteNotNil applies the NotNil predicate on the "admin_note" field.
func AdminNoteNotNil() predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldNotNull(FieldAdminNote))
}
// AdminNoteEqualFold applies the EqualFold predicate on the "admin_note" field.
func AdminNoteEqualFold(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldEqualFold(FieldAdminNote, v))
}
// AdminNoteContainsFold applies the ContainsFold predicate on the "admin_note" field.
func AdminNoteContainsFold(v string) predicate.AbuseReport {
return predicate.AbuseReport(sql.FieldContainsFold(FieldAdminNote, v))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.AbuseReport) predicate.AbuseReport {
return predicate.AbuseReport(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.AbuseReport) predicate.AbuseReport {
return predicate.AbuseReport(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.AbuseReport) predicate.AbuseReport {
return predicate.AbuseReport(sql.NotPredicates(p))
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,88 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/cloudreve/Cloudreve/v4/ent/abusereport"
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
)
// AbuseReportDelete is the builder for deleting a AbuseReport entity.
type AbuseReportDelete struct {
config
hooks []Hook
mutation *AbuseReportMutation
}
// Where appends a list predicates to the AbuseReportDelete builder.
func (ard *AbuseReportDelete) Where(ps ...predicate.AbuseReport) *AbuseReportDelete {
ard.mutation.Where(ps...)
return ard
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (ard *AbuseReportDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, ard.sqlExec, ard.mutation, ard.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (ard *AbuseReportDelete) ExecX(ctx context.Context) int {
n, err := ard.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (ard *AbuseReportDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(abusereport.Table, sqlgraph.NewFieldSpec(abusereport.FieldID, field.TypeInt))
if ps := ard.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, ard.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
ard.mutation.done = true
return affected, err
}
// AbuseReportDeleteOne is the builder for deleting a single AbuseReport entity.
type AbuseReportDeleteOne struct {
ard *AbuseReportDelete
}
// Where appends a list predicates to the AbuseReportDelete builder.
func (ardo *AbuseReportDeleteOne) Where(ps ...predicate.AbuseReport) *AbuseReportDeleteOne {
ardo.ard.mutation.Where(ps...)
return ardo
}
// Exec executes the deletion query.
func (ardo *AbuseReportDeleteOne) Exec(ctx context.Context) error {
n, err := ardo.ard.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{abusereport.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (ardo *AbuseReportDeleteOne) ExecX(ctx context.Context) {
if err := ardo.Exec(ctx); err != nil {
panic(err)
}
}

@ -0,0 +1,526 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"math"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/cloudreve/Cloudreve/v4/ent/abusereport"
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
)
// AbuseReportQuery is the builder for querying AbuseReport entities.
type AbuseReportQuery struct {
config
ctx *QueryContext
order []abusereport.OrderOption
inters []Interceptor
predicates []predicate.AbuseReport
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the AbuseReportQuery builder.
func (arq *AbuseReportQuery) Where(ps ...predicate.AbuseReport) *AbuseReportQuery {
arq.predicates = append(arq.predicates, ps...)
return arq
}
// Limit the number of records to be returned by this query.
func (arq *AbuseReportQuery) Limit(limit int) *AbuseReportQuery {
arq.ctx.Limit = &limit
return arq
}
// Offset to start from.
func (arq *AbuseReportQuery) Offset(offset int) *AbuseReportQuery {
arq.ctx.Offset = &offset
return arq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (arq *AbuseReportQuery) Unique(unique bool) *AbuseReportQuery {
arq.ctx.Unique = &unique
return arq
}
// Order specifies how the records should be ordered.
func (arq *AbuseReportQuery) Order(o ...abusereport.OrderOption) *AbuseReportQuery {
arq.order = append(arq.order, o...)
return arq
}
// First returns the first AbuseReport entity from the query.
// Returns a *NotFoundError when no AbuseReport was found.
func (arq *AbuseReportQuery) First(ctx context.Context) (*AbuseReport, error) {
nodes, err := arq.Limit(1).All(setContextOp(ctx, arq.ctx, "First"))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{abusereport.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (arq *AbuseReportQuery) FirstX(ctx context.Context) *AbuseReport {
node, err := arq.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first AbuseReport ID from the query.
// Returns a *NotFoundError when no AbuseReport ID was found.
func (arq *AbuseReportQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = arq.Limit(1).IDs(setContextOp(ctx, arq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{abusereport.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (arq *AbuseReportQuery) FirstIDX(ctx context.Context) int {
id, err := arq.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single AbuseReport entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one AbuseReport entity is found.
// Returns a *NotFoundError when no AbuseReport entities are found.
func (arq *AbuseReportQuery) Only(ctx context.Context) (*AbuseReport, error) {
nodes, err := arq.Limit(2).All(setContextOp(ctx, arq.ctx, "Only"))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{abusereport.Label}
default:
return nil, &NotSingularError{abusereport.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (arq *AbuseReportQuery) OnlyX(ctx context.Context) *AbuseReport {
node, err := arq.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only AbuseReport ID in the query.
// Returns a *NotSingularError when more than one AbuseReport ID is found.
// Returns a *NotFoundError when no entities are found.
func (arq *AbuseReportQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = arq.Limit(2).IDs(setContextOp(ctx, arq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{abusereport.Label}
default:
err = &NotSingularError{abusereport.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (arq *AbuseReportQuery) OnlyIDX(ctx context.Context) int {
id, err := arq.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of AbuseReports.
func (arq *AbuseReportQuery) All(ctx context.Context) ([]*AbuseReport, error) {
ctx = setContextOp(ctx, arq.ctx, "All")
if err := arq.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*AbuseReport, *AbuseReportQuery]()
return withInterceptors[[]*AbuseReport](ctx, arq, qr, arq.inters)
}
// AllX is like All, but panics if an error occurs.
func (arq *AbuseReportQuery) AllX(ctx context.Context) []*AbuseReport {
nodes, err := arq.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of AbuseReport IDs.
func (arq *AbuseReportQuery) IDs(ctx context.Context) (ids []int, err error) {
if arq.ctx.Unique == nil && arq.path != nil {
arq.Unique(true)
}
ctx = setContextOp(ctx, arq.ctx, "IDs")
if err = arq.Select(abusereport.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (arq *AbuseReportQuery) IDsX(ctx context.Context) []int {
ids, err := arq.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (arq *AbuseReportQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, arq.ctx, "Count")
if err := arq.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, arq, querierCount[*AbuseReportQuery](), arq.inters)
}
// CountX is like Count, but panics if an error occurs.
func (arq *AbuseReportQuery) CountX(ctx context.Context) int {
count, err := arq.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (arq *AbuseReportQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, arq.ctx, "Exist")
switch _, err := arq.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("ent: check existence: %w", err)
default:
return true, nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func (arq *AbuseReportQuery) ExistX(ctx context.Context) bool {
exist, err := arq.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the AbuseReportQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (arq *AbuseReportQuery) Clone() *AbuseReportQuery {
if arq == nil {
return nil
}
return &AbuseReportQuery{
config: arq.config,
ctx: arq.ctx.Clone(),
order: append([]abusereport.OrderOption{}, arq.order...),
inters: append([]Interceptor{}, arq.inters...),
predicates: append([]predicate.AbuseReport{}, arq.predicates...),
// clone intermediate query.
sql: arq.sql.Clone(),
path: arq.path,
}
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// CreatedAt time.Time `json:"created_at,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.AbuseReport.Query().
// GroupBy(abusereport.FieldCreatedAt).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (arq *AbuseReportQuery) GroupBy(field string, fields ...string) *AbuseReportGroupBy {
arq.ctx.Fields = append([]string{field}, fields...)
grbuild := &AbuseReportGroupBy{build: arq}
grbuild.flds = &arq.ctx.Fields
grbuild.label = abusereport.Label
grbuild.scan = grbuild.Scan
return grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// CreatedAt time.Time `json:"created_at,omitempty"`
// }
//
// client.AbuseReport.Query().
// Select(abusereport.FieldCreatedAt).
// Scan(ctx, &v)
func (arq *AbuseReportQuery) Select(fields ...string) *AbuseReportSelect {
arq.ctx.Fields = append(arq.ctx.Fields, fields...)
sbuild := &AbuseReportSelect{AbuseReportQuery: arq}
sbuild.label = abusereport.Label
sbuild.flds, sbuild.scan = &arq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a AbuseReportSelect configured with the given aggregations.
func (arq *AbuseReportQuery) Aggregate(fns ...AggregateFunc) *AbuseReportSelect {
return arq.Select().Aggregate(fns...)
}
func (arq *AbuseReportQuery) prepareQuery(ctx context.Context) error {
for _, inter := range arq.inters {
if inter == nil {
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
}
if trv, ok := inter.(Traverser); ok {
if err := trv.Traverse(ctx, arq); err != nil {
return err
}
}
}
for _, f := range arq.ctx.Fields {
if !abusereport.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if arq.path != nil {
prev, err := arq.path(ctx)
if err != nil {
return err
}
arq.sql = prev
}
return nil
}
func (arq *AbuseReportQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*AbuseReport, error) {
var (
nodes = []*AbuseReport{}
_spec = arq.querySpec()
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*AbuseReport).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &AbuseReport{config: arq.config}
nodes = append(nodes, node)
return node.assignValues(columns, values)
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, arq.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
return nodes, nil
}
func (arq *AbuseReportQuery) sqlCount(ctx context.Context) (int, error) {
_spec := arq.querySpec()
_spec.Node.Columns = arq.ctx.Fields
if len(arq.ctx.Fields) > 0 {
_spec.Unique = arq.ctx.Unique != nil && *arq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, arq.driver, _spec)
}
func (arq *AbuseReportQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(abusereport.Table, abusereport.Columns, sqlgraph.NewFieldSpec(abusereport.FieldID, field.TypeInt))
_spec.From = arq.sql
if unique := arq.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if arq.path != nil {
_spec.Unique = true
}
if fields := arq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, abusereport.FieldID)
for i := range fields {
if fields[i] != abusereport.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := arq.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := arq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := arq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := arq.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (arq *AbuseReportQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(arq.driver.Dialect())
t1 := builder.Table(abusereport.Table)
columns := arq.ctx.Fields
if len(columns) == 0 {
columns = abusereport.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if arq.sql != nil {
selector = arq.sql
selector.Select(selector.Columns(columns...)...)
}
if arq.ctx.Unique != nil && *arq.ctx.Unique {
selector.Distinct()
}
for _, p := range arq.predicates {
p(selector)
}
for _, p := range arq.order {
p(selector)
}
if offset := arq.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := arq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// AbuseReportGroupBy is the group-by builder for AbuseReport entities.
type AbuseReportGroupBy struct {
selector
build *AbuseReportQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (argb *AbuseReportGroupBy) Aggregate(fns ...AggregateFunc) *AbuseReportGroupBy {
argb.fns = append(argb.fns, fns...)
return argb
}
// Scan applies the selector query and scans the result into the given value.
func (argb *AbuseReportGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, argb.build.ctx, "GroupBy")
if err := argb.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*AbuseReportQuery, *AbuseReportGroupBy](ctx, argb.build, argb, argb.build.inters, v)
}
func (argb *AbuseReportGroupBy) sqlScan(ctx context.Context, root *AbuseReportQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(argb.fns))
for _, fn := range argb.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*argb.flds)+len(argb.fns))
for _, f := range *argb.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*argb.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := argb.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// AbuseReportSelect is the builder for selecting fields of AbuseReport entities.
type AbuseReportSelect struct {
*AbuseReportQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (ars *AbuseReportSelect) Aggregate(fns ...AggregateFunc) *AbuseReportSelect {
ars.fns = append(ars.fns, fns...)
return ars
}
// Scan applies the selector query and scans the result into the given value.
func (ars *AbuseReportSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, ars.ctx, "Select")
if err := ars.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*AbuseReportQuery, *AbuseReportSelect](ctx, ars.AbuseReportQuery, ars, ars.inters, v)
}
func (ars *AbuseReportSelect) sqlScan(ctx context.Context, root *AbuseReportQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(ars.fns))
for _, fn := range ars.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*ars.selector.flds); {
case n == 0 && len(aggregation) > 0:
selector.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
selector.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := ars.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}

@ -0,0 +1,680 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/cloudreve/Cloudreve/v4/ent/abusereport"
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
)
// AbuseReportUpdate is the builder for updating AbuseReport entities.
type AbuseReportUpdate struct {
config
hooks []Hook
mutation *AbuseReportMutation
}
// Where appends a list predicates to the AbuseReportUpdate builder.
func (aru *AbuseReportUpdate) Where(ps ...predicate.AbuseReport) *AbuseReportUpdate {
aru.mutation.Where(ps...)
return aru
}
// SetUpdatedAt sets the "updated_at" field.
func (aru *AbuseReportUpdate) SetUpdatedAt(t time.Time) *AbuseReportUpdate {
aru.mutation.SetUpdatedAt(t)
return aru
}
// SetDeletedAt sets the "deleted_at" field.
func (aru *AbuseReportUpdate) SetDeletedAt(t time.Time) *AbuseReportUpdate {
aru.mutation.SetDeletedAt(t)
return aru
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (aru *AbuseReportUpdate) SetNillableDeletedAt(t *time.Time) *AbuseReportUpdate {
if t != nil {
aru.SetDeletedAt(*t)
}
return aru
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (aru *AbuseReportUpdate) ClearDeletedAt() *AbuseReportUpdate {
aru.mutation.ClearDeletedAt()
return aru
}
// SetReporterID sets the "reporter_id" field.
func (aru *AbuseReportUpdate) SetReporterID(i int) *AbuseReportUpdate {
aru.mutation.ResetReporterID()
aru.mutation.SetReporterID(i)
return aru
}
// SetNillableReporterID sets the "reporter_id" field if the given value is not nil.
func (aru *AbuseReportUpdate) SetNillableReporterID(i *int) *AbuseReportUpdate {
if i != nil {
aru.SetReporterID(*i)
}
return aru
}
// AddReporterID adds i to the "reporter_id" field.
func (aru *AbuseReportUpdate) AddReporterID(i int) *AbuseReportUpdate {
aru.mutation.AddReporterID(i)
return aru
}
// ClearReporterID clears the value of the "reporter_id" field.
func (aru *AbuseReportUpdate) ClearReporterID() *AbuseReportUpdate {
aru.mutation.ClearReporterID()
return aru
}
// SetReporterEmail sets the "reporter_email" field.
func (aru *AbuseReportUpdate) SetReporterEmail(s string) *AbuseReportUpdate {
aru.mutation.SetReporterEmail(s)
return aru
}
// SetNillableReporterEmail sets the "reporter_email" field if the given value is not nil.
func (aru *AbuseReportUpdate) SetNillableReporterEmail(s *string) *AbuseReportUpdate {
if s != nil {
aru.SetReporterEmail(*s)
}
return aru
}
// ClearReporterEmail clears the value of the "reporter_email" field.
func (aru *AbuseReportUpdate) ClearReporterEmail() *AbuseReportUpdate {
aru.mutation.ClearReporterEmail()
return aru
}
// SetTargetType sets the "target_type" field.
func (aru *AbuseReportUpdate) SetTargetType(s string) *AbuseReportUpdate {
aru.mutation.SetTargetType(s)
return aru
}
// SetNillableTargetType sets the "target_type" field if the given value is not nil.
func (aru *AbuseReportUpdate) SetNillableTargetType(s *string) *AbuseReportUpdate {
if s != nil {
aru.SetTargetType(*s)
}
return aru
}
// SetTargetID sets the "target_id" field.
func (aru *AbuseReportUpdate) SetTargetID(i int) *AbuseReportUpdate {
aru.mutation.ResetTargetID()
aru.mutation.SetTargetID(i)
return aru
}
// SetNillableTargetID sets the "target_id" field if the given value is not nil.
func (aru *AbuseReportUpdate) SetNillableTargetID(i *int) *AbuseReportUpdate {
if i != nil {
aru.SetTargetID(*i)
}
return aru
}
// AddTargetID adds i to the "target_id" field.
func (aru *AbuseReportUpdate) AddTargetID(i int) *AbuseReportUpdate {
aru.mutation.AddTargetID(i)
return aru
}
// SetReason sets the "reason" field.
func (aru *AbuseReportUpdate) SetReason(i int) *AbuseReportUpdate {
aru.mutation.ResetReason()
aru.mutation.SetReason(i)
return aru
}
// SetNillableReason sets the "reason" field if the given value is not nil.
func (aru *AbuseReportUpdate) SetNillableReason(i *int) *AbuseReportUpdate {
if i != nil {
aru.SetReason(*i)
}
return aru
}
// AddReason adds i to the "reason" field.
func (aru *AbuseReportUpdate) AddReason(i int) *AbuseReportUpdate {
aru.mutation.AddReason(i)
return aru
}
// SetDescription sets the "description" field.
func (aru *AbuseReportUpdate) SetDescription(s string) *AbuseReportUpdate {
aru.mutation.SetDescription(s)
return aru
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (aru *AbuseReportUpdate) SetNillableDescription(s *string) *AbuseReportUpdate {
if s != nil {
aru.SetDescription(*s)
}
return aru
}
// ClearDescription clears the value of the "description" field.
func (aru *AbuseReportUpdate) ClearDescription() *AbuseReportUpdate {
aru.mutation.ClearDescription()
return aru
}
// SetStatus sets the "status" field.
func (aru *AbuseReportUpdate) SetStatus(s string) *AbuseReportUpdate {
aru.mutation.SetStatus(s)
return aru
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (aru *AbuseReportUpdate) SetNillableStatus(s *string) *AbuseReportUpdate {
if s != nil {
aru.SetStatus(*s)
}
return aru
}
// SetAdminNote sets the "admin_note" field.
func (aru *AbuseReportUpdate) SetAdminNote(s string) *AbuseReportUpdate {
aru.mutation.SetAdminNote(s)
return aru
}
// SetNillableAdminNote sets the "admin_note" field if the given value is not nil.
func (aru *AbuseReportUpdate) SetNillableAdminNote(s *string) *AbuseReportUpdate {
if s != nil {
aru.SetAdminNote(*s)
}
return aru
}
// ClearAdminNote clears the value of the "admin_note" field.
func (aru *AbuseReportUpdate) ClearAdminNote() *AbuseReportUpdate {
aru.mutation.ClearAdminNote()
return aru
}
// Mutation returns the AbuseReportMutation object of the builder.
func (aru *AbuseReportUpdate) Mutation() *AbuseReportMutation {
return aru.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (aru *AbuseReportUpdate) Save(ctx context.Context) (int, error) {
if err := aru.defaults(); err != nil {
return 0, err
}
return withHooks(ctx, aru.sqlSave, aru.mutation, aru.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (aru *AbuseReportUpdate) SaveX(ctx context.Context) int {
affected, err := aru.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (aru *AbuseReportUpdate) Exec(ctx context.Context) error {
_, err := aru.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (aru *AbuseReportUpdate) ExecX(ctx context.Context) {
if err := aru.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (aru *AbuseReportUpdate) defaults() error {
if _, ok := aru.mutation.UpdatedAt(); !ok {
if abusereport.UpdateDefaultUpdatedAt == nil {
return fmt.Errorf("ent: uninitialized abusereport.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
}
v := abusereport.UpdateDefaultUpdatedAt()
aru.mutation.SetUpdatedAt(v)
}
return nil
}
func (aru *AbuseReportUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := sqlgraph.NewUpdateSpec(abusereport.Table, abusereport.Columns, sqlgraph.NewFieldSpec(abusereport.FieldID, field.TypeInt))
if ps := aru.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := aru.mutation.UpdatedAt(); ok {
_spec.SetField(abusereport.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := aru.mutation.DeletedAt(); ok {
_spec.SetField(abusereport.FieldDeletedAt, field.TypeTime, value)
}
if aru.mutation.DeletedAtCleared() {
_spec.ClearField(abusereport.FieldDeletedAt, field.TypeTime)
}
if value, ok := aru.mutation.ReporterID(); ok {
_spec.SetField(abusereport.FieldReporterID, field.TypeInt, value)
}
if value, ok := aru.mutation.AddedReporterID(); ok {
_spec.AddField(abusereport.FieldReporterID, field.TypeInt, value)
}
if aru.mutation.ReporterIDCleared() {
_spec.ClearField(abusereport.FieldReporterID, field.TypeInt)
}
if value, ok := aru.mutation.ReporterEmail(); ok {
_spec.SetField(abusereport.FieldReporterEmail, field.TypeString, value)
}
if aru.mutation.ReporterEmailCleared() {
_spec.ClearField(abusereport.FieldReporterEmail, field.TypeString)
}
if value, ok := aru.mutation.TargetType(); ok {
_spec.SetField(abusereport.FieldTargetType, field.TypeString, value)
}
if value, ok := aru.mutation.TargetID(); ok {
_spec.SetField(abusereport.FieldTargetID, field.TypeInt, value)
}
if value, ok := aru.mutation.AddedTargetID(); ok {
_spec.AddField(abusereport.FieldTargetID, field.TypeInt, value)
}
if value, ok := aru.mutation.Reason(); ok {
_spec.SetField(abusereport.FieldReason, field.TypeInt, value)
}
if value, ok := aru.mutation.AddedReason(); ok {
_spec.AddField(abusereport.FieldReason, field.TypeInt, value)
}
if value, ok := aru.mutation.Description(); ok {
_spec.SetField(abusereport.FieldDescription, field.TypeString, value)
}
if aru.mutation.DescriptionCleared() {
_spec.ClearField(abusereport.FieldDescription, field.TypeString)
}
if value, ok := aru.mutation.Status(); ok {
_spec.SetField(abusereport.FieldStatus, field.TypeString, value)
}
if value, ok := aru.mutation.AdminNote(); ok {
_spec.SetField(abusereport.FieldAdminNote, field.TypeString, value)
}
if aru.mutation.AdminNoteCleared() {
_spec.ClearField(abusereport.FieldAdminNote, field.TypeString)
}
if n, err = sqlgraph.UpdateNodes(ctx, aru.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{abusereport.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
aru.mutation.done = true
return n, nil
}
// AbuseReportUpdateOne is the builder for updating a single AbuseReport entity.
type AbuseReportUpdateOne struct {
config
fields []string
hooks []Hook
mutation *AbuseReportMutation
}
// SetUpdatedAt sets the "updated_at" field.
func (aruo *AbuseReportUpdateOne) SetUpdatedAt(t time.Time) *AbuseReportUpdateOne {
aruo.mutation.SetUpdatedAt(t)
return aruo
}
// SetDeletedAt sets the "deleted_at" field.
func (aruo *AbuseReportUpdateOne) SetDeletedAt(t time.Time) *AbuseReportUpdateOne {
aruo.mutation.SetDeletedAt(t)
return aruo
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (aruo *AbuseReportUpdateOne) SetNillableDeletedAt(t *time.Time) *AbuseReportUpdateOne {
if t != nil {
aruo.SetDeletedAt(*t)
}
return aruo
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (aruo *AbuseReportUpdateOne) ClearDeletedAt() *AbuseReportUpdateOne {
aruo.mutation.ClearDeletedAt()
return aruo
}
// SetReporterID sets the "reporter_id" field.
func (aruo *AbuseReportUpdateOne) SetReporterID(i int) *AbuseReportUpdateOne {
aruo.mutation.ResetReporterID()
aruo.mutation.SetReporterID(i)
return aruo
}
// SetNillableReporterID sets the "reporter_id" field if the given value is not nil.
func (aruo *AbuseReportUpdateOne) SetNillableReporterID(i *int) *AbuseReportUpdateOne {
if i != nil {
aruo.SetReporterID(*i)
}
return aruo
}
// AddReporterID adds i to the "reporter_id" field.
func (aruo *AbuseReportUpdateOne) AddReporterID(i int) *AbuseReportUpdateOne {
aruo.mutation.AddReporterID(i)
return aruo
}
// ClearReporterID clears the value of the "reporter_id" field.
func (aruo *AbuseReportUpdateOne) ClearReporterID() *AbuseReportUpdateOne {
aruo.mutation.ClearReporterID()
return aruo
}
// SetReporterEmail sets the "reporter_email" field.
func (aruo *AbuseReportUpdateOne) SetReporterEmail(s string) *AbuseReportUpdateOne {
aruo.mutation.SetReporterEmail(s)
return aruo
}
// SetNillableReporterEmail sets the "reporter_email" field if the given value is not nil.
func (aruo *AbuseReportUpdateOne) SetNillableReporterEmail(s *string) *AbuseReportUpdateOne {
if s != nil {
aruo.SetReporterEmail(*s)
}
return aruo
}
// ClearReporterEmail clears the value of the "reporter_email" field.
func (aruo *AbuseReportUpdateOne) ClearReporterEmail() *AbuseReportUpdateOne {
aruo.mutation.ClearReporterEmail()
return aruo
}
// SetTargetType sets the "target_type" field.
func (aruo *AbuseReportUpdateOne) SetTargetType(s string) *AbuseReportUpdateOne {
aruo.mutation.SetTargetType(s)
return aruo
}
// SetNillableTargetType sets the "target_type" field if the given value is not nil.
func (aruo *AbuseReportUpdateOne) SetNillableTargetType(s *string) *AbuseReportUpdateOne {
if s != nil {
aruo.SetTargetType(*s)
}
return aruo
}
// SetTargetID sets the "target_id" field.
func (aruo *AbuseReportUpdateOne) SetTargetID(i int) *AbuseReportUpdateOne {
aruo.mutation.ResetTargetID()
aruo.mutation.SetTargetID(i)
return aruo
}
// SetNillableTargetID sets the "target_id" field if the given value is not nil.
func (aruo *AbuseReportUpdateOne) SetNillableTargetID(i *int) *AbuseReportUpdateOne {
if i != nil {
aruo.SetTargetID(*i)
}
return aruo
}
// AddTargetID adds i to the "target_id" field.
func (aruo *AbuseReportUpdateOne) AddTargetID(i int) *AbuseReportUpdateOne {
aruo.mutation.AddTargetID(i)
return aruo
}
// SetReason sets the "reason" field.
func (aruo *AbuseReportUpdateOne) SetReason(i int) *AbuseReportUpdateOne {
aruo.mutation.ResetReason()
aruo.mutation.SetReason(i)
return aruo
}
// SetNillableReason sets the "reason" field if the given value is not nil.
func (aruo *AbuseReportUpdateOne) SetNillableReason(i *int) *AbuseReportUpdateOne {
if i != nil {
aruo.SetReason(*i)
}
return aruo
}
// AddReason adds i to the "reason" field.
func (aruo *AbuseReportUpdateOne) AddReason(i int) *AbuseReportUpdateOne {
aruo.mutation.AddReason(i)
return aruo
}
// SetDescription sets the "description" field.
func (aruo *AbuseReportUpdateOne) SetDescription(s string) *AbuseReportUpdateOne {
aruo.mutation.SetDescription(s)
return aruo
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (aruo *AbuseReportUpdateOne) SetNillableDescription(s *string) *AbuseReportUpdateOne {
if s != nil {
aruo.SetDescription(*s)
}
return aruo
}
// ClearDescription clears the value of the "description" field.
func (aruo *AbuseReportUpdateOne) ClearDescription() *AbuseReportUpdateOne {
aruo.mutation.ClearDescription()
return aruo
}
// SetStatus sets the "status" field.
func (aruo *AbuseReportUpdateOne) SetStatus(s string) *AbuseReportUpdateOne {
aruo.mutation.SetStatus(s)
return aruo
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (aruo *AbuseReportUpdateOne) SetNillableStatus(s *string) *AbuseReportUpdateOne {
if s != nil {
aruo.SetStatus(*s)
}
return aruo
}
// SetAdminNote sets the "admin_note" field.
func (aruo *AbuseReportUpdateOne) SetAdminNote(s string) *AbuseReportUpdateOne {
aruo.mutation.SetAdminNote(s)
return aruo
}
// SetNillableAdminNote sets the "admin_note" field if the given value is not nil.
func (aruo *AbuseReportUpdateOne) SetNillableAdminNote(s *string) *AbuseReportUpdateOne {
if s != nil {
aruo.SetAdminNote(*s)
}
return aruo
}
// ClearAdminNote clears the value of the "admin_note" field.
func (aruo *AbuseReportUpdateOne) ClearAdminNote() *AbuseReportUpdateOne {
aruo.mutation.ClearAdminNote()
return aruo
}
// Mutation returns the AbuseReportMutation object of the builder.
func (aruo *AbuseReportUpdateOne) Mutation() *AbuseReportMutation {
return aruo.mutation
}
// Where appends a list predicates to the AbuseReportUpdate builder.
func (aruo *AbuseReportUpdateOne) Where(ps ...predicate.AbuseReport) *AbuseReportUpdateOne {
aruo.mutation.Where(ps...)
return aruo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (aruo *AbuseReportUpdateOne) Select(field string, fields ...string) *AbuseReportUpdateOne {
aruo.fields = append([]string{field}, fields...)
return aruo
}
// Save executes the query and returns the updated AbuseReport entity.
func (aruo *AbuseReportUpdateOne) Save(ctx context.Context) (*AbuseReport, error) {
if err := aruo.defaults(); err != nil {
return nil, err
}
return withHooks(ctx, aruo.sqlSave, aruo.mutation, aruo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (aruo *AbuseReportUpdateOne) SaveX(ctx context.Context) *AbuseReport {
node, err := aruo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (aruo *AbuseReportUpdateOne) Exec(ctx context.Context) error {
_, err := aruo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (aruo *AbuseReportUpdateOne) ExecX(ctx context.Context) {
if err := aruo.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (aruo *AbuseReportUpdateOne) defaults() error {
if _, ok := aruo.mutation.UpdatedAt(); !ok {
if abusereport.UpdateDefaultUpdatedAt == nil {
return fmt.Errorf("ent: uninitialized abusereport.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
}
v := abusereport.UpdateDefaultUpdatedAt()
aruo.mutation.SetUpdatedAt(v)
}
return nil
}
func (aruo *AbuseReportUpdateOne) sqlSave(ctx context.Context) (_node *AbuseReport, err error) {
_spec := sqlgraph.NewUpdateSpec(abusereport.Table, abusereport.Columns, sqlgraph.NewFieldSpec(abusereport.FieldID, field.TypeInt))
id, ok := aruo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AbuseReport.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := aruo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, abusereport.FieldID)
for _, f := range fields {
if !abusereport.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != abusereport.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := aruo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := aruo.mutation.UpdatedAt(); ok {
_spec.SetField(abusereport.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := aruo.mutation.DeletedAt(); ok {
_spec.SetField(abusereport.FieldDeletedAt, field.TypeTime, value)
}
if aruo.mutation.DeletedAtCleared() {
_spec.ClearField(abusereport.FieldDeletedAt, field.TypeTime)
}
if value, ok := aruo.mutation.ReporterID(); ok {
_spec.SetField(abusereport.FieldReporterID, field.TypeInt, value)
}
if value, ok := aruo.mutation.AddedReporterID(); ok {
_spec.AddField(abusereport.FieldReporterID, field.TypeInt, value)
}
if aruo.mutation.ReporterIDCleared() {
_spec.ClearField(abusereport.FieldReporterID, field.TypeInt)
}
if value, ok := aruo.mutation.ReporterEmail(); ok {
_spec.SetField(abusereport.FieldReporterEmail, field.TypeString, value)
}
if aruo.mutation.ReporterEmailCleared() {
_spec.ClearField(abusereport.FieldReporterEmail, field.TypeString)
}
if value, ok := aruo.mutation.TargetType(); ok {
_spec.SetField(abusereport.FieldTargetType, field.TypeString, value)
}
if value, ok := aruo.mutation.TargetID(); ok {
_spec.SetField(abusereport.FieldTargetID, field.TypeInt, value)
}
if value, ok := aruo.mutation.AddedTargetID(); ok {
_spec.AddField(abusereport.FieldTargetID, field.TypeInt, value)
}
if value, ok := aruo.mutation.Reason(); ok {
_spec.SetField(abusereport.FieldReason, field.TypeInt, value)
}
if value, ok := aruo.mutation.AddedReason(); ok {
_spec.AddField(abusereport.FieldReason, field.TypeInt, value)
}
if value, ok := aruo.mutation.Description(); ok {
_spec.SetField(abusereport.FieldDescription, field.TypeString, value)
}
if aruo.mutation.DescriptionCleared() {
_spec.ClearField(abusereport.FieldDescription, field.TypeString)
}
if value, ok := aruo.mutation.Status(); ok {
_spec.SetField(abusereport.FieldStatus, field.TypeString, value)
}
if value, ok := aruo.mutation.AdminNote(); ok {
_spec.SetField(abusereport.FieldAdminNote, field.TypeString, value)
}
if aruo.mutation.AdminNoteCleared() {
_spec.ClearField(abusereport.FieldAdminNote, field.TypeString)
}
_node = &AbuseReport{config: aruo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, aruo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{abusereport.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
aruo.mutation.done = true
return _node, nil
}

@ -15,6 +15,7 @@ import (
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"github.com/cloudreve/Cloudreve/v4/ent/abusereport"
"github.com/cloudreve/Cloudreve/v4/ent/aclentry"
"github.com/cloudreve/Cloudreve/v4/ent/activityevent"
"github.com/cloudreve/Cloudreve/v4/ent/credittxn"
@ -46,6 +47,8 @@ type Client struct {
config
// Schema is the client for creating, migrating and dropping schema.
Schema *migrate.Schema
// AbuseReport is the client for interacting with the AbuseReport builders.
AbuseReport *AbuseReportClient
// AclEntry is the client for interacting with the AclEntry builders.
AclEntry *AclEntryClient
// ActivityEvent is the client for interacting with the ActivityEvent builders.
@ -101,6 +104,7 @@ func NewClient(opts ...Option) *Client {
func (c *Client) init() {
c.Schema = migrate.NewSchema(c.driver)
c.AbuseReport = NewAbuseReportClient(c.config)
c.AclEntry = NewAclEntryClient(c.config)
c.ActivityEvent = NewActivityEventClient(c.config)
c.CreditTxn = NewCreditTxnClient(c.config)
@ -215,6 +219,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
return &Tx{
ctx: ctx,
config: cfg,
AbuseReport: NewAbuseReportClient(cfg),
AclEntry: NewAclEntryClient(cfg),
ActivityEvent: NewActivityEventClient(cfg),
CreditTxn: NewCreditTxnClient(cfg),
@ -256,6 +261,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
return &Tx{
ctx: ctx,
config: cfg,
AbuseReport: NewAbuseReportClient(cfg),
AclEntry: NewAclEntryClient(cfg),
ActivityEvent: NewActivityEventClient(cfg),
CreditTxn: NewCreditTxnClient(cfg),
@ -284,7 +290,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
//
// client.Debug().
// AclEntry.
// AbuseReport.
// Query().
// Count(ctx)
func (c *Client) Debug() *Client {
@ -307,10 +313,10 @@ func (c *Client) Close() error {
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
func (c *Client) Use(hooks ...Hook) {
for _, n := range []interface{ Use(...Hook) }{
c.AclEntry, c.ActivityEvent, c.CreditTxn, c.DavAccount, c.DirectLink, c.Entity,
c.File, c.FsEvent, c.GiftCode, c.Group, c.InvitationCode, c.Metadata, c.Node,
c.OAuthClient, c.OAuthGrant, c.Passkey, c.Setting, c.Share, c.StoragePolicy,
c.Task, c.User, c.UserGrant,
c.AbuseReport, c.AclEntry, c.ActivityEvent, c.CreditTxn, c.DavAccount,
c.DirectLink, c.Entity, c.File, c.FsEvent, c.GiftCode, c.Group,
c.InvitationCode, c.Metadata, c.Node, c.OAuthClient, c.OAuthGrant, c.Passkey,
c.Setting, c.Share, c.StoragePolicy, c.Task, c.User, c.UserGrant,
} {
n.Use(hooks...)
}
@ -320,10 +326,10 @@ func (c *Client) Use(hooks ...Hook) {
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
func (c *Client) Intercept(interceptors ...Interceptor) {
for _, n := range []interface{ Intercept(...Interceptor) }{
c.AclEntry, c.ActivityEvent, c.CreditTxn, c.DavAccount, c.DirectLink, c.Entity,
c.File, c.FsEvent, c.GiftCode, c.Group, c.InvitationCode, c.Metadata, c.Node,
c.OAuthClient, c.OAuthGrant, c.Passkey, c.Setting, c.Share, c.StoragePolicy,
c.Task, c.User, c.UserGrant,
c.AbuseReport, c.AclEntry, c.ActivityEvent, c.CreditTxn, c.DavAccount,
c.DirectLink, c.Entity, c.File, c.FsEvent, c.GiftCode, c.Group,
c.InvitationCode, c.Metadata, c.Node, c.OAuthClient, c.OAuthGrant, c.Passkey,
c.Setting, c.Share, c.StoragePolicy, c.Task, c.User, c.UserGrant,
} {
n.Intercept(interceptors...)
}
@ -332,6 +338,8 @@ func (c *Client) Intercept(interceptors ...Interceptor) {
// Mutate implements the ent.Mutator interface.
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
switch m := m.(type) {
case *AbuseReportMutation:
return c.AbuseReport.mutate(ctx, m)
case *AclEntryMutation:
return c.AclEntry.mutate(ctx, m)
case *ActivityEventMutation:
@ -381,6 +389,141 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
}
}
// AbuseReportClient is a client for the AbuseReport schema.
type AbuseReportClient struct {
config
}
// NewAbuseReportClient returns a client for the AbuseReport from the given config.
func NewAbuseReportClient(c config) *AbuseReportClient {
return &AbuseReportClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `abusereport.Hooks(f(g(h())))`.
func (c *AbuseReportClient) Use(hooks ...Hook) {
c.hooks.AbuseReport = append(c.hooks.AbuseReport, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `abusereport.Intercept(f(g(h())))`.
func (c *AbuseReportClient) Intercept(interceptors ...Interceptor) {
c.inters.AbuseReport = append(c.inters.AbuseReport, interceptors...)
}
// Create returns a builder for creating a AbuseReport entity.
func (c *AbuseReportClient) Create() *AbuseReportCreate {
mutation := newAbuseReportMutation(c.config, OpCreate)
return &AbuseReportCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of AbuseReport entities.
func (c *AbuseReportClient) CreateBulk(builders ...*AbuseReportCreate) *AbuseReportCreateBulk {
return &AbuseReportCreateBulk{config: c.config, builders: builders}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *AbuseReportClient) MapCreateBulk(slice any, setFunc func(*AbuseReportCreate, int)) *AbuseReportCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &AbuseReportCreateBulk{err: fmt.Errorf("calling to AbuseReportClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*AbuseReportCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &AbuseReportCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for AbuseReport.
func (c *AbuseReportClient) Update() *AbuseReportUpdate {
mutation := newAbuseReportMutation(c.config, OpUpdate)
return &AbuseReportUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *AbuseReportClient) UpdateOne(ar *AbuseReport) *AbuseReportUpdateOne {
mutation := newAbuseReportMutation(c.config, OpUpdateOne, withAbuseReport(ar))
return &AbuseReportUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *AbuseReportClient) UpdateOneID(id int) *AbuseReportUpdateOne {
mutation := newAbuseReportMutation(c.config, OpUpdateOne, withAbuseReportID(id))
return &AbuseReportUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for AbuseReport.
func (c *AbuseReportClient) Delete() *AbuseReportDelete {
mutation := newAbuseReportMutation(c.config, OpDelete)
return &AbuseReportDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *AbuseReportClient) DeleteOne(ar *AbuseReport) *AbuseReportDeleteOne {
return c.DeleteOneID(ar.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *AbuseReportClient) DeleteOneID(id int) *AbuseReportDeleteOne {
builder := c.Delete().Where(abusereport.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &AbuseReportDeleteOne{builder}
}
// Query returns a query builder for AbuseReport.
func (c *AbuseReportClient) Query() *AbuseReportQuery {
return &AbuseReportQuery{
config: c.config,
ctx: &QueryContext{Type: TypeAbuseReport},
inters: c.Interceptors(),
}
}
// Get returns a AbuseReport entity by its id.
func (c *AbuseReportClient) Get(ctx context.Context, id int) (*AbuseReport, error) {
return c.Query().Where(abusereport.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *AbuseReportClient) GetX(ctx context.Context, id int) *AbuseReport {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *AbuseReportClient) Hooks() []Hook {
hooks := c.hooks.AbuseReport
return append(hooks[:len(hooks):len(hooks)], abusereport.Hooks[:]...)
}
// Interceptors returns the client interceptors.
func (c *AbuseReportClient) Interceptors() []Interceptor {
inters := c.inters.AbuseReport
return append(inters[:len(inters):len(inters)], abusereport.Interceptors[:]...)
}
func (c *AbuseReportClient) mutate(ctx context.Context, m *AbuseReportMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&AbuseReportCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&AbuseReportUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&AbuseReportUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&AbuseReportDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown AbuseReport mutation op: %q", m.Op())
}
}
// AclEntryClient is a client for the AclEntry schema.
type AclEntryClient struct {
config
@ -4121,14 +4264,14 @@ func (c *UserGrantClient) mutate(ctx context.Context, m *UserGrantMutation) (Val
// hooks and interceptors per client, for fast access.
type (
hooks struct {
AclEntry, ActivityEvent, CreditTxn, DavAccount, DirectLink, Entity, File,
FsEvent, GiftCode, Group, InvitationCode, Metadata, Node, OAuthClient,
AbuseReport, AclEntry, ActivityEvent, CreditTxn, DavAccount, DirectLink, Entity,
File, FsEvent, GiftCode, Group, InvitationCode, Metadata, Node, OAuthClient,
OAuthGrant, Passkey, Setting, Share, StoragePolicy, Task, User,
UserGrant []ent.Hook
}
inters struct {
AclEntry, ActivityEvent, CreditTxn, DavAccount, DirectLink, Entity, File,
FsEvent, GiftCode, Group, InvitationCode, Metadata, Node, OAuthClient,
AbuseReport, AclEntry, ActivityEvent, CreditTxn, DavAccount, DirectLink, Entity,
File, FsEvent, GiftCode, Group, InvitationCode, Metadata, Node, OAuthClient,
OAuthGrant, Passkey, Setting, Share, StoragePolicy, Task, User,
UserGrant []ent.Interceptor
}

@ -12,6 +12,7 @@ import (
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"github.com/cloudreve/Cloudreve/v4/ent/abusereport"
"github.com/cloudreve/Cloudreve/v4/ent/aclentry"
"github.com/cloudreve/Cloudreve/v4/ent/activityevent"
"github.com/cloudreve/Cloudreve/v4/ent/credittxn"
@ -94,6 +95,7 @@ var (
func checkColumn(table, column string) error {
initCheck.Do(func() {
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
abusereport.Table: abusereport.ValidColumn,
aclentry.Table: aclentry.ValidColumn,
activityevent.Table: activityevent.ValidColumn,
credittxn.Table: credittxn.ValidColumn,

@ -9,6 +9,18 @@ import (
"github.com/cloudreve/Cloudreve/v4/ent"
)
// The AbuseReportFunc type is an adapter to allow the use of ordinary
// function as AbuseReport mutator.
type AbuseReportFunc func(context.Context, *ent.AbuseReportMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f AbuseReportFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.AbuseReportMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AbuseReportMutation", m)
}
// The AclEntryFunc type is an adapter to allow the use of ordinary
// function as AclEntry mutator.
type AclEntryFunc func(context.Context, *ent.AclEntryMutation) (ent.Value, error)

@ -8,6 +8,7 @@ import (
"entgo.io/ent/dialect/sql"
"github.com/cloudreve/Cloudreve/v4/ent"
"github.com/cloudreve/Cloudreve/v4/ent/abusereport"
"github.com/cloudreve/Cloudreve/v4/ent/aclentry"
"github.com/cloudreve/Cloudreve/v4/ent/activityevent"
"github.com/cloudreve/Cloudreve/v4/ent/credittxn"
@ -89,6 +90,33 @@ func (f TraverseFunc) Traverse(ctx context.Context, q ent.Query) error {
return f(ctx, query)
}
// The AbuseReportFunc type is an adapter to allow the use of ordinary function as a Querier.
type AbuseReportFunc func(context.Context, *ent.AbuseReportQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f AbuseReportFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.AbuseReportQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.AbuseReportQuery", q)
}
// The TraverseAbuseReport type is an adapter to allow the use of ordinary function as Traverser.
type TraverseAbuseReport func(context.Context, *ent.AbuseReportQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseAbuseReport) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseAbuseReport) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.AbuseReportQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.AbuseReportQuery", q)
}
// The AclEntryFunc type is an adapter to allow the use of ordinary function as a Querier.
type AclEntryFunc func(context.Context, *ent.AclEntryQuery) (ent.Value, error)
@ -686,6 +714,8 @@ func (f TraverseUserGrant) Traverse(ctx context.Context, q ent.Query) error {
// NewQuery returns the generic Query interface for the given typed query.
func NewQuery(q ent.Query) (Query, error) {
switch q := q.(type) {
case *ent.AbuseReportQuery:
return &query[*ent.AbuseReportQuery, predicate.AbuseReport, abusereport.OrderOption]{typ: ent.TypeAbuseReport, tq: q}, nil
case *ent.AclEntryQuery:
return &query[*ent.AclEntryQuery, predicate.AclEntry, aclentry.OrderOption]{typ: ent.TypeAclEntry, tq: q}, nil
case *ent.ActivityEventQuery:

File diff suppressed because one or more lines are too long

@ -8,6 +8,39 @@ import (
)
var (
// AbuseReportsColumns holds the columns for the "abuse_reports" table.
AbuseReportsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
{Name: "deleted_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"mysql": "datetime"}},
{Name: "reporter_id", Type: field.TypeInt, Nullable: true},
{Name: "reporter_email", Type: field.TypeString, Nullable: true},
{Name: "target_type", Type: field.TypeString},
{Name: "target_id", Type: field.TypeInt},
{Name: "reason", Type: field.TypeInt},
{Name: "description", Type: field.TypeString, Nullable: true},
{Name: "status", Type: field.TypeString, Default: "open"},
{Name: "admin_note", Type: field.TypeString, Nullable: true},
}
// AbuseReportsTable holds the schema information for the "abuse_reports" table.
AbuseReportsTable = &schema.Table{
Name: "abuse_reports",
Columns: AbuseReportsColumns,
PrimaryKey: []*schema.Column{AbuseReportsColumns[0]},
Indexes: []*schema.Index{
{
Name: "abusereport_status_created_at",
Unique: false,
Columns: []*schema.Column{AbuseReportsColumns[10], AbuseReportsColumns[1]},
},
{
Name: "abusereport_target_type_target_id",
Unique: false,
Columns: []*schema.Column{AbuseReportsColumns[6], AbuseReportsColumns[7]},
},
},
}
// ACLEntriesColumns holds the columns for the "acl_entries" table.
ACLEntriesColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
@ -756,6 +789,7 @@ var (
}
// Tables holds all the tables in the schema.
Tables = []*schema.Table{
AbuseReportsTable,
ACLEntriesTable,
ActivityEventsTable,
CreditTxnsTable,

File diff suppressed because it is too large Load Diff

@ -4,6 +4,12 @@ package ent
// SetUpdatedAt sets the "updated_at" field.
func (m *AbuseReportMutation) SetRawID(t int) {
m.id = &t
}
// SetUpdatedAt sets the "updated_at" field.
func (m *AclEntryMutation) SetRawID(t int) {
m.id = &t
}

@ -6,6 +6,9 @@ import (
"entgo.io/ent/dialect/sql"
)
// AbuseReport is the predicate function for abusereport builders.
type AbuseReport func(*sql.Selector)
// AclEntry is the predicate function for aclentry builders.
type AclEntry func(*sql.Selector)

@ -5,6 +5,7 @@ package runtime
import (
"time"
"github.com/cloudreve/Cloudreve/v4/ent/abusereport"
"github.com/cloudreve/Cloudreve/v4/ent/aclentry"
"github.com/cloudreve/Cloudreve/v4/ent/activityevent"
"github.com/cloudreve/Cloudreve/v4/ent/credittxn"
@ -35,6 +36,29 @@ import (
// (default values, validators, hooks and policies) and stitches it
// to their package variables.
func init() {
abusereportMixin := schema.AbuseReport{}.Mixin()
abusereportMixinHooks0 := abusereportMixin[0].Hooks()
abusereport.Hooks[0] = abusereportMixinHooks0[0]
abusereportMixinInters0 := abusereportMixin[0].Interceptors()
abusereport.Interceptors[0] = abusereportMixinInters0[0]
abusereportMixinFields0 := abusereportMixin[0].Fields()
_ = abusereportMixinFields0
abusereportFields := schema.AbuseReport{}.Fields()
_ = abusereportFields
// abusereportDescCreatedAt is the schema descriptor for created_at field.
abusereportDescCreatedAt := abusereportMixinFields0[0].Descriptor()
// abusereport.DefaultCreatedAt holds the default value on creation for the created_at field.
abusereport.DefaultCreatedAt = abusereportDescCreatedAt.Default.(func() time.Time)
// abusereportDescUpdatedAt is the schema descriptor for updated_at field.
abusereportDescUpdatedAt := abusereportMixinFields0[1].Descriptor()
// abusereport.DefaultUpdatedAt holds the default value on creation for the updated_at field.
abusereport.DefaultUpdatedAt = abusereportDescUpdatedAt.Default.(func() time.Time)
// abusereport.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
abusereport.UpdateDefaultUpdatedAt = abusereportDescUpdatedAt.UpdateDefault.(func() time.Time)
// abusereportDescStatus is the schema descriptor for status field.
abusereportDescStatus := abusereportFields[6].Descriptor()
// abusereport.DefaultStatus holds the default value on creation for the status field.
abusereport.DefaultStatus = abusereportDescStatus.Default.(string)
aclentryMixin := schema.AclEntry{}.Mixin()
aclentryMixinHooks0 := aclentryMixin[0].Hooks()
aclentry.Hooks[0] = aclentryMixinHooks0[0]

@ -0,0 +1,47 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// AbuseReport holds one user-submitted abuse report against a share or a
// user. Target references are plain IDs (no edges) so reports survive
// deletion of the reported share or user.
type AbuseReport struct {
ent.Schema
}
// Fields of the AbuseReport.
func (AbuseReport) Fields() []ent.Field {
return []ent.Field{
field.Int("reporter_id").
Optional(),
field.String("reporter_email").
Optional(),
field.String("target_type"),
field.Int("target_id"),
field.Int("reason"),
field.String("description").
Optional(),
field.String("status").
Default("open"),
field.String("admin_note").
Optional(),
}
}
// Indexes of the AbuseReport.
func (AbuseReport) Indexes() []ent.Index {
return []ent.Index{
index.Fields("status", "created_at"),
index.Fields("target_type", "target_id"),
}
}
func (AbuseReport) Mixin() []ent.Mixin {
return []ent.Mixin{
CommonMixin{},
}
}

@ -14,6 +14,8 @@ import (
// Tx is a transactional client that is created by calling Client.Tx().
type Tx struct {
config
// AbuseReport is the client for interacting with the AbuseReport builders.
AbuseReport *AbuseReportClient
// AclEntry is the client for interacting with the AclEntry builders.
AclEntry *AclEntryClient
// ActivityEvent is the client for interacting with the ActivityEvent builders.
@ -189,6 +191,7 @@ func (tx *Tx) Client() *Client {
}
func (tx *Tx) init() {
tx.AbuseReport = NewAbuseReportClient(tx.config)
tx.AclEntry = NewAclEntryClient(tx.config)
tx.ActivityEvent = NewActivityEventClient(tx.config)
tx.CreditTxn = NewCreditTxnClient(tx.config)
@ -220,7 +223,7 @@ func (tx *Tx) init() {
// of them in order to commit or rollback the transaction.
//
// If a closed transaction is embedded in one of the generated entities, and the entity
// applies a query, for example: AclEntry.QueryXXX(), the query will be executed
// applies a query, for example: AbuseReport.QueryXXX(), the query will be executed
// through the driver which created this transaction.
//
// Note that txDriver is not goroutine safe.

@ -1892,6 +1892,27 @@
"reporterID": "Reporter user ID",
"reportedUserID": "Reported user ID",
"shareID": "Shared ID",
"reason": "Reason"
"reason": "Reason",
"target": "Target",
"statusLabel": "Status",
"reportedAt": "Reported at",
"actions": "Actions",
"resolve": "Resolve",
"dismiss": "Dismiss",
"adminNote": "Admin note",
"blockShare": "Block the shared link",
"noReports": "No abuse reports",
"reviewSuccess": "Report updated.",
"status": {
"open": "Open",
"resolved": "Resolved",
"dismissed": "Dismissed",
"all": "All"
},
"markAs": {
"resolved": "Resolve report",
"dismissed": "Dismiss report",
"open": "Reopen report"
}
}
}

@ -1891,6 +1891,27 @@
"reporterID": "举报者用户 ID",
"reportedUserID": "举报对象用户 ID",
"shareID": "分享 ID",
"reason": "原因"
"reason": "原因",
"target": "举报对象",
"statusLabel": "状态",
"reportedAt": "举报时间",
"actions": "操作",
"resolve": "标记已处理",
"dismiss": "忽略",
"adminNote": "管理员备注",
"blockShare": "封禁此分享链接",
"noReports": "没有举报记录",
"reviewSuccess": "举报已更新。",
"status": {
"open": "待处理",
"resolved": "已处理",
"dismissed": "已忽略",
"all": "全部"
},
"markAs": {
"resolved": "标记为已处理",
"dismissed": "忽略此举报",
"open": "重新打开举报"
}
}
}

@ -3,6 +3,9 @@ import { EncryptedBlob } from "../component/Uploader/core/uploader/encrypt/blob.
import i18n from "../i18n.ts";
import {
ActivityEventListResponse,
AbuseReportListResponse,
ReportAbuseService,
UpdateAbuseReportService,
AdjustCreditService,
AdminListGroupResponse,
AdminListService,
@ -2726,6 +2729,56 @@ export function getFileActivity(uri: string, page: number, pageSize: number): Th
};
}
export function sendReportAbuse(args: ReportAbuseService): ThunkResponse<void> {
return async (dispatch, _getState) => {
return await dispatch(
send(
"/abuse/report",
{ method: "POST", data: args },
{
...defaultOpts,
},
),
);
};
}
export function adminListAbuseReports(args: {
page: number;
pageSize: number;
status?: string;
}): ThunkResponse<AbuseReportListResponse> {
return async (dispatch, _getState) => {
const params = new URLSearchParams({ page: String(args.page), page_size: String(args.pageSize) });
if (args.status) {
params.set("status", args.status);
}
return await dispatch(
send(
`/admin/abuse?${params.toString()}`,
{ method: "GET" },
{
...defaultOpts,
},
),
);
};
}
export function adminUpdateAbuseReport(id: string, args: UpdateAbuseReportService): ThunkResponse<void> {
return async (dispatch, _getState) => {
return await dispatch(
send(
`/admin/abuse/${id}`,
{ method: "PATCH", data: args },
{
...defaultOpts,
},
),
);
};
}
export function adminAdjustCredit(args: AdjustCreditService): ThunkResponse<void> {
return async (dispatch, _getState) => {
return await dispatch(

@ -685,3 +685,38 @@ export interface AdjustCreditService {
delta: number;
des?: string;
}
export type AbuseTargetType = "share" | "user";
export type AbuseReportStatus = "open" | "resolved" | "dismissed";
export interface AbuseReport {
id: string;
reporter_id?: string;
reporter_email?: string;
target_type: AbuseTargetType;
target_id: string;
reason: number;
description: string;
status: AbuseReportStatus;
admin_note: string;
created_at: number;
}
export interface AbuseReportListResponse {
reports: AbuseReport[];
total: number;
}
export interface ReportAbuseService {
target_type: AbuseTargetType;
target: string;
reason: number;
description?: string;
[x: string]: unknown;
}
export interface UpdateAbuseReportService {
status: AbuseReportStatus;
admin_note?: string;
block_share?: boolean;
}

@ -33,6 +33,7 @@ export interface SiteConfig {
sso_display_name?: string;
sso_auto_redirect?: boolean;
download_cdn_routes?: { name: string; url: string }[];
abuse_captcha?: boolean;
logo?: string;
logo_light?: string;
tos_url?: string;

@ -0,0 +1,285 @@
import {
Box,
Button,
Chip,
Collapse,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
FormControlLabel,
IconButton,
Stack,
Switch,
Table,
TableBody,
TableCell,
TableHead,
TableRow,
TextField,
useMediaQuery,
useTheme,
} from "@mui/material";
import { KeyboardArrowDown, KeyboardArrowUp } from "@mui/icons-material";
import { enqueueSnackbar } from "notistack";
import { useQueryState } from "nuqs";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { adminListAbuseReports, adminUpdateAbuseReport } from "../../../api/api";
import { AbuseReport, AbuseReportStatus } from "../../../api/dashboard";
import { useAppDispatch } from "../../../redux/hooks";
import { DefaultCloseAction } from "../../Common/Snackbar/snackbar";
import { DenseSelect, StyledTableContainerPaper } from "../../Common/StyledComponents";
import { SquareMenuItem } from "../../FileManager/ContextMenu/ContextMenu";
import PageContainer from "../../Pages/PageContainer";
import PageHeader from "../../Pages/PageHeader";
import TablePagination from "../Common/TablePagination";
import { PageQuery, PageSizeQuery } from "../StoragePolicy/StoragePolicySetting";
export const StatusQuery = "status";
const statusColor = (status: AbuseReportStatus): "warning" | "success" | "default" => {
switch (status) {
case "open":
return "warning";
case "resolved":
return "success";
default:
return "default";
}
};
const ReviewDialog = ({
report,
status,
onClose,
onDone,
}: {
report?: AbuseReport;
status: AbuseReportStatus;
onClose: () => void;
onDone: () => void;
}) => {
const { t } = useTranslation("dashboard");
const dispatch = useAppDispatch();
const [note, setNote] = useState("");
const [blockShare, setBlockShare] = useState(false);
const [loading, setLoading] = useState(false);
useEffect(() => {
setNote("");
setBlockShare(false);
}, [report, status]);
const onSubmit = () => {
if (!report) {
return;
}
setLoading(true);
dispatch(
adminUpdateAbuseReport(report.id, {
status,
admin_note: note || undefined,
block_share: blockShare,
}),
)
.then(() => {
enqueueSnackbar({
message: t("abuseReport.reviewSuccess"),
variant: "success",
action: DefaultCloseAction,
});
onDone();
})
.finally(() => setLoading(false));
};
return (
<Dialog open={!!report} onClose={onClose} fullWidth maxWidth="sm">
<DialogTitle>{t(`abuseReport.markAs.${status}`)}</DialogTitle>
<DialogContent>
<TextField
fullWidth
multiline
minRows={2}
label={t("abuseReport.adminNote")}
value={note}
onChange={(e) => setNote(e.target.value)}
inputProps={{ maxLength: 2000 }}
sx={{ mt: 1 }}
/>
{report?.target_type === "share" && (
<FormControlLabel
sx={{ mt: 1 }}
control={<Switch checked={blockShare} onChange={(e) => setBlockShare(e.target.checked)} />}
label={t("abuseReport.blockShare")}
/>
)}
</DialogContent>
<DialogActions>
<Button onClick={onClose}>{t("common:cancel")}</Button>
<Button variant="contained" onClick={onSubmit} disabled={loading}>
{t("common:ok")}
</Button>
</DialogActions>
</Dialog>
);
};
const ReportRow = ({ report, onReview }: { report: AbuseReport; onReview: (status: AbuseReportStatus) => void }) => {
const { t } = useTranslation("dashboard");
const [open, setOpen] = useState(false);
const reasonOptions = t("application:vas.reportReasonOptions", { returnObjects: true }) as string[];
return (
<>
<TableRow hover>
<TableCell>
<IconButton size="small" onClick={() => setOpen(!open)}>
{open ? <KeyboardArrowUp /> : <KeyboardArrowDown />}
</IconButton>
</TableCell>
<TableCell>
{report.target_type === "share"
? `${t("abuseReport.shareID")} #${report.target_id}`
: `${t("abuseReport.reportedUserID")} #${report.target_id}`}
</TableCell>
<TableCell>{reasonOptions[report.reason] ?? report.reason}</TableCell>
<TableCell>{report.reporter_email || report.reporter_id || "-"}</TableCell>
<TableCell>
<Chip size="small" color={statusColor(report.status)} label={t(`abuseReport.status.${report.status}`)} />
</TableCell>
<TableCell>{new Date(report.created_at * 1000).toLocaleString()}</TableCell>
<TableCell align="right">
{report.status === "open" && (
<Stack direction="row" spacing={1} justifyContent="flex-end">
<Button size="small" onClick={() => onReview("resolved")}>
{t("abuseReport.resolve")}
</Button>
<Button size="small" onClick={() => onReview("dismissed")}>
{t("abuseReport.dismiss")}
</Button>
</Stack>
)}
</TableCell>
</TableRow>
<TableRow>
<TableCell colSpan={7} sx={{ py: 0, borderBottom: open ? undefined : 0 }}>
<Collapse in={open}>
<Box sx={{ m: 1 }}>
{report.description && (
<Box sx={{ mb: 1, whiteSpace: "pre-wrap" }}>{report.description}</Box>
)}
{report.admin_note && (
<Box sx={{ color: "text.secondary", fontSize: 13 }}>
{t("abuseReport.adminNote")}: {report.admin_note}
</Box>
)}
</Box>
</Collapse>
</TableCell>
</TableRow>
</>
);
};
const AbuseReportList = () => {
const { t } = useTranslation("dashboard");
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
const dispatch = useAppDispatch();
const [loading, setLoading] = useState(true);
const [reports, setReports] = useState<AbuseReport[]>([]);
const [count, setCount] = useState(0);
const [page, setPage] = useQueryState(PageQuery, { defaultValue: "1" });
const [pageSize, setPageSize] = useQueryState(PageSizeQuery, { defaultValue: "25" });
const [status, setStatus] = useQueryState(StatusQuery, { defaultValue: "open" });
const [review, setReview] = useState<{ report: AbuseReport; status: AbuseReportStatus } | undefined>(undefined);
const pageInt = parseInt(page) ?? 1;
const pageSizeInt = parseInt(pageSize) ?? 25;
const load = () => {
setLoading(true);
dispatch(adminListAbuseReports({ page: pageInt, pageSize: pageSizeInt, status: status || undefined }))
.then((res) => {
setReports(res.reports);
setCount(res.total);
})
.finally(() => setLoading(false));
};
useEffect(load, [page, pageSize, status]);
return (
<PageContainer>
<PageHeader title={t("nav.abuseReport")} />
<Stack direction="row" spacing={1} sx={{ mb: 1 }}>
<DenseSelect
size="small"
value={status}
displayEmpty
onChange={(e) => {
setStatus(e.target.value as string);
setPage("1");
}}
sx={{ minWidth: 180 }}
>
<SquareMenuItem value="open">{t("abuseReport.status.open")}</SquareMenuItem>
<SquareMenuItem value="resolved">{t("abuseReport.status.resolved")}</SquareMenuItem>
<SquareMenuItem value="dismissed">{t("abuseReport.status.dismissed")}</SquareMenuItem>
<SquareMenuItem value="">{t("abuseReport.status.all")}</SquareMenuItem>
</DenseSelect>
</Stack>
<StyledTableContainerPaper>
<Table size={isMobile ? "small" : "medium"}>
<TableHead>
<TableRow>
<TableCell width={40} />
<TableCell>{t("abuseReport.target")}</TableCell>
<TableCell>{t("abuseReport.reason")}</TableCell>
<TableCell>{t("abuseReport.reporter")}</TableCell>
<TableCell>{t("abuseReport.statusLabel")}</TableCell>
<TableCell>{t("abuseReport.reportedAt")}</TableCell>
<TableCell align="right">{t("abuseReport.actions")}</TableCell>
</TableRow>
</TableHead>
<TableBody>
{reports.map((report) => (
<ReportRow
key={report.id}
report={report}
onReview={(s) => setReview({ report, status: s })}
/>
))}
{!loading && reports.length === 0 && (
<TableRow>
<TableCell colSpan={7} align="center">
{t("abuseReport.noReports")}
</TableCell>
</TableRow>
)}
</TableBody>
</Table>
</StyledTableContainerPaper>
<TablePagination
page={pageInt}
totalItems={count}
rowsPerPage={pageSizeInt}
onRowsPerPageChange={(size) => setPageSize(size.toString())}
onChange={(_e, value) => setPage(value.toString())}
/>
<ReviewDialog
report={review?.report}
status={review?.status ?? "resolved"}
onClose={() => setReview(undefined)}
onDone={() => {
setReview(undefined);
load();
}}
/>
</PageContainer>
);
};
export default AbuseReportList;

@ -1,3 +1,4 @@
import AbuseReportList from "./Abuse/AbuseReportList";
import EntitySetting from "./Entity/EntitySetting";
import EventList from "./Event/EventList";
import FileSetting from "./File/FileSetting";
@ -18,6 +19,7 @@ import TaskList from "./Task/TaskList";
import UserSetting from "./User/UserSetting";
export {
AbuseReportList,
EditGroup,
EditNode,
EditOAuthClient,

@ -79,6 +79,24 @@ const Captcha = () => {
<NoMarginHelperText>{t("settings.captchaForResetDes")}</NoMarginHelperText>
</FormControl>
</SettingForm>
<SettingForm lgWidth={5}>
<FormControl fullWidth>
<FormControlLabel
control={
<Switch
checked={isTrueVal(values.abuse_captcha)}
onChange={(e) =>
setSettings({
abuse_captcha: e.target.checked ? "1" : "0",
})
}
/>
}
label={t("settings.captchaForAbuseReport")}
/>
<NoMarginHelperText>{t("settings.captchaForAbuseReportDes")}</NoMarginHelperText>
</FormControl>
</SettingForm>
</SettingSectionContent>
</SettingSection>
<SettingSection>

@ -12,6 +12,7 @@ import ManageShares from "./Share/ManageShares.tsx";
import StoragePolicy from "./StoragePolicy.tsx";
import AclDialog from "./Acl/AclDialog.tsx";
import ActivityDialog from "./Activity/ActivityDialog.tsx";
import ReportAbuseDialog from "./ReportAbuse/ReportAbuseDialog.tsx";
import AnnouncementDialog from "./AnnouncementDialog.tsx";
import StaleVersionConfirm from "./StaleVersionConfirm.tsx";
import SaveAs from "./SaveAs.tsx";
@ -65,6 +66,7 @@ const Dialogs = () => {
<ManageShares />
<AclDialog />
<ActivityDialog />
<ReportAbuseDialog />
<StaleVersionConfirm />
<SaveAs />
<Photopea />

@ -0,0 +1,127 @@
import { LoadingButton } from "@mui/lab";
import {
DialogActions,
DialogContent,
FormControl,
InputLabel,
ListItemText,
TextField,
Typography,
} from "@mui/material";
import { enqueueSnackbar } from "notistack";
import { useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { sendReportAbuse } from "../../../../api/api.ts";
import { closeReportAbuseDialog } from "../../../../redux/globalStateSlice.ts";
import { useAppDispatch, useAppSelector } from "../../../../redux/hooks.ts";
import { Captcha, CaptchaParams } from "../../../Common/Captcha/Captcha.tsx";
import { DenseSelect } from "../../../Common/StyledComponents.tsx";
import { DefaultCloseAction } from "../../../Common/Snackbar/snackbar.tsx";
import DraggableDialog from "../../../Dialogs/DraggableDialog.tsx";
import { SquareMenuItem } from "../../ContextMenu/ContextMenu.tsx";
const ReportAbuseDialog = () => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const open = useAppSelector((state) => state.globalState.reportAbuseDialogOpen);
const targetType = useAppSelector((state) => state.globalState.reportAbuseTargetType);
const target = useAppSelector((state) => state.globalState.reportAbuseTarget);
const captchaEnabled = useAppSelector((state) => state.siteConfig.basic.config.abuse_captcha);
const reasonOptions = t("application:vas.reportReasonOptions", { returnObjects: true }) as string[];
const [reason, setReason] = useState(0);
const [description, setDescription] = useState("");
const [loading, setLoading] = useState(false);
const [captchaGen, setCaptchaGen] = useState(0);
const captchaState = useRef<CaptchaParams>({});
useEffect(() => {
if (open) {
setReason(0);
setDescription("");
captchaState.current = {};
}
}, [open]);
const onClose = () => dispatch(closeReportAbuseDialog());
const onSubmit = () => {
if (!targetType || !target) {
return;
}
setLoading(true);
dispatch(
sendReportAbuse({
target_type: targetType as "share" | "user",
target,
reason,
description: description || undefined,
...captchaState.current,
}),
)
.then(() => {
enqueueSnackbar({
message: t("application:vas.reportAbuseSuccess"),
variant: "success",
action: DefaultCloseAction,
});
onClose();
})
.catch(() => {
setCaptchaGen((g) => g + 1);
})
.finally(() => setLoading(false));
};
return (
<DraggableDialog
title={t("application:vas.report")}
dialogProps={{
open: open ?? false,
onClose,
fullWidth: true,
maxWidth: "sm",
}}
>
<DialogContent>
<Typography variant="body2" color="text.secondary" sx={{ mb: 2 }}>
{t("application:vas.reportTarget")}: {target}
</Typography>
<FormControl fullWidth sx={{ mb: 2 }}>
<InputLabel shrink>{t("application:vas.reportReason")}</InputLabel>
<DenseSelect
notched
label={t("application:vas.reportReason")}
value={String(reason)}
onChange={(e) => setReason(parseInt(e.target.value as string))}
>
{reasonOptions.map((r, i) => (
<SquareMenuItem key={i} value={String(i)}>
<ListItemText slotProps={{ primary: { variant: "body2" } }}>{r}</ListItemText>
</SquareMenuItem>
))}
</DenseSelect>
</FormControl>
<TextField
fullWidth
multiline
minRows={3}
label={t("application:vas.reportDescription")}
value={description}
onChange={(e) => setDescription(e.target.value)}
inputProps={{ maxLength: 2000 }}
/>
{captchaEnabled && <Captcha onStateChange={(s) => (captchaState.current = s)} generation={captchaGen} />}
</DialogContent>
<DialogActions>
<LoadingButton loading={loading} variant="contained" onClick={onSubmit}>
{t("common:ok")}
</LoadingButton>
</DialogActions>
</DraggableDialog>
);
};
export default ReportAbuseDialog;

@ -3,6 +3,7 @@ import { usePopupState } from "material-ui-popup-state/hooks";
import { useCallback, useContext } from "react";
import { useTranslation } from "react-i18next";
import { clearSelected } from "../../../redux/fileManagerSlice.ts";
import { setReportAbuseDialog } from "../../../redux/globalStateSlice.ts";
import { useAppDispatch, useAppSelector } from "../../../redux/hooks.ts";
import { NavigatorCapability } from "../../../api/explorer.ts";
import { downloadAll } from "../../../redux/thunks/download.ts";
@ -10,7 +11,7 @@ import { createShareShortcut, isMacbook } from "../../../redux/thunks/file.ts";
import { inverseSelection, pinCurrentView, refreshFileList, selectAll } from "../../../redux/thunks/filemanager.ts";
import SessionManager from "../../../session";
import Boolset from "../../../util/boolset.ts";
import { Filesystem } from "../../../util/uri.ts";
import CrUri, { Filesystem } from "../../../util/uri.ts";
import { KeyIndicator } from "../../Frame/NavBar/SearchBar.tsx";
import ArrowSync from "../../Icons/ArrowSync.tsx";
import Border from "../../Icons/Border.tsx";
@ -19,6 +20,7 @@ import BorderInside from "../../Icons/BorderInside.tsx";
import CloudDownloadOutlined from "../../Icons/CloudDownloadOutlined.tsx";
import FolderLink from "../../Icons/FolderLink.tsx";
import PinOutlined from "../../Icons/PinOutlined.tsx";
import WarningOutlined from "../../Icons/WarningOutlined.tsx";
import { DenseDivider, SquareMenu, SquareMenuItem } from "../ContextMenu/ContextMenu.tsx";
import { FmIndexContext } from "../FmIndexContext.tsx";
@ -26,6 +28,7 @@ const MoreActionMenu = ({ onClose, ...rest }: MenuProps) => {
const { t } = useTranslation();
const fmIndex = useContext(FmIndexContext);
const fs = useAppSelector((state) => state.fileManager[fmIndex].current_fs);
const path = useAppSelector((state) => state.fileManager[fmIndex].path);
const parentCapability = useAppSelector((state) => state.fileManager[fmIndex].list?.parent?.capability);
const canDownloadAll = new Boolset(parentCapability).enabled(NavigatorCapability.download_file);
const dispatch = useAppDispatch();
@ -73,6 +76,17 @@ const MoreActionMenu = ({ onClose, ...rest }: MenuProps) => {
dispatch(downloadAll(fmIndex));
}, [dispatch, onClose, fmIndex]);
const onReportClicked = useCallback(() => {
onClose && onClose({}, "escapeKeyDown");
if (!path) {
return;
}
const shareId = new CrUri(path).id();
if (shareId) {
dispatch(setReportAbuseDialog({ open: true, targetType: "share", target: shareId }));
}
}, [dispatch, onClose, path]);
return (
<SquareMenu
MenuListProps={{
@ -123,6 +137,14 @@ const MoreActionMenu = ({ onClose, ...rest }: MenuProps) => {
<ListItemText>{t("application:fileManager.downloadAll")}</ListItemText>
</SquareMenuItem>
)}
{fs == Filesystem.share && (
<SquareMenuItem onClick={onReportClicked}>
<ListItemIcon>
<WarningOutlined fontSize="small" />
</ListItemIcon>
<ListItemText>{t("application:vas.report")}</ListItemText>
</SquareMenuItem>
)}
{isLogin && <DenseDivider />}
<SquareMenuItem onClick={onSelectAllClicked}>
<ListItemIcon>

@ -164,6 +164,11 @@ export interface GlobalStateSlice {
activityDialogOpen?: boolean;
activityDialogFile?: FileResponse;
// Report abuse dialog
reportAbuseDialogOpen?: boolean;
reportAbuseTargetType?: string;
reportAbuseTarget?: string;
// Stale version action dialog
staleVersionDialogOpen?: boolean;
staleVersionUri?: string;
@ -824,6 +829,17 @@ export const globalStateSlice = createSlice({
closeActivityDialog: (state) => {
state.activityDialogOpen = false;
},
setReportAbuseDialog: (
state,
action: PayloadAction<{ open: boolean; targetType: string; target: string }>,
) => {
state.reportAbuseDialogOpen = action.payload.open;
state.reportAbuseTargetType = action.payload.targetType;
state.reportAbuseTarget = action.payload.target;
},
closeReportAbuseDialog: (state) => {
state.reportAbuseDialogOpen = false;
},
setImageViewer: (state, action: PayloadAction<ImageViewerState>) => {
state.imageViewer = action.payload;
},
@ -957,6 +973,8 @@ export const {
closeAclDialog,
setActivityDialog,
closeActivityDialog,
setReportAbuseDialog,
closeReportAbuseDialog,
setVersionControlDialog,
closeVersionControlDialog,
closeSidebar,

@ -221,6 +221,13 @@ export const router = createBrowserRouter([
return { Component: EventList };
},
},
{
path: "abuse",
async lazy() {
let { AbuseReportList } = await import("../component/Admin/AdminBundle.tsx");
return { Component: AbuseReportList };
},
},
{
path: "filesystem",
async lazy() {

@ -0,0 +1,97 @@
package inventory
import (
"context"
"github.com/cloudreve/Cloudreve/v4/ent"
"github.com/cloudreve/Cloudreve/v4/ent/abusereport"
)
type (
// AbuseReportClient persists abuse reports for the admin review queue.
AbuseReportClient interface {
TxOperator
// Create inserts a new open report.
Create(ctx context.Context, params *CreateAbuseReportParams) (*ent.AbuseReport, error)
// List returns a page of reports plus the filtered total.
List(ctx context.Context, args *ListAbuseReportArgs) (*ListAbuseReportResult, error)
// SetStatus updates status/admin note of one report.
SetStatus(ctx context.Context, id int, status, adminNote string) (*ent.AbuseReport, error)
}
CreateAbuseReportParams struct {
ReporterID int
ReporterEmail string
TargetType string
TargetID int
Reason int
Description string
}
ListAbuseReportArgs struct {
*PaginationArgs
Status string
}
ListAbuseReportResult struct {
Reports []*ent.AbuseReport
Total int
}
abuseReportClient struct {
client *ent.Client
}
)
// NewAbuseReportClient creates an AbuseReportClient.
func NewAbuseReportClient(client *ent.Client) AbuseReportClient {
return &abuseReportClient{client: client}
}
func (c *abuseReportClient) SetClient(newClient *ent.Client) TxOperator {
return &abuseReportClient{client: newClient}
}
func (c *abuseReportClient) GetClient() *ent.Client {
return c.client
}
func (c *abuseReportClient) Create(ctx context.Context, params *CreateAbuseReportParams) (*ent.AbuseReport, error) {
return c.client.AbuseReport.Create().
SetReporterID(params.ReporterID).
SetReporterEmail(params.ReporterEmail).
SetTargetType(params.TargetType).
SetTargetID(params.TargetID).
SetReason(params.Reason).
SetDescription(params.Description).
Save(ctx)
}
func (c *abuseReportClient) List(ctx context.Context, args *ListAbuseReportArgs) (*ListAbuseReportResult, error) {
q := c.client.AbuseReport.Query().Order(ent.Desc(abusereport.FieldCreatedAt))
if args.Status != "" {
q = q.Where(abusereport.StatusEQ(args.Status))
}
total, err := q.Clone().Count(ctx)
if err != nil {
return nil, err
}
reports, err := q.
Offset(args.Page * args.PageSize).
Limit(args.PageSize).
All(ctx)
if err != nil {
return nil, err
}
return &ListAbuseReportResult{Reports: reports, Total: total}, nil
}
func (c *abuseReportClient) SetStatus(ctx context.Context, id int, status, adminNote string) (*ent.AbuseReport, error) {
return c.client.AbuseReport.UpdateOneID(id).
SetStatus(status).
SetAdminNote(adminNote).
Save(ctx)
}

@ -0,0 +1,63 @@
package inventory
import (
"context"
"testing"
"github.com/cloudreve/Cloudreve/v4/ent/enttest"
"github.com/cloudreve/Cloudreve/v4/inventory/types"
"github.com/stretchr/testify/require"
)
func TestAbuseReportCreateListSetStatus(t *testing.T) {
client := enttest.Open(t, "sqlite3", "file:"+t.Name()+"?mode=memory&cache=shared")
defer client.Close()
c := NewAbuseReportClient(client)
ctx := context.Background()
r1, err := c.Create(ctx, &CreateAbuseReportParams{
ReporterID: 3,
ReporterEmail: "reporter@example.com",
TargetType: types.AbuseTargetShare,
TargetID: 11,
Reason: types.AbuseReasonCopyright,
Description: "pirated content",
})
require.NoError(t, err)
require.Equal(t, types.AbuseStatusOpen, r1.Status)
_, err = c.Create(ctx, &CreateAbuseReportParams{
TargetType: types.AbuseTargetUser,
TargetID: 5,
Reason: types.AbuseReasonSpam,
})
require.NoError(t, err)
all, err := c.List(ctx, &ListAbuseReportArgs{
PaginationArgs: &PaginationArgs{Page: 0, PageSize: 10},
})
require.NoError(t, err)
require.Equal(t, 2, all.Total)
require.Len(t, all.Reports, 2)
// Newest first.
require.Equal(t, types.AbuseTargetUser, all.Reports[0].TargetType)
openOnly, err := c.List(ctx, &ListAbuseReportArgs{
PaginationArgs: &PaginationArgs{Page: 0, PageSize: 10},
Status: types.AbuseStatusOpen,
})
require.NoError(t, err)
require.Equal(t, 2, openOnly.Total)
updated, err := c.SetStatus(ctx, r1.ID, types.AbuseStatusResolved, "share expired")
require.NoError(t, err)
require.Equal(t, types.AbuseStatusResolved, updated.Status)
require.Equal(t, "share expired", updated.AdminNote)
openOnly, err = c.List(ctx, &ListAbuseReportArgs{
PaginationArgs: &PaginationArgs{Page: 0, PageSize: 10},
Status: types.AbuseStatusOpen,
})
require.NoError(t, err)
require.Equal(t, 1, openOnly.Total)
}

@ -542,6 +542,7 @@ var DefaultSettings = map[string]string{
"reg_captcha": `0`,
"email_active": `0`,
"forget_captcha": `0`,
"abuse_captcha": `1`,
"gravatar_server": `https://www.gravatar.com/`,
"defaultTheme": `#1976d2`,
"theme_options": `{"#1976d2":{"light":{"palette":{"primary":{"main":"#1976d2","light":"#42a5f5","dark":"#1565c0"},"secondary":{"main":"#9c27b0","light":"#ba68c8","dark":"#7b1fa2"}}},"dark":{"palette":{"primary":{"main":"#90caf9","light":"#e3f2fd","dark":"#42a5f5"},"secondary":{"main":"#ce93d8","light":"#f3e5f5","dark":"#ab47bc"}}}},"#3f51b5":{"light":{"palette":{"primary":{"main":"#3f51b5"},"secondary":{"main":"#f50057"}}},"dark":{"palette":{"primary":{"main":"#9fa8da"},"secondary":{"main":"#ff4081"}}}}}`,

@ -57,6 +57,8 @@ type (
List(ctx context.Context, args *ListShareArgs) (*ListShareResult, error)
// CountByTimeRange counts the number of shares created in the given time range.
CountByTimeRange(ctx context.Context, start, end *time.Time) (int, error)
// Expire marks the share expired immediately (admin moderation block).
Expire(ctx context.Context, id int) error
}
CreateShareParams struct {
@ -206,6 +208,11 @@ func (c *shareClient) Delete(ctx context.Context, shareId int) error {
return c.client.Share.DeleteOneID(shareId).Exec(ctx)
}
// Expire marks the share expired immediately (admin moderation block).
func (c *shareClient) Expire(ctx context.Context, id int) error {
return c.client.Share.UpdateOneID(id).SetExpires(time.Now()).Exec(ctx)
}
// Viewed increments the view count of the share.
func (c *shareClient) Viewed(ctx context.Context, share *ent.Share) error {
_, err := c.client.Share.UpdateOneID(share.ID).AddViews(1).Save(ctx)

@ -0,0 +1,21 @@
package types
// Abuse report target and status constants.
const (
AbuseTargetShare = "share"
AbuseTargetUser = "user"
AbuseStatusOpen = "open"
AbuseStatusResolved = "resolved"
AbuseStatusDismissed = "dismissed"
)
// Abuse reasons, matching the frontend reportReasonOptions order.
const (
AbuseReasonCopyright = iota
AbuseReasonHarmful
AbuseReasonSpam
AbuseReasonOther
AbuseReasonMax = AbuseReasonOther
)

@ -35,6 +35,8 @@ type (
LoginCaptchaEnabled(ctx context.Context) bool
// ForgotPasswordCaptchaEnabled returns true if forgot password captcha is enabled.
ForgotPasswordCaptchaEnabled(ctx context.Context) bool
// AbuseCaptchaEnabled returns true if abuse reports require captcha.
AbuseCaptchaEnabled(ctx context.Context) bool
// CaptchaType returns the type of captcha used.
CaptchaType(ctx context.Context) CaptchaType
// ReCaptcha returns the Google reCaptcha settings.
@ -926,6 +928,10 @@ func (s *settingProvider) ForgotPasswordCaptchaEnabled(ctx context.Context) bool
return s.getBoolean(ctx, "forget_captcha", false)
}
func (s *settingProvider) AbuseCaptchaEnabled(ctx context.Context) bool {
return s.getBoolean(ctx, "abuse_captcha", true)
}
func (s *settingProvider) AuthnEnabled(ctx context.Context) bool {
return s.getBoolean(ctx, "authn_enabled", false)
}

@ -342,6 +342,26 @@ func AdminListEvents(c *gin.Context) {
c.JSON(200, serializer.Response{Data: res})
}
// AdminListAbuseReports lists the abuse report queue.
func AdminListAbuseReports(c *gin.Context) {
service := ParametersFromContext[*admin.AbuseListService](c, admin.AbuseListParamCtx{})
res, err := service.List(c)
if respondErr(c, err) {
return
}
c.JSON(200, serializer.Response{Data: res})
}
// AdminUpdateAbuseReport updates a report and optionally blocks the share.
func AdminUpdateAbuseReport(c *gin.Context) {
service := ParametersFromContext[*admin.AbuseUpdateService](c, admin.AbuseUpdateParamCtx{})
res, err := service.Update(c)
if respondErr(c, err) {
return
}
c.JSON(200, serializer.Response{Data: res})
}
// func AdminHashIDEncode(c *gin.Context) {
// service := ParametersFromContext[*admin.HashIDService](c, admin.HashIDParamCtx{})
// resp, err := service.Encode(c)

@ -3,6 +3,7 @@ package controllers
import (
"github.com/cloudreve/Cloudreve/v4/pkg/hashid"
"github.com/cloudreve/Cloudreve/v4/pkg/serializer"
"github.com/cloudreve/Cloudreve/v4/service/abuse"
"github.com/cloudreve/Cloudreve/v4/service/share"
"github.com/gin-gonic/gin"
"net/http"
@ -80,3 +81,12 @@ func ShareRedirect(c *gin.Context) {
service := ParametersFromContext[*share.ShortLinkRedirectService](c, share.ShortLinkRedirectParamCtx{})
c.Redirect(http.StatusFound, service.RedirectTo(c))
}
// ReportAbuse accepts an abuse report against a share or user.
func ReportAbuse(c *gin.Context) {
service := ParametersFromContext[*abuse.ReportService](c, abuse.ReportParamCtx{})
if err := service.Create(c); respondErr(c, err) {
return
}
c.JSON(200, serializer.Response{})
}

@ -16,6 +16,7 @@ import (
"github.com/cloudreve/Cloudreve/v4/pkg/logging"
"github.com/cloudreve/Cloudreve/v4/pkg/webdav"
"github.com/cloudreve/Cloudreve/v4/routers/controllers"
abusesvc "github.com/cloudreve/Cloudreve/v4/service/abuse"
adminsvc "github.com/cloudreve/Cloudreve/v4/service/admin"
"github.com/cloudreve/Cloudreve/v4/service/basic"
"github.com/cloudreve/Cloudreve/v4/service/explorer"
@ -962,11 +963,19 @@ func initMasterRouter(dep dependency.Dep) *gin.Engine {
// middleware.CheckShareUnlocked(),
// controllers.PreviewShareReadme,
//)
//// 举报分享
//share.POST("report/:id",
// middleware.CheckShareUnlocked(),
// controllers.ReportShare,
//)
}
// 举报滥用
abuse := v4.Group("abuse")
{
abuse.POST("report",
middleware.RateLimitByIP("abuse_report", 10, time.Hour),
middleware.CaptchaRequired(func(c *gin.Context) bool {
return dep.SettingProvider().AbuseCaptchaEnabled(c)
}),
controllers.FromJSON[abusesvc.ReportService](abusesvc.ReportParamCtx{}),
controllers.ReportAbuse,
)
}
// 需要登录保护的
@ -1324,6 +1333,21 @@ func initMasterRouter(dep dependency.Dep) *gin.Engine {
)
}
abuse := admin.Group("abuse", middleware.AdminSection(types.GroupPermissionAdminReports))
{
// 列出举报
abuse.GET("",
controllers.FromQuery[adminsvc.AbuseListService](adminsvc.AbuseListParamCtx{}),
controllers.AdminListAbuseReports,
)
// 更新举报状态
abuse.PATCH(":id",
middleware.HashID(hashid.AuditLogID),
controllers.FromJSON[adminsvc.AbuseUpdateService](adminsvc.AbuseUpdateParamCtx{}),
controllers.AdminUpdateAbuseReport,
)
}
file := admin.Group("file", middleware.AdminSection(types.GroupPermissionAdminFiles))
{
// 列出文件

@ -0,0 +1,78 @@
package abuse
import (
"github.com/cloudreve/Cloudreve/v4/application/dependency"
"github.com/cloudreve/Cloudreve/v4/inventory"
"github.com/cloudreve/Cloudreve/v4/inventory/types"
"github.com/cloudreve/Cloudreve/v4/pkg/activity"
"github.com/cloudreve/Cloudreve/v4/pkg/hashid"
"github.com/cloudreve/Cloudreve/v4/pkg/serializer"
"github.com/gin-gonic/gin"
)
type (
// ReportService accepts an abuse report from any visitor. CAPTCHA and
// rate limiting are enforced by route middleware.
ReportService struct {
TargetType string `json:"target_type" binding:"required,oneof=share user"`
Target string `json:"target" binding:"required"`
Reason int `json:"reason" binding:"min=0"`
Description string `json:"description" binding:"max=2000"`
}
ReportParamCtx struct{}
)
// Create validates the target, stores the report, and emits report_abuse.
func (s *ReportService) Create(c *gin.Context) error {
dep := dependency.FromContext(c)
if s.Reason > types.AbuseReasonMax {
return serializer.NewError(serializer.CodeParamErr, "Invalid reason", nil)
}
params := &inventory.CreateAbuseReportParams{
TargetType: s.TargetType,
Reason: s.Reason,
Description: s.Description,
}
if u := inventory.UserFromContext(c); u != nil && !inventory.IsAnonymousUser(u) {
params.ReporterID = u.ID
params.ReporterEmail = u.Email
}
var opts []activity.Opt
switch s.TargetType {
case types.AbuseTargetShare:
shareID, err := dep.HashIDEncoder().Decode(s.Target, hashid.ShareID)
if err != nil {
return serializer.NewError(serializer.CodeParamErr, "Invalid share", err)
}
if _, err := dep.ShareClient().GetByID(c, shareID); err != nil {
return serializer.NewError(serializer.CodeNotFound, "Share not found", err)
}
params.TargetID = shareID
opts = append(opts, activity.Share(shareID))
case types.AbuseTargetUser:
uid, err := dep.HashIDEncoder().Decode(s.Target, hashid.UserID)
if err != nil {
return serializer.NewError(serializer.CodeParamErr, "Invalid user", err)
}
if _, err := dep.UserClient().GetByID(c, uid); err != nil {
return serializer.NewError(serializer.CodeNotFound, "User not found", err)
}
params.TargetID = uid
}
report, err := dep.AbuseReportClient().Create(c, params)
if err != nil {
return serializer.NewError(serializer.CodeDBError, "Failed to submit report", err)
}
opts = append(opts, activity.Extra(map[string]any{
"report_id": report.ID,
"target_type": s.TargetType,
"reason": s.Reason,
}))
activity.Record(c, dep.SettingProvider(), dep.ActivityClient(), types.EventReportAbuse, opts...)
return nil
}

@ -0,0 +1,114 @@
package admin
import (
"github.com/cloudreve/Cloudreve/v4/application/dependency"
"github.com/cloudreve/Cloudreve/v4/ent"
"github.com/cloudreve/Cloudreve/v4/inventory"
"github.com/cloudreve/Cloudreve/v4/inventory/types"
"github.com/cloudreve/Cloudreve/v4/pkg/hashid"
"github.com/cloudreve/Cloudreve/v4/pkg/serializer"
"github.com/gin-gonic/gin"
)
type (
// AbuseListService pages the abuse report queue.
AbuseListService struct {
Page int `form:"page" binding:"required,min=0"`
PageSize int `form:"page_size" binding:"required,min=1,max=100"`
Status string `form:"status" binding:"omitempty,oneof=open resolved dismissed"`
}
AbuseListParamCtx struct{}
// AbuseReport is one queue entry.
AbuseReport struct {
ID string `json:"id"`
ReporterID string `json:"reporter_id,omitempty"`
ReporterEmail string `json:"reporter_email,omitempty"`
TargetType string `json:"target_type"`
TargetID string `json:"target_id"`
Reason int `json:"reason"`
Description string `json:"description"`
Status string `json:"status"`
AdminNote string `json:"admin_note"`
CreatedAt int64 `json:"created_at"`
}
AbuseListResponse struct {
Reports []*AbuseReport `json:"reports"`
Total int `json:"total"`
}
// AbuseUpdateService updates one report; block_share additionally expires
// the reported share.
AbuseUpdateService struct {
Status string `json:"status" binding:"required,oneof=open resolved dismissed"`
AdminNote string `json:"admin_note" binding:"max=2000"`
BlockShare bool `json:"block_share"`
}
AbuseUpdateParamCtx struct{}
)
func (s *AbuseListService) List(c *gin.Context) (*AbuseListResponse, error) {
dep := dependency.FromContext(c)
res, err := dep.AbuseReportClient().List(c, &inventory.ListAbuseReportArgs{
PaginationArgs: &inventory.PaginationArgs{
UseCursorPagination: false,
Page: s.Page,
PageSize: s.PageSize,
},
Status: s.Status,
})
if err != nil {
return nil, serializer.NewError(serializer.CodeDBError, "Failed to list reports", err)
}
return BuildAbuseListResponse(res, dep.HashIDEncoder()), nil
}
func BuildAbuseListResponse(res *inventory.ListAbuseReportResult, hasher hashid.Encoder) *AbuseListResponse {
reports := make([]*AbuseReport, 0, len(res.Reports))
for _, r := range res.Reports {
reports = append(reports, BuildAbuseReport(r, hasher))
}
return &AbuseListResponse{Reports: reports, Total: res.Total}
}
func BuildAbuseReport(r *ent.AbuseReport, hasher hashid.Encoder) *AbuseReport {
res := &AbuseReport{
ID: hashid.EncodeAuditLogID(hasher, r.ID),
ReporterEmail: r.ReporterEmail,
TargetType: r.TargetType,
Reason: r.Reason,
Description: r.Description,
Status: r.Status,
AdminNote: r.AdminNote,
CreatedAt: r.CreatedAt.Unix(),
}
if r.ReporterID > 0 {
res.ReporterID = hashid.EncodeUserID(hasher, r.ReporterID)
}
if r.TargetType == types.AbuseTargetShare {
res.TargetID = hashid.EncodeShareID(hasher, r.TargetID)
} else {
res.TargetID = hashid.EncodeUserID(hasher, r.TargetID)
}
return res
}
func (s *AbuseUpdateService) Update(c *gin.Context) (*AbuseReport, error) {
dep := dependency.FromContext(c)
reportID := hashid.FromContext(c)
report, err := dep.AbuseReportClient().SetStatus(c, reportID, s.Status, s.AdminNote)
if err != nil {
return nil, serializer.NewError(serializer.CodeDBError, "Failed to update report", err)
}
if s.BlockShare && report.TargetType == types.AbuseTargetShare {
if err := dep.ShareClient().Expire(c, report.TargetID); err != nil {
return nil, serializer.NewError(serializer.CodeDBError, "Failed to block share", err)
}
}
return BuildAbuseReport(report, dep.HashIDEncoder()), nil
}

@ -54,6 +54,9 @@ type SiteConfig struct {
// can offer a download-route picker (#2987).
DownloadCDNRoutes []setting.CDNRoute `json:"download_cdn_routes,omitempty"`
// AbuseCaptcha controls whether the report-abuse dialog shows captcha.
AbuseCaptcha bool `json:"abuse_captcha,omitempty"`
// Explorer section
Icons string `json:"icons,omitempty"`
EmojiPreset string `json:"emoji_preset,omitempty"`
@ -234,6 +237,7 @@ func (s *GetSettingService) GetSiteConfig(c *gin.Context) (*SiteConfig, error) {
ShareDefaultPrivate: shareDefaults.PrivateByDefault,
DefaultShareLinksInProfile: string(shareDefaults.LinksInProfile),
DownloadCDNRoutes: settings.DownloadCDNRoutes(c),
AbuseCaptcha: settings.AbuseCaptchaEnabled(c),
}, nil
}

Loading…
Cancel
Save