From: Michael Date: Sat, 24 Dec 2022 13:57:43 +0000 (+0000) Subject: Category added X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8a7d08ae2860d82fe98a26f4e86626b3c7eb4d1e;p=friendica.git Category added --- diff --git a/database.sql b/database.sql index 2f8882d4b4..8c24dd4eb6 100644 --- a/database.sql +++ b/database.sql @@ -1677,6 +1677,7 @@ CREATE TABLE IF NOT EXISTS `report` ( `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', diff --git a/doc/database/db_report.md b/doc/database/db_report.md index fcec88234d..56f51bdd41 100644 --- a/doc/database/db_report.md +++ b/doc/database/db_report.md @@ -6,16 +6,17 @@ Table 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 ------------ diff --git a/src/Moderation/Entity/Report.php b/src/Moderation/Entity/Report.php index 957cef8652..4689a11b33 100644 --- a/src/Moderation/Entity/Report.php +++ b/src/Moderation/Entity/Report.php @@ -42,6 +42,8 @@ class Report extends \Friendica\BaseEntity 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 */ @@ -49,13 +51,14 @@ class Report extends \Friendica\BaseEntity /** @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; diff --git a/src/Moderation/Factory/Report.php b/src/Moderation/Factory/Report.php index 918c10bc84..fbe0aa58b6 100644 --- a/src/Moderation/Factory/Report.php +++ b/src/Moderation/Factory/Report.php @@ -40,6 +40,7 @@ class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow $row['cid'], new \DateTime($row['created'] ?? 'now', new \DateTimeZone('UTC')), $row['comment'], + $row['category'], $row['forward'], $postUriIds, $row['id'], @@ -60,7 +61,7 @@ class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow * @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, @@ -68,6 +69,7 @@ class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow $cid, new \DateTime('now', new \DateTimeZone('UTC')), $comment, + $category, $forward, $postUriIds, ); diff --git a/src/Moderation/Repository/Report.php b/src/Moderation/Repository/Report.php index 1882d85710..78d8893788 100644 --- a/src/Moderation/Repository/Report.php +++ b/src/Moderation/Repository/Report.php @@ -57,6 +57,7 @@ class Report extends \Friendica\BaseRepository 'reporter-id' => $Report->reporterId, 'cid' => $Report->cid, 'comment' => $Report->comment, + 'category' => $Report->category, 'forward' => $Report->forward, ]; diff --git a/src/Module/Api/Mastodon/Reports.php b/src/Module/Api/Mastodon/Reports.php index c8dc0044c3..13d41eb233 100644 --- a/src/Module/Api/Mastodon/Reports.php +++ b/src/Module/Api/Mastodon/Reports.php @@ -54,10 +54,11 @@ class Reports extends BaseApi 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']); @@ -65,7 +66,7 @@ class Reports extends BaseApi 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); diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 25c09c9cb5..35bbc56233 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -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); Logger::info('Stored report', ['reporter' => $reporter_id, 'account_id' => $account_id, 'comment' => $activity['content'], 'status_ids' => $status_ids]); diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 59046a6cc4..8971118147 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -1676,6 +1676,7 @@ return [ "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"], diff --git a/tests/src/Moderation/Factory/ReportTest.php b/tests/src/Moderation/Factory/ReportTest.php index fa9461529d..ea4133fea4 100644 --- a/tests/src/Moderation/Factory/ReportTest.php +++ b/tests/src/Moderation/Factory/ReportTest.php @@ -48,6 +48,7 @@ class ReportTest extends MockedTest 13, new \DateTime('now', new \DateTimeZone('UTC')), '', + null, false, [], 11, @@ -70,6 +71,7 @@ class ReportTest extends MockedTest 13, new \DateTime('2021-10-12 12:23:00', new \DateTimeZone('UTC')), 'Report', + 'violation', true, [89, 90], 11 @@ -88,6 +90,7 @@ class ReportTest extends MockedTest 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); @@ -120,6 +123,7 @@ class ReportTest extends MockedTest 13, new \DateTime('now', new \DateTimeZone('UTC')), '', + null, false, [], null @@ -138,6 +142,7 @@ class ReportTest extends MockedTest 13, new \DateTime('now', new \DateTimeZone('UTC')), 'Report', + 'violation', true, [89, 90], null @@ -149,10 +154,10 @@ class ReportTest extends MockedTest /** * @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); } }