Only call resource provider if type matches

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2019-01-24 11:50:01 +01:00
parent d85e3e3a6d
commit 506eb885bc
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
3 changed files with 50 additions and 14 deletions

View File

@ -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;
}
}

View File

@ -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 '';
}
}

View File

@ -26,6 +26,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
*