aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2019-03-01 21:22:34 +0100
committerGitHub <noreply@github.com>2019-03-01 21:22:34 +0100
commit2398d1183e7e561c8d3db7c06d8919d09c26b9e8 (patch)
tree2c4f21d88de7366a4a930f130aa89c619b00d9ae /apps/files/lib
parent34677082d8fb73fe5e9cdfd3c89f03a7c87da4fe (diff)
parentca0624d79c8eadbed19346ebcc90b2b86ec0b6c8 (diff)
downloadnextcloud-server-2398d1183e7e561c8d3db7c06d8919d09c26b9e8.tar.gz
nextcloud-server-2398d1183e7e561c8d3db7c06d8919d09c26b9e8.zip
Merge pull request #11871 from nextcloud/feature/11015/collaboration-resources
Collaboration resources
Diffstat (limited to 'apps/files/lib')
-rw-r--r--apps/files/lib/AppInfo/Application.php11
-rw-r--r--apps/files/lib/Collaboration/Resources/Listener.php44
-rw-r--r--apps/files/lib/Collaboration/Resources/ResourceProvider.php140
3 files changed, 195 insertions, 0 deletions
diff --git a/apps/files/lib/AppInfo/Application.php b/apps/files/lib/AppInfo/Application.php
index d4dac5befa8..dc2ed59618e 100644
--- a/apps/files/lib/AppInfo/Application.php
+++ b/apps/files/lib/AppInfo/Application.php
@@ -27,9 +27,12 @@
namespace OCA\Files\AppInfo;
use OCA\Files\Activity\Helper;
+use OCA\Files\Collaboration\Resources\Listener;
+use OCA\Files\Collaboration\Resources\ResourceProvider;
use OCA\Files\Controller\ApiController;
use OCP\AppFramework\App;
use \OCA\Files\Service\TagService;
+use OCP\Collaboration\Resources\IManager;
use \OCP\IContainer;
use OCA\Files\Controller\ViewController;
use OCA\Files\Capabilities;
@@ -99,5 +102,13 @@ class Application extends App {
* Register capabilities
*/
$container->registerCapability(Capabilities::class);
+
+ /**
+ * Register Collaboration ResourceProvider
+ */
+ /** @var IManager $resourceManager */
+ $resourceManager = $container->query(IManager::class);
+ $resourceManager->registerResourceProvider(ResourceProvider::class);
+ Listener::register($server->getEventDispatcher());
}
}
diff --git a/apps/files/lib/Collaboration/Resources/Listener.php b/apps/files/lib/Collaboration/Resources/Listener.php
new file mode 100644
index 00000000000..a4e5284741c
--- /dev/null
+++ b/apps/files/lib/Collaboration/Resources/Listener.php
@@ -0,0 +1,44 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.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\Files\Collaboration\Resources;
+
+
+use OCP\Collaboration\Resources\IManager;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+
+class Listener {
+ public static function register(EventDispatcherInterface $dispatcher): void {
+ $dispatcher->addListener('OCP\Share::postShare', [self::class, 'shareModification']);
+ $dispatcher->addListener('OCP\Share::postUnshare', [self::class, 'shareModification']);
+ $dispatcher->addListener('OCP\Share::postUnshareFromSelf', [self::class, 'shareModification']);
+ }
+
+ public static function shareModification(): void {
+ /** @var IManager $resourceManager */
+ $resourceManager = \OC::$server->query(IManager::class);
+ /** @var ResourceProvider $resourceProvider */
+ $resourceProvider = \OC::$server->query(ResourceProvider::class);
+
+ $resourceManager->invalidateAccessCacheForProvider($resourceProvider);
+ }
+}
diff --git a/apps/files/lib/Collaboration/Resources/ResourceProvider.php b/apps/files/lib/Collaboration/Resources/ResourceProvider.php
new file mode 100644
index 00000000000..d29b18afea3
--- /dev/null
+++ b/apps/files/lib/Collaboration/Resources/ResourceProvider.php
@@ -0,0 +1,140 @@
+<?php
+/**
+ * @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.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\Files\Collaboration\Resources;
+
+
+use OCP\Collaboration\Resources\IProvider;
+use OCP\Collaboration\Resources\IResource;
+use OCP\Collaboration\Resources\ResourceException;
+use OCP\Files\IRootFolder;
+use OCP\Files\Node;
+use OCP\IURLGenerator;
+use OCP\IUser;
+
+class ResourceProvider implements IProvider {
+
+ const RESOURCE_TYPE = 'files';
+
+ /** @var IRootFolder */
+ protected $rootFolder;
+
+ /** @var IURLGenerator */
+ private $urlGenerator;
+
+ /** @var array */
+ protected $nodes = [];
+
+ public function __construct(IRootFolder $rootFolder, IURLGenerator $urlGenerator) {
+ $this->rootFolder = $rootFolder;
+ $this->urlGenerator = $urlGenerator;
+ }
+
+ private function getNode(IResource $resource): ?Node {
+ if (isset($this->nodes[(int) $resource->getId()])) {
+ return $this->nodes[(int) $resource->getId()];
+ }
+ $nodes = $this->rootFolder->getById((int) $resource->getId());
+ if (!empty($nodes)) {
+ $this->nodes[(int) $resource->getId()] = array_shift($nodes);
+ return $this->nodes[(int) $resource->getId()];
+ }
+ return null;
+ }
+
+ /**
+ * Get the display name of a resource
+ *
+ * @param IResource $resource
+ * @return string
+ * @since 15.0.0
+ */
+ public function getName(IResource $resource): string {
+ if (isset($this->nodes[(int) $resource->getId()])) {
+ return $this->nodes[(int) $resource->getId()]->getPath();
+ }
+ $node = $this->getNode($resource);
+ if ($node) {
+ return $node->getName();
+ }
+ return '';
+ }
+
+ /**
+ * Can a user/guest access the collection
+ *
+ * @param IResource $resource
+ * @param IUser $user
+ * @return bool
+ * @since 15.0.0
+ */
+ public function canAccessResource(IResource $resource, IUser $user = null): bool {
+ if (!$user instanceof IUser) {
+ return false;
+ }
+
+ $userFolder = $this->rootFolder->getUserFolder($user->getUID());
+ $nodes = $userFolder->getById((int) $resource->getId());
+
+ if (!empty($nodes)) {
+ $this->nodes[(int) $resource->getId()] = array_shift($nodes);
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Get the icon class of a resource
+ *
+ * @param IResource $resource
+ * @return string
+ * @since 15.0.0
+ */
+ public function getIconClass(IResource $resource): string {
+ $node = $this->getNode($resource);
+ if ($node && $node->getMimetype() === 'httpd/unix-directory') {
+ return 'icon-files-dark';
+ }
+ return 'icon-filetype-file';
+ }
+
+ /**
+ * Get the resource type of the provider
+ *
+ * @return string
+ * @since 15.0.0
+ */
+ public function getType(): string {
+ return self::RESOURCE_TYPE;
+ }
+
+ /**
+ * Get the link to a resource
+ *
+ * @param IResource $resource
+ * @return string
+ * @since 15.0.0
+ */
+ public function getLink(IResource $resource): string {
+ return $this->urlGenerator->linkToRoute('files.viewcontroller.showFile', ['fileid' => $resource->getId()]);
+ }
+}