From 15dd5d3e9fd6d07396cd0500f04c3dd61a068ce8 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Sat, 2 Mar 2019 17:23:34 -0500 Subject: [PATCH] Implement AddHandler --- src/Activities/AddHandler.php | 57 ++++++++++++++++++++++++++++++ test/Activities/AddHandlerTest.php | 14 ++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/Activities/AddHandler.php create mode 100644 test/Activities/AddHandlerTest.php diff --git a/src/Activities/AddHandler.php b/src/Activities/AddHandler.php new file mode 100644 index 0000000..bd2fdbe --- /dev/null +++ b/src/Activities/AddHandler.php @@ -0,0 +1,57 @@ + 'handleAdd', + OutboxActivityEvent::NAME => 'handleAdd', + ); + } + + public function __construct( ObjectsService $objectsService, + CollectionsService $collectionsService ) + { + $this->objectsService = $objectsService; + $this->collectionsService = $collectionsService; + } + + public function handleAdd( ActivityEvent $event ) + { + $activity = $event->getActivity(); + if ( $activity['type'] !== 'Add' ) { + return; + } + $collectionId = $activity['target']; + if ( is_array( $collectionId ) && array_key_exists( 'id', $collectionId ) ) { + $collectionId = $collectionId['id']; + } + $collection = $this->objectsService->dereference( $collectionId ); + $requestActor = $event->getRequest()->attributes->get( 'actor' ); + $requestActorHost = parse_url( $requestActor['id'], PHP_URL_HOST ); + $collectionHost = parse_url( $collection['id'], PHP_URL_HOST ); + if ( $requestActorHost !== $collectionHost ) { + throw new AccessDeniedHttpException(); + } + $object = $activity['object']; + $this->collectionsService->addItem( $collection, $object ); + } +} \ No newline at end of file diff --git a/test/Activities/AddHandlerTest.php b/test/Activities/AddHandlerTest.php new file mode 100644 index 0000000..957d359 --- /dev/null +++ b/test/Activities/AddHandlerTest.php @@ -0,0 +1,14 @@ +assertTrue( false ); + } +} \ No newline at end of file