Merge pull request #595 from nextcloud/bugfix/573/service-as-actor

Service as Actor
pull/582/head
Maxence Lange 2019-06-25 14:23:13 -01:00 zatwierdzone przez GitHub
commit d33e9f23a3
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
6 zmienionych plików z 131 dodań i 4 usunięć

Wyświetl plik

@ -41,6 +41,7 @@ use OCA\Social\Interfaces\Activity\AddInterface;
use OCA\Social\Interfaces\Activity\BlockInterface;
use OCA\Social\Interfaces\Activity\CreateInterface;
use OCA\Social\Interfaces\Activity\DeleteInterface;
use OCA\Social\Interfaces\Actor\ServiceInterface;
use OCA\Social\Interfaces\Object\FollowInterface;
use OCA\Social\Interfaces\Activity\LikeInterface;
use OCA\Social\Interfaces\Activity\RejectInterface;
@ -60,6 +61,7 @@ use OCA\Social\Model\ActivityPub\Activity\Add;
use OCA\Social\Model\ActivityPub\Activity\Block;
use OCA\Social\Model\ActivityPub\Activity\Create;
use OCA\Social\Model\ActivityPub\Activity\Delete;
use OCA\Social\Model\ActivityPub\Actor\Service;
use OCA\Social\Model\ActivityPub\Object\Follow;
use OCA\Social\Model\ActivityPub\Activity\Like;
use OCA\Social\Model\ActivityPub\Activity\Reject;
@ -134,6 +136,9 @@ class AP {
/** @var RemoveInterface */
public $removeInterface;
/** @var ServiceInterface */
public $serviceInterface;
/** @var UndoInterface */
public $undoInterface;
@ -177,6 +182,7 @@ class AP {
$ap->noteInterface = OC::$server->query(NoteInterface::class);
$ap->notificationInterface = OC::$server->query(SocialAppNotificationInterface::class);
$ap->personInterface = OC::$server->query(PersonInterface::class);
$ap->serviceInterface = OC::$server->query(ServiceInterface::class);
$ap->rejectInterface = OC::$server->query(RejectInterface::class);
$ap->removeInterface = OC::$server->query(RemoveInterface::class);
$ap->undoInterface = OC::$server->query(UndoInterface::class);
@ -334,6 +340,10 @@ class AP {
$item = new Remove();
break;
case Service::TYPE:
$item = new Service();
break;
case Tombstone::TYPE:
$item = new Tombstone();
break;
@ -435,6 +445,10 @@ class AP {
$interface = $this->removeInterface;
break;
case Service::TYPE:
$interface = $this->serviceInterface;
break;
case Undo::TYPE:
$interface = $this->undoInterface;
break;
@ -450,6 +464,22 @@ class AP {
return $interface;
}
/**
* @param ACore $item
*
* @return bool
*/
public function isActor(ACore $item): bool {
$types =
[
Person::TYPE,
Service::TYPE
];
return (in_array($item->getType(), $types));
}
}

Wyświetl plik

@ -35,6 +35,7 @@ use DateInterval;
use DateTime;
use Doctrine\DBAL\Query\QueryBuilder;
use Exception;
use OCA\Social\AP;
use OCA\Social\Exceptions\DateTimeException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Model\ActivityPub\Actor\Person;
@ -706,7 +707,7 @@ class CoreRequestBuilder {
$actor = new Person();
$actor->importFromDatabase($new);
if ($actor->getType() !== Person::TYPE) {
if (!AP::$activityPub->isActor($actor)) {
throw new InvalidResourceException();
}

Wyświetl plik

@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
/**
* Nextcloud - Social Support
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Social\Interfaces\Actor;
use OCA\Social\Interfaces\IActivityPubInterface;
/**
* Class ServiceInterface
*
* @package OCA\Social\Service\ActivityPub
*/
class ServiceInterface extends PersonInterface implements IActivityPubInterface {
}

Wyświetl plik

@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
/**
* Nextcloud - Social Support
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Social\Model\ActivityPub\Actor;
use JsonSerializable;
/**
* Class Service
*
* @package OCA\Social\Model\ActivityPub
*/
class Service extends Person implements JsonSerializable {
const TYPE = 'Service';
}

Wyświetl plik

@ -139,7 +139,7 @@ class CacheActorService {
/** @var Person $actor */
$actor = AP::$activityPub->getItemFromData($object);
if ($actor->getType() !== Person::TYPE) {
if (!AP::$activityPub->isActor($actor)) {
throw new InvalidResourceException();
}
@ -273,7 +273,7 @@ class CacheActorService {
*/
private function save(Person $actor) {
try {
$interface = AP::$activityPub->getInterfaceFromType(Person::TYPE);
$interface = AP::$activityPub->getInterfaceFromType($actor->getType());
$interface->save($actor);
} catch (ItemUnknownException $e) {
}

Wyświetl plik

@ -51,6 +51,7 @@ use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\UnauthorizedFediverseException;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Actor\Service;
class CurlService {
@ -209,7 +210,7 @@ class CurlService {
/** @var Person $actor */
$actor = AP::$activityPub->getItemFromData($data);
if ($actor->getType() !== Person::TYPE) {
if (!AP::$activityPub->isActor($actor)) {
throw new ItemUnknownException();
}