From 9411cf60461a2301a684a45214442c74fa470db4 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Mon, 24 Jun 2019 23:04:05 -0100 Subject: Service as Actor Signed-off-by: Maxence Lange --- lib/AP.php | 30 +++++++++++++++++++ lib/Db/CoreRequestBuilder.php | 3 +- lib/Interfaces/Actor/ServiceInterface.php | 46 +++++++++++++++++++++++++++++ lib/Model/ActivityPub/Actor/Service.php | 49 +++++++++++++++++++++++++++++++ lib/Service/CacheActorService.php | 4 +-- lib/Service/CurlService.php | 3 +- 6 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 lib/Interfaces/Actor/ServiceInterface.php create mode 100644 lib/Model/ActivityPub/Actor/Service.php diff --git a/lib/AP.php b/lib/AP.php index 80859eae..0efbd998 100644 --- a/lib/AP.php +++ b/lib/AP.php @@ -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)); + } + } diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php index 259b0374..fc9a835f 100644 --- a/lib/Db/CoreRequestBuilder.php +++ b/lib/Db/CoreRequestBuilder.php @@ -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(); } diff --git a/lib/Interfaces/Actor/ServiceInterface.php b/lib/Interfaces/Actor/ServiceInterface.php new file mode 100644 index 00000000..c764242c --- /dev/null +++ b/lib/Interfaces/Actor/ServiceInterface.php @@ -0,0 +1,46 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCA\Social\Interfaces\Actor; + + +use OCA\Social\Interfaces\IActivityPubInterface; + + +/** + * Class ServiceInterface + * + * @package OCA\Social\Service\ActivityPub + */ +class ServiceInterface extends PersonInterface implements IActivityPubInterface { + +} + + diff --git a/lib/Model/ActivityPub/Actor/Service.php b/lib/Model/ActivityPub/Actor/Service.php new file mode 100644 index 00000000..71b895d0 --- /dev/null +++ b/lib/Model/ActivityPub/Actor/Service.php @@ -0,0 +1,49 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCA\Social\Model\ActivityPub\Actor; + + +use JsonSerializable; + + +/** + * Class Service + * + * @package OCA\Social\Model\ActivityPub + */ +class Service extends Person implements JsonSerializable { + + + const TYPE = 'Service'; + + +} + diff --git a/lib/Service/CacheActorService.php b/lib/Service/CacheActorService.php index 41ec3954..7420dda5 100644 --- a/lib/Service/CacheActorService.php +++ b/lib/Service/CacheActorService.php @@ -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) { } diff --git a/lib/Service/CurlService.php b/lib/Service/CurlService.php index 7775baff..3b9b3c82 100644 --- a/lib/Service/CurlService.php +++ b/lib/Service/CurlService.php @@ -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(); } -- cgit v1.2.3