`reporter-id` int unsigned COMMENT 'Reporting contact',
`cid` int unsigned NOT NULL COMMENT 'Reported contact',
`comment` text COMMENT 'Report',
+ `category` varchar(20) COMMENT 'Category of the report (spam, violation, other)',
`forward` boolean COMMENT 'Forward the report to the remote server',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
`status` tinyint unsigned COMMENT 'Status of the report',
Fields
------
-| Field | Description | Type | Null | Key | Default | Extra |
-| ----------- | --------------------------------------- | ------------------ | ---- | --- | ------------------- | -------------- |
-| id | sequential ID | int unsigned | NO | PRI | NULL | auto_increment |
-| uid | Reporting user | mediumint unsigned | YES | | NULL | |
-| reporter-id | Reporting contact | int unsigned | YES | | NULL | |
-| cid | Reported contact | int unsigned | NO | | NULL | |
-| comment | Report | text | YES | | NULL | |
-| forward | Forward the report to the remote server | boolean | YES | | NULL | |
-| created | | datetime | NO | | 0001-01-01 00:00:00 | |
-| status | Status of the report | tinyint unsigned | YES | | NULL | |
+| Field | Description | Type | Null | Key | Default | Extra |
+| ----------- | ----------------------------------------------- | ------------------ | ---- | --- | ------------------- | -------------- |
+| id | sequential ID | int unsigned | NO | PRI | NULL | auto_increment |
+| uid | Reporting user | mediumint unsigned | YES | | NULL | |
+| reporter-id | Reporting contact | int unsigned | YES | | NULL | |
+| cid | Reported contact | int unsigned | NO | | NULL | |
+| comment | Report | text | YES | | NULL | |
+| category | Category of the report (spam, violation, other) | varchar(20) | YES | | NULL | |
+| forward | Forward the report to the remote server | boolean | YES | | NULL | |
+| created | | datetime | NO | | 0001-01-01 00:00:00 | |
+| status | Status of the report | tinyint unsigned | YES | | NULL | |
Indexes
------------
protected $cid;
/** @var string Optional comment */
protected $comment;
+ /** @var string Optional category */
+ protected $category;
/** @var bool Whether this report should be forwarded to the remote server */
protected $forward;
/** @var \DateTime|null When the report was created */
/** @var array Optional list of URI IDs of posts supporting the report*/
protected $postUriIds;
- public function __construct(int $uid = null, int $reporterId, int $cid, \DateTime $created, string $comment = '', bool $forward = false, array $postUriIds = [], int $id = null)
+ public function __construct(int $uid = null, int $reporterId, int $cid, \DateTime $created, string $comment = '', string $category = null, bool $forward = false, array $postUriIds = [], int $id = null)
{
$this->uid = $uid;
$this->reporterId = $reporterId;
$this->cid = $cid;
$this->created = $created;
$this->comment = $comment;
+ $this->category = $category;
$this->forward = $forward;
$this->postUriIds = $postUriIds;
$this->id = $id;
$row['cid'],
new \DateTime($row['created'] ?? 'now', new \DateTimeZone('UTC')),
$row['comment'],
+ $row['category'],
$row['forward'],
$postUriIds,
$row['id'],
* @return Entity\Report
* @throws \Exception
*/
- public function createFromReportsRequest(int $uid = null, int $reporterId, int $cid, string $comment = '', bool $forward = false, array $postUriIds = []): Entity\Report
+ public function createFromReportsRequest(int $uid = null, int $reporterId, int $cid, string $comment = '', string $category = null, bool $forward = false, array $postUriIds = []): Entity\Report
{
return new Entity\Report(
$uid,
$cid,
new \DateTime('now', new \DateTimeZone('UTC')),
$comment,
+ $category,
$forward,
$postUriIds,
);
'reporter-id' => $Report->reporterId,
'cid' => $Report->cid,
'comment' => $Report->comment,
+ 'category' => $Report->category,
'forward' => $Report->forward,
];
self::checkAllowedScope(self::SCOPE_WRITE);
$request = $this->getRequest([
- 'account_id' => '', // ID of the account to report
- 'status_ids' => [], // Array of Statuses to attach to the report, for context
- 'comment' => '', // Reason for the report (default max 1000 characters)
- 'forward' => false, // If the account is remote, should the report be forwarded to the remote admin?
+ 'account_id' => '', // ID of the account to report
+ 'status_ids' => [], // Array of Statuses to attach to the report, for context
+ 'comment' => '', // Reason for the report (default max 1000 characters)
+ 'category' => 'other', // Specify if the report is due to spam, violation of enumerated instance rules, or some other reason.
+ 'forward' => false, // If the account is remote, should the report be forwarded to the remote admin?
], $request);
$contact = Contact::getById($request['account_id'], ['id']);
throw new HTTPException\NotFoundException('Account ' . $request['account_id'] . ' not found');
}
- $report = $this->reportFactory->createFromReportsRequest(self::getCurrentUserID(), Contact::getPublicIdByUserId(self::getCurrentUserID()), $request['account_id'], $request['comment'], $request['forward'], $request['status_ids']);
+ $report = $this->reportFactory->createFromReportsRequest(self::getCurrentUserID(), Contact::getPublicIdByUserId(self::getCurrentUserID()), $request['account_id'], $request['comment'], $request['category'], $request['forward'], $request['status_ids']);
$this->reportRepo->save($report);
}
}
- $report = DI::reportFactory()->createFromReportsRequest(null, $reporter_id, $account_id, $activity['content'], false, $uri_ids);
+ $report = DI::reportFactory()->createFromReportsRequest(null, $reporter_id, $account_id, $activity['content'], null, false, $uri_ids);
DI::report()->save($report);
Logger::info('Stored report', ['reporter' => $reporter_id, 'account_id' => $account_id, 'comment' => $activity['content'], 'status_ids' => $status_ids]);
"reporter-id" => ["type" => "int unsigned", "foreign" => ["contact" => "id"], "comment" => "Reporting contact"],
"cid" => ["type" => "int unsigned", "not null" => "1", "foreign" => ["contact" => "id"], "comment" => "Reported contact"],
"comment" => ["type" => "text", "comment" => "Report"],
+ "category" => ["type" => "varchar(20)", "comment" => "Category of the report (spam, violation, other)"],
"forward" => ["type" => "boolean", "comment" => "Forward the report to the remote server"],
"created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
"status" => ["type" => "tinyint unsigned", "comment" => "Status of the report"],
13,
new \DateTime('now', new \DateTimeZone('UTC')),
'',
+ null,
false,
[],
11,
13,
new \DateTime('2021-10-12 12:23:00', new \DateTimeZone('UTC')),
'Report',
+ 'violation',
true,
[89, 90],
11
self::assertEquals($assertion->reporterId, $report->reporterId);
self::assertEquals($assertion->cid, $report->cid);
self::assertEquals($assertion->comment, $report->comment);
+ self::assertEquals($assertion->category, $report->category);
self::assertEquals($assertion->forward, $report->forward);
// No way to test "now" at the moment
//self::assertEquals($assertion->created, $report->created);
13,
new \DateTime('now', new \DateTimeZone('UTC')),
'',
+ null,
false,
[],
null
13,
new \DateTime('now', new \DateTimeZone('UTC')),
'Report',
+ 'violation',
true,
[89, 90],
null
/**
* @dataProvider dataCreateFromReportsRequest
*/
- public function testCreateFromReportsRequest(int $uid, int $reporter, int $cid, string $comment, bool $forward, array $postUriIds, Entity\Report $assertion)
+ public function testCreateFromReportsRequest(int $uid, int $reporter, int $cid, string $comment, string $category = null, bool $forward, array $postUriIds, Entity\Report $assertion)
{
$factory = new Factory\Report(new NullLogger());
- $this->assertReport($factory->createFromReportsRequest($uid, $reporter, $cid, $comment, $forward, $postUriIds), $assertion);
+ $this->assertReport($factory->createFromReportsRequest($uid, $reporter, $cid, $comment, $category, $forward, $postUriIds), $assertion);
}
}