Skip to content

Commit

Permalink
Show sharees via propfind
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
  • Loading branch information
tobiasKaminsky committed Feb 28, 2019
1 parent 1a537bc commit 3ff5424
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
5 changes: 5 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 SHAREES_PROPERTYNAME = '{http://nextcloud.org/ns}sharees';

/**
* 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::SHAREES_PROPERTYNAME;

// normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
$allowedProperties = ['{DAV:}getetag'];
Expand Down Expand Up @@ -359,6 +361,9 @@ 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::SHAREES_PROPERTYNAME, function() use ($node, $httpRequest) {
return $node->getShareeFromShare($httpRequest->getRawServerValue('PHP_AUTH_USER'));
});
}

if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
Expand Down
59 changes: 59 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,9 @@
use OCP\Files\StorageNotAvailableException;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use OCP\Share;
use OCP\Share\IShare;
use OCP\Lock\ILockingProvider;


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

/**
* @param string $user
* @return string
*/
public function getShareeFromShare($user) {
$sharees = [];

if ($user == null) {
return $sharees;
}
$types = [
Share::SHARE_TYPE_USER,
Share::SHARE_TYPE_REMOTE,
Share::SHARE_TYPE_GROUP,
];

if ($this->getPath() === "/") {
return $sharees;
}

$path = $this->getPath();

if ($path !== null) {
$userFolder = \OC::$server->getRootFolder()->getUserFolder($user);
try {
$path = $userFolder->get($path);
$this->lock($path);
} catch (\OCP\Files\NotFoundException $e) {
throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist'));
} catch (LockedException $e) {
throw new OCSNotFoundException($this->l->t('Could not lock path'));
}
}

foreach ($types as $shareType) {
$shares = $this->shareManager->getSharesBy($user, $shareType, $path, false, -1, 0);
foreach ($shares as $share) {
if ($share->getSharedBy() === $user) {
$sharees[] = $share->getSharedWith();
}
}
}
return implode(', ', $sharees);
}

/**
* Lock a Node
*
* @param \OCP\Files\Node $node
* @throws LockedException
*/
private function lock(\OCP\Files\Node $node) {
$node->lock(ILockingProvider::LOCK_SHARED);
$this->lockedNode = $node;
}

/**
* @return string
*/
Expand Down

0 comments on commit 3ff5424

Please sign in to comment.