aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Collaboration/Resources
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Collaboration/Resources')
-rw-r--r--lib/private/Collaboration/Resources/Collection.php81
-rw-r--r--lib/private/Collaboration/Resources/Listener.php65
-rw-r--r--lib/private/Collaboration/Resources/Manager.php94
-rw-r--r--lib/private/Collaboration/Resources/ProviderManager.php40
-rw-r--r--lib/private/Collaboration/Resources/Resource.php69
5 files changed, 76 insertions, 273 deletions
diff --git a/lib/private/Collaboration/Resources/Collection.php b/lib/private/Collaboration/Resources/Collection.php
index ba4005c2139..2481a3e9a09 100644
--- a/lib/private/Collaboration/Resources/Collection.php
+++ b/lib/private/Collaboration/Resources/Collection.php
@@ -3,27 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Collaboration\Resources;
@@ -37,47 +18,21 @@ use OCP\IDBConnection;
use OCP\IUser;
class Collection implements ICollection {
-
- /** @var IManager|Manager */
- protected $manager;
-
- /** @var IDBConnection */
- protected $connection;
-
- /** @var int */
- protected $id;
-
- /** @var string */
- protected $name;
-
- /** @var IUser|null */
- protected $userForAccess;
-
- /** @var bool|null */
- protected $access;
-
/** @var IResource[] */
- protected $resources;
+ protected array $resources = [];
public function __construct(
- IManager $manager,
- IDBConnection $connection,
- int $id,
- string $name,
- ?IUser $userForAccess = null,
- ?bool $access = null
+ /** @var Manager $manager */
+ protected IManager $manager,
+ protected IDBConnection $connection,
+ protected int $id,
+ protected string $name,
+ protected ?IUser $userForAccess = null,
+ protected ?bool $access = null,
) {
- $this->manager = $manager;
- $this->connection = $connection;
- $this->id = $id;
- $this->name = $name;
- $this->userForAccess = $userForAccess;
- $this->access = $access;
- $this->resources = [];
}
/**
- * @return int
* @since 16.0.0
*/
public function getId(): int {
@@ -85,7 +40,6 @@ class Collection implements ICollection {
}
/**
- * @return string
* @since 16.0.0
*/
public function getName(): string {
@@ -93,7 +47,6 @@ class Collection implements ICollection {
}
/**
- * @param string $name
* @since 16.0.0
*/
public function setName(string $name): void {
@@ -101,7 +54,7 @@ class Collection implements ICollection {
$query->update(Manager::TABLE_COLLECTIONS)
->set('name', $query->createNamedParameter($name))
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
- $query->execute();
+ $query->executeStatement();
$this->name = $name;
}
@@ -121,7 +74,6 @@ class Collection implements ICollection {
/**
* Adds a resource to a collection
*
- * @param IResource $resource
* @throws ResourceException when the resource is already part of the collection
* @since 16.0.0
*/
@@ -154,7 +106,6 @@ class Collection implements ICollection {
/**
* Removes a resource from a collection
*
- * @param IResource $resource
* @since 16.0.0
*/
public function removeResource(IResource $resource): void {
@@ -167,7 +118,7 @@ class Collection implements ICollection {
->where($query->expr()->eq('collection_id', $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType())))
->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId())));
- $query->execute();
+ $query->executeStatement();
if (empty($this->resources)) {
$this->removeCollection();
@@ -179,8 +130,6 @@ class Collection implements ICollection {
/**
* Can a user/guest access the collection
*
- * @param IUser|null $user
- * @return bool
* @since 16.0.0
*/
public function canAccess(?IUser $user): bool {
@@ -215,15 +164,15 @@ class Collection implements ICollection {
}
protected function isSameResource(IResource $resource1, IResource $resource2): bool {
- return $resource1->getType() === $resource2->getType() &&
- $resource1->getId() === $resource2->getId();
+ return $resource1->getType() === $resource2->getType()
+ && $resource1->getId() === $resource2->getId();
}
protected function removeCollection(): void {
$query = $this->connection->getQueryBuilder();
$query->delete(Manager::TABLE_COLLECTIONS)
->where($query->expr()->eq('id', $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT)));
- $query->execute();
+ $query->executeStatement();
$this->manager->invalidateAccessCacheForCollection($this);
$this->id = 0;
diff --git a/lib/private/Collaboration/Resources/Listener.php b/lib/private/Collaboration/Resources/Listener.php
index ba012b4ca44..dfdde24d78e 100644
--- a/lib/private/Collaboration/Resources/Listener.php
+++ b/lib/private/Collaboration/Resources/Listener.php
@@ -3,62 +3,47 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author 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/>.
- *
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Collaboration\Resources;
use OCP\Collaboration\Resources\IManager;
-use OCP\IGroup;
-use OCP\IUser;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Group\Events\BeforeGroupDeletedEvent;
+use OCP\Group\Events\UserAddedEvent;
+use OCP\Group\Events\UserRemovedEvent;
+use OCP\User\Events\UserDeletedEvent;
class Listener {
- public static function register(EventDispatcherInterface $dispatcher): void {
- $listener = function (GenericEvent $event) {
- /** @var IUser $user */
- $user = $event->getArgument('user');
+ public static function register(IEventDispatcher $eventDispatcher): void {
+ $eventDispatcher->addListener(UserAddedEvent::class, function (UserAddedEvent $event) {
+ $user = $event->getUser();
/** @var IManager $resourceManager */
- $resourceManager = \OC::$server->query(IManager::class);
+ $resourceManager = \OCP\Server::get(IManager::class);
$resourceManager->invalidateAccessCacheForUser($user);
- };
- $dispatcher->addListener(IGroup::class . '::postAddUser', $listener);
- $dispatcher->addListener(IGroup::class . '::postRemoveUser', $listener);
+ });
+ $eventDispatcher->addListener(UserRemovedEvent::class, function (UserRemovedEvent $event) {
+ $user = $event->getUser();
+ /** @var IManager $resourceManager */
+ $resourceManager = \OCP\Server::get(IManager::class);
+
+ $resourceManager->invalidateAccessCacheForUser($user);
+ });
- $dispatcher->addListener(IUser::class . '::postDelete', function (GenericEvent $event) {
- /** @var IUser $user */
- $user = $event->getSubject();
+ $eventDispatcher->addListener(UserDeletedEvent::class, function (UserDeletedEvent $event) {
+ $user = $event->getUser();
/** @var IManager $resourceManager */
- $resourceManager = \OC::$server->query(IManager::class);
+ $resourceManager = \OCP\Server::get(IManager::class);
$resourceManager->invalidateAccessCacheForUser($user);
});
- $dispatcher->addListener(IGroup::class . '::preDelete', function (GenericEvent $event) {
- /** @var IGroup $group */
- $group = $event->getSubject();
+ $eventDispatcher->addListener(BeforeGroupDeletedEvent::class, function (BeforeGroupDeletedEvent $event) {
+ $group = $event->getGroup();
/** @var IManager $resourceManager */
- $resourceManager = \OC::$server->query(IManager::class);
+ $resourceManager = \OCP\Server::get(IManager::class);
foreach ($group->getUsers() as $user) {
$resourceManager->invalidateAccessCacheForUser($user);
diff --git a/lib/private/Collaboration/Resources/Manager.php b/lib/private/Collaboration/Resources/Manager.php
index 8fc3d0dd5ea..8d1e4b13287 100644
--- a/lib/private/Collaboration/Resources/Manager.php
+++ b/lib/private/Collaboration/Resources/Manager.php
@@ -3,27 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com>
- *
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Julius Härtl <jus@bitgrid.net>
- *
- * @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/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Collaboration\Resources;
@@ -45,26 +26,17 @@ class Manager implements IManager {
public const TABLE_RESOURCES = 'collres_resources';
public const TABLE_ACCESS_CACHE = 'collres_accesscache';
- /** @var IDBConnection */
- protected $connection;
- /** @var IProviderManager */
- protected $providerManager;
- /** @var LoggerInterface */
- protected $logger;
-
/** @var string[] */
- protected $providers = [];
-
+ protected array $providers = [];
- public function __construct(IDBConnection $connection, IProviderManager $providerManager, LoggerInterface $logger) {
- $this->connection = $connection;
- $this->providerManager = $providerManager;
- $this->logger = $logger;
+ public function __construct(
+ protected IDBConnection $connection,
+ protected IProviderManager $providerManager,
+ protected LoggerInterface $logger,
+ ) {
}
/**
- * @param int $id
- * @return ICollection
* @throws CollectionException when the collection could not be found
* @since 16.0.0
*/
@@ -81,13 +53,10 @@ class Manager implements IManager {
throw new CollectionException('Collection not found');
}
- return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name']);
+ return new Collection($this, $this->connection, (int)$row['id'], (string)$row['name']);
}
/**
- * @param int $id
- * @param IUser|null $user
- * @return ICollection
* @throws CollectionException when the collection could not be found
* @since 16.0.0
*/
@@ -113,19 +82,15 @@ class Manager implements IManager {
throw new CollectionException('Collection not found');
}
- $access = $row['access'] === null ? null : (bool) $row['access'];
+ $access = $row['access'] === null ? null : (bool)$row['access'];
if ($user instanceof IUser) {
- return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name'], $user, $access);
+ return new Collection($this, $this->connection, (int)$row['id'], (string)$row['name'], $user, $access);
}
- return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name'], $user, $access);
+ return new Collection($this, $this->connection, (int)$row['id'], (string)$row['name'], $user, $access);
}
/**
- * @param IUser $user
- * @param string $filter
- * @param int $limit
- * @param int $start
* @return ICollection[]
* @since 16.0.0
*/
@@ -148,7 +113,7 @@ class Manager implements IManager {
->setFirstResult($start);
if ($filter !== '') {
- $query->where($query->expr()->iLike('c.name', $query->createNamedParameter('%' . $this->connection->escapeLikeParameter($filter) . '%')));
+ $query->andWhere($query->expr()->iLike('c.name', $query->createNamedParameter('%' . $this->connection->escapeLikeParameter($filter) . '%')));
}
$result = $query->execute();
@@ -157,7 +122,7 @@ class Manager implements IManager {
$foundResults = 0;
while ($row = $result->fetch()) {
$foundResults++;
- $access = $row['access'] === null ? null : (bool) $row['access'];
+ $access = $row['access'] === null ? null : (bool)$row['access'];
$collection = new Collection($this, $this->connection, (int)$row['id'], (string)$row['name'], $user, $access);
if ($collection->canAccess($user)) {
$collections[] = $collection;
@@ -173,8 +138,6 @@ class Manager implements IManager {
}
/**
- * @param string $name
- * @return ICollection
* @since 16.0.0
*/
public function newCollection(string $name): ICollection {
@@ -189,9 +152,6 @@ class Manager implements IManager {
}
/**
- * @param string $type
- * @param string $id
- * @return IResource
* @since 16.0.0
*/
public function createResource(string $type, string $id): IResource {
@@ -199,10 +159,6 @@ class Manager implements IManager {
}
/**
- * @param string $type
- * @param string $id
- * @param IUser|null $user
- * @return IResource
* @throws ResourceException
* @since 16.0.0
*/
@@ -230,7 +186,7 @@ class Manager implements IManager {
throw new ResourceException('Resource not found');
}
- $access = $row['access'] === null ? null : (bool) $row['access'];
+ $access = $row['access'] === null ? null : (bool)$row['access'];
if ($user instanceof IUser) {
return new Resource($this, $this->connection, $type, $id, $user, $access);
}
@@ -239,8 +195,6 @@ class Manager implements IManager {
}
/**
- * @param ICollection $collection
- * @param IUser|null $user
* @return IResource[]
* @since 16.0.0
*/
@@ -263,7 +217,7 @@ class Manager implements IManager {
$resources = [];
$result = $query->execute();
while ($row = $result->fetch()) {
- $access = $row['access'] === null ? null : (bool) $row['access'];
+ $access = $row['access'] === null ? null : (bool)$row['access'];
$resources[] = new Resource($this, $this->connection, $row['resource_type'], $row['resource_id'], $user, $access);
}
$result->closeCursor();
@@ -274,8 +228,6 @@ class Manager implements IManager {
/**
* Get the rich object data of a resource
*
- * @param IResource $resource
- * @return array
* @since 16.0.0
*/
public function getResourceRichObject(IResource $resource): array {
@@ -294,9 +246,6 @@ class Manager implements IManager {
/**
* Can a user/guest access the collection
*
- * @param IResource $resource
- * @param IUser|null $user
- * @return bool
* @since 16.0.0
*/
public function canAccessResource(IResource $resource, ?IUser $user): bool {
@@ -325,9 +274,6 @@ class Manager implements IManager {
/**
* Can a user/guest access the collection
*
- * @param ICollection $collection
- * @param IUser|null $user
- * @return bool
* @since 16.0.0
*/
public function canAccessCollection(ICollection $collection, ?IUser $user): bool {
@@ -365,7 +311,7 @@ class Manager implements IManager {
$hasAccess = null;
$result = $query->execute();
if ($row = $result->fetch()) {
- $hasAccess = (bool) $row['access'];
+ $hasAccess = (bool)$row['access'];
}
$result->closeCursor();
@@ -385,7 +331,7 @@ class Manager implements IManager {
$hasAccess = null;
$result = $query->execute();
if ($row = $result->fetch()) {
- $hasAccess = (bool) $row['access'];
+ $hasAccess = (bool)$row['access'];
}
$result->closeCursor();
@@ -505,9 +451,6 @@ class Manager implements IManager {
$query->execute();
}
- /**
- * @param string $provider
- */
public function registerResourceProvider(string $provider): void {
$this->logger->debug('\OC\Collaboration\Resources\Manager::registerResourceProvider is deprecated', ['provider' => $provider]);
$this->providerManager->registerResourceProvider($provider);
@@ -516,7 +459,6 @@ class Manager implements IManager {
/**
* Get the resource type of the provider
*
- * @return string
* @since 16.0.0
*/
public function getType(): string {
diff --git a/lib/private/Collaboration/Resources/ProviderManager.php b/lib/private/Collaboration/Resources/ProviderManager.php
index 4b099f33b4f..0ce4ae7155a 100644
--- a/lib/private/Collaboration/Resources/ProviderManager.php
+++ b/lib/private/Collaboration/Resources/ProviderManager.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2019 Daniel Kesselberg <mail@danielkesselberg.de>
- *
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- * @author 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/>.
- *
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Collaboration\Resources;
@@ -33,22 +15,16 @@ use OCP\IServerContainer;
use Psr\Log\LoggerInterface;
class ProviderManager implements IProviderManager {
-
/** @var string[] */
- protected $providers = [];
+ protected array $providers = [];
/** @var IProvider[] */
- protected $providerInstances = [];
-
- /** @var IServerContainer */
- protected $serverContainer;
-
- /** @var LoggerInterface */
- protected $logger;
+ protected array $providerInstances = [];
- public function __construct(IServerContainer $serverContainer, LoggerInterface $logger) {
- $this->serverContainer = $serverContainer;
- $this->logger = $logger;
+ public function __construct(
+ protected IServerContainer $serverContainer,
+ protected LoggerInterface $logger,
+ ) {
}
public function getResourceProviders(): array {
diff --git a/lib/private/Collaboration/Resources/Resource.php b/lib/private/Collaboration/Resources/Resource.php
index f138204403c..19da3da7e7d 100644
--- a/lib/private/Collaboration/Resources/Resource.php
+++ b/lib/private/Collaboration/Resources/Resource.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com>
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Julius Härtl <jus@bitgrid.net>
- *
- * @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/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Collaboration\Resources;
@@ -33,46 +15,19 @@ use OCP\IDBConnection;
use OCP\IUser;
class Resource implements IResource {
-
- /** @var IManager */
- protected $manager;
-
- /** @var IDBConnection */
- protected $connection;
-
- /** @var string */
- protected $type;
-
- /** @var string */
- protected $id;
-
- /** @var IUser|null */
- protected $userForAccess;
-
- /** @var bool|null */
- protected $access;
-
- /** @var array|null */
- protected $data;
+ protected ?array $data = null;
public function __construct(
- IManager $manager,
- IDBConnection $connection,
- string $type,
- string $id,
- ?IUser $userForAccess = null,
- ?bool $access = null
+ protected IManager $manager,
+ protected IDBConnection $connection,
+ protected string $type,
+ protected string $id,
+ protected ?IUser $userForAccess = null,
+ protected ?bool $access = null,
) {
- $this->manager = $manager;
- $this->connection = $connection;
- $this->type = $type;
- $this->id = $id;
- $this->userForAccess = $userForAccess;
- $this->access = $access;
}
/**
- * @return string
* @since 16.0.0
*/
public function getType(): string {
@@ -80,7 +35,6 @@ class Resource implements IResource {
}
/**
- * @return string
* @since 16.0.0
*/
public function getId(): string {
@@ -88,7 +42,6 @@ class Resource implements IResource {
}
/**
- * @return array
* @since 16.0.0
*/
public function getRichObject(): array {
@@ -102,8 +55,6 @@ class Resource implements IResource {
/**
* Can a user/guest access the resource
*
- * @param IUser|null $user
- * @return bool
* @since 16.0.0
*/
public function canAccess(?IUser $user): bool {
@@ -153,7 +104,7 @@ class Resource implements IResource {
$result = $query->execute();
while ($row = $result->fetch()) {
- $collections[] = $this->manager->getCollection((int) $row['collection_id']);
+ $collections[] = $this->manager->getCollection((int)$row['collection_id']);
}
$result->closeCursor();