diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index 28554bf3f1cd..082ebeacd344 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -61,6 +61,7 @@ class FilesPlugin extends ServerPlugin { const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name'; const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums'; const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint'; + const PRIVATE_LINK_PROPERTYNAME = '{http://owncloud.org/ns}privatelink'; /** * Reference to main server object @@ -140,6 +141,7 @@ public function initialize(\Sabre\DAV\Server $server) { $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME; $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME; $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME; + $server->protectedProperties[] = self::PRIVATE_LINK_PROPERTYNAME; // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH $allowedProperties = ['{DAV:}getetag']; @@ -308,6 +310,11 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { return $node->getSize(); }); + + $propFind->handle(self::PRIVATE_LINK_PROPERTYNAME, function() use ($node) { + return \OC::$server->getURLGenerator() + ->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileId' => $node->getInternalFileId()]); + }); } if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { diff --git a/apps/files/lib/Capabilities.php b/apps/files/lib/Capabilities.php index 9a2d90039230..983f10d57f14 100644 --- a/apps/files/lib/Capabilities.php +++ b/apps/files/lib/Capabilities.php @@ -57,6 +57,7 @@ public function getCapabilities() { 'preferredUploadType' => 'SHA1' ], 'files' => [ + 'privateLinks' => true, 'bigfilechunking' => true, 'blacklisted_files' => $this->config->getSystemValue('blacklisted_files', ['.htaccess']), ], diff --git a/tests/integration/features/bootstrap/WebDav.php b/tests/integration/features/bootstrap/WebDav.php index 7b2c87f7df32..eb2cdb931521 100644 --- a/tests/integration/features/bootstrap/WebDav.php +++ b/tests/integration/features/bootstrap/WebDav.php @@ -393,6 +393,36 @@ public function theSingleResponseShouldContainAPropertyWithValue($key, $expected } } + /** + * @Then the single response should contain a property :key with value like :regex + * @param string $key + * @param string $regex + * @throws \Exception + */ + public function theSingleResponseShouldContainAPropertyWithValueLike($key, $regex) { + $keys = $this->response; + if (!array_key_exists($key, $keys)) { + throw new \Exception("Cannot find property \"$key\" with \"$regex\""); + } + + $value = $keys[$key]; + if ($value instanceof ResourceType) { + $value = $value->getValue(); + if (empty($value)) { + $value = ''; + } else { + $value = $value[0]; + } + } + + if (preg_match($regex, $value)) { + return 0; + } else { + throw new \Exception("Property \"$key\" found with value \"$value\", expected \"$regex\""); + } + } + + /** * @Then the response should contain a share-types property with */ diff --git a/tests/integration/features/webdav-related-new-endpoint.feature b/tests/integration/features/webdav-related-new-endpoint.feature index 1c1a4d1b7d0f..914f1e50ee70 100644 --- a/tests/integration/features/webdav-related-new-endpoint.feature +++ b/tests/integration/features/webdav-related-new-endpoint.feature @@ -593,3 +593,12 @@ Feature: webdav-related-new-endpoint And user "user0" uploads new chunk file "3" with "CCCCC" to id "chunking-42" When user "user0" moves new chunk file with id "chunking-42" to "/myChunkedFile.txt" with size 15 Then the HTTP status code should be "201" + + Scenario: Retrieving private link + Given using new dav path + And user "user0" exists + And as an "user0" + And user "user0" uploads file "data/textfile.txt" to "/somefile.txt" + Then as "user0" gets properties of file "/somefile.txt" with + |{http://owncloud.org/ns}privatelink| + And the single response should contain a property "{http://owncloud.org/ns}privatelink" with value like "/(\/index.php\/f\/[0-9]*)/" diff --git a/tests/integration/features/webdav-related-old-endpoint.feature b/tests/integration/features/webdav-related-old-endpoint.feature index cf9c4883dffb..461091b419fe 100644 --- a/tests/integration/features/webdav-related-old-endpoint.feature +++ b/tests/integration/features/webdav-related-old-endpoint.feature @@ -507,3 +507,14 @@ Feature: webdav-related-old-endpoint And as "user1" the folder "/folderB/ONE" exists And as "user1" the folder "/folderB/ONE/TWO" exists And user "user1" checks id of file "/folderB/ONE" + + + Scenario: Retrieving private link + Given using old dav path + And user "user0" exists + And as an "user0" + And user "user0" uploads file "data/textfile.txt" to "/somefile.txt" + Then as "user0" gets properties of file "/somefile.txt" with + |{http://owncloud.org/ns}privatelink| + And the single response should contain a property "{http://owncloud.org/ns}privatelink" with value like "/(\/index.php\/f\/[0-9]*)/" +