]> git.mxchange.org Git - friendica.git/commitdiff
Category added
authorMichael <heluecht@pirati.ca>
Sat, 24 Dec 2022 13:57:43 +0000 (13:57 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 24 Dec 2022 13:57:43 +0000 (13:57 +0000)
database.sql
doc/database/db_report.md
src/Moderation/Entity/Report.php
src/Moderation/Factory/Report.php
src/Moderation/Repository/Report.php
src/Module/Api/Mastodon/Reports.php
src/Protocol/ActivityPub/Processor.php
static/dbstructure.config.php
tests/src/Moderation/Factory/ReportTest.php

index 2f8882d4b4e2ac964b86c898d68f494bd350fa1e..8c24dd4eb65d560a7b8f0eda3f0c268805a6ad4a 100644 (file)
@@ -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',
index fcec88234dffd12c9a86979614b62e037c1caa54..56f51bdd416e49aeebe6e18cba9723f9efdc4ccd 100644 (file)
@@ -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
 ------------
index 957cef86527403b796a4b7095ce02dc5175eb292..4689a11b33b6e944636ecf8157fa444c2e8b61e4 100644 (file)
@@ -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;
index 918c10bc8444b557643e08e4bf25b6152f732b04..fbe0aa58b65de166698ee3b28d8dd2048f83a1d3 100644 (file)
@@ -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,
                );
index 1882d857107b5f8ab140362b8bc0515eb20e81ce..78d88937888f31f093b48e64a44c826b4e34718d 100644 (file)
@@ -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,
                ];
 
index c8dc0044c36063d7796a7cf1439aa0d195168e9d..13d41eb2337fe498b8c28ed0644a2fdc4c25508a 100644 (file)
@@ -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);
 
index 25c09c9cb57e5b56a6b3c5ead808d90850482e03..35bbc56233f9067a08ab47653231d917dc57f1e2 100644 (file)
@@ -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]);
index 59046a6cc495f72537d95094a62c09914c4ffaac..8971118147568f2517a16f4eaa6a5ca6672c83a1 100644 (file)
@@ -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"],
index fa9461529dae1d9920d44162c49fb13dc0e9ce81..ea4133fea4e52c078d27eb21bd44f96ab4309381 100644 (file)
@@ -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);
        }
 }