`cid` int unsigned NOT NULL COMMENT 'Reported contact',
`comment` text COMMENT 'Report',
`category` varchar(20) COMMENT 'Category of the report (spam, violation, other)',
+ `rules` text COMMENT 'Violated rules',
`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',
| cid | Reported contact | int unsigned | NO | | NULL | |
| comment | Report | text | YES | | NULL | |
| category | Category of the report (spam, violation, other) | varchar(20) | YES | | NULL | |
+| rules | Violated rules | 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 | |
/**
* Fetch the system rules
+ * @param bool $numeric_id If set to "true", the rules are returned with a numeric id as key.
*
* @return array
*/
- public static function getRules(): array
+ public static function getRules(bool $numeric_id = false): array
{
$rules = [];
$id = 0;
foreach (explode("\n", trim($msg)) as $line) {
$line = trim($line);
if ($line) {
- $rules[] = ['id' => (string)++$id, 'text' => $line];
+ if ($numeric_id) {
+ $rules[++$id] = $line;
+ } else {
+ $rules[] = ['id' => (string)++$id, 'text' => $line];
+ }
}
}
}
protected $comment;
/** @var string Optional category */
protected $category;
+ /** @var string Violated rules */
+ protected $rules;
/** @var bool Whether this report should be forwarded to the remote server */
protected $forward;
/** @var \DateTime|null When the report was created */
/** @var int ID of the user making a moderation report*/
protected $uid;
- public function __construct(int $reporterId, int $cid, \DateTime $created, string $comment = '', string $category = null, bool $forward = false, array $postUriIds = [], int $uid = null, int $id = null)
+ public function __construct(int $reporterId, int $cid, \DateTime $created, string $comment = '', string $category = null, string $rules = '', bool $forward = false, array $postUriIds = [], int $uid = null, int $id = null)
{
$this->reporterId = $reporterId;
$this->cid = $cid;
$this->created = $created;
$this->comment = $comment;
$this->category = $category;
+ $this->rules = $rules;
$this->forward = $forward;
$this->postUriIds = $postUriIds;
$this->uid = $uid;
new \DateTime($row['created'] ?? 'now', new \DateTimeZone('UTC')),
$row['comment'],
$row['category'],
+ $row['rules'],
$row['forward'],
$postUriIds,
$row['uid'],
* @return Entity\Report
* @throws \Exception
*/
- public function createFromReportsRequest(int $reporterId, int $cid, string $comment = '', string $category = null, bool $forward = false, array $postUriIds = [], int $uid = null): Entity\Report
+ public function createFromReportsRequest(int $reporterId, int $cid, string $comment = '', string $category = null, string $rules = '', bool $forward = false, array $postUriIds = [], int $uid = null): Entity\Report
{
return new Entity\Report(
$reporterId,
new \DateTime('now', new \DateTimeZone('UTC')),
$comment,
$category,
+ $rules,
$forward,
$postUriIds,
$uid,
'cid' => $Report->cid,
'comment' => $Report->comment,
'category' => $Report->category,
+ 'rules' => $Report->rules,
'forward' => $Report->forward,
];
'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.
+ 'rule_ids' => [], // For violation category reports, specify the ID of the exact rules broken.
'forward' => false, // If the account is remote, should the report be forwarded to the remote admin?
], $request);
throw new HTTPException\NotFoundException('Account ' . $request['account_id'] . ' not found');
}
- $report = $this->reportFactory->createFromReportsRequest(Contact::getPublicIdByUserId(self::getCurrentUserID()), $request['account_id'], $request['comment'], $request['category'], $request['forward'], $request['status_ids'], self::getCurrentUserID());
+ $violation = '';
+ $rules = System::getRules(true);
+
+ foreach ($request['rule_ids'] as $key) {
+ if (!empty($rules[$key])) {
+ $violation .= $rules[$key] . "\n";
+ }
+ }
+
+ $report = $this->reportFactory->createFromReportsRequest(Contact::getPublicIdByUserId(self::getCurrentUserID()), $request['account_id'], $request['comment'], $request['category'], trim($violation), $request['forward'], $request['status_ids'], self::getCurrentUserID());
$this->reportRepo->save($report);
}
}
- $report = DI::reportFactory()->createFromReportsRequest($reporter_id, $account_id, $activity['content'], null, false, $uri_ids);
+ $report = DI::reportFactory()->createFromReportsRequest($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'], 'object_ids' => $activity['object_ids']]);
"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)"],
+ "rules" => ["type" => "text", "comment" => "Violated rules"],
"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"],
new \DateTime('now', new \DateTimeZone('UTC')),
'',
null,
+ '',
false,
[],
12,
'cid' => 13,
'comment' => 'Report',
'category' => 'violation',
+ 'rules' => 'Rules',
'forward' => true,
'created' => '2021-10-12 12:23:00'
],
new \DateTime('2021-10-12 12:23:00', new \DateTimeZone('UTC')),
'Report',
'violation',
+ 'Rules',
true,
[89, 90],
12,
'cid' => 13,
'comment' => '',
'category' => null,
+ 'rules' => null,
'forward' => false,
'postUriIds' => [],
'uid' => 12,
new \DateTime('now', new \DateTimeZone('UTC')),
'',
null,
+ '',
false,
[],
12,
new \DateTime('now', new \DateTimeZone('UTC')),
'Report',
'violation',
+ 'Rules',
true,
[89, 90],
12,
/**
* @dataProvider dataCreateFromReportsRequest
*/
- public function testCreateFromReportsRequest(int $reporter, int $cid, string $comment, string $category = null, bool $forward, array $postUriIds, int $uid, Entity\Report $assertion)
+ public function testCreateFromReportsRequest(int $reporter, int $cid, string $comment, string $category = null, string $rules = null, bool $forward, array $postUriIds, int $uid, Entity\Report $assertion)
{
$factory = new Factory\Report(new NullLogger());
- $this->assertReport($factory->createFromReportsRequest($reporter, $cid, $comment, $category, $forward, $postUriIds, $uid), $assertion);
+ $this->assertReport($factory->createFromReportsRequest($reporter, $cid, $comment, $category, $rules, $forward, $postUriIds, $uid), $assertion);
}
}