Skip to content

Commit

Permalink
Add note to dav endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasKaminsky committed Dec 10, 2018
1 parent b3de7a7 commit d1e6f2c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apps/dav/lib/Connector/Sabre/FilesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class FilesPlugin extends ServerPlugin {
const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview';
const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type';
const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted';
const SHARE_NOTE = '{http://nextcloud.org/ns}note';

/**
* Reference to main server object
Expand Down Expand Up @@ -161,6 +162,7 @@ public function initialize(\Sabre\DAV\Server $server) {
$server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME;
$server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME;
$server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME;
$server->protectedProperties[] = self::SHARE_NOTE;

// normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
$allowedProperties = ['{DAV:}getetag'];
Expand Down Expand Up @@ -359,6 +361,12 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
$propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
return $node->getFileInfo()->getMountPoint()->getMountType();
});

$propFind->handle(self::SHARE_NOTE, function() use ($node, $httpRequest) {
return $node->getNoteFromShare(
$httpRequest->getRawServerValue('PHP_AUTH_USER')
);
});
}

if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
Expand Down
29 changes: 29 additions & 0 deletions apps/dav/lib/Connector/Sabre/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
use OCP\Files\StorageNotAvailableException;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use OCP\Share;
use OCP\Share\IShare;


abstract class Node implements \Sabre\DAV\INode {
Expand Down Expand Up @@ -290,6 +292,33 @@ public function getSharePermissions($user) {
return $permissions;
}

/**
* @param string $user
* @return int
*/
public function getNoteFromShare($user) {
if ($user !== null) {
$userShares = $this->shareManager->getSharedWith($user, Share::SHARE_TYPE_USER, $this, -1);
$groupShares = $this->shareManager->getSharedWith($user, Share::SHARE_TYPE_GROUP, $this, -1);
$circleShares = $this->shareManager->getSharedWith($user, Share::SHARE_TYPE_CIRCLE, $this, -1);
$roomShares = $this->shareManager->getSharedWith($user, Share::SHARE_TYPE_ROOM, $this, -1);

$shares = array_merge($userShares, $groupShares, $circleShares, $roomShares);
$shares = array_filter($shares, function (IShare $share) use ($user) {
return $share->getShareOwner() !== $user;
});

$notes = "";
foreach ($shares as $share) {
$notes .= $share->getNote() . " ";
}

return $notes;
} else {
return "";
}
}

/**
* @return string
*/
Expand Down

0 comments on commit d1e6f2c

Please sign in to comment.