diff options
author | Julius Härtl <jus@bitgrid.net> | 2019-01-24 11:50:01 +0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-03-01 20:56:17 +0100 |
commit | 506eb885bcaf7d745b417a155defc7c1e0f344c1 (patch) | |
tree | befcc41987dc41476f71859026cd7b6685e14e54 | |
parent | d85e3e3a6d775261cd4a504e07b111224cda8fc8 (diff) | |
download | nextcloud-server-506eb885bcaf7d745b417a155defc7c1e0f344c1.tar.gz nextcloud-server-506eb885bcaf7d745b417a155defc7c1e0f344c1.zip |
Only call resource provider if type matches
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r-- | apps/files/lib/Collaboration/Resources/ResourceProvider.php | 18 | ||||
-rw-r--r-- | lib/private/Collaboration/Resources/Manager.php | 37 | ||||
-rw-r--r-- | lib/public/Collaboration/Resources/IProvider.php | 9 |
3 files changed, 50 insertions, 14 deletions
diff --git a/apps/files/lib/Collaboration/Resources/ResourceProvider.php b/apps/files/lib/Collaboration/Resources/ResourceProvider.php index 62dcbe19c1d..4beb882ae3f 100644 --- a/apps/files/lib/Collaboration/Resources/ResourceProvider.php +++ b/apps/files/lib/Collaboration/Resources/ResourceProvider.php @@ -24,12 +24,15 @@ 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\IUser; class ResourceProvider implements IProvider { + const RESOURCE_TYPE = 'files'; + /** @var IRootFolder */ protected $rootFolder; @@ -63,10 +66,6 @@ class ResourceProvider implements IProvider { * @since 15.0.0 */ public function canAccess(IResource $resource, IUser $user = null): bool { - if ($resource->getType() !== 'files') { - return false; - } - if (!$user instanceof IUser) { return false; } @@ -92,4 +91,15 @@ class ResourceProvider implements IProvider { public function getIconClass(IResource $resource): string { return 'icon-folder'; } + + /** + * Get the type of a resource + * + * @param IResource $resource + * @return string + * @since 15.0.0 + */ + public function getType(): string { + return self::RESOURCE_TYPE; + } } diff --git a/lib/private/Collaboration/Resources/Manager.php b/lib/private/Collaboration/Resources/Manager.php index 071fa3c9436..1214145bd03 100644 --- a/lib/private/Collaboration/Resources/Manager.php +++ b/lib/private/Collaboration/Resources/Manager.php @@ -110,9 +110,11 @@ class Manager implements IManager { */ public function getName(IResource $resource): string { foreach ($this->getProviders() as $provider) { - try { - return $provider->getName($resource); - } catch (ResourceException $e) { + if ($provider->getType() === $resource->getType()) { + try { + return $provider->getName($resource); + } catch (ResourceException $e) { + } } } @@ -126,9 +128,11 @@ class Manager implements IManager { */ public function getIconClass(IResource $resource): string { foreach ($this->getProviders() as $provider) { - try { - return $provider->getIconClass($resource); - } catch (ResourceException $e) { + if ($provider->getType() === $resource->getType()) { + try { + return $provider->getIconClass($resource); + } catch (ResourceException $e) { + } } } @@ -145,11 +149,13 @@ class Manager implements IManager { */ public function canAccess(IResource $resource, IUser $user = null): bool { foreach ($this->getProviders() as $provider) { - try { - if ($provider->canAccess($resource, $user)) { - return true; + if ($provider->getType() === $resource->getType()) { + try { + if ($provider->canAccess($resource, $user)) { + return true; + } + } catch (ResourceException $e) { } - } catch (ResourceException $e) { } } @@ -162,4 +168,15 @@ class Manager implements IManager { public function registerResourceProvider(IProvider $provider): void { $this->providers[] = $provider; } + + /** + * Get the type of a resource + * + * @param IResource $resource + * @return string + * @since 15.0.0 + */ + public function getType(): string { + return ''; + } } diff --git a/lib/public/Collaboration/Resources/IProvider.php b/lib/public/Collaboration/Resources/IProvider.php index c5f6f7ed560..0299bfd0ddf 100644 --- a/lib/public/Collaboration/Resources/IProvider.php +++ b/lib/public/Collaboration/Resources/IProvider.php @@ -27,6 +27,15 @@ use OCP\IUser; interface IProvider { /** + * Get the type of a resource + * + * @param IResource $resource + * @return string + * @since 15.0.0 + */ + public function getType(): string; + + /** * Get the display name of a resource * * @param IResource $resource |