diff options
Diffstat (limited to 'apps')
38 files changed, 2437 insertions, 182 deletions
diff --git a/apps/dav/appinfo/app.php b/apps/dav/appinfo/app.php index 4f4fbe6e126..089aaeb6c78 100644 --- a/apps/dav/appinfo/app.php +++ b/apps/dav/appinfo/app.php @@ -48,6 +48,19 @@ $eventDispatcher->addListener('OCP\Federation\TrustedServerEvent::remove', } ); +$eventHandler = function() use ($app) { + try { + $job = $app->getContainer()->query(\OCA\DAV\BackgroundJob\UpdateCalendarResourcesRoomsBackgroundJob::class); + $job->run([]); + $app->getContainer()->getServer()->getJobList()->setLastRun($job); + } catch(\Exception $ex) { + $app->getContainer()->getServer()->getLogger()->logException($ex); + } +}; + +$eventDispatcher->addListener('\OCP\Calendar\Resource\ForceRefreshEvent', $eventHandler); +$eventDispatcher->addListener('\OCP\Calendar\Room\ForceRefreshEvent', $eventHandler); + $cm = \OC::$server->getContactsManager(); $cm->register(function() use ($cm, $app) { $user = \OC::$server->getUserSession()->getUser(); diff --git a/apps/dav/appinfo/info.xml b/apps/dav/appinfo/info.xml index 2dcb986c841..d1f9a823fd7 100644 --- a/apps/dav/appinfo/info.xml +++ b/apps/dav/appinfo/info.xml @@ -5,7 +5,7 @@ <name>WebDAV</name> <summary>WebDAV endpoint</summary> <description>WebDAV endpoint</description> - <version>1.5.3</version> + <version>1.5.4</version> <licence>agpl</licence> <author>owncloud.org</author> <namespace>DAV</namespace> @@ -21,6 +21,7 @@ <background-jobs> <job>OCA\DAV\BackgroundJob\CleanupDirectLinksJob</job> + <job>OCA\DAV\BackgroundJob\UpdateCalendarResourcesRoomsBackgroundJob</job> </background-jobs> <repair-steps> diff --git a/apps/dav/composer/composer/autoload_classmap.php b/apps/dav/composer/composer/autoload_classmap.php index 30c51a4b36c..8ed5e068e2d 100644 --- a/apps/dav/composer/composer/autoload_classmap.php +++ b/apps/dav/composer/composer/autoload_classmap.php @@ -13,6 +13,7 @@ return array( 'OCA\\DAV\\Avatars\\RootCollection' => $baseDir . '/../lib/Avatars/RootCollection.php', 'OCA\\DAV\\BackgroundJob\\CleanupDirectLinksJob' => $baseDir . '/../lib/BackgroundJob/CleanupDirectLinksJob.php', 'OCA\\DAV\\BackgroundJob\\GenerateBirthdayCalendarBackgroundJob' => $baseDir . '/../lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php', + 'OCA\\DAV\\BackgroundJob\\UpdateCalendarResourcesRoomsBackgroundJob' => $baseDir . '/../lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php', 'OCA\\DAV\\CalDAV\\Activity\\Backend' => $baseDir . '/../lib/CalDAV/Activity/Backend.php', 'OCA\\DAV\\CalDAV\\Activity\\Filter\\Calendar' => $baseDir . '/../lib/CalDAV/Activity/Filter/Calendar.php', 'OCA\\DAV\\CalDAV\\Activity\\Filter\\Todo' => $baseDir . '/../lib/CalDAV/Activity/Filter/Todo.php', @@ -40,6 +41,9 @@ return array( 'OCA\\DAV\\CalDAV\\PublicCalendarRoot' => $baseDir . '/../lib/CalDAV/PublicCalendarRoot.php', 'OCA\\DAV\\CalDAV\\Publishing\\PublishPlugin' => $baseDir . '/../lib/CalDAV/Publishing/PublishPlugin.php', 'OCA\\DAV\\CalDAV\\Publishing\\Xml\\Publisher' => $baseDir . '/../lib/CalDAV/Publishing/Xml/Publisher.php', + 'OCA\\DAV\\CalDAV\\ResourceBooking\\AbstractPrincipalBackend' => $baseDir . '/../lib/CalDAV/ResourceBooking/AbstractPrincipalBackend.php', + 'OCA\\DAV\\CalDAV\\ResourceBooking\\ResourcePrincipalBackend' => $baseDir . '/../lib/CalDAV/ResourceBooking/ResourcePrincipalBackend.php', + 'OCA\\DAV\\CalDAV\\ResourceBooking\\RoomPrincipalBackend' => $baseDir . '/../lib/CalDAV/ResourceBooking/RoomPrincipalBackend.php', 'OCA\\DAV\\CalDAV\\Schedule\\IMipPlugin' => $baseDir . '/../lib/CalDAV/Schedule/IMipPlugin.php', 'OCA\\DAV\\CalDAV\\Schedule\\Plugin' => $baseDir . '/../lib/CalDAV/Schedule/Plugin.php', 'OCA\\DAV\\CalDAV\\Search\\SearchPlugin' => $baseDir . '/../lib/CalDAV/Search/SearchPlugin.php', @@ -145,6 +149,7 @@ return array( 'OCA\\DAV\\Migration\\Version1004Date20170924124212' => $baseDir . '/../lib/Migration/Version1004Date20170924124212.php', 'OCA\\DAV\\Migration\\Version1004Date20170926103422' => $baseDir . '/../lib/Migration/Version1004Date20170926103422.php', 'OCA\\DAV\\Migration\\Version1005Date20180413093149' => $baseDir . '/../lib/Migration/Version1005Date20180413093149.php', + 'OCA\\DAV\\Migration\\Version1005Date20180530124431' => $baseDir . '/../lib/Migration/Version1005Date20180530124431.php', 'OCA\\DAV\\RootCollection' => $baseDir . '/../lib/RootCollection.php', 'OCA\\DAV\\Server' => $baseDir . '/../lib/Server.php', 'OCA\\DAV\\Settings\\CalDAVSettings' => $baseDir . '/../lib/Settings/CalDAVSettings.php', diff --git a/apps/dav/composer/composer/autoload_static.php b/apps/dav/composer/composer/autoload_static.php index ff8208f5ca5..bdedf1a4404 100644 --- a/apps/dav/composer/composer/autoload_static.php +++ b/apps/dav/composer/composer/autoload_static.php @@ -28,6 +28,7 @@ class ComposerStaticInitDAV 'OCA\\DAV\\Avatars\\RootCollection' => __DIR__ . '/..' . '/../lib/Avatars/RootCollection.php', 'OCA\\DAV\\BackgroundJob\\CleanupDirectLinksJob' => __DIR__ . '/..' . '/../lib/BackgroundJob/CleanupDirectLinksJob.php', 'OCA\\DAV\\BackgroundJob\\GenerateBirthdayCalendarBackgroundJob' => __DIR__ . '/..' . '/../lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php', + 'OCA\\DAV\\BackgroundJob\\UpdateCalendarResourcesRoomsBackgroundJob' => __DIR__ . '/..' . '/../lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php', 'OCA\\DAV\\CalDAV\\Activity\\Backend' => __DIR__ . '/..' . '/../lib/CalDAV/Activity/Backend.php', 'OCA\\DAV\\CalDAV\\Activity\\Filter\\Calendar' => __DIR__ . '/..' . '/../lib/CalDAV/Activity/Filter/Calendar.php', 'OCA\\DAV\\CalDAV\\Activity\\Filter\\Todo' => __DIR__ . '/..' . '/../lib/CalDAV/Activity/Filter/Todo.php', @@ -55,6 +56,9 @@ class ComposerStaticInitDAV 'OCA\\DAV\\CalDAV\\PublicCalendarRoot' => __DIR__ . '/..' . '/../lib/CalDAV/PublicCalendarRoot.php', 'OCA\\DAV\\CalDAV\\Publishing\\PublishPlugin' => __DIR__ . '/..' . '/../lib/CalDAV/Publishing/PublishPlugin.php', 'OCA\\DAV\\CalDAV\\Publishing\\Xml\\Publisher' => __DIR__ . '/..' . '/../lib/CalDAV/Publishing/Xml/Publisher.php', + 'OCA\\DAV\\CalDAV\\ResourceBooking\\AbstractPrincipalBackend' => __DIR__ . '/..' . '/../lib/CalDAV/ResourceBooking/AbstractPrincipalBackend.php', + 'OCA\\DAV\\CalDAV\\ResourceBooking\\ResourcePrincipalBackend' => __DIR__ . '/..' . '/../lib/CalDAV/ResourceBooking/ResourcePrincipalBackend.php', + 'OCA\\DAV\\CalDAV\\ResourceBooking\\RoomPrincipalBackend' => __DIR__ . '/..' . '/../lib/CalDAV/ResourceBooking/RoomPrincipalBackend.php', 'OCA\\DAV\\CalDAV\\Schedule\\IMipPlugin' => __DIR__ . '/..' . '/../lib/CalDAV/Schedule/IMipPlugin.php', 'OCA\\DAV\\CalDAV\\Schedule\\Plugin' => __DIR__ . '/..' . '/../lib/CalDAV/Schedule/Plugin.php', 'OCA\\DAV\\CalDAV\\Search\\SearchPlugin' => __DIR__ . '/..' . '/../lib/CalDAV/Search/SearchPlugin.php', @@ -160,6 +164,7 @@ class ComposerStaticInitDAV 'OCA\\DAV\\Migration\\Version1004Date20170924124212' => __DIR__ . '/..' . '/../lib/Migration/Version1004Date20170924124212.php', 'OCA\\DAV\\Migration\\Version1004Date20170926103422' => __DIR__ . '/..' . '/../lib/Migration/Version1004Date20170926103422.php', 'OCA\\DAV\\Migration\\Version1005Date20180413093149' => __DIR__ . '/..' . '/../lib/Migration/Version1005Date20180413093149.php', + 'OCA\\DAV\\Migration\\Version1005Date20180530124431' => __DIR__ . '/..' . '/../lib/Migration/Version1005Date20180530124431.php', 'OCA\\DAV\\RootCollection' => __DIR__ . '/..' . '/../lib/RootCollection.php', 'OCA\\DAV\\Server' => __DIR__ . '/..' . '/../lib/Server.php', 'OCA\\DAV\\Settings\\CalDAVSettings' => __DIR__ . '/..' . '/../lib/Settings/CalDAVSettings.php', diff --git a/apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php b/apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php new file mode 100644 index 00000000000..a01540a6292 --- /dev/null +++ b/apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php @@ -0,0 +1,337 @@ +<?php +/** + * @copyright 2018, Georg Ehrke <oc.list@georgehrke.com> + * + * @author Georg Ehrke <oc.list@georgehrke.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\DAV\BackgroundJob; + +use OC\BackgroundJob\TimedJob; +use OCA\DAV\CalDAV\CalDavBackend; +use OCP\Calendar\BackendTemporarilyUnavailableException; +use OCP\Calendar\Resource\IManager as IResourceManager; +use OCP\Calendar\Resource\IResource; +use OCP\Calendar\Room\IManager as IRoomManager; +use OCP\Calendar\Room\IRoom; +use OCP\IDBConnection; + +class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { + + /** @var IResourceManager */ + private $resourceManager; + + /** @var IRoomManager */ + private $roomManager; + + /** @var IDBConnection */ + private $db; + + /** @var CalDavBackend */ + private $calDavBackend; + + /** @var string */ + private $resourceDbTable; + + /** @var string */ + private $resourcePrincipalUri; + + /** @var string */ + private $roomDbTable; + + /** @var string */ + private $roomPrincipalUri; + + /** + * UpdateCalendarResourcesRoomsBackgroundJob constructor. + * + * @param IResourceManager $resourceManager + * @param IRoomManager $roomManager + * @param IDBConnection $dbConnection + * @param CalDavBackend $calDavBackend + */ + public function __construct(IResourceManager $resourceManager, IRoomManager $roomManager, + IDBConnection $dbConnection, CalDavBackend $calDavBackend) { + $this->resourceManager = $resourceManager; + $this->roomManager = $roomManager; + $this->db = $dbConnection; + $this->calDavBackend = $calDavBackend; + $this->resourceDbTable = 'calendar_resources_cache'; + $this->resourcePrincipalUri = 'principals/calendar-resources'; + $this->roomDbTable = 'calendar_rooms_cache'; + $this->roomPrincipalUri = 'principals/calendar-rooms'; + + // run once an hour + $this->setInterval(60 * 60); + } + + /** + * @param $argument + */ + public function run($argument) { + $this->runResources(); + $this->runRooms(); + } + + /** + * run timed job for resources + */ + private function runResources() { + $resourceBackends = $this->resourceManager->getBackends(); + $cachedResources = $this->getCached($this->resourceDbTable); + $cachedResourceIds = $this->getCachedResourceIds($cachedResources); + + $remoteResourceIds = []; + foreach($resourceBackends as $resourceBackend) { + try { + $remoteResourceIds[$resourceBackend->getBackendIdentifier()] = + $resourceBackend->listAllResources(); + } catch(BackendTemporarilyUnavailableException $ex) { + // If the backend is temporarily unavailable + // ignore this backend in this execution + unset($cachedResourceIds[$resourceBackend->getBackendIdentifier()]); + } + } + + $sortedResources = $this->sortByNewDeletedExisting($cachedResourceIds, $remoteResourceIds); + + foreach($sortedResources['new'] as $backendId => $newResources) { + foreach ($newResources as $newResource) { + $resource = $this->resourceManager->getBackend($backendId) + ->getResource($newResource); + $this->addToCache($this->resourceDbTable, $resource); + } + } + foreach($sortedResources['deleted'] as $backendId => $deletedResources) { + foreach ($deletedResources as $deletedResource) { + $this->deleteFromCache($this->resourceDbTable, + $this->resourcePrincipalUri, $backendId, $deletedResource); + } + } + foreach($sortedResources['edited'] as $backendId => $editedResources) { + foreach ($editedResources as $editedResource) { + $resource = $this->resourceManager->getBackend($backendId) + ->getResource($editedResource); + $this->updateCache($this->resourceDbTable, $resource); + } + } + } + + /** + * run timed job for rooms + */ + private function runRooms() { + $roomBackends = $this->roomManager->getBackends(); + $cachedRooms = $this->getCached($this->roomDbTable); + $cachedRoomIds = $this->getCachedRoomIds($cachedRooms); + + $remoteRoomIds = []; + foreach($roomBackends as $roomBackend) { + try { + $remoteRoomIds[$roomBackend->getBackendIdentifier()] = + $roomBackend->listAllRooms(); + } catch(BackendTemporarilyUnavailableException $ex) { + // If the backend is temporarily unavailable + // ignore this backend in this execution + unset($cachedRoomIds[$roomBackend->getBackendIdentifier()]); + } + } + + $sortedRooms = $this->sortByNewDeletedExisting($cachedRoomIds, $remoteRoomIds); + + foreach($sortedRooms['new'] as $backendId => $newRooms) { + foreach ($newRooms as $newRoom) { + $resource = $this->roomManager->getBackend($backendId) + ->getRoom($newRoom); + $this->addToCache($this->roomDbTable, $resource); + } + } + foreach($sortedRooms['deleted'] as $backendId => $deletedRooms) { + foreach ($deletedRooms as $deletedRoom) { + $this->deleteFromCache($this->roomDbTable, + $this->roomPrincipalUri, $backendId, $deletedRoom); + } + } + foreach($sortedRooms['edited'] as $backendId => $editedRooms) { + foreach ($editedRooms as $editedRoom) { + $resource = $this->roomManager->getBackend($backendId) + ->getRoom($editedRoom); + $this->updateCache($this->roomDbTable, $resource); + } + } + } + + /** + * get cached db rows for resources / rooms + * @param string $tableName + * @return array + */ + private function getCached($tableName):array { + $query = $this->db->getQueryBuilder(); + $query->select('*')->from($tableName); + + $rows = []; + $stmt = $query->execute(); + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { + $rows[] = $row; + } + + return $rows; + } + + /** + * @param array $cachedResources + * @return array + */ + private function getCachedResourceIds(array $cachedResources):array { + $cachedResourceIds = []; + foreach ($cachedResources as $cachedResource) { + if (!isset($cachedResourceIds[$cachedResource['backend_id']])) { + $cachedResourceIds[$cachedResource['backend_id']] = []; + } + + $cachedResourceIds[$cachedResource['backend_id']][] = + $cachedResource['resource_id']; + } + + return $cachedResourceIds; + } + + /** + * @param array $cachedRooms + * @return array + */ + private function getCachedRoomIds(array $cachedRooms):array { + $cachedRoomIds = []; + foreach ($cachedRooms as $cachedRoom) { + if (!isset($cachedRoomIds[$cachedRoom['backend_id']])) { + $cachedRoomIds[$cachedRoom['backend_id']] = []; + } + + $cachedRoomIds[$cachedRoom['backend_id']][] = + $cachedRoom['resource_id']; + } + + return $cachedRoomIds; + } + + /** + * sort list of ids by whether they appear only in the backend / + * only in the cache / in both + * + * @param array $cached + * @param array $remote + * @return array + */ + private function sortByNewDeletedExisting(array $cached, array $remote):array { + $sorted = [ + 'new' => [], + 'deleted' => [], + 'edited' => [], + ]; + + $backendIds = array_merge(array_keys($cached), array_keys($remote)); + foreach($backendIds as $backendId) { + if (!isset($cached[$backendId])) { + $sorted['new'][$backendId] = $remote[$backendId]; + } elseif (!isset($remote[$backendId])) { + $sorted['deleted'][$backendId] = $cached[$backendId]; + } else { + $sorted['new'][$backendId] = array_diff($remote[$backendId], $cached[$backendId]); + $sorted['deleted'][$backendId] = array_diff($cached[$backendId], $remote[$backendId]); + $sorted['edited'][$backendId] = array_intersect($remote[$backendId], $cached[$backendId]); + } + } + + return $sorted; + } + + /** + * add entry to cache that exists remotely but not yet in cache + * + * @param string $table + * @param IResource|IRoom $remote + */ + private function addToCache($table, $remote) { + $query = $this->db->getQueryBuilder(); + $query->insert($table) + ->values([ + 'backend_id' => $query->createNamedParameter($remote->getBackend()->getBackendIdentifier()), + 'resource_id' => $query->createNamedParameter($remote->getId()), + 'email' => $query->createNamedParameter($remote->getEMail()), + 'displayname' => $query->createNamedParameter($remote->getDisplayName()), + 'group_restrictions' => $query->createNamedParameter( + $this->serializeGroupRestrictions( + $remote->getGroupRestrictions() + )) + ]) + ->execute(); + } + + /** + * delete entry from cache that does not exist anymore remotely + * + * @param string $table + * @param string $principalUri + * @param string $backendId + * @param string $resourceId + */ + private function deleteFromCache($table, $principalUri, $backendId, $resourceId) { + $query = $this->db->getQueryBuilder(); + $query->delete($table) + ->where($query->expr()->eq('backend_id', $query->createNamedParameter($backendId))) + ->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($resourceId))) + ->execute(); + + $calendar = $this->calDavBackend->getCalendarByUri($principalUri, implode('-', [$backendId, $resourceId])); + if ($calendar !== null) { + $this->calDavBackend->deleteCalendar($calendar['id']); + } + } + + /** + * update an existing entry in cache + * + * @param string $table + * @param IResource|IRoom $remote + */ + private function updateCache($table, $remote) { + $query = $this->db->getQueryBuilder(); + $query->update($table) + ->set('email', $query->createNamedParameter($remote->getEMail())) + ->set('displayname', $query->createNamedParameter($remote->getDisplayName())) + ->set('group_restrictions', $query->createNamedParameter( + $this->serializeGroupRestrictions( + $remote->getGroupRestrictions() + ))) + ->where($query->expr()->eq('backend_id', $query->createNamedParameter($remote->getBackend()->getBackendIdentifier()))) + ->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($remote->getId()))) + ->execute(); + } + + /** + * serialize array of group restrictions to store them in database + * + * @param array $groups + * @return string + */ + private function serializeGroupRestrictions(array $groups):string { + return \json_encode($groups); + } +} diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index b28c8534aaa..de46dfeb244 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -76,6 +76,9 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription const PERSONAL_CALENDAR_URI = 'personal'; const PERSONAL_CALENDAR_NAME = 'Personal'; + const RESOURCE_BOOKING_CALENDAR_URI = 'calendar'; + const RESOURCE_BOOKING_CALENDAR_NAME = 'Calendar'; + /** * We need to specify a max date, because we need to stop *somewhere* * diff --git a/apps/dav/lib/CalDAV/CalendarRoot.php b/apps/dav/lib/CalDAV/CalendarRoot.php index 2c1c8bb4ef2..f84e8a96780 100644 --- a/apps/dav/lib/CalDAV/CalendarRoot.php +++ b/apps/dav/lib/CalDAV/CalendarRoot.php @@ -27,4 +27,15 @@ class CalendarRoot extends \Sabre\CalDAV\CalendarRoot { function getChildForPrincipal(array $principal) { return new CalendarHome($this->caldavBackend, $principal); } + + function getName() { + if ($this->principalPrefix === 'principals/calendar-resources' || + $this->principalPrefix === 'principals/calendar-rooms') { + $parts = explode('/', $this->principalPrefix); + + return $parts[1]; + } + + return parent::getName(); + } }
\ No newline at end of file diff --git a/apps/dav/lib/CalDAV/Plugin.php b/apps/dav/lib/CalDAV/Plugin.php index 4aa9762899f..f37d9c571a0 100644 --- a/apps/dav/lib/CalDAV/Plugin.php +++ b/apps/dav/lib/CalDAV/Plugin.php @@ -25,15 +25,27 @@ namespace OCA\DAV\CalDAV; class Plugin extends \Sabre\CalDAV\Plugin { + const SYSTEM_CALENDAR_ROOT = 'system-calendars'; + /** * @inheritdoc */ - function getCalendarHomeForPrincipal($principalUrl) { + function getCalendarHomeForPrincipal($principalUrl):string { if (strrpos($principalUrl, 'principals/users', -strlen($principalUrl)) !== false) { list(, $principalId) = \Sabre\Uri\split($principalUrl); - return self::CALENDAR_ROOT .'/' . $principalId; + return self::CALENDAR_ROOT . '/' . $principalId; + } + if (strrpos($principalUrl, 'principals/calendar-resources', -strlen($principalUrl)) !== false) { + list(, $principalId) = \Sabre\Uri\split($principalUrl); + return self::SYSTEM_CALENDAR_ROOT . '/calendar-resources/' . $principalId; } + if (strrpos($principalUrl, 'principals/calendar-rooms', -strlen($principalUrl)) !== false) { + list(, $principalId) = \Sabre\Uri\split($principalUrl); + return self::SYSTEM_CALENDAR_ROOT . '/calendar-rooms/' . $principalId; + } + + throw new \LogicException('This is not supposed to happen'); } } diff --git a/apps/dav/lib/CalDAV/ResourceBooking/AbstractPrincipalBackend.php b/apps/dav/lib/CalDAV/ResourceBooking/AbstractPrincipalBackend.php new file mode 100644 index 00000000000..135bbe5827e --- /dev/null +++ b/apps/dav/lib/CalDAV/ResourceBooking/AbstractPrincipalBackend.php @@ -0,0 +1,361 @@ +<?php +/** + * @copyright 2018, Georg Ehrke <oc.list@georgehrke.com> + * + * @author Georg Ehrke <oc.list@georgehrke.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\DAV\CalDAV\ResourceBooking; + +use OCP\IDBConnection; +use OCP\IGroupManager; +use OCP\ILogger; +use OCP\IUserSession; +use Sabre\DAVACL\PrincipalBackend\BackendInterface; +use Sabre\DAV\Exception; +use \Sabre\DAV\PropPatch; + +abstract class AbstractPrincipalBackend implements BackendInterface { + + /** @var IDBConnection */ + private $db; + + /** @var IUserSession */ + private $userSession; + + /** @var IGroupManager */ + private $groupManager; + + /** @var ILogger */ + private $logger; + + /** @var string */ + private $principalPrefix; + + /** @var string */ + private $dbTableName; + + /** + * @param IDBConnection $dbConnection + * @param IUserSession $userSession + * @param IGroupManager $groupManager + * @param ILogger $logger + * @param string $principalPrefix + * @param string $dbPrefix + */ + public function __construct(IDBConnection $dbConnection, + IUserSession $userSession, + IGroupManager $groupManager, + ILogger $logger, + $principalPrefix, $dbPrefix) { + $this->db = $dbConnection; + $this->userSession = $userSession; + $this->groupManager = $groupManager; + $this->logger = $logger; + $this->principalPrefix = $principalPrefix; + $this->dbTableName = 'calendar_' . $dbPrefix . '_cache'; + } + + /** + * Returns a list of principals based on a prefix. + * + * This prefix will often contain something like 'principals'. You are only + * expected to return principals that are in this base path. + * + * You are expected to return at least a 'uri' for every user, you can + * return any additional properties if you wish so. Common properties are: + * {DAV:}displayname + * + * @param string $prefixPath + * @return string[] + */ + public function getPrincipalsByPrefix($prefixPath) { + $principals = []; + + if ($prefixPath === $this->principalPrefix) { + $query = $this->db->getQueryBuilder(); + $query->select(['id', 'backend_id', 'resource_id', 'email', 'displayname']) + ->from($this->dbTableName); + $stmt = $query->execute(); + + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { + $principals[] = $this->rowToPrincipal($row); + } + + $stmt->closeCursor(); + } + + return $principals; + } + + /** + * Returns a specific principal, specified by it's path. + * The returned structure should be the exact same as from + * getPrincipalsByPrefix. + * + * @param string $path + * @return array + */ + public function getPrincipalByPath($path) { + if (strpos($path, $this->principalPrefix) !== 0) { + return null; + } + list(, $name) = \Sabre\Uri\split($path); + + list($backendId, $resourceId) = explode('-', $name, 2); + + $query = $this->db->getQueryBuilder(); + $query->select(['id', 'backend_id', 'resource_id', 'email', 'displayname']) + ->from($this->dbTableName) + ->where($query->expr()->eq('backend_id', $query->createNamedParameter($backendId))) + ->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($resourceId))); + $stmt = $query->execute(); + $row = $stmt->fetch(\PDO::FETCH_ASSOC); + + if(!$row) { + return null; + } + + return $this->rowToPrincipal($row); + } + + /** + * Returns the list of members for a group-principal + * + * @param string $principal + * @return string[] + */ + public function getGroupMemberSet($principal) { + return []; + } + + /** + * Returns the list of groups a principal is a member of + * + * @param string $principal + * @return array + */ + public function getGroupMembership($principal) { + return []; + } + + /** + * Updates the list of group members for a group principal. + * + * The principals should be passed as a list of uri's. + * + * @param string $principal + * @param string[] $members + * @throws Exception + */ + public function setGroupMemberSet($principal, array $members) { + throw new Exception('Setting members of the group is not supported yet'); + } + + /** + * @param string $path + * @param PropPatch $propPatch + * @return int + */ + function updatePrincipal($path, PropPatch $propPatch) { + return 0; + } + + /** + * @param string $prefixPath + * @param array $searchProperties + * @param string $test + * @return array + */ + function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { + $results = []; + if (\count($searchProperties) === 0) { + return []; + } + if ($prefixPath !== $this->principalPrefix) { + return []; + } + + $user = $this->userSession->getUser(); + if (!$user) { + return []; + } + $usersGroups = $this->groupManager->getUserGroupIds($user); + + foreach ($searchProperties as $prop => $value) { + switch ($prop) { + case '{http://sabredav.org/ns}email-address': + $query = $this->db->getQueryBuilder(); + $query->select(['id', 'backend_id', 'resource_id', 'email', 'displayname', 'group_restrictions']) + ->from($this->dbTableName) + ->where($query->expr()->iLike('email', $query->createNamedParameter('%' . $this->db->escapeLikeParameter($value) . '%'))); + + $stmt = $query->execute(); + $principals = []; + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { + if (!$this->isAllowedToAccessResource($row, $usersGroups)) { + continue; + } + $principals[] = $this->rowToPrincipal($row)['uri']; + } + $results[] = $principals; + + $stmt->closeCursor(); + break; + + case '{DAV:}displayname': + $query = $this->db->getQueryBuilder(); + $query->select(['id', 'backend_id', 'resource_id', 'email', 'displayname', 'group_restrictions']) + ->from($this->dbTableName) + ->where($query->expr()->iLike('displayname', $query->createNamedParameter('%' . $this->db->escapeLikeParameter($value) . '%'))); + + $stmt = $query->execute(); + $principals = []; + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { + if (!$this->isAllowedToAccessResource($row, $usersGroups)) { + continue; + } + $principals[] = $this->rowToPrincipal($row)['uri']; + } + $results[] = $principals; + + $stmt->closeCursor(); + break; + + default: + $results[] = []; + break; + } + } + + // results is an array of arrays, so this is not the first search result + // but the results of the first searchProperty + if (count($results) === 1) { + return $results[0]; + } + + switch ($test) { + case 'anyof': + return array_values(array_unique(array_merge(...$results))); + + case 'allof': + default: + return array_values(array_intersect(...$results)); + } + } + + /** + * @param string $uri + * @param string $principalPrefix + * @return null|string + */ + function findByUri($uri, $principalPrefix) { + $user = $this->userSession->getUser(); + if (!$user) { + return null; + } + $usersGroups = $this->groupManager->getUserGroupIds($user); + + if (strpos($uri, 'mailto:') === 0) { + $email = substr($uri, 7); + $query = $this->db->getQueryBuilder(); + $query->select(['id', 'backend_id', 'resource_id', 'email', 'displayname', 'group_restrictions']) + ->from($this->dbTableName) + ->where($query->expr()->eq('email', $query->createNamedParameter($email))); + + $stmt = $query->execute(); + $row = $stmt->fetch(\PDO::FETCH_ASSOC); + + if(!$row) { + return null; + } + if (!$this->isAllowedToAccessResource($row, $usersGroups)) { + return null; + } + + return $this->rowToPrincipal($row)['uri']; + } + + if (strpos($uri, 'principal:') === 0) { + $path = substr($uri, 10); + if (strpos($path, $this->principalPrefix) !== 0) { + return null; + } + + list(, $name) = \Sabre\Uri\split($path); + list($backendId, $resourceId) = explode('-', $name, 2); + + $query = $this->db->getQueryBuilder(); + $query->select(['id', 'backend_id', 'resource_id', 'email', 'displayname', 'group_restrictions']) + ->from($this->dbTableName) + ->where($query->expr()->eq('backend_id', $query->createNamedParameter($backendId))) + ->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($resourceId))); + $stmt = $query->execute(); + $row = $stmt->fetch(\PDO::FETCH_ASSOC); + + if(!$row) { + return null; + } + if (!$this->isAllowedToAccessResource($row, $usersGroups)) { + return null; + } + + return $this->rowToPrincipal($row)['uri']; + } + + return null; + } + + /** + * convert database row to principal + */ + private function rowToPrincipal($row) { + return [ + 'uri' => $this->principalPrefix . '/' . $row['backend_id'] . '-' . $row['resource_id'], + '{DAV:}displayname' => $row['displayname'], + '{http://sabredav.org/ns}email-address' => $row['email'] + ]; + } + + /** + * @param $row + * @param $userGroups + * @return bool + */ + private function isAllowedToAccessResource($row, $userGroups) { + if (!isset($row['group_restrictions']) || + $row['group_restrictions'] === null || + $row['group_restrictions'] === '') { + return true; + } + + // group restrictions contains something, but not parsable, deny access and log warning + $json = json_decode($row['group_restrictions']); + if (!\is_array($json)) { + $this->logger->info('group_restrictions field could not be parsed for ' . $this->dbTableName . '::' . $row['id'] . ', denying access to resource'); + return false; + } + + // empty array => no group restrictions + if (empty($json)) { + return true; + } + + return !empty(array_intersect($json, $userGroups)); + } +} diff --git a/apps/dav/lib/CalDAV/ResourceBooking/ResourcePrincipalBackend.php b/apps/dav/lib/CalDAV/ResourceBooking/ResourcePrincipalBackend.php new file mode 100644 index 00000000000..a1030376c11 --- /dev/null +++ b/apps/dav/lib/CalDAV/ResourceBooking/ResourcePrincipalBackend.php @@ -0,0 +1,45 @@ +<?php +/** + * @copyright 2018, Georg Ehrke <oc.list@georgehrke.com> + * + * @author Georg Ehrke <oc.list@georgehrke.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\DAV\CalDAV\ResourceBooking; + +use OCP\IDBConnection; +use OCP\IGroupManager; +use OCP\ILogger; +use OCP\IUserSession; + +class ResourcePrincipalBackend extends AbstractPrincipalBackend { + + /** + * @param IDBConnection $dbConnection + * @param IUserSession $userSession + * @param IGroupManager $groupManager + * @param ILogger $logger + */ + public function __construct(IDBConnection $dbConnection, + IUserSession $userSession, + IGroupManager $groupManager, + ILogger $logger) { + parent::__construct($dbConnection, $userSession, $groupManager, $logger, + 'principals/calendar-resources', 'resources'); + } +} diff --git a/apps/dav/lib/CalDAV/ResourceBooking/RoomPrincipalBackend.php b/apps/dav/lib/CalDAV/ResourceBooking/RoomPrincipalBackend.php new file mode 100644 index 00000000000..1d22299515f --- /dev/null +++ b/apps/dav/lib/CalDAV/ResourceBooking/RoomPrincipalBackend.php @@ -0,0 +1,45 @@ +<?php +/** + * @copyright 2018, Georg Ehrke <oc.list@georgehrke.com> + * + * @author Georg Ehrke <oc.list@georgehrke.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\DAV\CalDAV\ResourceBooking; + +use OCP\IDBConnection; +use OCP\IGroupManager; +use OCP\ILogger; +use OCP\IUserSession; + +class RoomPrincipalBackend extends AbstractPrincipalBackend { + + /** + * @param IDBConnection $dbConnection + * @param IUserSession $userSession + * @param IGroupManager $groupManager + * @param ILogger $logger + */ + public function __construct(IDBConnection $dbConnection, + IUserSession $userSession, + IGroupManager $groupManager, + ILogger $logger) { + parent::__construct($dbConnection, $userSession, $groupManager, $logger, + 'principals/calendar-rooms', 'rooms'); + } +} diff --git a/apps/dav/lib/CalDAV/Schedule/Plugin.php b/apps/dav/lib/CalDAV/Schedule/Plugin.php index faf495a4de6..b3f7232c2fe 100644 --- a/apps/dav/lib/CalDAV/Schedule/Plugin.php +++ b/apps/dav/lib/CalDAV/Schedule/Plugin.php @@ -80,20 +80,32 @@ class Plugin extends \Sabre\CalDAV\Schedule\Plugin { $principalUrl = $node->getPrincipalUrl(); $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl); - if (!$calendarHomePath) { return null; } + if (strpos($principalUrl, 'principals/users') === 0) { + $uri = CalDavBackend::PERSONAL_CALENDAR_URI; + $displayname = CalDavBackend::PERSONAL_CALENDAR_NAME; + } elseif (strpos($principalUrl, 'principals/calendar-resources') === 0 || + strpos($principalUrl, 'principals/calendar-rooms') === 0) { + $uri = CalDavBackend::RESOURCE_BOOKING_CALENDAR_URI; + $displayname = CalDavBackend::RESOURCE_BOOKING_CALENDAR_NAME; + } else { + // How did we end up here? + // TODO - throw exception or just ignore? + return null; + } + /** @var CalendarHome $calendarHome */ $calendarHome = $this->server->tree->getNodeForPath($calendarHomePath); - if (!$calendarHome->childExists(CalDavBackend::PERSONAL_CALENDAR_URI)) { - $calendarHome->getCalDAVBackend()->createCalendar($principalUrl, CalDavBackend::PERSONAL_CALENDAR_URI, [ - '{DAV:}displayname' => CalDavBackend::PERSONAL_CALENDAR_NAME, + if (!$calendarHome->childExists($uri)) { + $calendarHome->getCalDAVBackend()->createCalendar($principalUrl, $uri, [ + '{DAV:}displayname' => $displayname, ]); } - $result = $this->server->getPropertiesForPath($calendarHomePath . '/' . CalDavBackend::PERSONAL_CALENDAR_URI, [], 1); + $result = $this->server->getPropertiesForPath($calendarHomePath . '/' . $uri, [], 1); if (empty($result)) { return null; } diff --git a/apps/dav/lib/Migration/Version1005Date20180530124431.php b/apps/dav/lib/Migration/Version1005Date20180530124431.php new file mode 100644 index 00000000000..ae9a40dc5b2 --- /dev/null +++ b/apps/dav/lib/Migration/Version1005Date20180530124431.php @@ -0,0 +1,87 @@ +<?php +/** + * @copyright 2017 Georg Ehrke <oc.list@georgehrke.com> + * + * @author Georg Ehrke <oc.list@georgehrke.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\DAV\Migration; + +use Doctrine\DBAL\Types\Type; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\SimpleMigrationStep; +use OCP\Migration\IOutput; + +/** + * Auto-generated migration step: Please modify to your needs! + */ +class Version1005Date20180530124431 extends SimpleMigrationStep { + + /** + * @param IOutput $output + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return null|ISchemaWrapper + * @since 13.0.0 + */ + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + $types = ['resources', 'rooms']; + foreach($types as $type) { + if (!$schema->hasTable('calendar_' . $type . '_cache')) { + $table = $schema->createTable('calendar_' . $type . '_cache'); + + $table->addColumn('id', Type::BIGINT, [ + 'autoincrement' => true, + 'notnull' => true, + 'length' => 11, + 'unsigned' => true, + ]); + $table->addColumn('backend_id', Type::STRING, [ + 'notnull' => false, + 'length' => 64, + ]); + $table->addColumn('resource_id', Type::STRING, [ + 'notnull' => false, + 'length' => 64, + ]); + $table->addColumn('email', Type::STRING, [ + 'notnull' => false, + 'length' => 255, + ]); + $table->addColumn('displayname', Type::STRING, [ + 'notnull' => false, + 'length' => 255, + ]); + $table->addColumn('group_restrictions', Type::STRING, [ + 'notnull' => false, + 'length' => 4000, + ]); + + $table->setPrimaryKey(['id'], 'calendar_' . $type . '_cache_id_idx'); + $table->addIndex(['backend_id', 'resource_id'], 'calendar_' . $type . '_cache_backendresource_idx'); + $table->addIndex(['email'], 'calendar_' . $type . '_cache_email_idx'); + $table->addIndex(['displayname'], 'calendar_' . $type . '_cache_displayname_idx'); + } + } + + return $schema; + } +} diff --git a/apps/dav/lib/RootCollection.php b/apps/dav/lib/RootCollection.php index b9f381b4b92..9a3261c388c 100644 --- a/apps/dav/lib/RootCollection.php +++ b/apps/dav/lib/RootCollection.php @@ -27,6 +27,8 @@ namespace OCA\DAV; use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CalDAV\CalendarRoot; use OCA\DAV\CalDAV\PublicCalendarRoot; +use OCA\DAV\CalDAV\ResourceBooking\ResourcePrincipalBackend; +use OCA\DAV\CalDAV\ResourceBooking\RoomPrincipalBackend; use OCA\DAV\CardDAV\AddressBookRoot; use OCA\DAV\CardDAV\CardDavBackend; use OCA\DAV\Connector\Sabre\Principal; @@ -43,6 +45,7 @@ class RootCollection extends SimpleCollection { $random = \OC::$server->getSecureRandom(); $logger = \OC::$server->getLogger(); $userManager = \OC::$server->getUserManager(); + $userSession = \OC::$server->getUserSession(); $groupManager = \OC::$server->getGroupManager(); $shareManager = \OC::$server->getShareManager(); $db = \OC::$server->getDatabaseConnection(); @@ -55,6 +58,8 @@ class RootCollection extends SimpleCollection { $config ); $groupPrincipalBackend = new GroupPrincipalBackend($groupManager); + $calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger); + $calendarRoomPrincipalBackend = new RoomPrincipalBackend($db, $userSession, $groupManager, $logger); // as soon as debug mode is enabled we allow listing of principals $disableListing = !$config->getSystemValue('debug', false); @@ -65,11 +70,25 @@ class RootCollection extends SimpleCollection { $groupPrincipals->disableListing = $disableListing; $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); $systemPrincipals->disableListing = $disableListing; + $calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources'); + $calendarResourcePrincipals->disableListing = $disableListing; + $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms'); + $calendarRoomPrincipals->disableListing = $disableListing; + + $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); $filesCollection->disableListing = $disableListing; $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); - $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); - $calendarRoot->disableListing = $disableListing; + $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); + $userCalendarRoot->disableListing = $disableListing; + + $resourceCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); + $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources'); + $resourceCalendarRoot->disableListing = $disableListing; + $roomCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); + $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $roomCalendarCaldavBackend, 'principals/calendar-rooms'); + $roomCalendarRoot->disableListing = $disableListing; + $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config); $publicCalendarRoot->disableListing = $disableListing; @@ -111,9 +130,15 @@ class RootCollection extends SimpleCollection { new SimpleCollection('principals', [ $userPrincipals, $groupPrincipals, - $systemPrincipals]), + $systemPrincipals, + $calendarResourcePrincipals, + $calendarRoomPrincipals]), $filesCollection, - $calendarRoot, + $userCalendarRoot, + new SimpleCollection('system-calendars', [ + $resourceCalendarRoot, + $roomCalendarRoot, + ]), $publicCalendarRoot, new SimpleCollection('addressbooks', [ $usersAddressBookRoot, diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php index 25a5b95f372..fc8bc91c80a 100644 --- a/apps/dav/lib/Server.php +++ b/apps/dav/lib/Server.php @@ -133,13 +133,15 @@ class Server { // acl $acl = new DavAclPlugin(); $acl->principalCollectionSet = [ - 'principals/users', 'principals/groups' + 'principals/users', 'principals/groups', + 'principals/calendar-resources', + 'principals/calendar-rooms', ]; $acl->defaultUsernamePath = 'principals/users'; $this->server->addPlugin($acl); // calendar plugins - if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'principals'])) { + if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) { $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); diff --git a/apps/dav/tests/unit/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJobTest.php b/apps/dav/tests/unit/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJobTest.php new file mode 100644 index 00000000000..56f768ceda0 --- /dev/null +++ b/apps/dav/tests/unit/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJobTest.php @@ -0,0 +1,285 @@ +<?php +/** + * @copyright Copyright (c) 2018, Georg Ehrke + * + * @author Georg Ehrke <oc.list@georgehrke.com> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCA\DAV\Tests\unit\BackgroundJob; + +use OCA\DAV\BackgroundJob\UpdateCalendarResourcesRoomsBackgroundJob; + +use OCA\DAV\CalDAV\CalDavBackend; +use OCP\Calendar\BackendTemporarilyUnavailableException; +use OCP\Calendar\Resource\IBackend; +use OCP\Calendar\Resource\IManager as IResourceManager; +use OCP\Calendar\Resource\IResource; +use OCP\Calendar\Room\IManager as IRoomManager; +use Test\TestCase; + +class UpdateCalendarResourcesRoomsBackgroundJobTest extends TestCase { + + /** @var UpdateCalendarResourcesRoomsBackgroundJob */ + private $backgroundJob; + + /** @var IResourceManager | \PHPUnit_Framework_MockObject_MockObject */ + private $resourceManager; + + /** @var IRoomManager | \PHPUnit_Framework_MockObject_MockObject */ + private $roomManager; + + /** @var CalDavBackend | \PHPUnit_Framework_MockObject_MockObject */ + private $calDavBackend; + + protected function setUp() { + parent::setUp(); + + $this->resourceManager = $this->createMock(IResourceManager::class); + $this->roomManager = $this->createMock(IRoomManager::class); + $this->calDavBackend = $this->createMock(CalDavBackend::class); + + $this->backgroundJob = new UpdateCalendarResourcesRoomsBackgroundJob( + $this->resourceManager, $this->roomManager, self::$realDatabase, + $this->calDavBackend); + } + + protected function tearDown() { + $query = self::$realDatabase->getQueryBuilder(); + $query->delete('calendar_resources_cache')->execute(); + $query->delete('calendar_rooms_cache')->execute(); + } + + /** + * Data in Cache: + * resources: + * [backend1, res1, Beamer1, {}] + * [backend1, res2, TV1, {}] + * [backend2, res3, Beamer2, {}] + * [backend2, res4, TV2, {}] + * [backend3, res5, Beamer3, {}] + * [backend3, res6, Pointer, {foo, bar}] + * + * Data in Backend: + * backend1 gone + * backend2 throws BackendTemporarilyUnavailableException + * [backend3, res6, Pointer123, {foo, biz}] + * [backend3, res7, Resource4, {biz}] + * [backend4, res8, Beamer, {}] + * [backend4, res9, Beamer2, {}] + * + * Expected after run: + * [backend2, res3, Beamer2, {}] + * [backend2, res4, TV2, {}] + * [backend3, res6, Pointer123, {foo, biz}] + * [backend3, res7, Resource4, {biz}] + * [backend4, res8, Beamer, {}] + * [backend4, res9, Beamer2, {}] + */ + + public function testRun() { + $this->createTestResourcesInCache(); + + $backend2 = $this->createMock(IBackend::class); + $backend3 = $this->createMock(IBackend::class); + $backend4 = $this->createMock(IBackend::class); + + $res6 = $this->createMock(IResource::class); + $res7 = $this->createMock(IResource::class); + $res8 = $this->createMock(IResource::class); + $res9 = $this->createMock(IResource::class); + + $backend2->method('getBackendIdentifier') + ->will($this->returnValue('backend2')); + $backend2->method('listAllResources') + ->will($this->throwException(new BackendTemporarilyUnavailableException())); + $backend2->method('getResource') + ->will($this->throwException(new BackendTemporarilyUnavailableException())); + $backend2->method('getAllResources') + ->will($this->throwException(new BackendTemporarilyUnavailableException())); + $backend3->method('getBackendIdentifier') + ->will($this->returnValue('backend3')); + $backend3->method('listAllResources') + ->will($this->returnValue(['res6', 'res7'])); + $backend3->method('getResource') + ->will($this->returnValueMap([ + ['res6', $res6], + ['res7', $res7], + ])); + $backend4->method('getBackendIdentifier') + ->will($this->returnValue('backend4')); + $backend4->method('listAllResources') + ->will($this->returnValue(['res8', 'res9'])); + $backend4->method('getResource') + ->will($this->returnValueMap([ + ['res8', $res8], + ['res9', $res9], + ])); + + $res6->method('getId')->will($this->returnValue('res6')); + $res6->method('getDisplayName')->will($this->returnValue('Pointer123')); + $res6->method('getGroupRestrictions')->will($this->returnValue(['foo', 'biz'])); + $res6->method('getEMail')->will($this->returnValue('res6@foo.bar')); + $res6->method('getBackend')->will($this->returnValue($backend3)); + + $res7->method('getId')->will($this->returnValue('res7')); + $res7->method('getDisplayName')->will($this->returnValue('Resource4')); + $res7->method('getGroupRestrictions')->will($this->returnValue(['biz'])); + $res7->method('getEMail')->will($this->returnValue('res7@foo.bar')); + $res7->method('getBackend')->will($this->returnValue($backend3)); + + $res8->method('getId')->will($this->returnValue('res8')); + $res8->method('getDisplayName')->will($this->returnValue('Beamer')); + $res8->method('getGroupRestrictions')->will($this->returnValue([])); + $res8->method('getEMail')->will($this->returnValue('res8@foo.bar')); + $res8->method('getBackend')->will($this->returnValue($backend4)); + + $res9->method('getId')->will($this->returnValue('res9')); + $res9->method('getDisplayName')->will($this->returnValue('Beamer2')); + $res9->method('getGroupRestrictions')->will($this->returnValue([])); + $res9->method('getEMail')->will($this->returnValue('res9@foo.bar')); + $res9->method('getBackend')->will($this->returnValue($backend4)); + + $this->resourceManager + ->method('getBackends') + ->will($this->returnValue([ + $backend2, $backend3, $backend4 + ])); + $this->resourceManager + ->method('getBackend') + ->will($this->returnValueMap([ + ['backend2', $backend2], + ['backend3', $backend3], + ['backend4', $backend4], + ])); + + $this->backgroundJob->run([]); + + $query = self::$realDatabase->getQueryBuilder(); + $query->select('*')->from('calendar_resources_cache'); + + $rows = []; + $stmt = $query->execute(); + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { + unset($row['id']); + $rows[] = $row; + } + + $this->assertEquals([ + [ + 'backend_id' => 'backend2', + 'resource_id' => 'res3', + 'displayname' => 'Beamer2', + 'email' => 'res3@foo.bar', + 'group_restrictions' => '[]', + ], + [ + 'backend_id' => 'backend2', + 'resource_id' => 'res4', + 'displayname' => 'TV2', + 'email' => 'res4@foo.bar', + 'group_restrictions' => '[]', + ], + [ + 'backend_id' => 'backend3', + 'resource_id' => 'res6', + 'displayname' => 'Pointer123', + 'email' => 'res6@foo.bar', + 'group_restrictions' => '["foo","biz"]', + ], + [ + 'backend_id' => 'backend3', + 'resource_id' => 'res7', + 'displayname' => 'Resource4', + 'email' => 'res7@foo.bar', + 'group_restrictions' => '["biz"]', + ], + [ + 'backend_id' => 'backend4', + 'resource_id' => 'res8', + 'displayname' => 'Beamer', + 'email' => 'res8@foo.bar', + 'group_restrictions' => '[]', + ], + [ + 'backend_id' => 'backend4', + 'resource_id' => 'res9', + 'displayname' => 'Beamer2', + 'email' => 'res9@foo.bar', + 'group_restrictions' => '[]', + ], + ], $rows); + } + + protected function createTestResourcesInCache() { + $query = self::$realDatabase->getQueryBuilder(); + $query->insert('calendar_resources_cache') + ->values([ + 'backend_id' => $query->createNamedParameter('backend1'), + 'resource_id' => $query->createNamedParameter('res1'), + 'email' => $query->createNamedParameter('res1@foo.bar'), + 'displayname' => $query->createNamedParameter('Beamer1'), + 'group_restrictions' => $query->createNamedParameter('[]'), + ]) + ->execute(); + $query->insert('calendar_resources_cache') + ->values([ + 'backend_id' => $query->createNamedParameter('backend1'), + 'resource_id' => $query->createNamedParameter('res2'), + 'email' => $query->createNamedParameter('res2@foo.bar'), + 'displayname' => $query->createNamedParameter('TV1'), + 'group_restrictions' => $query->createNamedParameter('[]'), + ]) + ->execute(); + $query->insert('calendar_resources_cache') + ->values([ + 'backend_id' => $query->createNamedParameter('backend2'), + 'resource_id' => $query->createNamedParameter('res3'), + 'email' => $query->createNamedParameter('res3@foo.bar'), + 'displayname' => $query->createNamedParameter('Beamer2'), + 'group_restrictions' => $query->createNamedParameter('[]'), + ]) + ->execute(); + $query->insert('calendar_resources_cache') + ->values([ + 'backend_id' => $query->createNamedParameter('backend2'), + 'resource_id' => $query->createNamedParameter('res4'), + 'email' => $query->createNamedParameter('res4@foo.bar'), + 'displayname' => $query->createNamedParameter('TV2'), + 'group_restrictions' => $query->createNamedParameter('[]'), + ]) + ->execute(); + $query->insert('calendar_resources_cache') + ->values([ + 'backend_id' => $query->createNamedParameter('backend3'), + 'resource_id' => $query->createNamedParameter('res5'), + 'email' => $query->createNamedParameter('res5@foo.bar'), + 'displayname' => $query->createNamedParameter('Beamer3'), + 'group_restrictions' => $query->createNamedParameter('[]'), + ]) + ->execute(); + $query->insert('calendar_resources_cache') + ->values([ + 'backend_id' => $query->createNamedParameter('backend3'), + 'resource_id' => $query->createNamedParameter('res6'), + 'email' => $query->createNamedParameter('res6@foo.bar'), + 'displayname' => $query->createNamedParameter('Pointer'), + 'group_restrictions' => $query->createNamedParameter('["foo", "bar"]'), + ]) + ->execute(); + } +} diff --git a/apps/dav/tests/unit/CalDAV/PluginTest.php b/apps/dav/tests/unit/CalDAV/PluginTest.php index 7d283b6d1ed..47190d583f0 100644 --- a/apps/dav/tests/unit/CalDAV/PluginTest.php +++ b/apps/dav/tests/unit/CalDAV/PluginTest.php @@ -43,8 +43,12 @@ class PluginTest extends TestCase { 'calendars/MyUserName', ], [ - 'FooFoo', - null, + 'principals/calendar-resources/Resource-ABC', + 'system-calendars/calendar-resources/Resource-ABC', + ], + [ + 'principals/calendar-rooms/Room-ABC', + 'system-calendars/calendar-rooms/Room-ABC', ], ]; } @@ -59,4 +63,11 @@ class PluginTest extends TestCase { $this->assertSame($expected, $this->plugin->getCalendarHomeForPrincipal($input)); } + /** + * @expectedException \LogicException + * @expectedExceptionMessage This is not supposed to happen + */ + public function testGetCalendarHomeForUnknownPrincipal() { + $this->plugin->getCalendarHomeForPrincipal('FOO/BAR/BLUB'); + } } diff --git a/apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php b/apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php new file mode 100644 index 00000000000..4dee0220fc8 --- /dev/null +++ b/apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php @@ -0,0 +1,930 @@ +<?php +/** + * @copyright Copyright (c) 2018, Georg Ehrke + * + * @author Georg Ehrke <oc.list@georgehrke.com> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCA\DAV\Tests\unit\CalDAV\ResourceBooking; + +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IDBConnection; +use OCP\IGroupManager; +use OCP\ILogger; +use OCP\IUser; +use OCP\IUserSession; +use Sabre\DAV\PropPatch; +use Test\TestCase; + +abstract class AbstractPrincipalBackendTest extends TestCase { + + /** @var \OCA\DAV\CalDAV\ResourceBooking\ResourcePrincipalBackend|\OCA\DAV\CalDAV\ResourceBooking\RoomPrincipalBackend */ + protected $principalBackend; + + /** @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject */ + protected $dbConnection; + + /** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */ + protected $userSession; + + /** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */ + protected $groupManager; + + /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ + protected $logger; + + /** @var string */ + protected $expectedDbTable; + + /** @var string */ + protected $principalPrefix; + + public function setUp() { + parent::setUp(); + + $this->dbConnection = $this->createMock(IDBConnection::class); + $this->userSession = $this->createMock(IUserSession::class); + $this->groupManager = $this->createMock(IGroupManager::class); + $this->logger = $this->createMock(ILogger::class); + } + + public function testGetPrincipalsByPrefix() { + $queryBuilder = $this->createMock(IQueryBuilder::class); + $stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class); + $this->dbConnection->expects($this->once()) + ->method('getQueryBuilder') + ->with() + ->will($this->returnValue($queryBuilder)); + + $queryBuilder->expects($this->at(0)) + ->method('select') + ->with(['id', 'backend_id', 'resource_id', 'email', 'displayname']) + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(1)) + ->method('from') + ->with($this->expectedDbTable) + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(2)) + ->method('execute') + ->with() + ->will($this->returnValue($stmt)); + + $stmt->expects($this->at(0)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue([ + 'id' => 0, + 'backend_id' => 'db', + 'resource_id' => '123', + 'email' => 'foo@bar.com', + 'displayname' => 'Resource 123' + ])); + $stmt->expects($this->at(1)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue([ + 'id' => 1, + 'backend_id' => 'ldap', + 'resource_id' => '123', + 'email' => 'ldap@bar.com', + 'displayname' => 'Resource 123 ldap' + ])); + $stmt->expects($this->at(2)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue([ + 'id' => 2, + 'backend_id' => 'db', + 'resource_id' => '456', + 'email' => 'bli@bar.com', + 'displayname' => 'Resource 456' + ])); + $stmt->expects($this->at(3)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue(null)); + $stmt->expects($this->at(4)) + ->method('closeCursor') + ->with(); + + $actual = $this->principalBackend->getPrincipalsByPrefix($this->principalPrefix); + $this->assertEquals([ + [ + 'uri' => $this->principalPrefix . '/db-123', + '{DAV:}displayname' => 'Resource 123', + '{http://sabredav.org/ns}email-address' => 'foo@bar.com', + ], + [ + 'uri' => $this->principalPrefix . '/ldap-123', + '{DAV:}displayname' => 'Resource 123 ldap', + '{http://sabredav.org/ns}email-address' => 'ldap@bar.com', + ], + [ + 'uri' => $this->principalPrefix . '/db-456', + '{DAV:}displayname' => 'Resource 456', + '{http://sabredav.org/ns}email-address' => 'bli@bar.com', + ], + ], $actual); + + } + + public function testGetNoPrincipalsByPrefixForWrongPrincipalPrefix() { + $this->dbConnection->expects($this->never()) + ->method('getQueryBuilder'); + + $actual = $this->principalBackend->getPrincipalsByPrefix('principals/users'); + $this->assertEquals([], $actual); + } + + public function testGetPrincipalByPath() { + $queryBuilder = $this->createMock(IQueryBuilder::class); + $stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class); + $expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class); + + $this->dbConnection->expects($this->at(0)) + ->method('getQueryBuilder') + ->with() + ->will($this->returnValue($queryBuilder)); + $queryBuilder->method('expr') + ->will($this->returnValue($expr)); + $expr->method('eq') + ->will($this->returnValueMap([ + ['backend_id', 'createNamedParameter-1', null, 'WHERE_CLAUSE_1'], + ['resource_id', 'createNamedParameter-2', null, 'WHERE_CLAUSE_2'], + ])); + $queryBuilder->method('createNamedParameter') + ->will($this->returnValueMap([ + ['db', \PDO::PARAM_STR, null, 'createNamedParameter-1'], + ['123', \PDO::PARAM_STR, null, 'createNamedParameter-2'], + ])); + + $queryBuilder->expects($this->at(0)) + ->method('select') + ->with(['id', 'backend_id', 'resource_id', 'email', 'displayname']) + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(1)) + ->method('from') + ->with($this->expectedDbTable) + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(4)) + ->method('where') + ->with('WHERE_CLAUSE_1') + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(7)) + ->method('andWhere') + ->with('WHERE_CLAUSE_2') + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(8)) + ->method('execute') + ->with() + ->will($this->returnValue($stmt)); + + $stmt->expects($this->at(0)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue([ + 'id' => 0, + 'backend_id' => 'db', + 'resource_id' => '123', + 'email' => 'foo@bar.com', + 'displayname' => 'Resource 123' + ])); + + $actual = $this->principalBackend->getPrincipalByPath($this->principalPrefix . '/db-123'); + $this->assertEquals([ + 'uri' => $this->principalPrefix . '/db-123', + '{DAV:}displayname' => 'Resource 123', + '{http://sabredav.org/ns}email-address' => 'foo@bar.com', + ], $actual); + } + + public function testGetPrincipalByPathNotFound() { + $queryBuilder = $this->createMock(IQueryBuilder::class); + $stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class); + $expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class); + + $this->dbConnection->expects($this->at(0)) + ->method('getQueryBuilder') + ->with() + ->will($this->returnValue($queryBuilder)); + $queryBuilder->method('expr') + ->will($this->returnValue($expr)); + $expr->method('eq') + ->will($this->returnValueMap([ + ['backend_id', 'createNamedParameter-1', null, 'WHERE_CLAUSE_1'], + ['resource_id', 'createNamedParameter-2', null, 'WHERE_CLAUSE_2'], + ])); + $queryBuilder->method('createNamedParameter') + ->will($this->returnValueMap([ + ['db', \PDO::PARAM_STR, null, 'createNamedParameter-1'], + ['123', \PDO::PARAM_STR, null, 'createNamedParameter-2'], + ])); + + $queryBuilder->expects($this->at(0)) + ->method('select') + ->with(['id', 'backend_id', 'resource_id', 'email', 'displayname']) + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(1)) + ->method('from') + ->with($this->expectedDbTable) + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(4)) + ->method('where') + ->with('WHERE_CLAUSE_1') + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(7)) + ->method('andWhere') + ->with('WHERE_CLAUSE_2') + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(8)) + ->method('execute') + ->with() + ->will($this->returnValue($stmt)); + + $stmt->expects($this->at(0)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue(false)); + + $actual = $this->principalBackend->getPrincipalByPath($this->principalPrefix . '/db-123'); + $this->assertEquals(null, $actual); + } + + public function testGetPrincipalByPathWrongPrefix() { + $this->dbConnection->expects($this->never()) + ->method('getQueryBuilder'); + + $actual = $this->principalBackend->getPrincipalByPath('principals/users/foo-bar'); + $this->assertEquals(null, $actual); + } + + public function testGetGroupMemberSet() { + $actual = $this->principalBackend->getGroupMemberSet($this->principalPrefix . '/foo-bar'); + $this->assertEquals([], $actual); + } + + public function testGetGroupMembership() { + $actual = $this->principalBackend->getGroupMembership($this->principalPrefix . '/foo-bar'); + $this->assertEquals([], $actual); + } + + /** + * @expectedException \Sabre\DAV\Exception + * @expectedExceptionMessage Setting members of the group is not supported yet + */ + public function testSetGroupMemberSet() { + $this->principalBackend->setGroupMemberSet($this->principalPrefix . '/foo-bar', ['foo', 'bar']); + } + + public function testUpdatePrincipal() { + $propPatch = $this->createMock(PropPatch::class); + $actual = $this->principalBackend->updatePrincipal($this->principalPrefix . '/foo-bar', $propPatch); + + $this->assertEquals(0, $actual); + } + + /** + * @dataProvider dataSearchPrincipals + */ + public function testSearchPrincipals($expected, $test) { + $user = $this->createMock(IUser::class); + $this->userSession->expects($this->once()) + ->method('getUser') + ->with() + ->will($this->returnValue($user)); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->will($this->returnValue(['group1', 'group2'])); + + $queryBuilder1 = $this->createMock(IQueryBuilder::class); + $queryBuilder2 = $this->createMock(IQueryBuilder::class); + $stmt1 = $this->createMock(\Doctrine\DBAL\Driver\Statement::class); + $stmt2 = $this->createMock(\Doctrine\DBAL\Driver\Statement::class); + $expr1 = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class); + $expr2 = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class); + + $this->dbConnection->expects($this->at(0)) + ->method('getQueryBuilder') + ->with() + ->will($this->returnValue($queryBuilder1)); + $this->dbConnection->expects($this->at(1)) + ->method('escapeLikeParameter') + ->with('foo') + ->will($this->returnValue('escapedFoo')); + $this->dbConnection->expects($this->at(2)) + ->method('getQueryBuilder') + ->with() + ->will($this->returnValue($queryBuilder2)); + $this->dbConnection->expects($this->at(3)) + ->method('escapeLikeParameter') + ->with('bar') + ->will($this->returnValue('escapedBar')); + + $queryBuilder1->method('expr') + ->will($this->returnValue($expr1)); + $queryBuilder2->method('expr') + ->will($this->returnValue($expr2)); + + $expr1->method('iLike') + ->will($this->returnValueMap([ + ['email', 'createNamedParameter-1', null, 'ILIKE_CLAUSE_1'], + ])); + $expr2->method('iLike') + ->will($this->returnValueMap([ + ['displayname', 'createNamedParameter-2', null, 'ILIKE_CLAUSE_2'], + ])); + + $queryBuilder1->method('expr') + ->will($this->returnValue($expr1)); + $queryBuilder2->method('expr') + ->will($this->returnValue($expr2)); + + $queryBuilder1->method('createNamedParameter') + ->will($this->returnValueMap([ + ['%escapedFoo%', \PDO::PARAM_STR, null, 'createNamedParameter-1'], + ])); + $queryBuilder2->method('createNamedParameter') + ->will($this->returnValueMap([ + ['%escapedBar%', \PDO::PARAM_STR, null, 'createNamedParameter-2'], + ])); + + $queryBuilder1->expects($this->at(0)) + ->method('select') + ->with(['id', 'backend_id', 'resource_id', 'email', 'displayname', 'group_restrictions']) + ->will($this->returnValue($queryBuilder1)); + $queryBuilder1->expects($this->at(1)) + ->method('from') + ->with($this->expectedDbTable) + ->will($this->returnValue($queryBuilder1)); + $queryBuilder1->expects($this->at(4)) + ->method('where') + ->with('ILIKE_CLAUSE_1') + ->will($this->returnValue($queryBuilder1)); + $queryBuilder1->expects($this->at(5)) + ->method('execute') + ->with() + ->will($this->returnValue($stmt1)); + + $queryBuilder2->expects($this->at(0)) + ->method('select') + ->with(['id', 'backend_id', 'resource_id', 'email', 'displayname', 'group_restrictions']) + ->will($this->returnValue($queryBuilder2)); + $queryBuilder2->expects($this->at(1)) + ->method('from') + ->with($this->expectedDbTable) + ->will($this->returnValue($queryBuilder2)); + $queryBuilder2->expects($this->at(4)) + ->method('where') + ->with('ILIKE_CLAUSE_2') + ->will($this->returnValue($queryBuilder2)); + $queryBuilder2->expects($this->at(5)) + ->method('execute') + ->with() + ->will($this->returnValue($stmt2)); + + $stmt1->expects($this->at(0)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue([ + 'id' => 0, + 'backend_id' => 'db', + 'resource_id' => '1', + 'email' => '1', + 'displayname' => 'Resource 1', + 'group_restrictions' => null, + ])); + $stmt1->expects($this->at(1)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue([ + 'id' => 1, + 'backend_id' => 'db', + 'resource_id' => '2', + 'email' => '2', + 'displayname' => 'Resource 2', + 'group_restrictions' => '', + ])); + $stmt1->expects($this->at(2)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue([ + 'id' => 2, + 'backend_id' => 'db', + 'resource_id' => '3', + 'email' => '3', + 'displayname' => 'Resource 3', + 'group_restrictions' => '["group3"]', + ])); + $stmt1->expects($this->at(3)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue([ + 'id' => 99, + 'backend_id' => 'db', + 'resource_id' => '99', + 'email' => '99', + 'displayname' => 'Resource 99', + 'group_restrictions' => '["group1", "group2"]', + ])); + $stmt1->expects($this->at(4)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue(null)); + + $stmt2->expects($this->at(0)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue([ + 'id' => 0, + 'backend_id' => 'db', + 'resource_id' => '4', + 'email' => '4', + 'displayname' => 'Resource 4', + 'group_restrictions' => '[]' + ])); + $stmt2->expects($this->at(1)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue([ + 'id' => 1, + 'backend_id' => 'db', + 'resource_id' => '5', + 'email' => '5', + 'displayname' => 'Resource 5', + 'group_restrictions' => '["group1", "group5"]' + ])); + $stmt2->expects($this->at(2)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue([ + 'id' => 99, + 'backend_id' => 'db', + 'resource_id' => '99', + 'email' => '99', + 'displayname' => 'Resource 99', + 'group_restrictions' => '["group1", "group2"]', + ])); + $stmt2->expects($this->at(3)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue(null)); + + $actual = $this->principalBackend->searchPrincipals($this->principalPrefix, [ + '{http://sabredav.org/ns}email-address' => 'foo', + '{DAV:}displayname' => 'bar', + ], $test); + + $this->assertEquals( + str_replace('%prefix%', $this->principalPrefix, $expected), + $actual); + } + + public function dataSearchPrincipals() { + // data providers are called before we subclass + // this class, $this->principalPrefix is null + // at that point, so we need this hack + return [ + [[ + '%prefix%/db-99' + ], 'allof'], + [[ + '%prefix%/db-1', + '%prefix%/db-2', + '%prefix%/db-99', + '%prefix%/db-4', + '%prefix%/db-5', + ], 'anyof'], + ]; + } + + public function testSearchPrincipalsEmptySearchProperties() { + $this->userSession->expects($this->never()) + ->method('getUser'); + $this->groupManager->expects($this->never()) + ->method('getUserGroupIds'); + $this->dbConnection->expects($this->never()) + ->method('getQueryBuilder'); + + $this->principalBackend->searchPrincipals($this->principalPrefix, []); + } + + public function testSearchPrincipalsWrongPrincipalPrefix() { + $this->userSession->expects($this->never()) + ->method('getUser'); + $this->groupManager->expects($this->never()) + ->method('getUserGroupIds'); + $this->dbConnection->expects($this->never()) + ->method('getQueryBuilder'); + + $this->principalBackend->searchPrincipals('principals/users', [ + '{http://sabredav.org/ns}email-address' => 'foo' + ]); + } + + public function testFindByUriByEmail() { + $user = $this->createMock(IUser::class); + $this->userSession->expects($this->once()) + ->method('getUser') + ->with() + ->will($this->returnValue($user)); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->will($this->returnValue(['group1', 'group2'])); + + $queryBuilder = $this->createMock(IQueryBuilder::class); + $stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class); + $expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class); + + $this->dbConnection->expects($this->at(0)) + ->method('getQueryBuilder') + ->with() + ->will($this->returnValue($queryBuilder)); + $queryBuilder->method('expr') + ->will($this->returnValue($expr)); + $expr->method('eq') + ->will($this->returnValueMap([ + ['email', 'createNamedParameter-1', null, 'WHERE_CLAUSE_1'], + ])); + $queryBuilder->method('createNamedParameter') + ->will($this->returnValueMap([ + ['foo@bar.com', \PDO::PARAM_STR, null, 'createNamedParameter-1'], + ])); + + $queryBuilder->expects($this->at(0)) + ->method('select') + ->with(['id', 'backend_id', 'resource_id', 'email', 'displayname', 'group_restrictions']) + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(1)) + ->method('from') + ->with($this->expectedDbTable) + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(4)) + ->method('where') + ->with('WHERE_CLAUSE_1') + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(5)) + ->method('execute') + ->with() + ->will($this->returnValue($stmt)); + + $stmt->expects($this->at(0)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue([ + 'id' => 0, + 'backend_id' => 'db', + 'resource_id' => '123', + 'email' => 'foo@bar.com', + 'displayname' => 'Resource 123', + 'group_restrictions' => '["group1"]', + ])); + + $actual = $this->principalBackend->findByUri('mailto:foo@bar.com', $this->principalPrefix); + $this->assertEquals($this->principalPrefix . '/db-123', $actual); + } + + public function testFindByUriByEmailForbiddenResource() { + $user = $this->createMock(IUser::class); + $this->userSession->expects($this->once()) + ->method('getUser') + ->with() + ->will($this->returnValue($user)); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->will($this->returnValue(['group1', 'group2'])); + + $queryBuilder = $this->createMock(IQueryBuilder::class); + $stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class); + $expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class); + + $this->dbConnection->expects($this->at(0)) + ->method('getQueryBuilder') + ->with() + ->will($this->returnValue($queryBuilder)); + $queryBuilder->method('expr') + ->will($this->returnValue($expr)); + $expr->method('eq') + ->will($this->returnValueMap([ + ['email', 'createNamedParameter-1', null, 'WHERE_CLAUSE_1'], + ])); + $queryBuilder->method('createNamedParameter') + ->will($this->returnValueMap([ + ['foo@bar.com', \PDO::PARAM_STR, null, 'createNamedParameter-1'], + ])); + + $queryBuilder->expects($this->at(0)) + ->method('select') + ->with(['id', 'backend_id', 'resource_id', 'email', 'displayname', 'group_restrictions']) + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(1)) + ->method('from') + ->with($this->expectedDbTable) + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(4)) + ->method('where') + ->with('WHERE_CLAUSE_1') + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(5)) + ->method('execute') + ->with() + ->will($this->returnValue($stmt)); + + $stmt->expects($this->at(0)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue([ + 'id' => 0, + 'backend_id' => 'db', + 'resource_id' => '123', + 'email' => 'foo@bar.com', + 'displayname' => 'Resource 123', + 'group_restrictions' => '["group3"]', + ])); + + $actual = $this->principalBackend->findByUri('mailto:foo@bar.com', $this->principalPrefix); + $this->assertEquals(null, $actual); + } + + public function testFindByUriByEmailNotFound() { + $user = $this->createMock(IUser::class); + $this->userSession->expects($this->once()) + ->method('getUser') + ->with() + ->will($this->returnValue($user)); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->will($this->returnValue(['group1', 'group2'])); + + $queryBuilder = $this->createMock(IQueryBuilder::class); + $stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class); + $expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class); + + $this->dbConnection->expects($this->at(0)) + ->method('getQueryBuilder') + ->with() + ->will($this->returnValue($queryBuilder)); + $queryBuilder->method('expr') + ->will($this->returnValue($expr)); + $expr->method('eq') + ->will($this->returnValueMap([ + ['email', 'createNamedParameter-1', null, 'WHERE_CLAUSE_1'], + ])); + $queryBuilder->method('createNamedParameter') + ->will($this->returnValueMap([ + ['foo@bar.com', \PDO::PARAM_STR, null, 'createNamedParameter-1'], + ])); + + $queryBuilder->expects($this->at(0)) + ->method('select') + ->with(['id', 'backend_id', 'resource_id', 'email', 'displayname', 'group_restrictions']) + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(1)) + ->method('from') + ->with($this->expectedDbTable) + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(4)) + ->method('where') + ->with('WHERE_CLAUSE_1') + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(5)) + ->method('execute') + ->with() + ->will($this->returnValue($stmt)); + + $stmt->expects($this->at(0)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue(null)); + + $actual = $this->principalBackend->findByUri('mailto:foo@bar.com', $this->principalPrefix); + $this->assertEquals(null, $actual); + } + + public function testFindByUriByPrincipal() { + $user = $this->createMock(IUser::class); + $this->userSession->expects($this->once()) + ->method('getUser') + ->with() + ->will($this->returnValue($user)); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->will($this->returnValue(['group1', 'group2'])); + + $queryBuilder = $this->createMock(IQueryBuilder::class); + $stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class); + $expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class); + + $this->dbConnection->expects($this->at(0)) + ->method('getQueryBuilder') + ->with() + ->will($this->returnValue($queryBuilder)); + $queryBuilder->method('expr') + ->will($this->returnValue($expr)); + $expr->method('eq') + ->will($this->returnValueMap([ + ['email', 'createNamedParameter-1', null, 'WHERE_CLAUSE_1'], + ])); + $queryBuilder->method('createNamedParameter') + ->will($this->returnValueMap([ + ['foo@bar.com', \PDO::PARAM_STR, null, 'createNamedParameter-1'], + ])); + + $queryBuilder->expects($this->at(0)) + ->method('select') + ->with(['id', 'backend_id', 'resource_id', 'email', 'displayname', 'group_restrictions']) + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(1)) + ->method('from') + ->with($this->expectedDbTable) + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(4)) + ->method('where') + ->with('WHERE_CLAUSE_1') + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(5)) + ->method('execute') + ->with() + ->will($this->returnValue($stmt)); + + $stmt->expects($this->at(0)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue([ + 'id' => 0, + 'backend_id' => 'db', + 'resource_id' => '123', + 'email' => 'foo@bar.com', + 'displayname' => 'Resource 123', + 'group_restrictions' => '["group1"]', + ])); + + $actual = $this->principalBackend->findByUri('mailto:foo@bar.com', $this->principalPrefix); + $this->assertEquals($this->principalPrefix . '/db-123', $actual); + } + + public function testFindByUriByPrincipalForbiddenResource() { + $user = $this->createMock(IUser::class); + $this->userSession->expects($this->once()) + ->method('getUser') + ->with() + ->will($this->returnValue($user)); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->will($this->returnValue(['group1', 'group2'])); + + $queryBuilder = $this->createMock(IQueryBuilder::class); + $stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class); + $expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class); + + $this->dbConnection->expects($this->at(0)) + ->method('getQueryBuilder') + ->with() + ->will($this->returnValue($queryBuilder)); + $queryBuilder->method('expr') + ->will($this->returnValue($expr)); + $expr->method('eq') + ->will($this->returnValueMap([ + ['backend_id', 'createNamedParameter-1', null, 'WHERE_CLAUSE_1'], + ['resource_id', 'createNamedParameter-2', null, 'WHERE_CLAUSE_2'], + ])); + $queryBuilder->method('createNamedParameter') + ->will($this->returnValueMap([ + ['db', \PDO::PARAM_STR, null, 'createNamedParameter-1'], + ['123', \PDO::PARAM_STR, null, 'createNamedParameter-2'], + ])); + + $queryBuilder->expects($this->at(0)) + ->method('select') + ->with(['id', 'backend_id', 'resource_id', 'email', 'displayname', 'group_restrictions']) + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(1)) + ->method('from') + ->with($this->expectedDbTable) + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(4)) + ->method('where') + ->with('WHERE_CLAUSE_1') + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(7)) + ->method('andWhere') + ->with('WHERE_CLAUSE_2') + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(8)) + ->method('execute') + ->with() + ->will($this->returnValue($stmt)); + + $stmt->expects($this->at(0)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue([ + 'id' => 0, + 'backend_id' => 'db', + 'resource_id' => '123', + 'email' => 'foo@bar.com', + 'displayname' => 'Resource 123', + 'group_restrictions' => '["group3"]', + ])); + + $actual = $this->principalBackend->findByUri('principal:' . $this->principalPrefix . '/db-123', $this->principalPrefix); + $this->assertEquals(null, $actual); + } + + public function testFindByUriByPrincipalNotFound() { + $user = $this->createMock(IUser::class); + $this->userSession->expects($this->once()) + ->method('getUser') + ->with() + ->will($this->returnValue($user)); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->will($this->returnValue(['group1', 'group2'])); + + $queryBuilder = $this->createMock(IQueryBuilder::class); + $stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class); + $expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class); + + $this->dbConnection->expects($this->at(0)) + ->method('getQueryBuilder') + ->with() + ->will($this->returnValue($queryBuilder)); + $queryBuilder->method('expr') + ->will($this->returnValue($expr)); + $expr->method('eq') + ->will($this->returnValueMap([ + ['backend_id', 'createNamedParameter-1', null, 'WHERE_CLAUSE_1'], + ['resource_id', 'createNamedParameter-2', null, 'WHERE_CLAUSE_2'], + ])); + $queryBuilder->method('createNamedParameter') + ->will($this->returnValueMap([ + ['db', \PDO::PARAM_STR, null, 'createNamedParameter-1'], + ['123', \PDO::PARAM_STR, null, 'createNamedParameter-2'], + ])); + + $queryBuilder->expects($this->at(0)) + ->method('select') + ->with(['id', 'backend_id', 'resource_id', 'email', 'displayname', 'group_restrictions']) + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(1)) + ->method('from') + ->with($this->expectedDbTable) + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(4)) + ->method('where') + ->with('WHERE_CLAUSE_1') + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(7)) + ->method('andWhere') + ->with('WHERE_CLAUSE_2') + ->will($this->returnValue($queryBuilder)); + $queryBuilder->expects($this->at(8)) + ->method('execute') + ->with() + ->will($this->returnValue($stmt)); + + $stmt->expects($this->at(0)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->returnValue(null)); + + $actual = $this->principalBackend->findByUri('principal:' . $this->principalPrefix . '/db-123', $this->principalPrefix); + $this->assertEquals(null, $actual); + } + + public function testFindByUriByUnknownUri() { + $user = $this->createMock(IUser::class); + $this->userSession->expects($this->once()) + ->method('getUser') + ->with() + ->will($this->returnValue($user)); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->will($this->returnValue(['group1', 'group2'])); + + $actual = $this->principalBackend->findByUri('foobar:blub', $this->principalPrefix); + $this->assertEquals(null, $actual); + } + +} diff --git a/apps/dav/tests/unit/CalDAV/ResourceBooking/ResourcePrincipalBackendTest.php b/apps/dav/tests/unit/CalDAV/ResourceBooking/ResourcePrincipalBackendTest.php new file mode 100644 index 00000000000..f2c6b6f5f5e --- /dev/null +++ b/apps/dav/tests/unit/CalDAV/ResourceBooking/ResourcePrincipalBackendTest.php @@ -0,0 +1,35 @@ +<?php +/** + * @copyright Copyright (c) 2018, Georg Ehrke + * + * @author Georg Ehrke <oc.list@georgehrke.com> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCA\DAV\Tests\unit\CalDAV\ResourceBooking; + +use OCA\DAV\CalDAV\ResourceBooking\ResourcePrincipalBackend; + +Class ResourcePrincipalBackendTest extends AbstractPrincipalBackendTest { + public function setUp() { + parent::setUp(); + + $this->principalBackend = new ResourcePrincipalBackend($this->dbConnection, + $this->userSession, $this->groupManager, $this->logger); + $this->expectedDbTable = 'calendar_resources_cache'; + $this->principalPrefix = 'principals/calendar-resources'; + } +} diff --git a/apps/dav/tests/unit/CalDAV/ResourceBooking/RoomPrincipalBackendTest.php b/apps/dav/tests/unit/CalDAV/ResourceBooking/RoomPrincipalBackendTest.php new file mode 100644 index 00000000000..f45121f4548 --- /dev/null +++ b/apps/dav/tests/unit/CalDAV/ResourceBooking/RoomPrincipalBackendTest.php @@ -0,0 +1,35 @@ +<?php +/** + * @copyright Copyright (c) 2018, Georg Ehrke + * + * @author Georg Ehrke <oc.list@georgehrke.com> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCA\DAV\Tests\unit\CalDAV\ResourceBooking; + +use OCA\DAV\CalDAV\ResourceBooking\RoomPrincipalBackend; + +Class RoomPrincipalBackendTest extends AbstractPrincipalBackendTest { + public function setUp() { + parent::setUp(); + + $this->principalBackend = new RoomPrincipalBackend($this->dbConnection, + $this->userSession, $this->groupManager, $this->logger); + $this->expectedDbTable = 'calendar_rooms_cache'; + $this->principalPrefix = 'principals/calendar-rooms'; + } +} diff --git a/apps/files_trashbin/l10n/sr.js b/apps/files_trashbin/l10n/sr.js index c48ae127087..2a2e6b3a5a9 100644 --- a/apps/files_trashbin/l10n/sr.js +++ b/apps/files_trashbin/l10n/sr.js @@ -16,6 +16,7 @@ OC.L10N.register( "No entries found in this folder" : "Нема ничега у овој фасцикли", "Select all" : "Означи све", "Name" : "Назив", + "Actions" : "Радње", "Deleted" : "Обрисано" }, "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);"); diff --git a/apps/files_trashbin/l10n/sr.json b/apps/files_trashbin/l10n/sr.json index fd856ecb81c..73d531bd165 100644 --- a/apps/files_trashbin/l10n/sr.json +++ b/apps/files_trashbin/l10n/sr.json @@ -14,6 +14,7 @@ "No entries found in this folder" : "Нема ничега у овој фасцикли", "Select all" : "Означи све", "Name" : "Назив", + "Actions" : "Радње", "Deleted" : "Обрисано" },"pluralForm" :"nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);" }
\ No newline at end of file diff --git a/apps/provisioning_api/lib/Controller/AUserData.php b/apps/provisioning_api/lib/Controller/AUserData.php index 2e29cc1df12..f08fef91417 100644 --- a/apps/provisioning_api/lib/Controller/AUserData.php +++ b/apps/provisioning_api/lib/Controller/AUserData.php @@ -123,6 +123,7 @@ abstract class AUserData extends OCSController { $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value']; $data['groups'] = $gids; $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'); + $data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale'); return $data; } diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index 2e46492b842..52021ec2486 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -13,6 +13,7 @@ declare(strict_types=1); * @author Thomas Müller <thomas.mueller@tmit.eu> * @author Tom Needham <tom@owncloud.com> * @author John Molakvoæ <skjnldsv@protonmail.com> + * @author Thomas Citharel <tcit@tcit.fr> * * @license AGPL-3.0 * @@ -430,6 +431,11 @@ class UsersController extends AUserData { $permittedFields[] = 'language'; } + if ($this->config->getSystemValue('force_locale', false) === false || + $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { + $permittedFields[] = 'locale'; + } + if ($this->appManager->isEnabledForUser('federatedfilesharing')) { $federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application(); $shareProvider = $federatedFileSharing->getFederatedShareProvider(); @@ -456,6 +462,7 @@ class UsersController extends AUserData { $permittedFields[] = AccountManager::PROPERTY_EMAIL; $permittedFields[] = 'password'; $permittedFields[] = 'language'; + $permittedFields[] = 'locale'; $permittedFields[] = AccountManager::PROPERTY_PHONE; $permittedFields[] = AccountManager::PROPERTY_ADDRESS; $permittedFields[] = AccountManager::PROPERTY_WEBSITE; @@ -505,6 +512,12 @@ class UsersController extends AUserData { } $this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value); break; + case 'locale': + if (!$this->l10nFactory->localeExists($value)) { + throw new OCSException('Invalid locale', 102); + } + $this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value); + break; case AccountManager::PROPERTY_EMAIL: if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') { $targetUser->setEMailAddress($value); diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php index 114742de4f9..af4d5958b53 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -760,7 +760,7 @@ class UsersControllerTest extends TestCase { ->method('getBackendClassName') ->will($this->returnValue('Database')); $targetUser - ->expects($this->exactly(5)) + ->expects($this->exactly(6)) ->method('getUID') ->will($this->returnValue('UID')); @@ -780,6 +780,7 @@ class UsersControllerTest extends TestCase { 'twitter' => 'twitter', 'groups' => ['group0', 'group1', 'group2'], 'language' => 'de', + 'locale' => null, ]; $this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID'])); } @@ -865,7 +866,7 @@ class UsersControllerTest extends TestCase { ->method('getBackendClassName') ->will($this->returnValue('Database')); $targetUser - ->expects($this->exactly(5)) + ->expects($this->exactly(6)) ->method('getUID') ->will($this->returnValue('UID')); $this->accountManager->expects($this->any())->method('getUser') @@ -895,6 +896,7 @@ class UsersControllerTest extends TestCase { 'twitter' => 'twitter', 'groups' => [], 'language' => 'da', + 'locale' => null, ]; $this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID'])); } @@ -1004,7 +1006,7 @@ class UsersControllerTest extends TestCase { ->method('getEMailAddress') ->will($this->returnValue('subadmin@nextcloud.com')); $targetUser - ->expects($this->exactly(5)) + ->expects($this->exactly(6)) ->method('getUID') ->will($this->returnValue('UID')); $targetUser @@ -1050,6 +1052,7 @@ class UsersControllerTest extends TestCase { 'twitter' => 'twitter', 'groups' => [], 'language' => 'ru', + 'locale' => null, ]; $this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID'])); } @@ -1236,7 +1239,7 @@ class UsersControllerTest extends TestCase { ->with('UserToEdit') ->will($this->returnValue($targetUser)); $this->groupManager - ->expects($this->exactly(2)) + ->expects($this->exactly(3)) ->method('isAdmin') ->with('UID') ->will($this->returnValue(true)); @@ -1271,7 +1274,7 @@ class UsersControllerTest extends TestCase { ->with('UserToEdit') ->will($this->returnValue($targetUser)); $this->groupManager - ->expects($this->exactly(2)) + ->expects($this->exactly(3)) ->method('isAdmin') ->with('UID') ->will($this->returnValue(true)); diff --git a/apps/updatenotification/l10n/de.js b/apps/updatenotification/l10n/de.js index d1a5881f1e9..907f95260a4 100644 --- a/apps/updatenotification/l10n/de.js +++ b/apps/updatenotification/l10n/de.js @@ -20,6 +20,7 @@ OC.L10N.register( "<strong>All</strong> apps have an update for this version available" : "Für <strong>alle</strong> Apps steht eine Aktualisierung zur Verfügung", "_<strong>%n</strong> app has no update for this version available_::_<strong>%n</strong> apps have no update for this version available_" : ["Für <strong>%n</strong> App steht keine Aktualisierung für diese Version zur Verfügung","Für <strong>%n</strong> Apps stehen keine Aktualisierungen für diese Version zur Verfügung"], "<strong>production</strong> will always provide the latest patch level, but not update to the next major release immediately. That update usually happens with the second minor release (x.0.2)." : "<strong>Produktion</strong> bietet immer die neuesten Patch-Stände an, jedoch nicht sofort die nächste Hauptversion. Diese Aktualisierung erfolgt normalerweise nach der zweiten kleineren Aktualisierung (x.0.2).", + "<strong>stable</strong> is the most recent stable version. It is suited for regular use and will always update to the latest major version." : "<strong>stabil</strong> ist die aktuellste stabile Version. Die stabile Version ist für den normalen Gebrauch gedacht und wird jeweils auf die aktuelle Hauptversion aktualisiert.", "<strong>beta</strong> is a pre-release version only for testing new features, not for production environments." : "<strong>Beta</strong> bietet eine Vorabversion an und dient zum Testen von neuen Funktionen. Nicht für den Einsatz in Produktivumgebungen geeignet.", "Could not start updater, please try the manual update" : "Der Updater konnte nicht gestartet werden, bitte versuche ein manuelles Update", "Update notifications" : "Update-Benachrichtigungen", diff --git a/apps/updatenotification/l10n/de.json b/apps/updatenotification/l10n/de.json index 8c642227848..da1dc9a429f 100644 --- a/apps/updatenotification/l10n/de.json +++ b/apps/updatenotification/l10n/de.json @@ -18,6 +18,7 @@ "<strong>All</strong> apps have an update for this version available" : "Für <strong>alle</strong> Apps steht eine Aktualisierung zur Verfügung", "_<strong>%n</strong> app has no update for this version available_::_<strong>%n</strong> apps have no update for this version available_" : ["Für <strong>%n</strong> App steht keine Aktualisierung für diese Version zur Verfügung","Für <strong>%n</strong> Apps stehen keine Aktualisierungen für diese Version zur Verfügung"], "<strong>production</strong> will always provide the latest patch level, but not update to the next major release immediately. That update usually happens with the second minor release (x.0.2)." : "<strong>Produktion</strong> bietet immer die neuesten Patch-Stände an, jedoch nicht sofort die nächste Hauptversion. Diese Aktualisierung erfolgt normalerweise nach der zweiten kleineren Aktualisierung (x.0.2).", + "<strong>stable</strong> is the most recent stable version. It is suited for regular use and will always update to the latest major version." : "<strong>stabil</strong> ist die aktuellste stabile Version. Die stabile Version ist für den normalen Gebrauch gedacht und wird jeweils auf die aktuelle Hauptversion aktualisiert.", "<strong>beta</strong> is a pre-release version only for testing new features, not for production environments." : "<strong>Beta</strong> bietet eine Vorabversion an und dient zum Testen von neuen Funktionen. Nicht für den Einsatz in Produktivumgebungen geeignet.", "Could not start updater, please try the manual update" : "Der Updater konnte nicht gestartet werden, bitte versuche ein manuelles Update", "Update notifications" : "Update-Benachrichtigungen", diff --git a/apps/updatenotification/l10n/de_DE.js b/apps/updatenotification/l10n/de_DE.js index 529e98545a1..d86fd30cb0e 100644 --- a/apps/updatenotification/l10n/de_DE.js +++ b/apps/updatenotification/l10n/de_DE.js @@ -20,6 +20,7 @@ OC.L10N.register( "<strong>All</strong> apps have an update for this version available" : "Für <strong>alle</strong> Apps steht eine Aktualisierung zur Verfügung", "_<strong>%n</strong> app has no update for this version available_::_<strong>%n</strong> apps have no update for this version available_" : ["Für <strong>%n</strong> App steht keine Aktualisierung für diese Version zur Verfügung","Für <strong>%n</strong> Apps stehen keine Aktualisierungen für diese Version zur Verfügung"], "<strong>production</strong> will always provide the latest patch level, but not update to the next major release immediately. That update usually happens with the second minor release (x.0.2)." : "<strong>Produktion</strong> bietet immer die neuesten Patch-Stände an, jedoch nicht sofort die nächste Hauptversion. Diese Aktualisierung erfolgt normalerweise nach der zweiten kleineren Aktualisierung (x.0.2).", + "<strong>stable</strong> is the most recent stable version. It is suited for regular use and will always update to the latest major version." : "<strong>stabil</strong> ist die aktuellste stabile Version. Die stabile Version ist für den normalen Gebrauch gedacht und wird jeweils auf die aktuelle Hauptversion aktualisiert.", "<strong>beta</strong> is a pre-release version only for testing new features, not for production environments." : "<strong>Beta</strong> bietet eine Vorabversion an und dient zum Testen von neuen Funktionen. Nicht für den Einsatz in Produktivumgebungen geeignet.", "Could not start updater, please try the manual update" : "Der Updater konnte nicht gestartet werden, bitte versuchen Sie ein manuelles Update", "Update notifications" : "Update-Benachrichtigungen", diff --git a/apps/updatenotification/l10n/de_DE.json b/apps/updatenotification/l10n/de_DE.json index c06139abfc6..821fa0a62c8 100644 --- a/apps/updatenotification/l10n/de_DE.json +++ b/apps/updatenotification/l10n/de_DE.json @@ -18,6 +18,7 @@ "<strong>All</strong> apps have an update for this version available" : "Für <strong>alle</strong> Apps steht eine Aktualisierung zur Verfügung", "_<strong>%n</strong> app has no update for this version available_::_<strong>%n</strong> apps have no update for this version available_" : ["Für <strong>%n</strong> App steht keine Aktualisierung für diese Version zur Verfügung","Für <strong>%n</strong> Apps stehen keine Aktualisierungen für diese Version zur Verfügung"], "<strong>production</strong> will always provide the latest patch level, but not update to the next major release immediately. That update usually happens with the second minor release (x.0.2)." : "<strong>Produktion</strong> bietet immer die neuesten Patch-Stände an, jedoch nicht sofort die nächste Hauptversion. Diese Aktualisierung erfolgt normalerweise nach der zweiten kleineren Aktualisierung (x.0.2).", + "<strong>stable</strong> is the most recent stable version. It is suited for regular use and will always update to the latest major version." : "<strong>stabil</strong> ist die aktuellste stabile Version. Die stabile Version ist für den normalen Gebrauch gedacht und wird jeweils auf die aktuelle Hauptversion aktualisiert.", "<strong>beta</strong> is a pre-release version only for testing new features, not for production environments." : "<strong>Beta</strong> bietet eine Vorabversion an und dient zum Testen von neuen Funktionen. Nicht für den Einsatz in Produktivumgebungen geeignet.", "Could not start updater, please try the manual update" : "Der Updater konnte nicht gestartet werden, bitte versuchen Sie ein manuelles Update", "Update notifications" : "Update-Benachrichtigungen", diff --git a/apps/updatenotification/l10n/it.js b/apps/updatenotification/l10n/it.js index f6f7ef64a3f..38799e47b8c 100644 --- a/apps/updatenotification/l10n/it.js +++ b/apps/updatenotification/l10n/it.js @@ -20,6 +20,7 @@ OC.L10N.register( "<strong>All</strong> apps have an update for this version available" : "<strong>Tutte</strong> le applicazioni hanno un aggiornamento disponibile per questa versione", "_<strong>%n</strong> app has no update for this version available_::_<strong>%n</strong> apps have no update for this version available_" : ["<strong>%n</strong> applicazione non ha un aggiornamento disponibile per questa versione","<strong>%n</strong> applicazioni non hanno un aggiornamento disponibile per questa versione"], "<strong>production</strong> will always provide the latest patch level, but not update to the next major release immediately. That update usually happens with the second minor release (x.0.2)." : "<strong>produzione</strong> fornirà sempre l'ultimo livello di patch, ma non aggiornerà immediatamente alla successiva versione principale. Tale aggiornamento di solito avviene con la seconda versione minore (x.0.2).", + "<strong>stable</strong> is the most recent stable version. It is suited for regular use and will always update to the latest major version." : "<strong>stabile</strong> è la versione stabile più recente. È appropriata per l'utilizzo di tutti i giorni e sarà sempre aggiornata all'ultima versione principale.", "<strong>beta</strong> is a pre-release version only for testing new features, not for production environments." : "<strong>beta</strong> è una versione pre-rilascio solo per provare le nuove funzionalità, non per ambienti di produzione.", "Could not start updater, please try the manual update" : "Impossibile avviare lo strumento di aggiornamento, prova l'aggiornamento manuale", "Update notifications" : "Notifiche degli aggiornamenti", diff --git a/apps/updatenotification/l10n/it.json b/apps/updatenotification/l10n/it.json index 4ee66f5277c..734692254c4 100644 --- a/apps/updatenotification/l10n/it.json +++ b/apps/updatenotification/l10n/it.json @@ -18,6 +18,7 @@ "<strong>All</strong> apps have an update for this version available" : "<strong>Tutte</strong> le applicazioni hanno un aggiornamento disponibile per questa versione", "_<strong>%n</strong> app has no update for this version available_::_<strong>%n</strong> apps have no update for this version available_" : ["<strong>%n</strong> applicazione non ha un aggiornamento disponibile per questa versione","<strong>%n</strong> applicazioni non hanno un aggiornamento disponibile per questa versione"], "<strong>production</strong> will always provide the latest patch level, but not update to the next major release immediately. That update usually happens with the second minor release (x.0.2)." : "<strong>produzione</strong> fornirà sempre l'ultimo livello di patch, ma non aggiornerà immediatamente alla successiva versione principale. Tale aggiornamento di solito avviene con la seconda versione minore (x.0.2).", + "<strong>stable</strong> is the most recent stable version. It is suited for regular use and will always update to the latest major version." : "<strong>stabile</strong> è la versione stabile più recente. È appropriata per l'utilizzo di tutti i giorni e sarà sempre aggiornata all'ultima versione principale.", "<strong>beta</strong> is a pre-release version only for testing new features, not for production environments." : "<strong>beta</strong> è una versione pre-rilascio solo per provare le nuove funzionalità, non per ambienti di produzione.", "Could not start updater, please try the manual update" : "Impossibile avviare lo strumento di aggiornamento, prova l'aggiornamento manuale", "Update notifications" : "Notifiche degli aggiornamenti", diff --git a/apps/updatenotification/l10n/pt_BR.js b/apps/updatenotification/l10n/pt_BR.js index e08b3cd8ff1..5d3942f791c 100644 --- a/apps/updatenotification/l10n/pt_BR.js +++ b/apps/updatenotification/l10n/pt_BR.js @@ -20,6 +20,7 @@ OC.L10N.register( "<strong>All</strong> apps have an update for this version available" : "<strong>Todos</strong> os aplicativos tem uma atualização disponível", "_<strong>%n</strong> app has no update for this version available_::_<strong>%n</strong> apps have no update for this version available_" : ["<strong>%n</strong> aplicativo não tem atualização disponível","<strong>%n</strong> aplicativos tem uma atualização disponível"], "<strong>production</strong> will always provide the latest patch level, but not update to the next major release immediately. That update usually happens with the second minor release (x.0.2)." : "<strong>produção</strong> sempre fornecerá o nível de patch mais recente, mas não será atualizada para a próxima versão principal imediatamente. Essa atualização geralmente acontece com o segundo lançamento menor (x.0.2).", + "<strong>stable</strong> is the most recent stable version. It is suited for regular use and will always update to the latest major version." : "<strong>estável</strong> é a versão estável mais recente. É adequado para uso regular e será sempre atualizado para a versão principal mais recente.", "<strong>beta</strong> is a pre-release version only for testing new features, not for production environments." : "<strong>beta</strong> é uma versão de pré-lançamento apenas para testar novos recursos, não para ambientes de produção.", "Could not start updater, please try the manual update" : "Não foi possível iniciar o atualizador, tente a atualização manual", "Update notifications" : "Notificações de atualização", diff --git a/apps/updatenotification/l10n/pt_BR.json b/apps/updatenotification/l10n/pt_BR.json index 210d5bbdb10..3281d874baa 100644 --- a/apps/updatenotification/l10n/pt_BR.json +++ b/apps/updatenotification/l10n/pt_BR.json @@ -18,6 +18,7 @@ "<strong>All</strong> apps have an update for this version available" : "<strong>Todos</strong> os aplicativos tem uma atualização disponível", "_<strong>%n</strong> app has no update for this version available_::_<strong>%n</strong> apps have no update for this version available_" : ["<strong>%n</strong> aplicativo não tem atualização disponível","<strong>%n</strong> aplicativos tem uma atualização disponível"], "<strong>production</strong> will always provide the latest patch level, but not update to the next major release immediately. That update usually happens with the second minor release (x.0.2)." : "<strong>produção</strong> sempre fornecerá o nível de patch mais recente, mas não será atualizada para a próxima versão principal imediatamente. Essa atualização geralmente acontece com o segundo lançamento menor (x.0.2).", + "<strong>stable</strong> is the most recent stable version. It is suited for regular use and will always update to the latest major version." : "<strong>estável</strong> é a versão estável mais recente. É adequado para uso regular e será sempre atualizado para a versão principal mais recente.", "<strong>beta</strong> is a pre-release version only for testing new features, not for production environments." : "<strong>beta</strong> é uma versão de pré-lançamento apenas para testar novos recursos, não para ambientes de produção.", "Could not start updater, please try the manual update" : "Não foi possível iniciar o atualizador, tente a atualização manual", "Update notifications" : "Notificações de atualização", diff --git a/apps/updatenotification/l10n/sr.js b/apps/updatenotification/l10n/sr.js index 673bfe5249d..f09dd0b92ed 100644 --- a/apps/updatenotification/l10n/sr.js +++ b/apps/updatenotification/l10n/sr.js @@ -20,6 +20,7 @@ OC.L10N.register( "<strong>All</strong> apps have an update for this version available" : "<strong>Све</strong> апликације имају доступна ажурирања за ову верзију", "_<strong>%n</strong> app has no update for this version available_::_<strong>%n</strong> apps have no update for this version available_" : ["<strong>%n</strong> апликација имају доступна ажурирања за ову верзију","<strong>%n</strong> апликације имају доступна ажурирања за ову верзију","<strong>%n</strong> апликација имају доступна ажурирања за ову верзију"], "<strong>production</strong> will always provide the latest patch level, but not update to the next major release immediately. That update usually happens with the second minor release (x.0.2)." : "<strong>радна</strong> ће увек давати последњи ниво закрпа али неће се одмах ажурирати на следеће главно издање. То ажурирање се углавном обавља по изласку другог мањег издања (x.0.2).", + "<strong>stable</strong> is the most recent stable version. It is suited for regular use and will always update to the latest major version." : "<strong>стабилна</strong> је најновија стабилна верзија. Прикладна за свакодневну употребу и увек се ажурира на најновију главну верзију.", "<strong>beta</strong> is a pre-release version only for testing new features, not for production environments." : "<strong>бета</strong> је пред-издање и служи само за тестирање нових могућности, не за свакодневни рад.", "Could not start updater, please try the manual update" : "Не могу да покренем програм за ажурирање, покушајте ручно ажурирање", "Update notifications" : "Обавештења о ажурирању", diff --git a/apps/updatenotification/l10n/sr.json b/apps/updatenotification/l10n/sr.json index e1d2f8838d4..576ad98a979 100644 --- a/apps/updatenotification/l10n/sr.json +++ b/apps/updatenotification/l10n/sr.json @@ -18,6 +18,7 @@ "<strong>All</strong> apps have an update for this version available" : "<strong>Све</strong> апликације имају доступна ажурирања за ову верзију", "_<strong>%n</strong> app has no update for this version available_::_<strong>%n</strong> apps have no update for this version available_" : ["<strong>%n</strong> апликација имају доступна ажурирања за ову верзију","<strong>%n</strong> апликације имају доступна ажурирања за ову верзију","<strong>%n</strong> апликација имају доступна ажурирања за ову верзију"], "<strong>production</strong> will always provide the latest patch level, but not update to the next major release immediately. That update usually happens with the second minor release (x.0.2)." : "<strong>радна</strong> ће увек давати последњи ниво закрпа али неће се одмах ажурирати на следеће главно издање. То ажурирање се углавном обавља по изласку другог мањег издања (x.0.2).", + "<strong>stable</strong> is the most recent stable version. It is suited for regular use and will always update to the latest major version." : "<strong>стабилна</strong> је најновија стабилна верзија. Прикладна за свакодневну употребу и увек се ажурира на најновију главну верзију.", "<strong>beta</strong> is a pre-release version only for testing new features, not for production environments." : "<strong>бета</strong> је пред-издање и служи само за тестирање нових могућности, не за свакодневни рад.", "Could not start updater, please try the manual update" : "Не могу да покренем програм за ажурирање, покушајте ручно ажурирање", "Update notifications" : "Обавештења о ажурирању", diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php index 6140aa297b4..977b7c54425 100644 --- a/apps/user_ldap/lib/Connection.php +++ b/apps/user_ldap/lib/Connection.php @@ -57,6 +57,9 @@ use OCP\ILogger; * @property string ldapUuidGroupAttribute * @property string ldapExpertUUIDUserAttr * @property string ldapExpertUUIDGroupAttr + * @property string ldapQuotaAttribute + * @property string ldapQuotaDefault + * @property string ldapEmailAttribute */ class Connection extends LDAPUtility { private $ldapConnectionRes = null; diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php index 27578921450..5dfeb6da544 100644 --- a/apps/user_ldap/lib/User/User.php +++ b/apps/user_ldap/lib/User/User.php @@ -37,8 +37,8 @@ use OCP\IAvatarManager; use OCP\IConfig; use OCP\ILogger; use OCP\Image; +use OCP\IUser; use OCP\IUserManager; -use OCP\Util; use OCP\Notification\IManager as INotificationManager; /** @@ -499,44 +499,39 @@ class User { return; } + $quotaAttribute = $this->connection->ldapQuotaAttribute; + $defaultQuota = $this->connection->ldapQuotaDefault; + if($quotaAttribute === '' && $defaultQuota === '') { + return; + } + $quota = false; - if(is_null($valueFromLDAP)) { - $quotaAttribute = $this->connection->ldapQuotaAttribute; - if ($quotaAttribute !== '') { - $aQuota = $this->access->readAttribute($this->dn, $quotaAttribute); - if($aQuota && (count($aQuota) > 0)) { - if ($this->verifyQuotaValue($aQuota[0])) { - $quota = $aQuota[0]; - } else { - $this->log->log('not suitable LDAP quota found for user ' . $this->uid . ': [' . $aQuota[0] . ']', ILogger::WARN); - } - } + if(is_null($valueFromLDAP) && $quotaAttribute !== '') { + $aQuota = $this->access->readAttribute($this->dn, $quotaAttribute); + if($aQuota && (count($aQuota) > 0) && $this->verifyQuotaValue($aQuota[0])) { + $quota = $aQuota[0]; + } else if(is_array($aQuota) && isset($aQuota[0])) { + $this->log->log('no suitable LDAP quota found for user ' . $this->uid . ': [' . $aQuota[0] . ']', ILogger::DEBUG); } + } else if ($this->verifyQuotaValue($valueFromLDAP)) { + $quota = $valueFromLDAP; } else { - if ($this->verifyQuotaValue($valueFromLDAP)) { - $quota = $valueFromLDAP; - } else { - $this->log->log('not suitable LDAP quota found for user ' . $this->uid . ': [' . $valueFromLDAP . ']', ILogger::WARN); - } + $this->log->log('no suitable LDAP quota found for user ' . $this->uid . ': [' . $valueFromLDAP . ']', ILogger::DEBUG); } - if ($quota === false) { + if ($quota === false && $this->verifyQuotaValue($defaultQuota)) { // quota not found using the LDAP attribute (or not parseable). Try the default quota - $defaultQuota = $this->connection->ldapQuotaDefault; - if ($this->verifyQuotaValue($defaultQuota)) { - $quota = $defaultQuota; - } + $quota = $defaultQuota; + } else if($quota === false) { + $this->log->log('no suitable default quota found for user ' . $this->uid . ': [' . $defaultQuota . ']', ILogger::DEBUG); + return; } $targetUser = $this->userManager->get($this->uid); - if ($targetUser) { - if($quota !== false) { - $targetUser->setQuota($quota); - } else { - $this->log->log('not suitable default quota found for user ' . $this->uid . ': [' . $defaultQuota . ']', ILogger::WARN); - } + if ($targetUser instanceof IUser) { + $targetUser->setQuota($quota); } else { - $this->log->log('trying to set a quota for user ' . $this->uid . ' but the user is missing', ILogger::ERROR); + $this->log->log('trying to set a quota for user ' . $this->uid . ' but the user is missing', ILogger::INFO); } } diff --git a/apps/user_ldap/tests/User/UserTest.php b/apps/user_ldap/tests/User/UserTest.php index c61a9bd3d47..ccf584aa300 100644 --- a/apps/user_ldap/tests/User/UserTest.php +++ b/apps/user_ldap/tests/User/UserTest.php @@ -32,14 +32,12 @@ namespace OCA\User_LDAP\Tests\User; use OCA\User_LDAP\Access; use OCA\User_LDAP\Connection; use OCA\User_LDAP\FilesystemHelper; -use OCA\User_LDAP\ILDAPWrapper; use OCA\User_LDAP\LogWrapper; use OCA\User_LDAP\User\IUserTools; use OCA\User_LDAP\User\User; use OCP\IAvatar; use OCP\IAvatarManager; use OCP\IConfig; -use OCP\IDBConnection; use OCP\Image; use OCP\IUser; use OCP\IUserManager; @@ -79,15 +77,14 @@ class UserTest extends \Test\TestCase { $log = $this->createMock(LogWrapper::class); $avaMgr = $this->createMock(IAvatarManager::class); $image = $this->createMock(Image::class); - $dbc = $this->createMock(IDBConnection::class); $userMgr = $this->createMock(IUserManager::class); $notiMgr = $this->createMock(INotificationManager::class); - return array($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr); + return array($access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr); } public function testGetDNandUsername() { - list($access, $config, $filesys, $image, $log, $avaMgr, $db, $userMgr, $notiMgr) = + list($access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $uid = 'alice'; @@ -101,7 +98,7 @@ class UserTest extends \Test\TestCase { } public function testUpdateEmailProvided() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $this->connection->expects($this->once()) @@ -135,7 +132,7 @@ class UserTest extends \Test\TestCase { } public function testUpdateEmailNotProvided() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $this->connection->expects($this->once()) @@ -161,7 +158,7 @@ class UserTest extends \Test\TestCase { } public function testUpdateEmailNotConfigured() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $this->connection->expects($this->once()) @@ -185,15 +182,15 @@ class UserTest extends \Test\TestCase { } public function testUpdateQuotaAllProvided() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); - $this->connection->expects($this->at(0)) + $this->connection->expects($this->exactly(2)) ->method('__get') - ->with($this->equalTo('ldapQuotaAttribute')) - ->will($this->returnValue('myquota')); - $this->connection->expects($this->exactly(1)) - ->method('__get'); + ->willReturnMap([ + ['ldapQuotaAttribute', 'myquota'], + ['ldapQuotaDefault', ''] + ]); $this->access->expects($this->once()) ->method('readAttribute') @@ -206,7 +203,7 @@ class UserTest extends \Test\TestCase { ->method('setQuota') ->with('42 GB'); - $userMgr->expects($this->once()) + $userMgr->expects($this->atLeastOnce()) ->method('get') ->with('alice') ->will($this->returnValue($user)); @@ -221,15 +218,15 @@ class UserTest extends \Test\TestCase { } public function testUpdateQuotaToDefaultAllProvided() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); - $this->connection->expects($this->at(0)) + $this->connection->expects($this->exactly(2)) ->method('__get') - ->with($this->equalTo('ldapQuotaAttribute')) - ->will($this->returnValue('myquota')); - $this->connection->expects($this->exactly(1)) - ->method('__get'); + ->willReturnMap([ + ['ldapQuotaAttribute', 'myquota'], + ['ldapQuotaDefault', ''] + ]); $this->access->expects($this->once()) ->method('readAttribute') @@ -257,15 +254,15 @@ class UserTest extends \Test\TestCase { } public function testUpdateQuotaToNoneAllProvided() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); - $this->connection->expects($this->at(0)) + $this->connection->expects($this->exactly(2)) ->method('__get') - ->with($this->equalTo('ldapQuotaAttribute')) - ->will($this->returnValue('myquota')); - $this->connection->expects($this->exactly(1)) - ->method('__get'); + ->willReturnMap([ + ['ldapQuotaAttribute', 'myquota'], + ['ldapQuotaDefault', ''] + ]); $this->access->expects($this->once()) ->method('readAttribute') @@ -293,7 +290,7 @@ class UserTest extends \Test\TestCase { } public function testUpdateQuotaDefaultProvided() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $this->connection->expects($this->at(0)) @@ -333,15 +330,15 @@ class UserTest extends \Test\TestCase { } public function testUpdateQuotaIndividualProvided() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); - $this->connection->expects($this->at(0)) + $this->connection->expects($this->exactly(2)) ->method('__get') - ->with($this->equalTo('ldapQuotaAttribute')) - ->will($this->returnValue('myquota')); - $this->connection->expects($this->exactly(1)) - ->method('__get'); + ->willReturnMap([ + ['ldapQuotaAttribute', 'myquota'], + ['ldapQuotaDefault', ''] + ]); $this->access->expects($this->once()) ->method('readAttribute') @@ -369,19 +366,15 @@ class UserTest extends \Test\TestCase { } public function testUpdateQuotaNoneProvided() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); - $this->connection->expects($this->at(0)) - ->method('__get') - ->with($this->equalTo('ldapQuotaAttribute')) - ->will($this->returnValue('myquota')); - $this->connection->expects($this->at(1)) - ->method('__get') - ->with($this->equalTo('ldapQuotaDefault')) - ->will($this->returnValue('')); $this->connection->expects($this->exactly(2)) - ->method('__get'); + ->method('__get') + ->willReturnMap([ + ['ldapQuotaAttribute', 'myquota'], + ['ldapQuotaDefault', ''] + ]); $this->access->expects($this->once()) ->method('readAttribute') @@ -393,10 +386,9 @@ class UserTest extends \Test\TestCase { $user->expects($this->never()) ->method('setQuota'); - $userMgr->expects($this->once()) + $userMgr->expects($this->never()) ->method('get') - ->with('alice') - ->will($this->returnValue($user)); + ->with('alice'); $config->expects($this->never()) ->method('setUserValue'); @@ -411,28 +403,22 @@ class UserTest extends \Test\TestCase { } public function testUpdateQuotaNoneConfigured() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); - $this->connection->expects($this->at(0)) - ->method('__get') - ->with($this->equalTo('ldapQuotaAttribute')) - ->will($this->returnValue('')); - $this->connection->expects($this->at(1)) - ->method('__get') - ->with($this->equalTo('ldapQuotaDefault')) - ->will($this->returnValue('')); $this->connection->expects($this->exactly(2)) - ->method('__get'); + ->method('__get') + ->willReturnMap([ + ['ldapQuotaAttribute', ''], + ['ldapQuotaDefault', ''] + ]); $user = $this->createMock('\OCP\IUser'); $user->expects($this->never()) ->method('setQuota'); - $userMgr->expects($this->once()) - ->method('get') - ->with('alice') - ->will($this->returnValue($user)); + $userMgr->expects($this->never()) + ->method('get'); $this->access->expects($this->never()) ->method('readAttribute'); @@ -450,14 +436,17 @@ class UserTest extends \Test\TestCase { } public function testUpdateQuotaFromValue() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $readQuota = '19 GB'; - $this->connection->expects($this->never()) + $this->connection->expects($this->exactly(2)) ->method('__get') - ->with($this->equalTo('ldapQuotaDefault')); + ->willReturnMap([ + ['ldapQuotaAttribute', 'myquota'], + ['ldapQuotaDefault', ''] + ]); $this->access->expects($this->never()) ->method('readAttribute'); @@ -485,19 +474,15 @@ class UserTest extends \Test\TestCase { * Unparseable quota will fallback to use the LDAP default */ public function testUpdateWrongQuotaAllProvided() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); - $this->connection->expects($this->at(0)) - ->method('__get') - ->with($this->equalTo('ldapQuotaAttribute')) - ->will($this->returnValue('myquota')); - $this->connection->expects($this->at(1)) - ->method('__get') - ->with($this->equalTo('ldapQuotaDefault')) - ->will($this->returnValue('23 GB')); $this->connection->expects($this->exactly(2)) - ->method('__get'); + ->method('__get') + ->willReturnMap([ + ['ldapQuotaAttribute', 'myquota'], + ['ldapQuotaDefault', '23 GB'] + ]); $this->access->expects($this->once()) ->method('readAttribute') @@ -528,19 +513,15 @@ class UserTest extends \Test\TestCase { * No user quota and wrong default will set 'default' as quota */ public function testUpdateWrongDefaultQuotaProvided() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); - $this->connection->expects($this->at(0)) - ->method('__get') - ->with($this->equalTo('ldapQuotaAttribute')) - ->will($this->returnValue('myquota')); - $this->connection->expects($this->at(1)) - ->method('__get') - ->with($this->equalTo('ldapQuotaDefault')) - ->will($this->returnValue('23 GBwowowo')); $this->connection->expects($this->exactly(2)) - ->method('__get'); + ->method('__get') + ->willReturnMap([ + ['ldapQuotaAttribute', 'myquota'], + ['ldapQuotaDefault', '23 GBwowowo'] + ]); $this->access->expects($this->once()) ->method('readAttribute') @@ -552,10 +533,8 @@ class UserTest extends \Test\TestCase { $user->expects($this->never()) ->method('setQuota'); - $userMgr->expects($this->once()) - ->method('get') - ->with('alice') - ->will($this->returnValue($user)); + $userMgr->expects($this->never()) + ->method('get'); $uid = 'alice'; $dn = 'uid=alice,dc=foo,dc=bar'; @@ -570,19 +549,15 @@ class UserTest extends \Test\TestCase { * Wrong user quota and wrong default will set 'default' as quota */ public function testUpdateWrongQuotaAndDefaultAllProvided() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); - $this->connection->expects($this->at(0)) - ->method('__get') - ->with($this->equalTo('ldapQuotaAttribute')) - ->will($this->returnValue('myquota')); - $this->connection->expects($this->at(1)) - ->method('__get') - ->with($this->equalTo('ldapQuotaDefault')) - ->will($this->returnValue('23 GBwowowo')); $this->connection->expects($this->exactly(2)) - ->method('__get'); + ->method('__get') + ->willReturnMap([ + ['ldapQuotaAttribute', 'myquota'], + ['ldapQuotaDefault', '23 GBwowowo'] + ]); $this->access->expects($this->once()) ->method('readAttribute') @@ -594,10 +569,8 @@ class UserTest extends \Test\TestCase { $user->expects($this->never()) ->method('setQuota'); - $userMgr->expects($this->once()) - ->method('get') - ->with('alice') - ->will($this->returnValue($user)); + $userMgr->expects($this->never()) + ->method('get'); $uid = 'alice'; $dn = 'uid=alice,dc=foo,dc=bar'; @@ -612,19 +585,15 @@ class UserTest extends \Test\TestCase { * No quota attribute set and wrong default will set 'default' as quota */ public function testUpdateWrongDefaultQuotaNotProvided() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); - $this->connection->expects($this->at(0)) - ->method('__get') - ->with($this->equalTo('ldapQuotaAttribute')) - ->will($this->returnValue('')); - $this->connection->expects($this->at(1)) - ->method('__get') - ->with($this->equalTo('ldapQuotaDefault')) - ->will($this->returnValue('23 GBwowowo')); $this->connection->expects($this->exactly(2)) - ->method('__get'); + ->method('__get') + ->willReturnMap([ + ['ldapQuotaAttribute', ''], + ['ldapQuotaDefault', '23 GBwowowo'] + ]); $this->access->expects($this->never()) ->method('readAttribute'); @@ -633,10 +602,8 @@ class UserTest extends \Test\TestCase { $user->expects($this->never()) ->method('setQuota'); - $userMgr->expects($this->once()) - ->method('get') - ->with('alice') - ->will($this->returnValue($user)); + $userMgr->expects($this->never()) + ->method('get'); $uid = 'alice'; $dn = 'uid=alice,dc=foo,dc=bar'; @@ -649,7 +616,7 @@ class UserTest extends \Test\TestCase { //the testUpdateAvatar series also implicitely tests getAvatarImage public function testUpdateAvatarJpegPhotoProvided() { - list(, $config, $filesys, $image, $log, $avaMgr, , $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $this->access->expects($this->once()) @@ -695,7 +662,7 @@ class UserTest extends \Test\TestCase { } public function testUpdateAvatarThumbnailPhotoProvided() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $this->access->expects($this->any()) @@ -750,7 +717,7 @@ class UserTest extends \Test\TestCase { } public function testUpdateAvatarNotProvided() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $this->access->expects($this->any()) @@ -793,7 +760,7 @@ class UserTest extends \Test\TestCase { } public function testUpdateBeforeFirstLogin() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $config->expects($this->at(0)) @@ -823,7 +790,7 @@ class UserTest extends \Test\TestCase { } public function testUpdateAfterFirstLogin() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $config->expects($this->at(0)) @@ -857,7 +824,7 @@ class UserTest extends \Test\TestCase { } public function testUpdateNoRefresh() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $config->expects($this->at(0)) @@ -894,7 +861,7 @@ class UserTest extends \Test\TestCase { } public function testMarkLogin() { - list(, $config, $filesys, $image, $log, $avaMgr, $db, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $config->expects($this->once()) @@ -915,7 +882,7 @@ class UserTest extends \Test\TestCase { } public function testGetAvatarImageProvided() { - list(, $config, $filesys, $image, $log, $avaMgr, $db, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $this->access->expects($this->once()) @@ -938,7 +905,7 @@ class UserTest extends \Test\TestCase { } public function testProcessAttributes() { - list(, $config, $filesys, $image, $log, $avaMgr, , $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $uid = 'alice'; @@ -954,7 +921,8 @@ class UserTest extends \Test\TestCase { 'updateAvatar' ); - $userMock = $this->getMockBuilder('OCA\User_LDAP\User\User') + /** @var User|\PHPUnit_Framework_MockObject_MockObject $userMock */ + $userMock = $this->getMockBuilder(User::class) ->setConstructorArgs(array($uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr)) ->setMethods($requiredMethods) ->getMock(); @@ -1002,7 +970,7 @@ class UserTest extends \Test\TestCase { * @dataProvider emptyHomeFolderAttributeValueProvider */ public function testGetHomePathNotConfigured($attributeValue) { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $this->connection->expects($this->any()) @@ -1027,7 +995,7 @@ class UserTest extends \Test\TestCase { } public function testGetHomePathConfiguredNotAvailableAllowed() { - list(, $config, $filesys, $image, $log, $avaMgr, , $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $this->connection->expects($this->any()) @@ -1059,7 +1027,7 @@ class UserTest extends \Test\TestCase { * @expectedException \Exception */ public function testGetHomePathConfiguredNotAvailableNotAllowed() { - list(, $config, $filesys, $image, $log, $avaMgr, , $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $this->connection->expects($this->any()) @@ -1097,7 +1065,7 @@ class UserTest extends \Test\TestCase { * @dataProvider displayNameProvider */ public function testComposeAndStoreDisplayName($part1, $part2, $expected) { - list(, $config, $filesys, $image, $log, $avaMgr, , $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $config->expects($this->once()) @@ -1111,7 +1079,7 @@ class UserTest extends \Test\TestCase { } public function testHandlePasswordExpiryWarningDefaultPolicy() { - list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $uid = 'alice'; @@ -1181,7 +1149,7 @@ class UserTest extends \Test\TestCase { } public function testHandlePasswordExpiryWarningCustomPolicy() { - list(, $config, $filesys, $image, $log, $avaMgr, , $userMgr, $notiMgr) = + list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) = $this->getTestInstances(); $uid = 'alice'; |