diff options
author | Joas Schilling <coding@schilljs.com> | 2018-10-18 13:00:25 +0200 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-03-01 20:56:15 +0100 |
commit | 5dfc56e925309d637be6f5a69cc16d0baaf20d03 (patch) | |
tree | 6bcee736d8e9369a2c519103bb0c005ca82e3e40 /core/Controller/CollaborationResourcesController.php | |
parent | 136d2c39ac72f837a3ea9a3f698be963fefb69a3 (diff) | |
download | nextcloud-server-5dfc56e925309d637be6f5a69cc16d0baaf20d03.tar.gz nextcloud-server-5dfc56e925309d637be6f5a69cc16d0baaf20d03.zip |
Allow to create collections
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'core/Controller/CollaborationResourcesController.php')
-rw-r--r-- | core/Controller/CollaborationResourcesController.php | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/core/Controller/CollaborationResourcesController.php b/core/Controller/CollaborationResourcesController.php index bd8c8442ae5..453a6405e56 100644 --- a/core/Controller/CollaborationResourcesController.php +++ b/core/Controller/CollaborationResourcesController.php @@ -160,8 +160,40 @@ class CollaborationResourcesController extends OCSController { return new DataResponse(array_map([$this, 'prepareCollection'], $resource->getCollections())); } + /** + * @NoAdminRequired + * + * @param string $baseResourceType + * @param string $baseResourceId + * @param string $resourceType + * @param string $resourceId + * @return DataResponse + */ + public function createCollectionOnResource(string $baseResourceType, string $baseResourceId, string $resourceType, string $resourceId): DataResponse { + try { + $baseResource = $this->manager->getResource($baseResourceType, $baseResourceId); + $resource = $this->manager->getResource($resourceType, $resourceId); + } catch (CollectionException $e) { + return new DataResponse([], Http::STATUS_NOT_FOUND); + } + + if (!$baseResource->canAccess($this->userSession->getUser()) || + !$resource->canAccess($this->userSession->getUser())) { + return new DataResponse([], Http::STATUS_NOT_FOUND); + } + + $collection = $this->manager->newCollection(); + $collection->addResource($baseResource); + $collection->addResource($resource); + + return new DataResponse($this->prepareCollection($collection)); + } + protected function prepareCollection(ICollection $collection): array { - return array_map([$this, 'prepareResources'], $collection->getResources()); + return [ + 'id' => $collection->getId(), + 'resources' => array_map([$this, 'prepareResources'], $collection->getResources()), + ]; } protected function prepareResources(IResource $resource): array { |