Category added
This commit is contained in:
parent
bf4d321aa3
commit
8a7d08ae28
|
@ -1677,6 +1677,7 @@ CREATE TABLE IF NOT EXISTS `report` (
|
||||||
`reporter-id` int unsigned COMMENT 'Reporting contact',
|
`reporter-id` int unsigned COMMENT 'Reporting contact',
|
||||||
`cid` int unsigned NOT NULL COMMENT 'Reported contact',
|
`cid` int unsigned NOT NULL COMMENT 'Reported contact',
|
||||||
`comment` text COMMENT 'Report',
|
`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',
|
`forward` boolean COMMENT 'Forward the report to the remote server',
|
||||||
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
|
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
|
||||||
`status` tinyint unsigned COMMENT 'Status of the report',
|
`status` tinyint unsigned COMMENT 'Status of the report',
|
||||||
|
|
|
@ -7,12 +7,13 @@ Fields
|
||||||
------
|
------
|
||||||
|
|
||||||
| Field | Description | Type | Null | Key | Default | Extra |
|
| Field | Description | Type | Null | Key | Default | Extra |
|
||||||
| ----------- | --------------------------------------- | ------------------ | ---- | --- | ------------------- | -------------- |
|
| ----------- | ----------------------------------------------- | ------------------ | ---- | --- | ------------------- | -------------- |
|
||||||
| id | sequential ID | int unsigned | NO | PRI | NULL | auto_increment |
|
| id | sequential ID | int unsigned | NO | PRI | NULL | auto_increment |
|
||||||
| uid | Reporting user | mediumint unsigned | YES | | NULL | |
|
| uid | Reporting user | mediumint unsigned | YES | | NULL | |
|
||||||
| reporter-id | Reporting contact | int unsigned | YES | | NULL | |
|
| reporter-id | Reporting contact | int unsigned | YES | | NULL | |
|
||||||
| cid | Reported contact | int unsigned | NO | | NULL | |
|
| cid | Reported contact | int unsigned | NO | | NULL | |
|
||||||
| comment | Report | text | YES | | 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 | |
|
| forward | Forward the report to the remote server | boolean | YES | | NULL | |
|
||||||
| created | | datetime | NO | | 0001-01-01 00:00:00 | |
|
| created | | datetime | NO | | 0001-01-01 00:00:00 | |
|
||||||
| status | Status of the report | tinyint unsigned | YES | | NULL | |
|
| status | Status of the report | tinyint unsigned | YES | | NULL | |
|
||||||
|
|
|
@ -42,6 +42,8 @@ class Report extends \Friendica\BaseEntity
|
||||||
protected $cid;
|
protected $cid;
|
||||||
/** @var string Optional comment */
|
/** @var string Optional comment */
|
||||||
protected $comment;
|
protected $comment;
|
||||||
|
/** @var string Optional category */
|
||||||
|
protected $category;
|
||||||
/** @var bool Whether this report should be forwarded to the remote server */
|
/** @var bool Whether this report should be forwarded to the remote server */
|
||||||
protected $forward;
|
protected $forward;
|
||||||
/** @var \DateTime|null When the report was created */
|
/** @var \DateTime|null When the report was created */
|
||||||
|
@ -49,13 +51,14 @@ class Report extends \Friendica\BaseEntity
|
||||||
/** @var array Optional list of URI IDs of posts supporting the report*/
|
/** @var array Optional list of URI IDs of posts supporting the report*/
|
||||||
protected $postUriIds;
|
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->uid = $uid;
|
||||||
$this->reporterId = $reporterId;
|
$this->reporterId = $reporterId;
|
||||||
$this->cid = $cid;
|
$this->cid = $cid;
|
||||||
$this->created = $created;
|
$this->created = $created;
|
||||||
$this->comment = $comment;
|
$this->comment = $comment;
|
||||||
|
$this->category = $category;
|
||||||
$this->forward = $forward;
|
$this->forward = $forward;
|
||||||
$this->postUriIds = $postUriIds;
|
$this->postUriIds = $postUriIds;
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
|
|
|
@ -40,6 +40,7 @@ class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow
|
||||||
$row['cid'],
|
$row['cid'],
|
||||||
new \DateTime($row['created'] ?? 'now', new \DateTimeZone('UTC')),
|
new \DateTime($row['created'] ?? 'now', new \DateTimeZone('UTC')),
|
||||||
$row['comment'],
|
$row['comment'],
|
||||||
|
$row['category'],
|
||||||
$row['forward'],
|
$row['forward'],
|
||||||
$postUriIds,
|
$postUriIds,
|
||||||
$row['id'],
|
$row['id'],
|
||||||
|
@ -60,7 +61,7 @@ class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow
|
||||||
* @return Entity\Report
|
* @return Entity\Report
|
||||||
* @throws \Exception
|
* @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(
|
return new Entity\Report(
|
||||||
$uid,
|
$uid,
|
||||||
|
@ -68,6 +69,7 @@ class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow
|
||||||
$cid,
|
$cid,
|
||||||
new \DateTime('now', new \DateTimeZone('UTC')),
|
new \DateTime('now', new \DateTimeZone('UTC')),
|
||||||
$comment,
|
$comment,
|
||||||
|
$category,
|
||||||
$forward,
|
$forward,
|
||||||
$postUriIds,
|
$postUriIds,
|
||||||
);
|
);
|
||||||
|
|
|
@ -57,6 +57,7 @@ class Report extends \Friendica\BaseRepository
|
||||||
'reporter-id' => $Report->reporterId,
|
'reporter-id' => $Report->reporterId,
|
||||||
'cid' => $Report->cid,
|
'cid' => $Report->cid,
|
||||||
'comment' => $Report->comment,
|
'comment' => $Report->comment,
|
||||||
|
'category' => $Report->category,
|
||||||
'forward' => $Report->forward,
|
'forward' => $Report->forward,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ class Reports extends BaseApi
|
||||||
'account_id' => '', // ID of the account to report
|
'account_id' => '', // ID of the account to report
|
||||||
'status_ids' => [], // Array of Statuses to attach to the report, for context
|
'status_ids' => [], // Array of Statuses to attach to the report, for context
|
||||||
'comment' => '', // Reason for the report (default max 1000 characters)
|
'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?
|
'forward' => false, // If the account is remote, should the report be forwarded to the remote admin?
|
||||||
], $request);
|
], $request);
|
||||||
|
|
||||||
|
@ -65,7 +66,7 @@ class Reports extends BaseApi
|
||||||
throw new HTTPException\NotFoundException('Account ' . $request['account_id'] . ' not found');
|
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);
|
$this->reportRepo->save($report);
|
||||||
|
|
||||||
|
|
|
@ -1855,7 +1855,7 @@ class Processor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$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);
|
DI::report()->save($report);
|
||||||
|
|
||||||
Logger::info('Stored report', ['reporter' => $reporter_id, 'account_id' => $account_id, 'comment' => $activity['content'], 'status_ids' => $status_ids]);
|
Logger::info('Stored report', ['reporter' => $reporter_id, 'account_id' => $account_id, 'comment' => $activity['content'], 'status_ids' => $status_ids]);
|
||||||
|
|
|
@ -1676,6 +1676,7 @@ return [
|
||||||
"reporter-id" => ["type" => "int unsigned", "foreign" => ["contact" => "id"], "comment" => "Reporting contact"],
|
"reporter-id" => ["type" => "int unsigned", "foreign" => ["contact" => "id"], "comment" => "Reporting contact"],
|
||||||
"cid" => ["type" => "int unsigned", "not null" => "1", "foreign" => ["contact" => "id"], "comment" => "Reported contact"],
|
"cid" => ["type" => "int unsigned", "not null" => "1", "foreign" => ["contact" => "id"], "comment" => "Reported contact"],
|
||||||
"comment" => ["type" => "text", "comment" => "Report"],
|
"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"],
|
"forward" => ["type" => "boolean", "comment" => "Forward the report to the remote server"],
|
||||||
"created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
|
"created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
|
||||||
"status" => ["type" => "tinyint unsigned", "comment" => "Status of the report"],
|
"status" => ["type" => "tinyint unsigned", "comment" => "Status of the report"],
|
||||||
|
|
|
@ -48,6 +48,7 @@ class ReportTest extends MockedTest
|
||||||
13,
|
13,
|
||||||
new \DateTime('now', new \DateTimeZone('UTC')),
|
new \DateTime('now', new \DateTimeZone('UTC')),
|
||||||
'',
|
'',
|
||||||
|
null,
|
||||||
false,
|
false,
|
||||||
[],
|
[],
|
||||||
11,
|
11,
|
||||||
|
@ -70,6 +71,7 @@ class ReportTest extends MockedTest
|
||||||
13,
|
13,
|
||||||
new \DateTime('2021-10-12 12:23:00', new \DateTimeZone('UTC')),
|
new \DateTime('2021-10-12 12:23:00', new \DateTimeZone('UTC')),
|
||||||
'Report',
|
'Report',
|
||||||
|
'violation',
|
||||||
true,
|
true,
|
||||||
[89, 90],
|
[89, 90],
|
||||||
11
|
11
|
||||||
|
@ -88,6 +90,7 @@ class ReportTest extends MockedTest
|
||||||
self::assertEquals($assertion->reporterId, $report->reporterId);
|
self::assertEquals($assertion->reporterId, $report->reporterId);
|
||||||
self::assertEquals($assertion->cid, $report->cid);
|
self::assertEquals($assertion->cid, $report->cid);
|
||||||
self::assertEquals($assertion->comment, $report->comment);
|
self::assertEquals($assertion->comment, $report->comment);
|
||||||
|
self::assertEquals($assertion->category, $report->category);
|
||||||
self::assertEquals($assertion->forward, $report->forward);
|
self::assertEquals($assertion->forward, $report->forward);
|
||||||
// No way to test "now" at the moment
|
// No way to test "now" at the moment
|
||||||
//self::assertEquals($assertion->created, $report->created);
|
//self::assertEquals($assertion->created, $report->created);
|
||||||
|
@ -120,6 +123,7 @@ class ReportTest extends MockedTest
|
||||||
13,
|
13,
|
||||||
new \DateTime('now', new \DateTimeZone('UTC')),
|
new \DateTime('now', new \DateTimeZone('UTC')),
|
||||||
'',
|
'',
|
||||||
|
null,
|
||||||
false,
|
false,
|
||||||
[],
|
[],
|
||||||
null
|
null
|
||||||
|
@ -138,6 +142,7 @@ class ReportTest extends MockedTest
|
||||||
13,
|
13,
|
||||||
new \DateTime('now', new \DateTimeZone('UTC')),
|
new \DateTime('now', new \DateTimeZone('UTC')),
|
||||||
'Report',
|
'Report',
|
||||||
|
'violation',
|
||||||
true,
|
true,
|
||||||
[89, 90],
|
[89, 90],
|
||||||
null
|
null
|
||||||
|
@ -149,10 +154,10 @@ class ReportTest extends MockedTest
|
||||||
/**
|
/**
|
||||||
* @dataProvider dataCreateFromReportsRequest
|
* @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());
|
$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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue