Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip
Signed-off-by: tobiasKaminsky <[email protected]>
  • Loading branch information
tobiasKaminsky committed Jul 22, 2019
commit b81fb182b3d793882a1942c852e8c3d2262b3de9
4 changes: 4 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ Options -Indexes
<IfModule pagespeed_module>
ModPagespeed Off
</IfModule>
#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####

ErrorDocument 403 //
ErrorDocument 404 //
6 changes: 1 addition & 5 deletions apps/dav/lib/Connector/Sabre/FilesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class FilesPlugin extends ServerPlugin {
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';
const SHAREES_PROPERTYNAME = '{http://nextcloud.org/ns}sharees';

/**
* Reference to main server object
Expand Down Expand Up @@ -164,7 +163,6 @@ public function initialize(\Sabre\DAV\Server $server) {
$server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME;
$server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME;
$server->protectedProperties[] = self::SHARE_NOTE;
$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 @@ -363,14 +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')
);
});
$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
57 changes: 0 additions & 57 deletions apps/dav/lib/Connector/Sabre/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
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 @@ -324,62 +323,6 @@ public function getNoteFromShare($user) {
return '';
}

/**
* @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
71 changes: 71 additions & 0 deletions apps/dav/lib/Connector/Sabre/SharesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,23 @@
*/
namespace OCA\DAV\Connector\Sabre;

use OCA\DAV\Connector\Sabre\Exception\FileLocked;
use \Sabre\DAV\PropFind;
use OCP\IUserSession;
use OCP\Share\IShare;
use OCP\Files\NotFoundException;
use OCP\Lock\LockedException;
use \OCA\DAV\Connector\Sabre\Node;

/**
* Sabre Plugin to provide share-related properties
*/
class SharesPlugin extends \Sabre\DAV\ServerPlugin {

const NS_OWNCLOUD = 'http://owncloud.org/ns';
const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
const SHARETYPES_PROPERTYNAME = '{http://owncloud.org/ns}share-types';
const SHAREES_PROPERTYNAME = '{http://nextcloud.org/ns}sharees';

/**
* Reference to main server object
Expand Down Expand Up @@ -106,6 +112,7 @@ public function initialize(\Sabre\DAV\Server $server) {
$server->xml->namespacesMap[self::NS_OWNCLOUD] = 'oc';
$server->xml->elementMap[self::SHARETYPES_PROPERTYNAME] = ShareTypeList::class;
$server->protectedProperties[] = self::SHARETYPES_PROPERTYNAME;
$server->protectedProperties[] = self::SHAREES_PROPERTYNAME;

$this->server = $server;
$this->server->on('propFind', array($this, 'handleGetProperties'));
Expand Down Expand Up @@ -214,5 +221,69 @@ public function handleGetProperties(

return new ShareTypeList($shareTypes);
});

$propFind->handle(self::SHAREES_PROPERTYNAME, function() use ($sabreNode) {
$test = $this->server->httpRequest->getRawServerValue('PHP_AUTH_USER');
return $this->getShareeFromShare($sabreNode, $test);
});
}

/**
* @param \Sabre\DAV\INode $sabreNode
* @param string $user
* @return string
* @throws FileLocked
* @throws NotFoundException
*/
public function getShareeFromShare(\Sabre\DAV\INode $sabreNode, $user) {
$sharees = [];

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

if ($sabreNode->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 NotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist'));
} catch (LockedException $e) {
throw new FileLocked($e->getMessage(), $e->getCode(), $e);
}
}

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;
}
}