From bdeb3bcff53c97d8e9a4fba0dbd94a9721220f9f Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Wed, 19 Jan 2022 02:22:29 +0000 Subject: [PATCH] [PLUGIN][ActivityPub] Federate Actor of types other than Person Fix some other minor bugs --- components/Collection/Collection.php | 3 +-- components/Feed/Controller/Feeds.php | 2 +- components/Group/Controller/Group.php | 23 ----------------------- components/Group/Group.php | 1 - plugins/ActivityPub/Util/Model/Actor.php | 20 +++++++++++++++++--- src/Entity/Actor.php | 16 +++++----------- 6 files changed, 24 insertions(+), 41 deletions(-) diff --git a/components/Collection/Collection.php b/components/Collection/Collection.php index 409bc72c2e..d58cc3c60a 100644 --- a/components/Collection/Collection.php +++ b/components/Collection/Collection.php @@ -128,8 +128,7 @@ class Collection extends Component [ Actor::PERSON => ['person', 'people'], Actor::GROUP => ['group', 'groups'], - Actor::ORGANIZATION => ['org', 'orgs', 'organization', 'organizations', 'organisation', 'organisations'], - Actor::BUSINESS => ['business', 'businesses'], + Actor::ORGANISATION => ['org', 'orgs', 'organization', 'organizations', 'organisation', 'organisations'], Actor::BOT => ['bot', 'bots'], ] as $type => $match) { if (array_intersect(explode(',', $term[1]), $match) !== []) { diff --git a/components/Feed/Controller/Feeds.php b/components/Feed/Controller/Feeds.php index e43c622032..987558adf9 100644 --- a/components/Feed/Controller/Feeds.php +++ b/components/Feed/Controller/Feeds.php @@ -61,7 +61,7 @@ class Feeds extends FeedController public function home(Request $request): array { Common::ensureLoggedIn(); - $data = $this->query('note-from:subscribed-person,subscribed-group,subscribed-organization,subscribed-business'); + $data = $this->query('note-from:subscribed-person,subscribed-group,subscribed-organisation'); return [ '_template' => 'collection/notes.html.twig', 'page_title' => _m('Home'), diff --git a/components/Group/Controller/Group.php b/components/Group/Controller/Group.php index 374a86c261..db19544889 100644 --- a/components/Group/Controller/Group.php +++ b/components/Group/Controller/Group.php @@ -42,7 +42,6 @@ use App\Util\Exception\RedirectException; use App\Util\Exception\ServerException; use App\Util\Form\ActorForms; use App\Util\Nickname; -use Component\Collection\Util\ActorControllerTrait; use Component\Collection\Util\Controller\FeedController; use Component\Group\Entity\GroupMember; use Component\Group\Entity\LocalGroup; @@ -53,28 +52,6 @@ use Symfony\Component\HttpFoundation\Request; class Group extends FeedController { - use ActorControllerTrait; - - /** - * View a group providing its id - * - * @param int $id The id of the group to be shown - * - * @throws ClientException - * - * @return array Containing both the template to be used and the group actor - */ - public function groupViewId(Request $request, int $id) - { - return $this->handleActorById( - $id, - fn ($actor) => [ - '_template' => 'group/view.html.twig', - 'actor' => $actor, - ], - ); - } - /** * View a group feed by its nickname * diff --git a/components/Group/Group.php b/components/Group/Group.php index e22dee0141..93fd56cf22 100644 --- a/components/Group/Group.php +++ b/components/Group/Group.php @@ -40,7 +40,6 @@ class Group extends Component public function onAddRoute(RouteLoader $r): bool { $r->connect(id: 'group_create', uri_path: '/group/new', target: [C\Group::class, 'groupCreate']); - $r->connect(id: 'group_actor_view_id', uri_path: '/group/{id<\d+>}', target: [C\Group::class, 'groupViewId']); $r->connect(id: 'group_actor_view_nickname', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\Group::class, 'groupViewNickname'], options: ['is_system_path' => false]); $r->connect(id: 'group_settings', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}/settings', target: [C\Group::class, 'groupSettings'], options: ['is_system_path' => false]); return Event::next; diff --git a/plugins/ActivityPub/Util/Model/Actor.php b/plugins/ActivityPub/Util/Model/Actor.php index e203d55bb6..6cb4aeede3 100644 --- a/plugins/ActivityPub/Util/Model/Actor.php +++ b/plugins/ActivityPub/Util/Model/Actor.php @@ -61,6 +61,20 @@ use Plugin\ActivityPub\Util\Model; */ class Actor extends Model { + private static array $_gs_actor_type_to_as2_actor_type = [ + GSActor::PERSON => 'Person', + GSActor::GROUP => 'Group', + GSActor::ORGANISATION => 'Organization', + GSActor::BOT => 'Application', + ]; + private static array $_as2_actor_type_to_gs_actor_type = [ + 'Person' => GSActor::PERSON, + 'Group' => GSActor::GROUP, + 'Organization' => GSActor::ORGANISATION, + 'Application' => GSActor::BOT, + 'Service' => null, + ]; + /** * Create an Entity from an ActivityStreams 2.0 JSON string * This will persist a new GSActor, ActivityPubRSA, and ActivityPubActor @@ -77,8 +91,8 @@ class Actor extends Model 'fullname' => !empty($person->get('name')) ? $person->get('name') : null, 'created' => new DateTime($person->get('published') ?? 'now'), 'bio' => $person->get('summary'), - 'is_local' => false, - 'type' => GSActor::PERSON, + 'is_local' => false, // duh! + 'type' => self::$_as2_actor_type_to_gs_actor_type[$person->get('type')], 'roles' => UserRoles::USER, 'modified' => new DateTime(), ]; @@ -184,7 +198,7 @@ class Actor extends Model $uri = $object->getUri(Router::ABSOLUTE_URL); $attr = [ '@context' => 'https://www.w3.org/ns/activitystreams', - 'type' => 'Person', + 'type' => self::$_gs_actor_type_to_as2_actor_type[$object->getType()], 'id' => $uri, 'inbox' => Router::url('activitypub_actor_inbox', ['gsactor_id' => $object->getId()], Router::ABSOLUTE_URL), 'outbox' => Router::url('activitypub_actor_outbox', ['gsactor_id' => $object->getId()], Router::ABSOLUTE_URL), diff --git a/src/Entity/Actor.php b/src/Entity/Actor.php index 8bc3e744ff..a3f2ab6c02 100644 --- a/src/Entity/Actor.php +++ b/src/Entity/Actor.php @@ -243,9 +243,8 @@ class Actor extends Entity public const PERSON = 1; public const GROUP = 2; - public const ORGANIZATION = 3; - public const BUSINESS = 4; - public const BOT = 5; + public const ORGANISATION = 3; + public const BOT = 4; public static function cacheKeys(int|self $actor_id, mixed $other = null): array { @@ -422,13 +421,10 @@ class Actor extends Entity if (Event::handle('StartGetActorUri', [$this, $type, &$uri]) === Event::next) { switch ($this->type) { case self::PERSON: - case self::ORGANIZATION: - case self::BUSINESS: + case self::ORGANISATION: case self::BOT: - $uri = Router::url('actor_view_id', ['id' => $this->getId()], $type); - break; case self::GROUP: - $uri = Router::url('group_actor_view_id', ['id' => $this->getId()], $type); + $uri = Router::url('actor_view_id', ['id' => $this->getId()], $type); break; default: throw new BugFoundException('Actor type added but `Actor::getUri` was not updated'); @@ -448,8 +444,7 @@ class Actor extends Entity if (Event::handle('StartGetActorUrl', [$this, $type, &$url]) === Event::next) { switch ($this->type) { case self::PERSON: - case self::ORGANIZATION: - case self::BUSINESS: + case self::ORGANISATION: case self::BOT: $url = Router::url('actor_view_nickname', ['nickname' => $this->getNickname()], $type); break; @@ -538,7 +533,6 @@ class Actor extends Entity * @method bool isPerson() * @method bool isGroup() * @method bool isOrganization() - * @method bool isBusiness() * @method bool isBot() */ public function __call(string $name, array $arguments): mixed