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
parent
60138e322c
commit
4018d04a5f
@ -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
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -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{},
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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;
|
||||||
@ -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;
|
||||||
@ -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)
|
||||||
|
}
|
||||||
@ -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
|
||||||
|
)
|
||||||
@ -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
|
||||||
|
}
|
||||||
Loading…
Reference in new issue