diff options
Diffstat (limited to 'apps')
25 files changed, 295 insertions, 92 deletions
diff --git a/apps/dav/appinfo/application.php b/apps/dav/appinfo/application.php index c3811a40845..328f86c877f 100644 --- a/apps/dav/appinfo/application.php +++ b/apps/dav/appinfo/application.php @@ -153,11 +153,6 @@ class Application extends App { return $this->getContainer()->query('SyncService'); } - public function setupCron() { - $jl = $this->getContainer()->getServer()->getJobList(); - $jl->add(new SyncJob()); - } - public function generateBirthdays() { try { /** @var BirthdayService $migration */ diff --git a/apps/dav/appinfo/database.xml b/apps/dav/appinfo/database.xml index 71dec639064..f79ea07ae76 100644 --- a/apps/dav/appinfo/database.xml +++ b/apps/dav/appinfo/database.xml @@ -259,11 +259,13 @@ CREATE TABLE calendarobjects ( <name>firstoccurence</name> <type>integer</type> <unsigned>true</unsigned> + <length>11</length> </field> <field> <name>lastoccurence</name> <type>integer</type> <unsigned>true</unsigned> + <length>11</length> </field> <field> <name>uid</name> diff --git a/apps/dav/appinfo/info.xml b/apps/dav/appinfo/info.xml index a8e7df6e8e2..e2688e2f923 100644 --- a/apps/dav/appinfo/info.xml +++ b/apps/dav/appinfo/info.xml @@ -5,7 +5,7 @@ <description>ownCloud WebDAV endpoint</description> <licence>AGPL</licence> <author>owncloud.org</author> - <version>0.2.3</version> + <version>0.2.4</version> <default_enable/> <types> <filesystem/> @@ -16,4 +16,7 @@ <dependencies> <owncloud min-version="9.1" max-version="9.1" /> </dependencies> + <background-jobs> + <job>OCA\DAV\CardDAV\Sync\SyncJob</job> + </background-jobs> </info> diff --git a/apps/dav/appinfo/install.php b/apps/dav/appinfo/install.php index fbd41d25f49..dbb23022b38 100644 --- a/apps/dav/appinfo/install.php +++ b/apps/dav/appinfo/install.php @@ -22,5 +22,4 @@ use OCA\Dav\AppInfo\Application; $app = new Application(); -$app->setupCron(); $app->generateBirthdays(); diff --git a/apps/dav/appinfo/update.php b/apps/dav/appinfo/update.php index fbd41d25f49..dbb23022b38 100644 --- a/apps/dav/appinfo/update.php +++ b/apps/dav/appinfo/update.php @@ -22,5 +22,4 @@ use OCA\Dav\AppInfo\Application; $app = new Application(); -$app->setupCron(); $app->generateBirthdays(); diff --git a/apps/dav/lib/connector/sabre/principal.php b/apps/dav/lib/connector/sabre/principal.php index 18f28a916f1..787bcdf469b 100644 --- a/apps/dav/lib/connector/sabre/principal.php +++ b/apps/dav/lib/connector/sabre/principal.php @@ -196,6 +196,14 @@ class Principal implements BackendInterface { * @return string */ function findByUri($uri, $principalPrefix) { + if (substr($uri, 0, 7) === 'mailto:') { + $email = substr($uri, 7); + $users = $this->userManager->getByEmail($email); + if (count($users) === 1) { + return $this->principalPrefix . '/' . $users[0]->getUID(); + } + } + return ''; } diff --git a/apps/dav/lib/server.php b/apps/dav/lib/server.php index 73e24c9a292..edaa7ac8552 100644 --- a/apps/dav/lib/server.php +++ b/apps/dav/lib/server.php @@ -84,6 +84,9 @@ class Server { // acl $acl = new DavAclPlugin(); + $acl->principalCollectionSet = [ + 'principals/users', 'principals/groups' + ]; $acl->defaultUsernamePath = 'principals/users'; $this->server->addPlugin($acl); diff --git a/apps/dav/tests/unit/caldav/caldavbackendtest.php b/apps/dav/tests/unit/caldav/caldavbackendtest.php index 440db7636e1..89be5671ca8 100644 --- a/apps/dav/tests/unit/caldav/caldavbackendtest.php +++ b/apps/dav/tests/unit/caldav/caldavbackendtest.php @@ -328,6 +328,7 @@ EOD; $events[0] = $this->createEvent($calendarId, '20130912T130000Z', '20130912T140000Z'); $events[1] = $this->createEvent($calendarId, '20130912T150000Z', '20130912T170000Z'); $events[2] = $this->createEvent($calendarId, '20130912T173000Z', '20130912T220000Z'); + $events[3] = $this->createEvent($calendarId, '21130912T130000Z', '22130912T130000Z'); $result = $this->backend->calendarQuery($calendarId, [ 'name' => '', @@ -351,11 +352,12 @@ EOD; public function providesCalendarQueryParameters() { return [ - 'all' => [[0, 1, 2], [], []], + 'all' => [[0, 1, 2, 3], [], []], 'only-todos' => [[], ['name' => 'VTODO'], []], - 'only-events' => [[0, 1, 2], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => null, 'end' => null], 'prop-filters' => []]],], - 'start' => [[1, 2], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => new DateTime('2013-09-12 14:00:00', new DateTimeZone('UTC')), 'end' => null], 'prop-filters' => []]],], + 'only-events' => [[0, 1, 2, 3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => null, 'end' => null], 'prop-filters' => []]],], + 'start' => [[1, 2, 3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => new DateTime('2013-09-12 14:00:00', new DateTimeZone('UTC')), 'end' => null], 'prop-filters' => []]],], 'end' => [[0], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => null, 'end' => new DateTime('2013-09-12 14:00:00', new DateTimeZone('UTC'))], 'prop-filters' => []]],], + 'future' => [[3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => new DateTime('2099-09-12 14:00:00', new DateTimeZone('UTC')), 'end' => null], 'prop-filters' => []]],], ]; } diff --git a/apps/dav/tests/unit/connector/sabre/principal.php b/apps/dav/tests/unit/connector/sabre/principal.php index 1747885240a..75076e9618b 100644 --- a/apps/dav/tests/unit/connector/sabre/principal.php +++ b/apps/dav/tests/unit/connector/sabre/principal.php @@ -255,4 +255,19 @@ class Principal extends TestCase { public function testSearchPrincipals() { $this->assertSame([], $this->connector->searchPrincipals('principals/users', [])); } + + public function testFindByUri() { + $fooUser = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $fooUser + ->expects($this->exactly(1)) + ->method('getUID') + ->will($this->returnValue('foo')); + + $this->userManager->expects($this->once())->method('getByEmail')->willReturn([ + $fooUser + ]); + $ret = $this->connector->findByUri('mailto:foo@bar.net', 'principals/users'); + $this->assertSame('principals/users/foo', $ret); + } } diff --git a/apps/files/command/scan.php b/apps/files/command/scan.php index f607b3e1af1..1ae04c585bb 100644 --- a/apps/files/command/scan.php +++ b/apps/files/command/scan.php @@ -89,6 +89,15 @@ class Scan extends Base { ); } + public function checkScanWarning($fullPath, OutputInterface $output) { + $normalizedPath = basename(\OC\Files\Filesystem::normalizePath($fullPath)); + $path = basename($fullPath); + + if ($normalizedPath !== $path) { + $output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>'); + } + } + protected function scanFiles($user, $path, $verbose, OutputInterface $output) { $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception @@ -126,6 +135,12 @@ class Scan extends Base { } }); } + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) use ($output) { + $this->checkScanWarning($path, $output); + }); + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) use ($output) { + $this->checkScanWarning($path, $output); + }); try { $scanner->scan($path); @@ -133,7 +148,9 @@ class Scan extends Base { $output->writeln("<error>Home storage for user $user not writable</error>"); $output->writeln("Make sure you're running the scan command only as the user the web server runs as"); } catch (\Exception $e) { - # exit the function if ctrl-c has been pressed + if ($e->getMessage() !== 'ctrl-c') { + $output->writeln('<error>Exception while scanning: ' . $e->getMessage() . "\n" . $e->getTraceAsString() . '</error>'); + } return; } } diff --git a/apps/files/l10n/nn_NO.js b/apps/files/l10n/nn_NO.js index 1e138d91b85..ee983939e7d 100644 --- a/apps/files/l10n/nn_NO.js +++ b/apps/files/l10n/nn_NO.js @@ -17,6 +17,7 @@ OC.L10N.register( "Upload failed. Could not get file info." : "Feil ved opplasting. Klarte ikkje å henta filinfo.", "Invalid directory." : "Ugyldig mappe.", "Files" : "Filer", + "All files" : "Alle filer", "Favorites" : "Favorittar", "Home" : "Heime", "Close" : "Lukk", diff --git a/apps/files/l10n/nn_NO.json b/apps/files/l10n/nn_NO.json index 5645a61b6bc..ec9b4efef11 100644 --- a/apps/files/l10n/nn_NO.json +++ b/apps/files/l10n/nn_NO.json @@ -15,6 +15,7 @@ "Upload failed. Could not get file info." : "Feil ved opplasting. Klarte ikkje å henta filinfo.", "Invalid directory." : "Ugyldig mappe.", "Files" : "Filer", + "All files" : "Alle filer", "Favorites" : "Favorittar", "Home" : "Heime", "Close" : "Lukk", diff --git a/apps/files/l10n/ru.js b/apps/files/l10n/ru.js index 183953629a2..8e20c65f548 100644 --- a/apps/files/l10n/ru.js +++ b/apps/files/l10n/ru.js @@ -105,6 +105,7 @@ OC.L10N.register( "With PHP-FPM it might take 5 minutes for changes to be applied." : "В режиме PHP-FPM применение изменений может занять до 5 минут.", "Missing permissions to edit from here." : "Отсутствуют права на удаление.", "Settings" : "Настройки", + "Show hidden files" : "Показать скрытые файлы", "WebDAV" : "WebDAV", "Use this address to <a href=\"%s\" target=\"_blank\" rel=\"noreferrer\">access your Files via WebDAV</a>" : "Используйте этот адрес для <a href=\"%s\" target=\"_blank\" rel=\"noreferrer\">для доступа к вашим файлам по WebDAV</a>", "Cancel upload" : "Отменить загрузку", diff --git a/apps/files/l10n/ru.json b/apps/files/l10n/ru.json index f75736df6ba..d4f8617e343 100644 --- a/apps/files/l10n/ru.json +++ b/apps/files/l10n/ru.json @@ -103,6 +103,7 @@ "With PHP-FPM it might take 5 minutes for changes to be applied." : "В режиме PHP-FPM применение изменений может занять до 5 минут.", "Missing permissions to edit from here." : "Отсутствуют права на удаление.", "Settings" : "Настройки", + "Show hidden files" : "Показать скрытые файлы", "WebDAV" : "WebDAV", "Use this address to <a href=\"%s\" target=\"_blank\" rel=\"noreferrer\">access your Files via WebDAV</a>" : "Используйте этот адрес для <a href=\"%s\" target=\"_blank\" rel=\"noreferrer\">для доступа к вашим файлам по WebDAV</a>", "Cancel upload" : "Отменить загрузку", diff --git a/apps/files/tests/activitytest.php b/apps/files/tests/activitytest.php index 5e73ff0b5dd..bc062dd0542 100644 --- a/apps/files/tests/activitytest.php +++ b/apps/files/tests/activitytest.php @@ -33,7 +33,7 @@ use Test\TestCase; */ class ActivityTest extends TestCase { - /** @var \OC\ActivityManager */ + /** @var \OCP\Activity\IManager */ private $activityManager; /** @var \OCP\IRequest|\PHPUnit_Framework_MockObject_MockObject */ @@ -70,7 +70,7 @@ class ActivityTest extends TestCase { ->disableOriginalConstructor() ->getMock(); - $this->activityManager = new \OC\ActivityManager( + $this->activityManager = new \OC\Activity\Manager( $this->request, $this->session, $this->config diff --git a/apps/files_external/lib/storage/smb.php b/apps/files_external/lib/storage/smb.php index 4249d13168c..868c52a63b4 100644 --- a/apps/files_external/lib/storage/smb.php +++ b/apps/files_external/lib/storage/smb.php @@ -100,7 +100,7 @@ class SMB extends \OC\Files\Storage\Common { * @return string */ protected function buildPath($path) { - return Filesystem::normalizePath($this->root . '/' . $path); + return Filesystem::normalizePath($this->root . '/' . $path, true, false, true); } /** diff --git a/apps/files_sharing/api/share20ocs.php b/apps/files_sharing/api/share20ocs.php index 68098530017..af762845326 100644 --- a/apps/files_sharing/api/share20ocs.php +++ b/apps/files_sharing/api/share20ocs.php @@ -28,11 +28,12 @@ use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUser; use OCP\Files\IRootFolder; +use OCP\Lock\LockedException; use OCP\Share; use OCP\Share\IManager; - use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\Exceptions\GenericShareException; +use OCP\Lock\ILockingProvider; /** * Class Share20OCS @@ -205,12 +206,21 @@ class Share20OCS { return new \OC_OCS_Result(null, 404, $this->l->t('Wrong share ID, share doesn\'t exist')); } + try { + $share->getNode()->lock(ILockingProvider::LOCK_SHARED); + } catch (LockedException $e) { + return new \OC_OCS_Result(null, 404, 'could not delete share'); + } + if (!$this->canAccessShare($share)) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, $this->l->t('Could not delete share')); } $this->shareManager->deleteShare($share); + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); + return new \OC_OCS_Result(); } @@ -233,12 +243,18 @@ class Share20OCS { $userFolder = $this->rootFolder->getUserFolder($this->currentUser->getUID()); try { $path = $userFolder->get($path); - } catch (\OCP\Files\NotFoundException $e) { + } catch (NotFoundException $e) { return new \OC_OCS_Result(null, 404, $this->l->t('Wrong path, file/folder doesn\'t exist')); } $share->setNode($path); + try { + $share->getNode()->lock(ILockingProvider::LOCK_SHARED); + } catch (LockedException $e) { + return new \OC_OCS_Result(null, 404, 'Could not create share'); + } + // Parse permissions (if available) $permissions = $this->request->getParam('permissions', null); if ($permissions === null) { @@ -248,6 +264,7 @@ class Share20OCS { } if ($permissions < 0 || $permissions > \OCP\Constants::PERMISSION_ALL) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, 'invalid permissions'); } @@ -275,17 +292,20 @@ class Share20OCS { if ($shareType === \OCP\Share::SHARE_TYPE_USER) { // Valid user is required to share if ($shareWith === null || !$this->userManager->userExists($shareWith)) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, $this->l->t('Please specify a valid user')); } $share->setSharedWith($shareWith); $share->setPermissions($permissions); } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { if (!$this->shareManager->allowGroupSharing()) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, $this->l->t('Group sharing is disabled by the administrator')); } // Valid group is required to share if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, $this->l->t('Please specify a valid group')); } $share->setSharedWith($shareWith); @@ -293,6 +313,7 @@ class Share20OCS { } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { //Can we even share links? if (!$this->shareManager->shareApiAllowLinks()) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, $this->l->t('Public link sharing is disabled by the administrator')); } @@ -302,6 +323,7 @@ class Share20OCS { */ $existingShares = $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0); if (!empty($existingShares)) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result($this->formatShare($existingShares[0])); } @@ -309,11 +331,13 @@ class Share20OCS { if ($publicUpload === 'true') { // Check if public upload is allowed if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 403, $this->l->t('Public upload disabled by the administrator')); } // Public upload can only be set for folders if ($path instanceof \OCP\Files\File) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, $this->l->t('Public upload is only possible for publicly shared folders')); } @@ -341,18 +365,21 @@ class Share20OCS { $expireDate = $this->parseDate($expireDate); $share->setExpirationDate($expireDate); } catch (\Exception $e) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, $this->l->t('Invalid date, date format must be YYYY-MM-DD')); } } } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 403, $this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType])); } $share->setSharedWith($shareWith); $share->setPermissions($permissions); } else { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 400, $this->l->t('Unknown share type')); } @@ -363,13 +390,18 @@ class Share20OCS { $share = $this->shareManager->createShare($share); } catch (GenericShareException $e) { $code = $e->getCode() === 0 ? 403 : $e->getCode(); + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, $code, $e->getHint()); }catch (\Exception $e) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 403, $e->getMessage()); } - $share = $this->formatShare($share); - return new \OC_OCS_Result($share); + $output = $this->formatShare($share); + + $share->getNode()->unlock(\OCP\Lock\ILockingProvider::LOCK_SHARED); + + return new \OC_OCS_Result($output); } /** @@ -454,17 +486,28 @@ class Share20OCS { $userFolder = $this->rootFolder->getUserFolder($this->currentUser->getUID()); try { $path = $userFolder->get($path); + $path->lock(ILockingProvider::LOCK_SHARED); } catch (\OCP\Files\NotFoundException $e) { return new \OC_OCS_Result(null, 404, $this->l->t('Wrong path, file/folder doesn\'t exist')); + } catch (LockedException $e) { + return new \OC_OCS_Result(null, 404, $this->l->t('Could not lock path')); } } if ($sharedWithMe === 'true') { - return $this->getSharedWithMe($path); + $result = $this->getSharedWithMe($path); + if ($path !== null) { + $path->unlock(ILockingProvider::LOCK_SHARED); + } + return $result; } if ($subfiles === 'true') { - return $this->getSharesInDir($path); + $result = $this->getSharesInDir($path); + if ($path !== null) { + $path->unlock(ILockingProvider::LOCK_SHARED); + } + return $result; } if ($reshares === 'true') { @@ -494,6 +537,10 @@ class Share20OCS { } } + if ($path !== null) { + $path->unlock(ILockingProvider::LOCK_SHARED); + } + return new \OC_OCS_Result($formatted); } @@ -512,7 +559,10 @@ class Share20OCS { return new \OC_OCS_Result(null, 404, $this->l->t('Wrong share ID, share doesn\'t exist')); } + $share->getNode()->lock(\OCP\Lock\ILockingProvider::LOCK_SHARED); + if (!$this->canAccessShare($share)) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, $this->l->t('Wrong share ID, share doesn\'t exist')); } @@ -526,6 +576,7 @@ class Share20OCS { */ if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 400, 'Wrong or no update parameter given'); } @@ -543,15 +594,18 @@ class Share20OCS { if ($newPermissions !== null && $newPermissions !== \OCP\Constants::PERMISSION_READ && $newPermissions !== (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 400, $this->l->t('Can\'t change permissions for public share links')); } if ($newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)) { if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 403, $this->l->t('Public upload disabled by the administrator')); } if (!($share->getNode() instanceof \OCP\Files\Folder)) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 400, $this->l->t('Public upload is only possible for publicly shared folders')); } } @@ -566,6 +620,7 @@ class Share20OCS { try { $expireDate = $this->parseDate($expireDate); } catch (\Exception $e) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 400, $e->getMessage()); } $share->setExpirationDate($expireDate); @@ -580,6 +635,7 @@ class Share20OCS { } else { // For other shares only permissions is valid. if ($permissions === null) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 400, $this->l->t('Wrong or no update parameter given')); } else { $permissions = (int)$permissions; @@ -599,6 +655,7 @@ class Share20OCS { } if ($share->getPermissions() & ~$maxPermissions) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 404, $this->l->t('Cannot increase permissions')); } } @@ -608,9 +665,12 @@ class Share20OCS { try { $share = $this->shareManager->updateShare($share); } catch (\Exception $e) { + $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new \OC_OCS_Result(null, 400, $e->getMessage()); } + $share->getNode()->unlock(\OCP\Lock\ILockingProvider::LOCK_SHARED); + return new \OC_OCS_Result($this->formatShare($share)); } diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index e0cbfd7f5ba..da573d11ec5 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -33,13 +33,6 @@ $l = \OC::$server->getL10N('files_sharing'); \OC::$CLASSPATH['OC_Share_Backend_File'] = 'files_sharing/lib/share/file.php'; \OC::$CLASSPATH['OC_Share_Backend_Folder'] = 'files_sharing/lib/share/folder.php'; \OC::$CLASSPATH['OC\Files\Storage\Shared'] = 'files_sharing/lib/sharedstorage.php'; -\OC::$CLASSPATH['OC\Files\Cache\SharedScanner'] = 'files_sharing/lib/scanner.php'; -\OC::$CLASSPATH['OC\Files\Cache\Shared_Cache'] = 'files_sharing/lib/cache.php'; -\OC::$CLASSPATH['OC\Files\Cache\Shared_Permissions'] = 'files_sharing/lib/permissions.php'; -\OC::$CLASSPATH['OC\Files\Cache\Shared_Updater'] = 'files_sharing/lib/updater.php'; -\OC::$CLASSPATH['OC\Files\Cache\Shared_Watcher'] = 'files_sharing/lib/watcher.php'; -\OC::$CLASSPATH['OCA\Files\Share\Maintainer'] = 'files_sharing/lib/maintainer.php'; -\OC::$CLASSPATH['OCA\Files\Share\Proxy'] = 'files_sharing/lib/proxy.php'; $application = new Application(); $application->registerMountProviders(); diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index 4dcdaa892ad..abd75282579 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -23,7 +23,7 @@ * */ -namespace OC\Files\Cache; +namespace OCA\Files_Sharing; use OC\Files\Cache\Wrapper\CacheJail; use OCP\Files\Cache\ICacheEntry; @@ -34,7 +34,7 @@ use OCP\Files\Storage\IStorage; * * don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead */ -class Shared_Cache extends CacheJail { +class Cache extends CacheJail { /** * @var \OC\Files\Storage\Shared */ diff --git a/apps/files_sharing/lib/helper.php b/apps/files_sharing/lib/helper.php index 8dad84eca49..500d82cb2d2 100644 --- a/apps/files_sharing/lib/helper.php +++ b/apps/files_sharing/lib/helper.php @@ -36,9 +36,9 @@ use OCP\User; class Helper { public static function registerHooks() { - \OCP\Util::connectHook('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Shared_Updater', 'renameHook'); + \OCP\Util::connectHook('OC_Filesystem', 'post_rename', '\OCA\Files_Sharing\Updater', 'renameHook'); \OCP\Util::connectHook('OC_Filesystem', 'post_delete', '\OCA\Files_Sharing\Hooks', 'unshareChildren'); - \OCP\Util::connectHook('OC_Appconfig', 'post_set_value', '\OCA\Files\Share\Maintainer', 'configChangeHook'); + \OCP\Util::connectHook('OC_Appconfig', 'post_set_value', '\OCA\Files_Sharing\Maintainer', 'configChangeHook'); \OCP\Util::connectHook('OC_User', 'post_deleteUser', '\OCA\Files_Sharing\Hooks', 'deleteUser'); } diff --git a/apps/files_sharing/lib/maintainer.php b/apps/files_sharing/lib/maintainer.php index a728f6bbb67..1d06a34bd0c 100644 --- a/apps/files_sharing/lib/maintainer.php +++ b/apps/files_sharing/lib/maintainer.php @@ -20,7 +20,7 @@ * */ -namespace OCA\Files\Share; +namespace OCA\Files_Sharing; /** * Maintains stuff around the sharing functionality diff --git a/apps/files_sharing/lib/scanner.php b/apps/files_sharing/lib/scanner.php index 2e951423aa2..215c0a7b6ae 100644 --- a/apps/files_sharing/lib/scanner.php +++ b/apps/files_sharing/lib/scanner.php @@ -21,15 +21,14 @@ * */ -namespace OC\Files\Cache; +namespace OCA\Files_Sharing; use OC\Files\ObjectStore\NoopScanner; -use OC\Files\Storage\Shared; /** * Scanner for SharedStorage */ -class SharedScanner extends Scanner { +class Scanner extends \OC\Files\Cache\Scanner { private $sourceScanner; /** diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 1a040364f11..ce214822aa7 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -318,14 +318,14 @@ class Shared extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage { if (!$storage) { $storage = $this; } - return new \OC\Files\Cache\Shared_Cache($storage, $this->sourceStorage, $this->sourceRootInfo); + return new \OCA\Files_Sharing\Cache($storage, $this->sourceStorage, $this->sourceRootInfo); } public function getScanner($path = '', $storage = null) { if (!$storage) { $storage = $this; } - return new \OC\Files\Cache\SharedScanner($storage); + return new \OCA\Files_Sharing\Scanner($storage); } public function getPropagator($storage = null) { diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index de68e2ea0fc..02c349e94b6 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -25,9 +25,9 @@ * */ -namespace OC\Files\Cache; +namespace OCA\Files_Sharing; -class Shared_Updater { +class Updater { /** * @param array $params @@ -85,21 +85,6 @@ class Shared_Updater { } /** - * clean up oc_share table from files which are no longer exists - * - * This fixes issues from updates from files_sharing < 0.3.5.6 (ownCloud 4.5) - * It will just be called during the update of the app - */ - static public function fixBrokenSharesOnAppUpdate() { - // delete all shares where the original file no longer exists - $findAndRemoveShares = \OCP\DB::prepare('DELETE FROM `*PREFIX*share` ' . - 'WHERE `item_type` IN (\'file\', \'folder\') ' . - 'AND `file_source` NOT IN (SELECT `fileid` FROM `*PREFIX*filecache`)' - ); - $findAndRemoveShares->execute(array()); - } - - /** * rename mount point from the children if the parent was renamed * * @param string $oldPath old path relative to data/user/files diff --git a/apps/files_sharing/tests/api/share20ocstest.php b/apps/files_sharing/tests/api/share20ocstest.php index 56c350aa99a..ffb74da2af7 100644 --- a/apps/files_sharing/tests/api/share20ocstest.php +++ b/apps/files_sharing/tests/api/share20ocstest.php @@ -29,6 +29,7 @@ use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUser; use OCP\Files\IRootFolder; +use OCP\Lock\LockedException; /** * Class Share20OCSTest @@ -137,8 +138,11 @@ class Share20OCSTest extends \Test\TestCase { } public function testDeleteShare() { + $node = $this->getMock('\OCP\Files\File'); + $share = $this->newShare(); - $share->setSharedBy($this->currentUser->getUID()); + $share->setSharedBy($this->currentUser->getUID()) + ->setNode($node); $this->shareManager ->expects($this->once()) ->method('getShareById') @@ -149,10 +153,45 @@ class Share20OCSTest extends \Test\TestCase { ->method('deleteShare') ->with($share); + $node->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $node->expects($this->once()) + ->method('unlock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $expected = new \OC_OCS_Result(); $this->assertEquals($expected, $this->ocs->deleteShare(42)); } + public function testDeleteShareLocked() { + $node = $this->getMock('\OCP\Files\File'); + + $share = $this->newShare(); + $share->setSharedBy($this->currentUser->getUID()) + ->setNode($node); + $this->shareManager + ->expects($this->once()) + ->method('getShareById') + ->with('ocinternal:42') + ->willReturn($share); + $this->shareManager + ->expects($this->never()) + ->method('deleteShare') + ->with($share); + + $node->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED) + ->will($this->throwException(new LockedException('mypath'))); + $node->expects($this->never()) + ->method('unlock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + + $expected = new \OC_OCS_Result(null, 404, 'could not delete share'); + $this->assertEquals($expected, $this->ocs->deleteShare(42)); + } + /* * FIXME: Enable once we have a federated Share Provider @@ -526,7 +565,7 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareInvalidPermissions() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); $this->request @@ -548,6 +587,10 @@ class Share20OCSTest extends \Test\TestCase { ->with('valid-path') ->willReturn($path); + $path->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $expected = new \OC_OCS_Result(null, 404, 'invalid permissions'); $result = $this->ocs->createShare(); @@ -557,7 +600,7 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareUserNoShareWith() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); $this->request @@ -585,6 +628,10 @@ class Share20OCSTest extends \Test\TestCase { ->with('valid-path') ->willReturn($path); + $path->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $expected = new \OC_OCS_Result(null, 404, 'Please specify a valid user'); $result = $this->ocs->createShare(); @@ -594,7 +641,7 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareUserNoValidShareWith() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); $this->request @@ -625,6 +672,10 @@ class Share20OCSTest extends \Test\TestCase { $expected = new \OC_OCS_Result(null, 404, 'Please specify a valid user'); + $path->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $result = $this->ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -632,9 +683,8 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareUser() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); - $this->shareManager->method('createShare')->will($this->returnArgument(0)); $ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS') ->setConstructorArgs([ @@ -677,15 +727,26 @@ class Share20OCSTest extends \Test\TestCase { $this->userManager->method('userExists')->with('validUser')->willReturn(true); - $share->method('setNode')->with($path); - $share->method('setPermissions') - ->with( - \OCP\Constants::PERMISSION_ALL & - ~\OCP\Constants::PERMISSION_DELETE & - ~\OCP\Constants::PERMISSION_CREATE); - $share->method('setShareType')->with(\OCP\Share::SHARE_TYPE_USER); - $share->method('setSharedWith')->with('validUser'); - $share->method('setSharedBy')->with('currentUser'); + $path->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $path->expects($this->once()) + ->method('unlock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + + $this->shareManager->method('createShare') + ->with($this->callback(function (\OCP\Share\IShare $share) use ($path) { + return $share->getNode() === $path && + $share->getPermissions() === ( + \OCP\Constants::PERMISSION_ALL & + ~\OCP\Constants::PERMISSION_DELETE & + ~\OCP\Constants::PERMISSION_CREATE + ) && + $share->getShareType() === \OCP\Share::SHARE_TYPE_USER && + $share->getSharedWith() === 'validUser' && + $share->getSharedBy() === 'currentUser'; + })) + ->will($this->returnArgument(0)); $expected = new \OC_OCS_Result(); $result = $ocs->createShare(); @@ -695,7 +756,7 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareGroupNoValidShareWith() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); $this->shareManager->method('createShare')->will($this->returnArgument(0)); @@ -727,6 +788,10 @@ class Share20OCSTest extends \Test\TestCase { $expected = new \OC_OCS_Result(null, 404, 'Please specify a valid user'); + $path->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $result = $this->ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -734,9 +799,8 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareGroup() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); - $this->shareManager->method('createShare')->will($this->returnArgument(0)); $ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS') ->setConstructorArgs([ @@ -783,11 +847,22 @@ class Share20OCSTest extends \Test\TestCase { ->method('allowGroupSharing') ->willReturn(true); - $share->method('setNode')->with($path); - $share->method('setPermissions')->with(\OCP\Constants::PERMISSION_ALL); - $share->method('setShareType')->with(\OCP\Share::SHARE_TYPE_GROUP); - $share->method('setSharedWith')->with('validGroup'); - $share->method('setSharedBy')->with('currentUser'); + $path->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $path->expects($this->once()) + ->method('unlock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + + $this->shareManager->method('createShare') + ->with($this->callback(function (\OCP\Share\IShare $share) use ($path) { + return $share->getNode() === $path && + $share->getPermissions() === \OCP\Constants::PERMISSION_ALL && + $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && + $share->getSharedWith() === 'validGroup' && + $share->getSharedBy() === 'currentUser'; + })) + ->will($this->returnArgument(0)); $expected = new \OC_OCS_Result(); $result = $ocs->createShare(); @@ -797,7 +872,7 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareGroupNotAllowed() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); $this->request @@ -832,9 +907,8 @@ class Share20OCSTest extends \Test\TestCase { ->method('allowGroupSharing') ->willReturn(false); - $share->method('setNode')->with($path); - $expected = new \OC_OCS_Result(null, 404, 'Group sharing is disabled by the administrator'); + $result = $this->ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1154,7 +1228,13 @@ class Share20OCSTest extends \Test\TestCase { } public function testUpdateShareCantAccess() { - $share = \OC::$server->getShareManager()->newShare(); + $node = $this->getMock('\OCP\Files\Folder'); + $share = $this->newShare(); + $share->setNode($node); + + $node->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); @@ -1166,10 +1246,16 @@ class Share20OCSTest extends \Test\TestCase { } public function testUpdateNoParametersLink() { - $share = \OC::$server->getShareManager()->newShare(); + $node = $this->getMock('\OCP\Files\Folder'); + $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setSharedBy($this->currentUser->getUID()) - ->setShareType(\OCP\Share::SHARE_TYPE_LINK); + ->setShareType(\OCP\Share::SHARE_TYPE_LINK) + ->setNode($node); + + $node->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); @@ -1181,10 +1267,16 @@ class Share20OCSTest extends \Test\TestCase { } public function testUpdateNoParametersOther() { - $share = \OC::$server->getShareManager()->newShare(); + $node = $this->getMock('\OCP\Files\Folder'); + $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setSharedBy($this->currentUser->getUID()) - ->setShareType(\OCP\Share::SHARE_TYPE_GROUP); + ->setShareType(\OCP\Share::SHARE_TYPE_GROUP) + ->setNode($node); + + $node->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); @@ -1198,13 +1290,22 @@ class Share20OCSTest extends \Test\TestCase { public function testUpdateLinkShareClear() { $ocs = $this->mockFormatShare(); - $share = \OC::$server->getShareManager()->newShare(); + $node = $this->getMock('\OCP\Files\Folder'); + $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setSharedBy($this->currentUser->getUID()) ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setPassword('password') ->setExpirationDate(new \DateTime()) - ->setPermissions(\OCP\Constants::PERMISSION_ALL); + ->setPermissions(\OCP\Constants::PERMISSION_ALL) + ->setNode($node); + + $node->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $node->expects($this->once()) + ->method('unlock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); $this->request ->method('getParam') @@ -1364,13 +1465,22 @@ class Share20OCSTest extends \Test\TestCase { $date = new \DateTime('2000-01-01'); $date->setTime(0,0,0); - $share = \OC::$server->getShareManager()->newShare(); + $node = $this->getMock('\OCP\Files\File'); + $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setSharedBy($this->currentUser->getUID()) ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setPassword('password') ->setExpirationDate($date) - ->setPermissions(\OCP\Constants::PERMISSION_ALL); + ->setPermissions(\OCP\Constants::PERMISSION_ALL) + ->setNode($node); + + $node->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $node->expects($this->once()) + ->method('unlock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); $this->request ->method('getParam') @@ -1398,13 +1508,15 @@ class Share20OCSTest extends \Test\TestCase { public function testUpdateLinkShareExpireDateDoesNotChangeOther() { $ocs = $this->mockFormatShare(); - $share = \OC::$server->getShareManager()->newShare(); + $node = $this->getMock('\OCP\Files\File'); + $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setSharedBy($this->currentUser->getUID()) ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setPassword('password') ->setExpirationDate(new \DateTime()) - ->setPermissions(\OCP\Constants::PERMISSION_ALL); + ->setPermissions(\OCP\Constants::PERMISSION_ALL) + ->setNode($node); $this->request ->method('getParam') @@ -1412,6 +1524,13 @@ class Share20OCSTest extends \Test\TestCase { ['expireDate', null, '2010-12-23'], ])); + $node->expects($this->once()) + ->method('lock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $node->expects($this->once()) + ->method('unlock') + ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->expects($this->once())->method('updateShare')->with( |