summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2019-06-25 14:23:13 -0100
committerGitHub <noreply@github.com>2019-06-25 14:23:13 -0100
commitd33e9f23a344f440bd4dc91c816110aaa274b610 (patch)
tree31f707ca866704c61ed5e9807e84c0476e0477cd
parente499140035e6d98d0e06563778dc8878bc271593 (diff)
parent9411cf60461a2301a684a45214442c74fa470db4 (diff)
Merge pull request #595 from nextcloud/bugfix/573/service-as-actor
Service as Actor
-rw-r--r--lib/AP.php30
-rw-r--r--lib/Db/CoreRequestBuilder.php3
-rw-r--r--lib/Interfaces/Actor/ServiceInterface.php46
-rw-r--r--lib/Model/ActivityPub/Actor/Service.php49
-rw-r--r--lib/Service/CacheActorService.php4
-rw-r--r--lib/Service/CurlService.php3
6 files changed, 131 insertions, 4 deletions
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 @@
+<?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 {
+
+}
+
+
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 @@
+<?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';
+
+
+}
+
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();
}