Return -3 for unlimited quota
Returns -3 for unlimited quota in Webdav response. Also adjusted personal page to show unlimited quota when set.
This commit is contained in:
parent
a38e8b6436
commit
11215f4e27
9 changed files with 158 additions and 23 deletions
|
@ -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) {
|
||||
|
|
|
@ -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->once())
|
||||
$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' => 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')
|
||||
->will($this->returnValueMap([
|
||||
['\OC\Files\Storage\Shared', false],
|
||||
['\OC\Files\Storage\Wrapper\Quota', true],
|
||||
]));
|
||||
|
||||
$storage->expects($this->once())
|
||||
->method('getQuota')
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -530,6 +530,14 @@ trait Provisioning {
|
|||
$this->sendingToWith("PUT", "/cloud/users/" . $user, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given user :user has unlimited quota
|
||||
*/
|
||||
public function userHasUnlimitedQuota($user)
|
||||
{
|
||||
$this->userHasAQuotaOf($user, 'none');
|
||||
}
|
||||
|
||||
/**
|
||||
* @BeforeScenario
|
||||
* @AfterScenario
|
||||
|
|
|
@ -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) {
|
||||
|
@ -49,6 +49,14 @@ trait Sharing{
|
|||
$this->lastShareData = $this->response->xml();
|
||||
}
|
||||
|
||||
/**
|
||||
* @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$/
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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')];
|
||||
|
|
Loading…
Reference in a new issue