summaryrefslogtreecommitdiffstats
path: root/lib/private/Collaboration
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2018-10-17 20:03:44 +0200
committerJulius Härtl <jus@bitgrid.net>2019-03-01 20:56:15 +0100
commit136d2c39ac72f837a3ea9a3f698be963fefb69a3 (patch)
tree5b6f44f7a8e49a23533060fd50c0bbeccd292ba2 /lib/private/Collaboration
parent65a9ab47ea233701b559d08d89e36649a3d5a30b (diff)
downloadnextcloud-server-136d2c39ac72f837a3ea9a3f698be963fefb69a3.tar.gz
nextcloud-server-136d2c39ac72f837a3ea9a3f698be963fefb69a3.zip
Provider functionality
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/Collaboration')
-rw-r--r--lib/private/Collaboration/Resources/Collection.php18
-rw-r--r--lib/private/Collaboration/Resources/Manager.php50
-rw-r--r--lib/private/Collaboration/Resources/Resource.php28
3 files changed, 96 insertions, 0 deletions
diff --git a/lib/private/Collaboration/Resources/Collection.php b/lib/private/Collaboration/Resources/Collection.php
index 8509b4442de..e89f62c0518 100644
--- a/lib/private/Collaboration/Resources/Collection.php
+++ b/lib/private/Collaboration/Resources/Collection.php
@@ -30,6 +30,7 @@ use OCP\Collaboration\Resources\ICollection;
use OCP\Collaboration\Resources\IResource;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
+use OCP\IUser;
class Collection implements ICollection {
@@ -131,6 +132,23 @@ class Collection implements ICollection {
}
}
+ /**
+ * Can a user/guest access the collection
+ *
+ * @param IUser $user
+ * @return bool
+ * @since 15.0.0
+ */
+ public function canAccess(IUser $user = null): bool {
+ foreach ($this->getResources() as $resource) {
+ if ($resource->canAccess($user)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
protected function isSameResource(IResource $resource1, IResource $resource2): bool {
return $resource1->getType() === $resource2->getType() &&
$resource1->getId() === $resource2->getId();
diff --git a/lib/private/Collaboration/Resources/Manager.php b/lib/private/Collaboration/Resources/Manager.php
index e36c4ab1d38..8302d4a1002 100644
--- a/lib/private/Collaboration/Resources/Manager.php
+++ b/lib/private/Collaboration/Resources/Manager.php
@@ -25,8 +25,11 @@ namespace OC\Collaboration\Resources;
use OCP\Collaboration\Resources\ICollection;
use OCP\Collaboration\Resources\IManager;
+use OCP\Collaboration\Resources\IProvider;
use OCP\Collaboration\Resources\IResource;
+use OCP\Collaboration\Resources\ResourceException;
use OCP\IDBConnection;
+use OCP\IUser;
class Manager implements IManager {
@@ -55,4 +58,51 @@ class Manager implements IManager {
public function getResource(string $type, string $id): IResource {
return new Resource($this, $this->connection, $type, $id);
}
+
+ /**
+ * @return IProvider[]
+ * @since 15.0.0
+ */
+ public function getProviders(): array {
+ return [];
+ }
+
+ /**
+ * Get the display name of a resource
+ *
+ * @param IResource $resource
+ * @return string
+ * @since 15.0.0
+ */
+ public function getName(IResource $resource): string {
+ foreach ($this->getProviders() as $provider) {
+ try {
+ return $provider->getName($resource);
+ } catch (ResourceException $e) {
+ }
+ }
+
+ return '';
+ }
+
+ /**
+ * Can a user/guest access the collection
+ *
+ * @param IResource $resource
+ * @param IUser $user
+ * @return bool
+ * @since 15.0.0
+ */
+ public function canAccess(IResource $resource, IUser $user = null): bool {
+ foreach ($this->getProviders() as $provider) {
+ try {
+ if ($provider->canAccess($resource, $user)) {
+ return true;
+ }
+ } catch (ResourceException $e) {
+ }
+ }
+
+ return false;
+ }
}
diff --git a/lib/private/Collaboration/Resources/Resource.php b/lib/private/Collaboration/Resources/Resource.php
index 0eda8ba55c2..144af6d358e 100644
--- a/lib/private/Collaboration/Resources/Resource.php
+++ b/lib/private/Collaboration/Resources/Resource.php
@@ -26,7 +26,9 @@ namespace OC\Collaboration\Resources;
use OCP\Collaboration\Resources\ICollection;
use OCP\Collaboration\Resources\IManager;
use OCP\Collaboration\Resources\IResource;
+use OCP\Collaboration\Resources\ResourceException;
use OCP\IDBConnection;
+use OCP\IUser;
class Resource implements IResource {
@@ -42,6 +44,9 @@ class Resource implements IResource {
/** @var string */
protected $id;
+ /** @var string|null */
+ protected $name;
+
public function __construct(IManager $manager, IDBConnection $connection, string $type, string $id) {
$this->manager = $manager;
$this->connection = $connection;
@@ -66,6 +71,29 @@ class Resource implements IResource {
}
/**
+ * @return string
+ * @since 15.0.0
+ */
+ public function getName(): string {
+ if ($this->name === null) {
+ $this->name = $this->manager->getName($this);
+ }
+
+ return $this->name;
+ }
+
+ /**
+ * Can a user/guest access the resource
+ *
+ * @param IUser $user
+ * @return bool
+ * @since 15.0.0
+ */
+ public function canAccess(IUser $user = null): bool {
+ return $this->manager->canAccess($this, $user);
+ }
+
+ /**
* @return ICollection[]
* @since 15.0.0
*/