Skip to content

Commit

Permalink
feat: Own the handling of the is-encrypted DAV property
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed Aug 26, 2024
1 parent da63d9d commit ce0ad25
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/Connector/Sabre/PropFindPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
use Sabre\HTTP\RequestInterface;

class PropFindPlugin extends APlugin {
public const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted';

private UserAgentManager $userAgentManager;
private IRequest $request;
protected ?Server $server = null;
Expand All @@ -59,9 +61,19 @@ public function initialize(Server $server) {

$this->server = $server;
$this->server->on('afterMethod:PROPFIND', [$this, 'checkAccess'], 50);
$this->server->on('propFind', [$this, 'setEncryptedProperty'], 104);
$this->server->on('propFind', [$this, 'updateProperty'], 105);
}

public function setEncryptedProperty(PropFind $propFind, \Sabre\DAV\INode $node) {
// Only folders can be e2e encrypted, so we only respond for directories.
if ($node instanceof Directory) {
$propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function () use ($node) {
return $node->getFileInfo()->isEncrypted() ? '1' : '0';
});
}
}

/**
* Remove permissions of end-to-end encrypted files for unsupported clients
*
Expand Down
1 change: 1 addition & 0 deletions tests/stub.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace Sabre\DAV {
public function set(string $key, string $value, int $stuff) {}
public function getPath(): string {}
public function setPath(string $string): void {}
public function handle($propertyName, $valueOrCallBack)
}

class Server {
Expand Down

0 comments on commit ce0ad25

Please sign in to comment.