diff options
-rw-r--r-- | apps/dav/lib/connector/sabre/directory.php | 7 | ||||
-rw-r--r-- | apps/dav/tests/unit/connector/sabre/directory.php | 39 | ||||
-rw-r--r-- | apps/files_sharing/lib/sharedstorage.php | 4 | ||||
-rw-r--r-- | build/integration/features/bootstrap/Provisioning.php | 8 | ||||
-rw-r--r-- | build/integration/features/bootstrap/Sharing.php | 16 | ||||
-rw-r--r-- | build/integration/features/bootstrap/WebDav.php | 47 | ||||
-rw-r--r-- | build/integration/features/webdav-related.feature | 38 | ||||
-rw-r--r-- | lib/private/helper.php | 11 | ||||
-rw-r--r-- | settings/personal.php | 9 |
9 files changed, 157 insertions, 22 deletions
diff --git a/apps/dav/lib/connector/sabre/directory.php b/apps/dav/lib/connector/sabre/directory.php index 0119879a171..f31eff30b65 100644 --- a/apps/dav/lib/connector/sabre/directory.php +++ b/apps/dav/lib/connector/sabre/directory.php @@ -291,9 +291,14 @@ class Directory extends \OCA\DAV\Connector\Sabre\Node } try { $storageInfo = \OC_Helper::getStorageInfo($this->info->getPath(), $this->info); + if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) { + $free = \OCP\Files\FileInfo::SPACE_UNLIMITED; + } else { + $free = $storageInfo['free']; + } $this->quotaInfo = array( $storageInfo['used'], - $storageInfo['free'] + $free ); return $this->quotaInfo; } catch (\OCP\Files\StorageNotAvailableException $e) { diff --git a/apps/dav/tests/unit/connector/sabre/directory.php b/apps/dav/tests/unit/connector/sabre/directory.php index 317e089925b..c4ddc38b3e1 100644 --- a/apps/dav/tests/unit/connector/sabre/directory.php +++ b/apps/dav/tests/unit/connector/sabre/directory.php @@ -199,15 +199,48 @@ class Directory extends \Test\TestCase { $dir->getChild('.'); } - public function testGetQuotaInfo() { + public function testGetQuotaInfoUnlimited() { $storage = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Quota') ->disableOriginalConstructor() ->getMock(); + $storage->expects($this->any()) + ->method('instanceOfStorage') + ->will($this->returnValueMap([ + '\OC\Files\Storage\Shared' => false, + '\OC\Files\Storage\Wrapper\Quota' => false, + ])); + + $storage->expects($this->never()) + ->method('getQuota'); + $storage->expects($this->once()) + ->method('free_space') + ->will($this->returnValue(800)); + + $this->info->expects($this->once()) + ->method('getSize') + ->will($this->returnValue(200)); + + $this->info->expects($this->once()) + ->method('getStorage') + ->will($this->returnValue($storage)); + + $dir = new \OCA\DAV\Connector\Sabre\Directory($this->view, $this->info); + $this->assertEquals([200, -3], $dir->getQuotaInfo()); //200 used, unlimited + } + + public function testGetQuotaInfoSpecific() { + $storage = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Quota') + ->disableOriginalConstructor() + ->getMock(); + + $storage->expects($this->any()) ->method('instanceOfStorage') - ->with('\OC\Files\Storage\Wrapper\Quota') - ->will($this->returnValue(true)); + ->will($this->returnValueMap([ + ['\OC\Files\Storage\Shared', false], + ['\OC\Files\Storage\Wrapper\Quota', true], + ])); $storage->expects($this->once()) ->method('getQuota') diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 101503a03fb..600599d7175 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -725,4 +725,8 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage { list($targetStorage) = $this->ownerView->resolvePath($ownerPath); return $targetStorage->isLocal(); } + + public function getSourceStorage() { + return $this->sourceStorage; + } } diff --git a/build/integration/features/bootstrap/Provisioning.php b/build/integration/features/bootstrap/Provisioning.php index 65a6611b06c..6d710b2016f 100644 --- a/build/integration/features/bootstrap/Provisioning.php +++ b/build/integration/features/bootstrap/Provisioning.php @@ -531,6 +531,14 @@ trait Provisioning { } /** + * @Given user :user has unlimited quota + */ + public function userHasUnlimitedQuota($user) + { + $this->userHasAQuotaOf($user, 'none'); + } + + /** * @BeforeScenario * @AfterScenario */ diff --git a/build/integration/features/bootstrap/Sharing.php b/build/integration/features/bootstrap/Sharing.php index faf8e0bf507..ec270ef05ce 100644 --- a/build/integration/features/bootstrap/Sharing.php +++ b/build/integration/features/bootstrap/Sharing.php @@ -18,17 +18,17 @@ trait Sharing{ private $lastShareData = null; /** - * @When /^creating a share with$/ + * @Given /^as "([^"]*)" creating a share with$/ * @param \Behat\Gherkin\Node\TableNode|null $formData */ - public function creatingShare($body) { + public function asCreatingAShareWith($user, $body) { $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v1/shares"; $client = new Client(); $options = []; - if ($this->currentUser === 'admin') { + if ($user === 'admin') { $options['auth'] = $this->adminUser; } else { - $options['auth'] = [$this->currentUser, $this->regularUser]; + $options['auth'] = [$user, $this->regularUser]; } if ($body instanceof \Behat\Gherkin\Node\TableNode) { @@ -50,6 +50,14 @@ trait Sharing{ } /** + * @When /^creating a share with$/ + * @param \Behat\Gherkin\Node\TableNode|null $formData + */ + public function creatingShare($body) { + return $this->asCreatingAShareWith($this->currentUser, $body); + } + + /** * @Then /^Public shared file "([^"]*)" can be downloaded$/ */ public function checkPublicSharedFile($filename) { diff --git a/build/integration/features/bootstrap/WebDav.php b/build/integration/features/bootstrap/WebDav.php index be87a09731b..fa6761d9f71 100644 --- a/build/integration/features/bootstrap/WebDav.php +++ b/build/integration/features/bootstrap/WebDav.php @@ -20,7 +20,7 @@ trait WebDav { */ public function usingDavPath($davPath) { $this->davPath = $davPath; - } + } public function makeDavRequest($user, $method, $path, $headers, $body = null){ $fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath . "$path"; @@ -34,7 +34,7 @@ trait WebDav { $request = $client->createRequest($method, $fullUrl, $options); if (!is_null($headers)){ foreach ($headers as $key => $value) { - $request->addHeader($key, $value); + $request->addHeader($key, $value); } } @@ -84,7 +84,7 @@ trait WebDav { $client = new GClient(); $options = []; $options['auth'] = [$token, ""]; - + $request = $client->createRequest("GET", $fullUrl, $options); $request->addHeader('Range', $range); @@ -149,8 +149,37 @@ trait WebDav { } } + /** + * @Then /^as "([^"]*)" gets properties of folder "([^"]*)" with$/ + * @param \Behat\Gherkin\Node\TableNode|null $propertiesTable + */ + public function asGetsPropertiesOfFolderWith($user, $path, $propertiesTable) { + $properties = null; + if ($propertiesTable instanceof \Behat\Gherkin\Node\TableNode) { + foreach ($propertiesTable->getRows() as $row) { + $properties[] = $row[0]; + } + } + $this->response = $this->listFolder($user, $path, 0, $properties); + } + + /** + * @Then the single response should contain a property :key with value :value + */ + public function theSingleResponseShouldContainAPropertyWithValue($key, $expectedValue) { + $keys = $this->response; + if (!isset($keys[$key])) { + throw new \Exception("Cannot find property \"$key\" with \"$expectedalue\""); + } + + $value = $keys[$key]; + if ($value !== $expectedValue) { + throw new \Exception("Property \"$key\" found with value \"$value\", expected \"$expectedValue\""); + } + } + /*Returns the elements of a propfind, $folderDepth requires 1 to see elements without children*/ - public function listFolder($user, $path, $folderDepth){ + public function listFolder($user, $path, $folderDepth, $properties = null){ $fullUrl = substr($this->baseUrl, 0, -4); $settings = array( @@ -166,9 +195,13 @@ trait WebDav { $client = new SClient($settings); - $response = $client->propfind($this->davPath . "/", array( - '{DAV:}getetag' - ), $folderDepth); + if (!$properties) { + $properties = [ + '{DAV:}getetag' + ]; + } + + $response = $client->propfind($this->davPath . '/' . ltrim($path, '/'), $properties, $folderDepth); return $response; } diff --git a/build/integration/features/webdav-related.feature b/build/integration/features/webdav-related.feature index c4623a01ba2..63f205d1e4c 100644 --- a/build/integration/features/webdav-related.feature +++ b/build/integration/features/webdav-related.feature @@ -1,4 +1,4 @@ -Feature: sharing +Feature: webdav-related Background: Given using api version "1" @@ -23,6 +23,42 @@ Feature: sharing When User "user0" uploads file "data/textfile.txt" to "/asdf.txt" Then the HTTP status code should be "507" + Scenario: Retrieving folder quota when no quota is set + Given using dav path "remote.php/webdav" + And As an "admin" + And user "user0" exists + When user "user0" has unlimited quota + Then as "user0" gets properties of folder "/" with + |{DAV:}quota-available-bytes| + And the single response should contain a property "{DAV:}quota-available-bytes" with value "-3" + + Scenario: Retrieving folder quota when quota is set + Given using dav path "remote.php/webdav" + And As an "admin" + And user "user0" exists + When user "user0" has a quota of "10 MB" + Then as "user0" gets properties of folder "/" with + |{DAV:}quota-available-bytes| + And the single response should contain a property "{DAV:}quota-available-bytes" with value "10485429" + + Scenario: Retrieving folder quota of shared folder with quota when no quota is set for recipient + Given using dav path "remote.php/webdav" + And As an "admin" + And user "user0" exists + And user "user1" exists + And user "user0" has unlimited quota + And user "user1" has a quota of "10 MB" + And As an "user1" + And user "user1" created a folder "/testquota" + And as "user1" creating a share with + | path | testquota | + | shareType | 0 | + | permissions | 31 | + | shareWith | user0 | + Then as "user0" gets properties of folder "/testquota" with + |{DAV:}quota-available-bytes| + And the single response should contain a property "{DAV:}quota-available-bytes" with value "10485429" + Scenario: download a public shared file with range Given user "user0" exists And As an "user0" diff --git a/lib/private/helper.php b/lib/private/helper.php index 23068330f81..acdd27fc564 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -610,10 +610,12 @@ class OC_Helper { if ($used < 0) { $used = 0; } - $quota = 0; + $quota = \OCP\Files\FileInfo::SPACE_UNLIMITED; $storage = $rootInfo->getStorage(); - if ($includeExtStorage && $storage->instanceOfStorage('\OC\Files\Storage\Shared')) { + $sourceStorage = $storage; + if ($storage->instanceOfStorage('\OC\Files\Storage\Shared')) { $includeExtStorage = false; + $sourceStorage = $storage->getSourceStorage(); } if ($includeExtStorage) { $quota = OC_Util::getUserQuota(\OCP\User::getUser()); @@ -624,9 +626,9 @@ class OC_Helper { } // TODO: need a better way to get total space from storage - if ($storage->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota')) { + if ($sourceStorage->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota')) { /** @var \OC\Files\Storage\Wrapper\Quota $storage */ - $quota = $storage->getQuota(); + $quota = $sourceStorage->getQuota(); } $free = $storage->free_space(''); if ($free >= 0) { @@ -654,6 +656,7 @@ class OC_Helper { return [ 'free' => $free, 'used' => $used, + 'quota' => $quota, 'total' => $total, 'relative' => $relative, 'owner' => $ownerId, diff --git a/settings/personal.php b/settings/personal.php index d2d4fc90f5e..62a718985f8 100644 --- a/settings/personal.php +++ b/settings/personal.php @@ -137,9 +137,15 @@ if ($externalStorageEnabled) { // Return template +$l = \OC::$server->getL10N('settings'); $tmpl = new OC_Template( 'settings', 'personal', 'user'); $tmpl->assign('usage', OC_Helper::humanFileSize($storageInfo['used'])); -$tmpl->assign('total_space', OC_Helper::humanFileSize($storageInfo['total'])); +if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) { + $totalSpace = $l->t('Unlimited'); +} else { + $totalSpace = OC_Helper::humanFileSize($storageInfo['total']); +} +$tmpl->assign('total_space', $totalSpace); $tmpl->assign('usage_relative', $storageInfo['relative']); $tmpl->assign('clients', $clients); $tmpl->assign('email', $email); @@ -162,7 +168,6 @@ sort($groups2); $tmpl->assign('groups', $groups2); // add hardcoded forms from the template -$l = \OC::$server->getL10N('settings'); $formsAndMore = []; $formsAndMore[]= ['anchor' => 'avatar', 'section-name' => $l->t('Personal info')]; $formsAndMore[]= ['anchor' => 'clientsbox', 'section-name' => $l->t('Sync clients')]; |