2018-05-27 09:36:35 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"errors"
|
|
|
|
"strconv"
|
|
|
|
|
2019-07-26 22:26:52 +00:00
|
|
|
qgen "github.com/Azareal/Gosora/query_gen"
|
2018-05-27 09:36:35 +00:00
|
|
|
)
|
|
|
|
|
2018-06-06 00:21:22 +00:00
|
|
|
// TODO: Make the default report forum ID configurable
|
|
|
|
// TODO: Make sure this constant is used everywhere for the report forum ID
|
|
|
|
const ReportForumID = 1
|
|
|
|
|
2018-05-27 09:36:35 +00:00
|
|
|
var Reports ReportStore
|
|
|
|
var ErrAlreadyReported = errors.New("This item has already been reported")
|
|
|
|
|
|
|
|
// The report system mostly wraps around the topic system for simplicty
|
|
|
|
type ReportStore interface {
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
Create(title, content string, user *User, itemType string, itemID int) (int, error)
|
2018-05-27 09:36:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type DefaultReportStore struct {
|
|
|
|
create *sql.Stmt
|
|
|
|
exists *sql.Stmt
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDefaultReportStore(acc *qgen.Accumulator) (*DefaultReportStore, error) {
|
2019-10-28 07:46:14 +00:00
|
|
|
t := "topics"
|
2018-05-27 09:36:35 +00:00
|
|
|
return &DefaultReportStore{
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
create: acc.Insert(t).Columns("title, content, parsed_content, ip, createdAt, lastReplyAt, createdBy, lastReplyBy, data, parentID, css_class").Fields("?,?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),?,?,?,?,'report'").Prepare(),
|
|
|
|
exists: acc.Count(t).Where("data=? AND data!='' AND parentID=?").Prepare(),
|
2018-05-27 09:36:35 +00:00
|
|
|
}, acc.FirstError()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ! There's a data race in this. If two users report one item at the exact same time, then both reports will go through
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func (s *DefaultReportStore) Create(title, content string, u *User, itemType string, itemID int) (tid int, err error) {
|
2018-05-27 09:36:35 +00:00
|
|
|
var count int
|
2019-10-28 07:46:14 +00:00
|
|
|
err = s.exists.QueryRow(itemType+"_"+strconv.Itoa(itemID), ReportForumID).Scan(&count)
|
2018-05-27 09:36:35 +00:00
|
|
|
if err != nil && err != sql.ErrNoRows {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
if count != 0 {
|
|
|
|
return 0, ErrAlreadyReported
|
|
|
|
}
|
|
|
|
|
2020-01-02 21:52:41 +00:00
|
|
|
ip := u.GetIP()
|
|
|
|
if Config.DisablePostIP {
|
2020-02-04 11:47:03 +00:00
|
|
|
ip = ""
|
2020-01-02 21:52:41 +00:00
|
|
|
}
|
2020-02-04 11:47:03 +00:00
|
|
|
res, err := s.create.Exec(title, content, ParseMessage(content, 0, "", nil, nil), ip, u.ID, u.ID, itemType+"_"+strconv.Itoa(itemID), ReportForumID)
|
2018-05-27 09:36:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
lastID, err := res.LastInsertId()
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2019-10-28 07:46:14 +00:00
|
|
|
tid = int(lastID)
|
2019-12-31 21:57:54 +00:00
|
|
|
|
2019-12-08 03:40:56 +00:00
|
|
|
return tid, Forums.AddTopic(tid, u.ID, ReportForumID)
|
2018-05-27 09:36:35 +00:00
|
|
|
}
|