Skip to content

Commit 3dfbab0

Browse files
authored
Merge pull request #733 from nextcloud/artonge/dept/own_is-encrypted
feat: Own the handling of the is-encrypted DAV property
2 parents da63d9d + e13fe98 commit 3dfbab0

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

lib/Connector/Sabre/PropFindPlugin.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
use Sabre\HTTP\RequestInterface;
3838

3939
class PropFindPlugin extends APlugin {
40+
public const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted';
41+
4042
private UserAgentManager $userAgentManager;
4143
private IRequest $request;
4244
protected ?Server $server = null;
@@ -59,9 +61,19 @@ public function initialize(Server $server) {
5961

6062
$this->server = $server;
6163
$this->server->on('afterMethod:PROPFIND', [$this, 'checkAccess'], 50);
64+
$this->server->on('propFind', [$this, 'setEncryptedProperty'], 104);
6265
$this->server->on('propFind', [$this, 'updateProperty'], 105);
6366
}
6467

68+
public function setEncryptedProperty(PropFind $propFind, \Sabre\DAV\INode $node) {
69+
// Only folders can be e2e encrypted, so we only respond for directories.
70+
if ($node instanceof Directory) {
71+
$propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function () use ($node) {
72+
return $node->getFileInfo()->isEncrypted() ? '1' : '0';
73+
});
74+
}
75+
}
76+
6577
/**
6678
* Remove permissions of end-to-end encrypted files for unsupported clients
6779
*

tests/Unit/Connector/Sabre/PropFindPluginTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public function testInitialize(): void {
8686
->method('on')
8787
->withConsecutive(
8888
['afterMethod:PROPFIND', [$this->plugin, 'checkAccess'], 50],
89+
['propFind', [$this->plugin, 'setEncryptedProperty'], 104],
8990
['propFind', [$this->plugin, 'updateProperty'], 105],
9091
);
9192

tests/stub.phpstub

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ namespace Sabre\DAV {
6565
public function set(string $key, string $value, int $stuff) {}
6666
public function getPath(): string {}
6767
public function setPath(string $string): void {}
68+
public function handle($propertyName, $valueOrCallBack)
6869
}
6970

7071
class Server {

0 commit comments

Comments
 (0)