Merge pull request #12978 from tobiasKaminsky/noteOnDav

Add note to dav endpoint
This commit is contained in:
Morris Jobke 2019-03-04 12:58:09 +01:00 committed by GitHub
commit daee222534
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 0 deletions

View File

@ -70,6 +70,7 @@ class FilesPlugin extends ServerPlugin {
const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview'; const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview';
const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type'; const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type';
const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted'; const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted';
const SHARE_NOTE = '{http://nextcloud.org/ns}note';
/** /**
* Reference to main server object * Reference to main server object
@ -161,6 +162,7 @@ class FilesPlugin extends ServerPlugin {
$server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME; $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME;
$server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME; $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME;
$server->protectedProperties[] = self::IS_ENCRYPTED_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 // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
$allowedProperties = ['{DAV:}getetag']; $allowedProperties = ['{DAV:}getetag'];
@ -359,6 +361,12 @@ class FilesPlugin extends ServerPlugin {
$propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
return $node->getFileInfo()->getMountPoint()->getMountType(); 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) { if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {

View File

@ -41,6 +41,8 @@ use OCP\Files\FileInfo;
use OCP\Files\StorageNotAvailableException; use OCP\Files\StorageNotAvailableException;
use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager; use OCP\Share\IManager;
use OCP\Share;
use OCP\Share\IShare;
abstract class Node implements \Sabre\DAV\INode { abstract class Node implements \Sabre\DAV\INode {
@ -290,6 +292,35 @@ abstract class Node implements \Sabre\DAV\INode {
return $permissions; return $permissions;
} }
/**
* @param string $user
* @return string
*/
public function getNoteFromShare($user) {
if ($user === null) {
return '';
}
$types = [
Share::SHARE_TYPE_USER,
Share::SHARE_TYPE_GROUP,
Share::SHARE_TYPE_CIRCLE,
Share::SHARE_TYPE_ROOM
];
foreach ($types as $shareType) {
$shares = $this->shareManager->getSharedWith($user, $shareType, $this, -1);
foreach ($shares as $share) {
$note = $share->getNote();
if($share->getShareOwner() !== $user && !empty($note)) {
return $note;
}
}
}
return '';
}
/** /**
* @return string * @return string
*/ */