Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 70 additions & 26 deletions apps/files_sharing/js/dist/files_sharing.3.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/files_sharing/js/dist/files_sharing.3.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/files_sharing/js/dist/files_sharing.4.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/files_sharing/js/dist/files_sharing.4.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions apps/files_sharing/src/views/CollaborationView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@
<script>
import { CollectionList } from 'nextcloud-vue-collections'

/**
* Those translations will be used by the vue component but they should be shipped with the server
* t('files_sharing', 'Add to a collection')
* t('files_sharing', 'Details')
* t('files_sharing', 'Rename collection')
*/

export default {
name: 'CollaborationView',
computed: {
Expand Down
72 changes: 59 additions & 13 deletions core/Controller/CollaborationResourcesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

namespace OC\Core\Controller;

use Exception;
use OCP\AppFramework\Http;
use OCP\AppFramework\OCSController;
use OCP\AppFramework\Http\DataResponse;
Expand All @@ -30,27 +31,31 @@
use OCP\Collaboration\Resources\IManager;
use OCP\Collaboration\Resources\IResource;
use OCP\Collaboration\Resources\ResourceException;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserSession;

class CollaborationResourcesController extends OCSController {

/** @var IManager */
private $manager;

/** @var IUserSession */
private $userSession;
/** @var ILogger */
private $logger;

public function __construct(
string $appName,
IRequest $request,
IManager $manager,
IUserSession $userSession
IUserSession $userSession,
ILogger $logger
) {
parent::__construct($appName, $request);

$this->manager = $manager;
$this->userSession = $userSession;
$this->logger = $logger;
}

/**
Expand Down Expand Up @@ -81,7 +86,7 @@ public function listCollection(int $collectionId): DataResponse {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}

return new DataResponse($this->prepareCollection($collection));
return $this->respondCollection($collection);
}

/**
Expand All @@ -97,7 +102,7 @@ public function searchCollections(string $filter): DataResponse {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}

return new DataResponse(array_map([$this, 'prepareCollection'], $collections));
return new DataResponse($this->prepareCollections($collections));
}

/**
Expand Down Expand Up @@ -126,7 +131,7 @@ public function addResource(int $collectionId, string $resourceType, string $res
} catch (ResourceException $e) {
}

return new DataResponse($this->prepareCollection($collection));
return $this->respondCollection($collection);
}

/**
Expand All @@ -152,7 +157,7 @@ public function removeResource(int $collectionId, string $resourceType, string $

$collection->removeResource($resource);

return new DataResponse($this->prepareCollection($collection));
return $this->respondCollection($collection);
}

/**
Expand All @@ -173,7 +178,7 @@ public function getCollectionsByResource(string $resourceType, string $resourceI
return new DataResponse([], Http::STATUS_NOT_FOUND);
}

return new DataResponse(array_map([$this, 'prepareCollection'], $resource->getCollections()));
return new DataResponse($this->prepareCollections($resource->getCollections()));
}

/**
Expand Down Expand Up @@ -202,7 +207,7 @@ public function createCollectionOnResource(string $baseResourceType, string $bas
$collection = $this->manager->newCollection($name);
$collection->addResource($resource);

return new DataResponse($this->prepareCollection($collection));
return $this->respondCollection($collection);
}

/**
Expand All @@ -221,24 +226,65 @@ public function renameCollection(int $collectionId, string $collectionName): Dat

$collection->setName($collectionName);

return new DataResponse($this->prepareCollection($collection));
return $this->respondCollection($collection);
}

protected function respondCollection(ICollection $collection): DataResponse {
try {
return new DataResponse($this->prepareCollection($collection));
} catch (CollectionException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (Exception $e) {
$this->logger->logException($e);
return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}
}

protected function prepareCollections(array $collections): array {
$result = [];

foreach ($collections as $collection) {
try {
$result[] = $this->prepareCollection($collection);
} catch (CollectionException $e) {
} catch (Exception $e) {
$this->logger->logException($e);
}
}

return $result;
}

protected function prepareCollection(ICollection $collection): array {
if (!$collection->canAccess($this->userSession->getUser())) {
return null;
throw new CollectionException('Can not access collection');
}

return [
'id' => $collection->getId(),
'name' => $collection->getName(),
'resources' => array_values(array_filter(array_map([$this, 'prepareResources'], $collection->getResources()))),
'resources' => $this->prepareResources($collection->getResources()),
];
}

protected function prepareResources(IResource $resource): ?array {
protected function prepareResources(array $resources): ?array {
$result = [];

foreach ($resources as $resource) {
try {
$result[] = $this->prepareResource($resource);
} catch (ResourceException $e) {
} catch (Exception $e) {
$this->logger->logException($e);
}
}

return $result;
}

protected function prepareResource(IResource $resource): array {
if (!$resource->canAccess($this->userSession->getUser())) {
return null;
throw new ResourceException('Can not access resource');
}

return $resource->getRichObject();
Expand Down
Loading