Skip to content
16 changes: 9 additions & 7 deletions apps/dav/lib/BulkUpload/BulkUploadPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @copyright Copyright (c) 2021, Louis Chemineau <[email protected]>
*
* @author Louis Chemineau <[email protected]>
* @author Côme Chilliet <[email protected]>
*
* @license AGPL-3.0
*
Expand Down Expand Up @@ -32,14 +33,13 @@
use OCA\DAV\Connector\Sabre\MtimeSanitizer;

class BulkUploadPlugin extends ServerPlugin {
private Folder $userFolder;
private LoggerInterface $logger;

/** @var Folder */
private $userFolder;

/** @var LoggerInterface */
private $logger;

public function __construct(Folder $userFolder, LoggerInterface $logger) {
public function __construct(
Folder $userFolder,
LoggerInterface $logger
) {
$this->userFolder = $userFolder;
$this->logger = $logger;
}
Expand Down Expand Up @@ -95,6 +95,8 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
$writtenFiles[$headers['x-file-path']] = [
"error" => false,
"etag" => $node->getETag(),
"fileid" => \OCP\Util::getDavFileId($node->getId()),
"permissions" => \OCP\Util::getDavPermissions($node),
];
} catch (\Exception $e) {
$this->logger->error($e->getMessage(), ['path' => $headers['x-file-path']]);
Expand Down
16 changes: 13 additions & 3 deletions apps/dav/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
* @author Thomas Müller <[email protected]>
* @author Louis Chemineau <[email protected]>
* @author Côme Chilliet <[email protected]>
*
* @license AGPL-3.0
*
Expand All @@ -23,15 +24,24 @@
namespace OCA\DAV;

use OCP\Capabilities\ICapability;
use OCP\IConfig;

class Capabilities implements ICapability {
private IConfig $config;

public function __construct(IConfig $config) {
$this->config = $config;
}

public function getCapabilities() {
return [
$capabilities = [
'dav' => [
'chunking' => '1.0',
// disabled because of https://github.com/nextcloud/desktop/issues/4243
// 'bulkupload' => '1.0',
]
];
if ($this->config->getSystemValueBool('bulkupload.enabled', true)) {
$capabilities['dav']['bulkupload'] = '1.0';
}
return $capabilities;
}
}
36 changes: 3 additions & 33 deletions apps/dav/lib/Connector/Sabre/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,8 @@ public function getId() {
* @return string|null
*/
public function getFileId() {
if ($this->info->getId()) {
$instanceId = \OC_Util::getInstanceId();
$id = sprintf('%08d', $this->info->getId());
return $id . $instanceId;
if ($id = $this->info->getId()) {
return \OCP\Util::getDavFileId($id);
}

return null;
Expand Down Expand Up @@ -381,35 +379,7 @@ public function getNoteFromShare($user) {
* @return string
*/
public function getDavPermissions() {
$p = '';
if ($this->info->isShared()) {
$p .= 'S';
}
if ($this->info->isShareable()) {
$p .= 'R';
}
if ($this->info->isMounted()) {
$p .= 'M';
}
if ($this->info->isReadable()) {
$p .= 'G';
}
if ($this->info->isDeletable()) {
$p .= 'D';
}
if ($this->info->isUpdateable()) {
$p .= 'NV'; // Renameable, Moveable
}
if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
if ($this->info->isUpdateable()) {
$p .= 'W';
}
} else {
if ($this->info->isCreatable()) {
$p .= 'CK';
}
}
return $p;
return \OCP\Util::getDavPermissions($this->info);
}

public function getOwner() {
Expand Down
5 changes: 4 additions & 1 deletion apps/dav/lib/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@ public function __construct(IRequest $request, string $baseUri) {
$view
));
$this->server->addPlugin(
new BulkUploadPlugin($userFolder, $logger)
new BulkUploadPlugin(
$userFolder,
$logger
)
);
}
$this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin(
Expand Down
26 changes: 23 additions & 3 deletions apps/dav/tests/unit/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,39 @@
namespace OCA\DAV\Tests\unit;

use OCA\DAV\Capabilities;
use OCP\IConfig;
use Test\TestCase;

/**
* @package OCA\DAV\Tests\unit
*/
class CapabilitiesTest extends TestCase {
public function testGetCapabilities() {
$capabilities = new Capabilities();
$config = $this->createMock(IConfig::class);
$config->expects($this->once())
->method('getSystemValueBool')
->with('bulkupload.enabled', $this->isType('bool'))
->willReturn(false);
$capabilities = new Capabilities($config);
$expected = [
'dav' => [
'chunking' => '1.0',
// disabled because of https://github.com/nextcloud/desktop/issues/4243
// 'bulkupload' => '1.0',
],
];
$this->assertSame($expected, $capabilities->getCapabilities());
}

public function testGetCapabilitiesWithBulkUpload() {
$config = $this->createMock(IConfig::class);
$config->expects($this->once())
->method('getSystemValueBool')
->with('bulkupload.enabled', $this->isType('bool'))
->willReturn(true);
$capabilities = new Capabilities($config);
$expected = [
'dav' => [
'chunking' => '1.0',
'bulkupload' => '1.0',
],
];
$this->assertSame($expected, $capabilities->getCapabilities());
Expand Down
7 changes: 7 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -2238,4 +2238,11 @@
* Defaults to ``false``
*/
'projects.enabled' => false,

/**
* Enable the bulk upload feature.
*
* Defaults to ``true``
*/
'bulkupload.enabled' => true,
];
49 changes: 49 additions & 0 deletions lib/public/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,4 +628,53 @@ public static function isFunctionEnabled(string $functionName): bool {
}
return true;
}

/**
* Compute the fileId to use for dav responses
*
* @param int $id Id of the file returned by FileInfo::getId
* @since 25.0.0
*/
public static function getDavFileId(int $id): string {
$instanceId = \OC_Util::getInstanceId();
$id = sprintf('%08d', $id);
return $id . $instanceId;
}

/**
* Compute the format needed for returning permissions for dav
*
* @since 25.0.0
*/
public static function getDavPermissions(\OCP\Files\FileInfo $info): string {
$p = '';
if ($info->isShared()) {
$p .= 'S';
}
if ($info->isShareable()) {
$p .= 'R';
}
if ($info->isMounted()) {
$p .= 'M';
}
if ($info->isReadable()) {
$p .= 'G';
}
if ($info->isDeletable()) {
$p .= 'D';
}
if ($info->isUpdateable()) {
$p .= 'NV'; // Renameable, Moveable
}
if ($info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
if ($info->isUpdateable()) {
$p .= 'W';
}
} else {
if ($info->isCreatable()) {
$p .= 'CK';
}
}
return $p;
}
}