]> git.mxchange.org Git - friendica.git/commitdiff
Reports: The reporting contact id is added
authorMichael <heluecht@pirati.ca>
Sat, 24 Dec 2022 08:03:37 +0000 (08:03 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 24 Dec 2022 08:03:37 +0000 (08:03 +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 d93c979f05c5ef0c4ec27b55802d49c2f9f22663..2f8882d4b4e2ac964b86c898d68f494bd350fa1e 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2023.03-dev (Giant Rhubarb)
--- DB_UPDATE_VERSION 1503
+-- DB_UPDATE_VERSION 1504
 -- ------------------------------------------
 
 
@@ -1674,6 +1674,7 @@ CREATE TABLE IF NOT EXISTS `register` (
 CREATE TABLE IF NOT EXISTS `report` (
        `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
        `uid` mediumint unsigned COMMENT 'Reporting user',
+       `reporter-id` int unsigned COMMENT 'Reporting contact',
        `cid` int unsigned NOT NULL COMMENT 'Reported contact',
        `comment` text COMMENT 'Report',
        `forward` boolean COMMENT 'Forward the report to the remote server',
@@ -1682,7 +1683,9 @@ CREATE TABLE IF NOT EXISTS `report` (
         PRIMARY KEY(`id`),
         INDEX `uid` (`uid`),
         INDEX `cid` (`cid`),
+        INDEX `reporter-id` (`reporter-id`),
        FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
+       FOREIGN KEY (`reporter-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
        FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
 
index 9a87abe1f4c459d583eff0e737e4d977d75ea02c..fcec88234dffd12c9a86979614b62e037c1caa54 100644 (file)
@@ -6,24 +6,26 @@ 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                |                |
-| 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                |                |
+| 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
 ------------
 
-| Name    | Fields |
-| ------- | ------ |
-| PRIMARY | id     |
-| uid     | uid    |
-| cid     | cid    |
+| Name        | Fields      |
+| ----------- | ----------- |
+| PRIMARY     | id          |
+| uid         | uid         |
+| cid         | cid         |
+| reporter-id | reporter-id |
 
 Foreign Keys
 ------------
@@ -31,6 +33,7 @@ Foreign Keys
 | Field | Target Table | Target Field |
 |-------|--------------|--------------|
 | uid | [user](help/database/db_user) | uid |
+| reporter-id | [contact](help/database/db_contact) | id |
 | cid | [contact](help/database/db_contact) | id |
 
 Return to [database documentation](help/database)
index 93d42b94ef0cf7d439e540df1652056422afe6bd..957cef86527403b796a4b7095ce02dc5175eb292 100644 (file)
@@ -35,6 +35,8 @@ class Report extends \Friendica\BaseEntity
        /** @var int|null */
        protected $id;
        /** @var int ID of the user making a moderation report*/
+       protected $reporterId;
+       /** @var int ID of the contact making a moderation report*/
        protected $uid;
        /** @var int ID of the contact being reported*/
        protected $cid;
@@ -47,9 +49,10 @@ class Report extends \Friendica\BaseEntity
        /** @var array Optional list of URI IDs of posts supporting the report*/
        protected $postUriIds;
 
-       public function __construct(int $uid, 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 = '', bool $forward = false, array $postUriIds = [], int $id = null)
        {
                $this->uid        = $uid;
+               $this->reporterId = $reporterId;
                $this->cid        = $cid;
                $this->created    = $created;
                $this->comment    = $comment;
index 17203d3078d26eb781eaf1847bbb13f9930de9d7..918c10bc8444b557643e08e4bf25b6152f732b04 100644 (file)
@@ -36,6 +36,7 @@ class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow
        {
                return new Entity\Report(
                        $row['uid'],
+                       $row['reporter-id'],
                        $row['cid'],
                        new \DateTime($row['created'] ?? 'now', new \DateTimeZone('UTC')),
                        $row['comment'],
@@ -51,6 +52,7 @@ class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow
         * @see \Friendica\Module\Api\Mastodon\Reports::post()
         *
         * @param int    $uid
+        * @param int    $reporterId
         * @param int    $cid
         * @param string $comment
         * @param bool   $forward
@@ -58,10 +60,11 @@ class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow
         * @return Entity\Report
         * @throws \Exception
         */
-       public function createFromReportsRequest(int $uid, int $cid, string $comment = '', bool $forward = false, array $postUriIds = []): Entity\Report
+       public function createFromReportsRequest(int $uid = null, int $reporterId, int $cid, string $comment = '', bool $forward = false, array $postUriIds = []): Entity\Report
        {
                return new Entity\Report(
                        $uid,
+                       $reporterId,
                        $cid,
                        new \DateTime('now', new \DateTimeZone('UTC')),
                        $comment,
index 75a7f06dcdb3914890ec0564464d65bcc3c8249f..1882d857107b5f8ab140362b8bc0515eb20e81ce 100644 (file)
@@ -53,10 +53,11 @@ class Report extends \Friendica\BaseRepository
        public function save(\Friendica\Moderation\Entity\Report $Report)
        {
                $fields = [
-                       'uid'     => $Report->uid,
-                       'cid'     => $Report->cid,
-                       'comment' => $Report->comment,
-                       'forward' => $Report->forward,
+                       'uid'         => $Report->uid,
+                       'reporter-id' => $Report->reporterId,
+                       'cid'         => $Report->cid,
+                       'comment'     => $Report->comment,
+                       'forward'     => $Report->forward,
                ];
 
                $postUriIds = $Report->postUriIds;
index 6ae54eb6f67241103b28817261791f1f3ffc6cf2..c8dc0044c36063d7796a7cf1439aa0d195168e9d 100644 (file)
@@ -65,7 +65,7 @@ class Reports extends BaseApi
                        throw new HTTPException\NotFoundException('Account ' . $request['account_id'] . ' not found');
                }
 
-               $report = $this->reportFactory->createFromReportsRequest(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['forward'], $request['status_ids']);
 
                $this->reportRepo->save($report);
 
index 843f4b8cf6c3fd690f50adafab1830da43e9a140..76d050bd293d98ecf4633df7dbeee5ebda7e54fe 100644 (file)
@@ -1837,6 +1837,13 @@ class Processor
                        return;
                }
 
+               $reporter_id = Contact::getIdForURL($activity['actor']);
+               if (empty($account_id)) {
+                       Logger::info('Unknown actor', ['activity' => $activity]);
+                       Queue::remove($activity);
+                       return;
+               }
+
                $status_ids = $activity['object_ids'];
                array_shift($status_ids);
 
@@ -1848,11 +1855,10 @@ class Processor
                        }
                }
 
-               // @todo We should store the actor
-               $report = DI::reportFactory()->createFromReportsRequest(0, $account_id, $activity['content'], false, $uri_ids);
+               $report = DI::reportFactory()->createFromReportsRequest(null, $reporter_id, $account_id, $activity['content'], false, $uri_ids);
                DI::report()->save($report);
 
-               Logger::info('Stored report', ['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]);
        }
 
        /**
index ac2bb0e1ea5323f62d9221203d551afc5a62c609..59046a6cc495f72537d95094a62c09914c4ffaac 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1503);
+       define('DB_UPDATE_VERSION', 1504);
 }
 
 return [
@@ -1673,6 +1673,7 @@ return [
                "fields" => [
                        "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
                        "uid" => ["type" => "mediumint unsigned", "foreign" => ["user" => "uid"], "comment" => "Reporting user"],
+                       "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"],
                        "forward" => ["type" => "boolean", "comment" => "Forward the report to the remote server"],
@@ -1683,6 +1684,7 @@ return [
                        "PRIMARY" => ["id"],
                        "uid" => ["uid"],
                        "cid" => ["cid"],
+                       "reporter-id" => ["reporter-id"],
                ]
        ],
        "report-post" => [
index 0f29709100670a0879f41c411251aed96f3b3f29..fa9461529dae1d9920d44162c49fb13dc0e9ce81 100644 (file)
@@ -33,16 +33,18 @@ class ReportTest extends MockedTest
                return [
                        'default' => [
                                'row' => [
-                                       'id'      => 11,
-                                       'uid'     => 12,
-                                       'cid'     => 13,
-                                       'comment' => '',
-                                       'forward' => false,
-                                       'created' => null
+                                       'id'          => 11,
+                                       'uid'         => 12,
+                                       'reporter-id' => 14,
+                                       'cid'         => 13,
+                                       'comment'     => '',
+                                       'forward'     => false,
+                                       'created'     => null
                                ],
                                'postUriIds' => [],
                                'assertion'  => new Entity\Report(
                                        12,
+                                       14,
                                        13,
                                        new \DateTime('now', new \DateTimeZone('UTC')),
                                        '',
@@ -53,16 +55,18 @@ class ReportTest extends MockedTest
                        ],
                        'full' => [
                                'row' => [
-                                       'id'      => 11,
-                                       'uid'     => 12,
-                                       'cid'     => 13,
-                                       'comment' => 'Report',
-                                       'forward' => true,
-                                       'created' => '2021-10-12 12:23:00'
+                                       'id'          => 11,
+                                       'uid'         => 12,
+                                       'reporter-id' => 14,
+                                       'cid'         => 13,
+                                       'comment'     => 'Report',
+                                       'forward'     => true,
+                                       'created'     => '2021-10-12 12:23:00'
                                ],
                                'postUriIds' => [89, 90],
                                'assertion'  => new Entity\Report(
                                        12,
+                                       14,
                                        13,
                                        new \DateTime('2021-10-12 12:23:00', new \DateTimeZone('UTC')),
                                        'Report',
@@ -81,6 +85,7 @@ class ReportTest extends MockedTest
                        $report->id
                );
                self::assertEquals($assertion->uid, $report->uid);
+               self::assertEquals($assertion->reporterId, $report->reporterId);
                self::assertEquals($assertion->cid, $report->cid);
                self::assertEquals($assertion->comment, $report->comment);
                self::assertEquals($assertion->forward, $report->forward);
@@ -103,13 +108,15 @@ class ReportTest extends MockedTest
        {
                return [
                        'default' => [
-                               'uid'        => 12,
-                               'cid'        => 13,
-                               'comment'    => '',
-                               'forward'    => false,
-                               'postUriIds' => [],
-                               'assertion'  => new Entity\Report(
+                               'uid'         => 12,
+                               'reporter-id' => 14,
+                               'cid'         => 13,
+                               'comment'     => '',
+                               'forward'     => false,
+                               'postUriIds'  => [],
+                               'assertion'   => new Entity\Report(
                                        12,
+                                       14,
                                        13,
                                        new \DateTime('now', new \DateTimeZone('UTC')),
                                        '',
@@ -119,13 +126,15 @@ class ReportTest extends MockedTest
                                ),
                        ],
                        'full' => [
-                               'uid'        => 12,
-                               'cid'        => 13,
-                               'comment'    => 'Report',
-                               'forward'    => true,
-                               'postUriIds' => [89, 90],
-                               'assertion'  => new Entity\Report(
+                               'uid'         => 12,
+                               'reporter-id' => 14,
+                               'cid'         => 13,
+                               'comment'     => 'Report',
+                               'forward'     => true,
+                               'postUriIds'  => [89, 90],
+                               'assertion'   => new Entity\Report(
                                        12,
+                                       14,
                                        13,
                                        new \DateTime('now', new \DateTimeZone('UTC')),
                                        'Report',
@@ -140,10 +149,10 @@ class ReportTest extends MockedTest
        /**
         * @dataProvider dataCreateFromReportsRequest
         */
-       public function testCreateFromReportsRequest(int $uid, int $cid, string $comment, bool $forward, array $postUriIds, Entity\Report $assertion)
+       public function testCreateFromReportsRequest(int $uid, int $reporter, int $cid, string $comment, bool $forward, array $postUriIds, Entity\Report $assertion)
        {
                $factory = new Factory\Report(new NullLogger());
 
-               $this->assertReport($factory->createFromReportsRequest($uid, $cid, $comment, $forward, $postUriIds), $assertion);
+               $this->assertReport($factory->createFromReportsRequest($uid, $reporter, $cid, $comment, $forward, $postUriIds), $assertion);
        }
 }