kopia lustrzana https://github.com/friendica/friendica
				
				
				
			Category added
							rodzic
							
								
									bf4d321aa3
								
							
						
					
					
						commit
						8a7d08ae28
					
				| 
						 | 
				
			
			@ -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',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,12 +7,13 @@ 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                |                |
 | 
			
		||||
| 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                |                |
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,
 | 
			
		||||
		);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,
 | 
			
		||||
		];
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -57,6 +57,7 @@ class Reports extends BaseApi
 | 
			
		|||
			'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);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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]);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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"],
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue