Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2019-07-23 10:31:13 +02:00
parent b81fb182b3
commit efa0733b04
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
2 changed files with 34 additions and 64 deletions

View file

@ -65,7 +65,3 @@ Options -Indexes
<IfModule pagespeed_module> <IfModule pagespeed_module>
ModPagespeed Off ModPagespeed Off
</IfModule> </IfModule>
#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####
ErrorDocument 403 //
ErrorDocument 404 //

View file

@ -27,13 +27,9 @@
*/ */
namespace OCA\DAV\Connector\Sabre; namespace OCA\DAV\Connector\Sabre;
use OCA\DAV\Connector\Sabre\Exception\FileLocked;
use \Sabre\DAV\PropFind; use \Sabre\DAV\PropFind;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\Share\IShare; 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 * Sabre Plugin to provide share-related properties
@ -223,67 +219,45 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
}); });
$propFind->handle(self::SHAREES_PROPERTYNAME, function() use ($sabreNode) { $propFind->handle(self::SHAREES_PROPERTYNAME, function() use ($sabreNode) {
$test = $this->server->httpRequest->getRawServerValue('PHP_AUTH_USER'); $user = $this->server->httpRequest->getRawServerValue('PHP_AUTH_USER');
return $this->getShareeFromShare($sabreNode, $test);
});
}
/** if ($user == null) {
* @param \Sabre\DAV\INode $sabreNode return [];
* @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) { if ($sabreNode->getPath() === "/") {
$shares = $this->shareManager->getSharesBy($user, $shareType, $path, false, -1, 0); return [];
foreach ($shares as $share) { }
if ($share->getSharedBy() === $user) {
$sharees[] = $share->getSharedWith(); $userFolder = \OC::$server->getRootFolder()->getUserFolder($user);
$path = $userFolder->get($sabreNode->getPath());
if (isset($this->cachedShareTypes[$sabreNode->getId()])) {
$shareTypes = $this->cachedShareTypes[$sabreNode->getId()];
} else {
list($parentPath,) = \Sabre\Uri\split($sabreNode->getPath());
if ($parentPath === '') {
$parentPath = '/';
}
// if we already cached the folder this file is in we know there are no shares for this file
if (array_search($parentPath, $this->cachedFolders) === false) {
$node = $this->userFolder->get($sabreNode->getPath());
$shareTypes = $this->getShareTypes($node);
} else {
return [];
} }
} }
}
return implode(', ', $sharees);
}
/** foreach ($shareTypes as $shareType) {
* Lock a Node $shares = $this->shareManager->getSharesBy($user, $shareType, $path, false, -1, 0);
*
* @param \OCP\Files\Node $node foreach ($shares as $share) {
* @throws LockedException if ($share->getSharedBy() === $user) {
*/ $sharees[] = $share->getSharedWith();
private function lock(\OCP\Files\Node $node) { }
$node->lock(ILockingProvider::LOCK_SHARED); }
$this->lockedNode = $node; }
return implode(', ', $sharees);
});
} }
} }