@@ -24,42 +24,42 @@ |
||
| 24 | 24 | |
| 25 | 25 | class Forbidden extends \Sabre\DAV\Exception\Forbidden { |
| 26 | 26 | |
| 27 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 27 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var bool |
|
| 31 | - */ |
|
| 32 | - private $retry; |
|
| 29 | + /** |
|
| 30 | + * @var bool |
|
| 31 | + */ |
|
| 32 | + private $retry; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param string $message |
|
| 36 | - * @param bool $retry |
|
| 37 | - * @param \Exception $previous |
|
| 38 | - */ |
|
| 39 | - public function __construct($message, $retry = false, \Exception $previous = null) { |
|
| 40 | - parent::__construct($message, 0, $previous); |
|
| 41 | - $this->retry = $retry; |
|
| 42 | - } |
|
| 34 | + /** |
|
| 35 | + * @param string $message |
|
| 36 | + * @param bool $retry |
|
| 37 | + * @param \Exception $previous |
|
| 38 | + */ |
|
| 39 | + public function __construct($message, $retry = false, \Exception $previous = null) { |
|
| 40 | + parent::__construct($message, 0, $previous); |
|
| 41 | + $this->retry = $retry; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * This method allows the exception to include additional information |
|
| 46 | - * into the WebDAV error response |
|
| 47 | - * |
|
| 48 | - * @param \Sabre\DAV\Server $server |
|
| 49 | - * @param \DOMElement $errorNode |
|
| 50 | - * @return void |
|
| 51 | - */ |
|
| 52 | - public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
| 44 | + /** |
|
| 45 | + * This method allows the exception to include additional information |
|
| 46 | + * into the WebDAV error response |
|
| 47 | + * |
|
| 48 | + * @param \Sabre\DAV\Server $server |
|
| 49 | + * @param \DOMElement $errorNode |
|
| 50 | + * @return void |
|
| 51 | + */ |
|
| 52 | + public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
| 53 | 53 | |
| 54 | - // set ownCloud namespace |
|
| 55 | - $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
| 54 | + // set ownCloud namespace |
|
| 55 | + $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
| 56 | 56 | |
| 57 | - // adding the retry node |
|
| 58 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
| 59 | - $errorNode->appendChild($error); |
|
| 57 | + // adding the retry node |
|
| 58 | + $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
| 59 | + $errorNode->appendChild($error); |
|
| 60 | 60 | |
| 61 | - // adding the message node |
|
| 62 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
| 63 | - $errorNode->appendChild($error); |
|
| 64 | - } |
|
| 61 | + // adding the message node |
|
| 62 | + $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
| 63 | + $errorNode->appendChild($error); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -49,17 +49,17 @@ |
||
| 49 | 49 | * @param \DOMElement $errorNode |
| 50 | 50 | * @return void |
| 51 | 51 | */ |
| 52 | - public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
| 52 | + public function serialize(\Sabre\DAV\Server $server, \DOMElement $errorNode) { |
|
| 53 | 53 | |
| 54 | 54 | // set ownCloud namespace |
| 55 | 55 | $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
| 56 | 56 | |
| 57 | 57 | // adding the retry node |
| 58 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
| 58 | + $error = $errorNode->ownerDocument->createElementNS('o:', 'o:retry', var_export($this->retry, true)); |
|
| 59 | 59 | $errorNode->appendChild($error); |
| 60 | 60 | |
| 61 | 61 | // adding the message node |
| 62 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
| 62 | + $error = $errorNode->ownerDocument->createElementNS('o:', 'o:reason', $this->getMessage()); |
|
| 63 | 63 | $errorNode->appendChild($error); |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -26,53 +26,53 @@ |
||
| 26 | 26 | |
| 27 | 27 | class InvalidPath extends Exception { |
| 28 | 28 | |
| 29 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 29 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var bool |
|
| 33 | - */ |
|
| 34 | - private $retry; |
|
| 31 | + /** |
|
| 32 | + * @var bool |
|
| 33 | + */ |
|
| 34 | + private $retry; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param string $message |
|
| 38 | - * @param bool $retry |
|
| 39 | - */ |
|
| 40 | - public function __construct($message, $retry = false) { |
|
| 41 | - parent::__construct($message); |
|
| 42 | - $this->retry = $retry; |
|
| 43 | - } |
|
| 36 | + /** |
|
| 37 | + * @param string $message |
|
| 38 | + * @param bool $retry |
|
| 39 | + */ |
|
| 40 | + public function __construct($message, $retry = false) { |
|
| 41 | + parent::__construct($message); |
|
| 42 | + $this->retry = $retry; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Returns the HTTP status code for this exception |
|
| 47 | - * |
|
| 48 | - * @return int |
|
| 49 | - */ |
|
| 50 | - public function getHTTPCode() { |
|
| 45 | + /** |
|
| 46 | + * Returns the HTTP status code for this exception |
|
| 47 | + * |
|
| 48 | + * @return int |
|
| 49 | + */ |
|
| 50 | + public function getHTTPCode() { |
|
| 51 | 51 | |
| 52 | - return 400; |
|
| 52 | + return 400; |
|
| 53 | 53 | |
| 54 | - } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * This method allows the exception to include additional information |
|
| 58 | - * into the WebDAV error response |
|
| 59 | - * |
|
| 60 | - * @param \Sabre\DAV\Server $server |
|
| 61 | - * @param \DOMElement $errorNode |
|
| 62 | - * @return void |
|
| 63 | - */ |
|
| 64 | - public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
| 56 | + /** |
|
| 57 | + * This method allows the exception to include additional information |
|
| 58 | + * into the WebDAV error response |
|
| 59 | + * |
|
| 60 | + * @param \Sabre\DAV\Server $server |
|
| 61 | + * @param \DOMElement $errorNode |
|
| 62 | + * @return void |
|
| 63 | + */ |
|
| 64 | + public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
| 65 | 65 | |
| 66 | - // set ownCloud namespace |
|
| 67 | - $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
| 66 | + // set ownCloud namespace |
|
| 67 | + $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
| 68 | 68 | |
| 69 | - // adding the retry node |
|
| 70 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
| 71 | - $errorNode->appendChild($error); |
|
| 69 | + // adding the retry node |
|
| 70 | + $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
| 71 | + $errorNode->appendChild($error); |
|
| 72 | 72 | |
| 73 | - // adding the message node |
|
| 74 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
| 75 | - $errorNode->appendChild($error); |
|
| 76 | - } |
|
| 73 | + // adding the message node |
|
| 74 | + $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
| 75 | + $errorNode->appendChild($error); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | } |
@@ -61,17 +61,17 @@ |
||
| 61 | 61 | * @param \DOMElement $errorNode |
| 62 | 62 | * @return void |
| 63 | 63 | */ |
| 64 | - public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
| 64 | + public function serialize(\Sabre\DAV\Server $server, \DOMElement $errorNode) { |
|
| 65 | 65 | |
| 66 | 66 | // set ownCloud namespace |
| 67 | 67 | $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
| 68 | 68 | |
| 69 | 69 | // adding the retry node |
| 70 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
| 70 | + $error = $errorNode->ownerDocument->createElementNS('o:', 'o:retry', var_export($this->retry, true)); |
|
| 71 | 71 | $errorNode->appendChild($error); |
| 72 | 72 | |
| 73 | 73 | // adding the message node |
| 74 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
| 74 | + $error = $errorNode->ownerDocument->createElementNS('o:', 'o:reason', $this->getMessage()); |
|
| 75 | 75 | $errorNode->appendChild($error); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -29,27 +29,27 @@ |
||
| 29 | 29 | |
| 30 | 30 | class PasswordLoginForbidden extends NotAuthenticated { |
| 31 | 31 | |
| 32 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 33 | - |
|
| 34 | - public function getHTTPCode() { |
|
| 35 | - return 401; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * This method allows the exception to include additional information |
|
| 40 | - * into the WebDAV error response |
|
| 41 | - * |
|
| 42 | - * @param Server $server |
|
| 43 | - * @param DOMElement $errorNode |
|
| 44 | - * @return void |
|
| 45 | - */ |
|
| 46 | - public function serialize(Server $server, DOMElement $errorNode) { |
|
| 47 | - |
|
| 48 | - // set ownCloud namespace |
|
| 49 | - $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
| 50 | - |
|
| 51 | - $error = $errorNode->ownerDocument->createElementNS('o:', 'o:hint', 'password login forbidden'); |
|
| 52 | - $errorNode->appendChild($error); |
|
| 53 | - } |
|
| 32 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 33 | + |
|
| 34 | + public function getHTTPCode() { |
|
| 35 | + return 401; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * This method allows the exception to include additional information |
|
| 40 | + * into the WebDAV error response |
|
| 41 | + * |
|
| 42 | + * @param Server $server |
|
| 43 | + * @param DOMElement $errorNode |
|
| 44 | + * @return void |
|
| 45 | + */ |
|
| 46 | + public function serialize(Server $server, DOMElement $errorNode) { |
|
| 47 | + |
|
| 48 | + // set ownCloud namespace |
|
| 49 | + $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
| 50 | + |
|
| 51 | + $error = $errorNode->ownerDocument->createElementNS('o:', 'o:hint', 'password login forbidden'); |
|
| 52 | + $errorNode->appendChild($error); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | 55 | } |
@@ -30,20 +30,20 @@ |
||
| 30 | 30 | |
| 31 | 31 | class FileLocked extends \Sabre\DAV\Exception { |
| 32 | 32 | |
| 33 | - public function __construct($message = "", $code = 0, Exception $previous = null) { |
|
| 34 | - if($previous instanceof \OCP\Files\LockNotAcquiredException) { |
|
| 35 | - $message = sprintf('Target file %s is locked by another process.', $previous->path); |
|
| 36 | - } |
|
| 37 | - parent::__construct($message, $code, $previous); |
|
| 38 | - } |
|
| 33 | + public function __construct($message = "", $code = 0, Exception $previous = null) { |
|
| 34 | + if($previous instanceof \OCP\Files\LockNotAcquiredException) { |
|
| 35 | + $message = sprintf('Target file %s is locked by another process.', $previous->path); |
|
| 36 | + } |
|
| 37 | + parent::__construct($message, $code, $previous); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Returns the HTTP status code for this exception |
|
| 42 | - * |
|
| 43 | - * @return int |
|
| 44 | - */ |
|
| 45 | - public function getHTTPCode() { |
|
| 40 | + /** |
|
| 41 | + * Returns the HTTP status code for this exception |
|
| 42 | + * |
|
| 43 | + * @return int |
|
| 44 | + */ |
|
| 45 | + public function getHTTPCode() { |
|
| 46 | 46 | |
| 47 | - return 423; |
|
| 48 | - } |
|
| 47 | + return 423; |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | class FileLocked extends \Sabre\DAV\Exception { |
| 32 | 32 | |
| 33 | 33 | public function __construct($message = "", $code = 0, Exception $previous = null) { |
| 34 | - if($previous instanceof \OCP\Files\LockNotAcquiredException) { |
|
| 34 | + if ($previous instanceof \OCP\Files\LockNotAcquiredException) { |
|
| 35 | 35 | $message = sprintf('Target file %s is locked by another process.', $previous->path); |
| 36 | 36 | } |
| 37 | 37 | parent::__construct($message, $code, $previous); |
@@ -31,15 +31,15 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class UnsupportedMediaType extends \Sabre\DAV\Exception { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Returns the HTTP status code for this exception |
|
| 36 | - * |
|
| 37 | - * @return int |
|
| 38 | - */ |
|
| 39 | - public function getHTTPCode() { |
|
| 34 | + /** |
|
| 35 | + * Returns the HTTP status code for this exception |
|
| 36 | + * |
|
| 37 | + * @return int |
|
| 38 | + */ |
|
| 39 | + public function getHTTPCode() { |
|
| 40 | 40 | |
| 41 | - return 415; |
|
| 41 | + return 415; |
|
| 42 | 42 | |
| 43 | - } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | } |
@@ -31,15 +31,15 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class EntityTooLarge extends \Sabre\DAV\Exception { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Returns the HTTP status code for this exception |
|
| 36 | - * |
|
| 37 | - * @return int |
|
| 38 | - */ |
|
| 39 | - public function getHTTPCode() { |
|
| 34 | + /** |
|
| 35 | + * Returns the HTTP status code for this exception |
|
| 36 | + * |
|
| 37 | + * @return int |
|
| 38 | + */ |
|
| 39 | + public function getHTTPCode() { |
|
| 40 | 40 | |
| 41 | - return 413; |
|
| 41 | + return 413; |
|
| 42 | 42 | |
| 43 | - } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
| 118 | 118 | // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
| 119 | 119 | // we do not provide locking we emulate it using a fake locking plugin. |
| 120 | - if($this->request->isUserAgent([ |
|
| 120 | + if ($this->request->isUserAgent([ |
|
| 121 | 121 | '/WebDAVFS/', |
| 122 | 122 | '/Microsoft Office OneNote 2013/', |
| 123 | 123 | '/Microsoft-WebDAV-MiniRedir/', |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // wait with registering these until auth is handled and the filesystem is setup |
| 133 | - $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) { |
|
| 133 | + $server->on('beforeMethod', function() use ($server, $objectTree, $viewCallBack) { |
|
| 134 | 134 | // ensure the skeleton is copied |
| 135 | 135 | $userFolder = \OC::$server->getUserFolder(); |
| 136 | 136 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | ); |
| 163 | 163 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view)); |
| 164 | 164 | |
| 165 | - if($this->userSession->isLoggedIn()) { |
|
| 165 | + if ($this->userSession->isLoggedIn()) { |
|
| 166 | 166 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); |
| 167 | 167 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin( |
| 168 | 168 | $objectTree, |
@@ -43,158 +43,158 @@ |
||
| 43 | 43 | use Sabre\DAV\Auth\Plugin; |
| 44 | 44 | |
| 45 | 45 | class ServerFactory { |
| 46 | - /** @var IConfig */ |
|
| 47 | - private $config; |
|
| 48 | - /** @var ILogger */ |
|
| 49 | - private $logger; |
|
| 50 | - /** @var IDBConnection */ |
|
| 51 | - private $databaseConnection; |
|
| 52 | - /** @var IUserSession */ |
|
| 53 | - private $userSession; |
|
| 54 | - /** @var IMountManager */ |
|
| 55 | - private $mountManager; |
|
| 56 | - /** @var ITagManager */ |
|
| 57 | - private $tagManager; |
|
| 58 | - /** @var IRequest */ |
|
| 59 | - private $request; |
|
| 60 | - /** @var IPreview */ |
|
| 61 | - private $previewManager; |
|
| 46 | + /** @var IConfig */ |
|
| 47 | + private $config; |
|
| 48 | + /** @var ILogger */ |
|
| 49 | + private $logger; |
|
| 50 | + /** @var IDBConnection */ |
|
| 51 | + private $databaseConnection; |
|
| 52 | + /** @var IUserSession */ |
|
| 53 | + private $userSession; |
|
| 54 | + /** @var IMountManager */ |
|
| 55 | + private $mountManager; |
|
| 56 | + /** @var ITagManager */ |
|
| 57 | + private $tagManager; |
|
| 58 | + /** @var IRequest */ |
|
| 59 | + private $request; |
|
| 60 | + /** @var IPreview */ |
|
| 61 | + private $previewManager; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @param IConfig $config |
|
| 65 | - * @param ILogger $logger |
|
| 66 | - * @param IDBConnection $databaseConnection |
|
| 67 | - * @param IUserSession $userSession |
|
| 68 | - * @param IMountManager $mountManager |
|
| 69 | - * @param ITagManager $tagManager |
|
| 70 | - * @param IRequest $request |
|
| 71 | - * @param IPreview $previewManager |
|
| 72 | - */ |
|
| 73 | - public function __construct( |
|
| 74 | - IConfig $config, |
|
| 75 | - ILogger $logger, |
|
| 76 | - IDBConnection $databaseConnection, |
|
| 77 | - IUserSession $userSession, |
|
| 78 | - IMountManager $mountManager, |
|
| 79 | - ITagManager $tagManager, |
|
| 80 | - IRequest $request, |
|
| 81 | - IPreview $previewManager |
|
| 82 | - ) { |
|
| 83 | - $this->config = $config; |
|
| 84 | - $this->logger = $logger; |
|
| 85 | - $this->databaseConnection = $databaseConnection; |
|
| 86 | - $this->userSession = $userSession; |
|
| 87 | - $this->mountManager = $mountManager; |
|
| 88 | - $this->tagManager = $tagManager; |
|
| 89 | - $this->request = $request; |
|
| 90 | - $this->previewManager = $previewManager; |
|
| 91 | - } |
|
| 63 | + /** |
|
| 64 | + * @param IConfig $config |
|
| 65 | + * @param ILogger $logger |
|
| 66 | + * @param IDBConnection $databaseConnection |
|
| 67 | + * @param IUserSession $userSession |
|
| 68 | + * @param IMountManager $mountManager |
|
| 69 | + * @param ITagManager $tagManager |
|
| 70 | + * @param IRequest $request |
|
| 71 | + * @param IPreview $previewManager |
|
| 72 | + */ |
|
| 73 | + public function __construct( |
|
| 74 | + IConfig $config, |
|
| 75 | + ILogger $logger, |
|
| 76 | + IDBConnection $databaseConnection, |
|
| 77 | + IUserSession $userSession, |
|
| 78 | + IMountManager $mountManager, |
|
| 79 | + ITagManager $tagManager, |
|
| 80 | + IRequest $request, |
|
| 81 | + IPreview $previewManager |
|
| 82 | + ) { |
|
| 83 | + $this->config = $config; |
|
| 84 | + $this->logger = $logger; |
|
| 85 | + $this->databaseConnection = $databaseConnection; |
|
| 86 | + $this->userSession = $userSession; |
|
| 87 | + $this->mountManager = $mountManager; |
|
| 88 | + $this->tagManager = $tagManager; |
|
| 89 | + $this->request = $request; |
|
| 90 | + $this->previewManager = $previewManager; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * @param string $baseUri |
|
| 95 | - * @param string $requestUri |
|
| 96 | - * @param Plugin $authPlugin |
|
| 97 | - * @param callable $viewCallBack callback that should return the view for the dav endpoint |
|
| 98 | - * @return Server |
|
| 99 | - */ |
|
| 100 | - public function createServer($baseUri, |
|
| 101 | - $requestUri, |
|
| 102 | - Plugin $authPlugin, |
|
| 103 | - callable $viewCallBack) { |
|
| 104 | - // Fire up server |
|
| 105 | - $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree(); |
|
| 106 | - $server = new \OCA\DAV\Connector\Sabre\Server($objectTree); |
|
| 107 | - // Set URL explicitly due to reverse-proxy situations |
|
| 108 | - $server->httpRequest->setUrl($requestUri); |
|
| 109 | - $server->setBaseUri($baseUri); |
|
| 93 | + /** |
|
| 94 | + * @param string $baseUri |
|
| 95 | + * @param string $requestUri |
|
| 96 | + * @param Plugin $authPlugin |
|
| 97 | + * @param callable $viewCallBack callback that should return the view for the dav endpoint |
|
| 98 | + * @return Server |
|
| 99 | + */ |
|
| 100 | + public function createServer($baseUri, |
|
| 101 | + $requestUri, |
|
| 102 | + Plugin $authPlugin, |
|
| 103 | + callable $viewCallBack) { |
|
| 104 | + // Fire up server |
|
| 105 | + $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree(); |
|
| 106 | + $server = new \OCA\DAV\Connector\Sabre\Server($objectTree); |
|
| 107 | + // Set URL explicitly due to reverse-proxy situations |
|
| 108 | + $server->httpRequest->setUrl($requestUri); |
|
| 109 | + $server->setBaseUri($baseUri); |
|
| 110 | 110 | |
| 111 | - // Load plugins |
|
| 112 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); |
|
| 113 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config)); |
|
| 114 | - $server->addPlugin($authPlugin); |
|
| 115 | - // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to / |
|
| 116 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin()); |
|
| 117 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger)); |
|
| 118 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 119 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 120 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
| 121 | - if($this->request->isUserAgent([ |
|
| 122 | - '/WebDAVFS/', |
|
| 123 | - '/Microsoft Office OneNote 2013/', |
|
| 124 | - '/Microsoft-WebDAV-MiniRedir/', |
|
| 125 | - ])) { |
|
| 126 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin()); |
|
| 127 | - } |
|
| 111 | + // Load plugins |
|
| 112 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); |
|
| 113 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config)); |
|
| 114 | + $server->addPlugin($authPlugin); |
|
| 115 | + // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to / |
|
| 116 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin()); |
|
| 117 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger)); |
|
| 118 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 119 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 120 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
| 121 | + if($this->request->isUserAgent([ |
|
| 122 | + '/WebDAVFS/', |
|
| 123 | + '/Microsoft Office OneNote 2013/', |
|
| 124 | + '/Microsoft-WebDAV-MiniRedir/', |
|
| 125 | + ])) { |
|
| 126 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin()); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) { |
|
| 130 | - $server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 131 | - } |
|
| 129 | + if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) { |
|
| 130 | + $server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - // wait with registering these until auth is handled and the filesystem is setup |
|
| 134 | - $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) { |
|
| 135 | - // ensure the skeleton is copied |
|
| 136 | - $userFolder = \OC::$server->getUserFolder(); |
|
| 133 | + // wait with registering these until auth is handled and the filesystem is setup |
|
| 134 | + $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) { |
|
| 135 | + // ensure the skeleton is copied |
|
| 136 | + $userFolder = \OC::$server->getUserFolder(); |
|
| 137 | 137 | |
| 138 | - /** @var \OC\Files\View $view */ |
|
| 139 | - $view = $viewCallBack($server); |
|
| 140 | - if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) { |
|
| 141 | - $rootInfo = $userFolder; |
|
| 142 | - } else { |
|
| 143 | - $rootInfo = $view->getFileInfo(''); |
|
| 144 | - } |
|
| 138 | + /** @var \OC\Files\View $view */ |
|
| 139 | + $view = $viewCallBack($server); |
|
| 140 | + if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) { |
|
| 141 | + $rootInfo = $userFolder; |
|
| 142 | + } else { |
|
| 143 | + $rootInfo = $view->getFileInfo(''); |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - // Create Nextcloud Dir |
|
| 147 | - if ($rootInfo->getType() === 'dir') { |
|
| 148 | - $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree); |
|
| 149 | - } else { |
|
| 150 | - $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo); |
|
| 151 | - } |
|
| 152 | - $objectTree->init($root, $view, $this->mountManager); |
|
| 146 | + // Create Nextcloud Dir |
|
| 147 | + if ($rootInfo->getType() === 'dir') { |
|
| 148 | + $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree); |
|
| 149 | + } else { |
|
| 150 | + $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo); |
|
| 151 | + } |
|
| 152 | + $objectTree->init($root, $view, $this->mountManager); |
|
| 153 | 153 | |
| 154 | - $server->addPlugin( |
|
| 155 | - new \OCA\DAV\Connector\Sabre\FilesPlugin( |
|
| 156 | - $objectTree, |
|
| 157 | - $this->config, |
|
| 158 | - $this->request, |
|
| 159 | - $this->previewManager, |
|
| 160 | - false, |
|
| 161 | - !$this->config->getSystemValue('debug', false) |
|
| 162 | - ) |
|
| 163 | - ); |
|
| 164 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view)); |
|
| 154 | + $server->addPlugin( |
|
| 155 | + new \OCA\DAV\Connector\Sabre\FilesPlugin( |
|
| 156 | + $objectTree, |
|
| 157 | + $this->config, |
|
| 158 | + $this->request, |
|
| 159 | + $this->previewManager, |
|
| 160 | + false, |
|
| 161 | + !$this->config->getSystemValue('debug', false) |
|
| 162 | + ) |
|
| 163 | + ); |
|
| 164 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view)); |
|
| 165 | 165 | |
| 166 | - if($this->userSession->isLoggedIn()) { |
|
| 167 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); |
|
| 168 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin( |
|
| 169 | - $objectTree, |
|
| 170 | - $this->userSession, |
|
| 171 | - $userFolder, |
|
| 172 | - \OC::$server->getShareManager() |
|
| 173 | - )); |
|
| 174 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession)); |
|
| 175 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin( |
|
| 176 | - $objectTree, |
|
| 177 | - $view, |
|
| 178 | - \OC::$server->getSystemTagManager(), |
|
| 179 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 180 | - \OC::$server->getTagManager(), |
|
| 181 | - $this->userSession, |
|
| 182 | - \OC::$server->getGroupManager(), |
|
| 183 | - $userFolder |
|
| 184 | - )); |
|
| 185 | - // custom properties plugin must be the last one |
|
| 186 | - $server->addPlugin( |
|
| 187 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 188 | - new \OCA\DAV\Connector\Sabre\CustomPropertiesBackend( |
|
| 189 | - $objectTree, |
|
| 190 | - $this->databaseConnection, |
|
| 191 | - $this->userSession->getUser() |
|
| 192 | - ) |
|
| 193 | - ) |
|
| 194 | - ); |
|
| 195 | - } |
|
| 196 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin()); |
|
| 197 | - }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request |
|
| 198 | - return $server; |
|
| 199 | - } |
|
| 166 | + if($this->userSession->isLoggedIn()) { |
|
| 167 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); |
|
| 168 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin( |
|
| 169 | + $objectTree, |
|
| 170 | + $this->userSession, |
|
| 171 | + $userFolder, |
|
| 172 | + \OC::$server->getShareManager() |
|
| 173 | + )); |
|
| 174 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession)); |
|
| 175 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin( |
|
| 176 | + $objectTree, |
|
| 177 | + $view, |
|
| 178 | + \OC::$server->getSystemTagManager(), |
|
| 179 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 180 | + \OC::$server->getTagManager(), |
|
| 181 | + $this->userSession, |
|
| 182 | + \OC::$server->getGroupManager(), |
|
| 183 | + $userFolder |
|
| 184 | + )); |
|
| 185 | + // custom properties plugin must be the last one |
|
| 186 | + $server->addPlugin( |
|
| 187 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 188 | + new \OCA\DAV\Connector\Sabre\CustomPropertiesBackend( |
|
| 189 | + $objectTree, |
|
| 190 | + $this->databaseConnection, |
|
| 191 | + $this->userSession->getUser() |
|
| 192 | + ) |
|
| 193 | + ) |
|
| 194 | + ); |
|
| 195 | + } |
|
| 196 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin()); |
|
| 197 | + }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request |
|
| 198 | + return $server; |
|
| 199 | + } |
|
| 200 | 200 | } |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | // verify path of the target |
| 131 | 131 | $this->verifyPath(); |
| 132 | 132 | |
| 133 | - $newPath = $parentPath . '/' . $newName; |
|
| 133 | + $newPath = $parentPath.'/'.$newName; |
|
| 134 | 134 | |
| 135 | 135 | $this->fileView->rename($this->path, $newPath); |
| 136 | 136 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | public function getLastModified() { |
| 152 | 152 | $timestamp = $this->info->getMtime(); |
| 153 | 153 | if (!empty($timestamp)) { |
| 154 | - return (int)$timestamp; |
|
| 154 | + return (int) $timestamp; |
|
| 155 | 155 | } |
| 156 | 156 | return $timestamp; |
| 157 | 157 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | * @return string |
| 179 | 179 | */ |
| 180 | 180 | public function getETag() { |
| 181 | - return '"' . $this->info->getEtag() . '"'; |
|
| 181 | + return '"'.$this->info->getEtag().'"'; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | if ($this->info->getId()) { |
| 218 | 218 | $instanceId = \OC_Util::getInstanceId(); |
| 219 | 219 | $id = sprintf('%08d', $this->info->getId()); |
| 220 | - return $id . $instanceId; |
|
| 220 | + return $id.$instanceId; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | return null; |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | |
| 253 | 253 | if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
| 254 | 254 | /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
| 255 | - $permissions = (int)$storage->getShare()->getPermissions(); |
|
| 255 | + $permissions = (int) $storage->getShare()->getPermissions(); |
|
| 256 | 256 | } else { |
| 257 | 257 | $permissions = $storage->getPermissions($path); |
| 258 | 258 | } |
@@ -43,315 +43,315 @@ |
||
| 43 | 43 | |
| 44 | 44 | abstract class Node implements \Sabre\DAV\INode { |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var \OC\Files\View |
|
| 48 | - */ |
|
| 49 | - protected $fileView; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * The path to the current node |
|
| 53 | - * |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - protected $path; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * node properties cache |
|
| 60 | - * |
|
| 61 | - * @var array |
|
| 62 | - */ |
|
| 63 | - protected $property_cache = null; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var \OCP\Files\FileInfo |
|
| 67 | - */ |
|
| 68 | - protected $info; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @var IManager |
|
| 72 | - */ |
|
| 73 | - protected $shareManager; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Sets up the node, expects a full path name |
|
| 77 | - * |
|
| 78 | - * @param \OC\Files\View $view |
|
| 79 | - * @param \OCP\Files\FileInfo $info |
|
| 80 | - * @param IManager $shareManager |
|
| 81 | - */ |
|
| 82 | - public function __construct(View $view, FileInfo $info, IManager $shareManager = null) { |
|
| 83 | - $this->fileView = $view; |
|
| 84 | - $this->path = $this->fileView->getRelativePath($info->getPath()); |
|
| 85 | - $this->info = $info; |
|
| 86 | - if ($shareManager) { |
|
| 87 | - $this->shareManager = $shareManager; |
|
| 88 | - } else { |
|
| 89 | - $this->shareManager = \OC::$server->getShareManager(); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - protected function refreshInfo() { |
|
| 94 | - $this->info = $this->fileView->getFileInfo($this->path); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Returns the name of the node |
|
| 99 | - * |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - public function getName() { |
|
| 103 | - return $this->info->getName(); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Returns the full path |
|
| 108 | - * |
|
| 109 | - * @return string |
|
| 110 | - */ |
|
| 111 | - public function getPath() { |
|
| 112 | - return $this->path; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Renames the node |
|
| 117 | - * |
|
| 118 | - * @param string $name The new name |
|
| 119 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
| 120 | - * @throws \Sabre\DAV\Exception\Forbidden |
|
| 121 | - */ |
|
| 122 | - public function setName($name) { |
|
| 123 | - |
|
| 124 | - // rename is only allowed if the update privilege is granted |
|
| 125 | - if (!$this->info->isUpdateable()) { |
|
| 126 | - throw new \Sabre\DAV\Exception\Forbidden(); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - list($parentPath,) = \Sabre\Uri\split($this->path); |
|
| 130 | - list(, $newName) = \Sabre\Uri\split($name); |
|
| 131 | - |
|
| 132 | - // verify path of the target |
|
| 133 | - $this->verifyPath(); |
|
| 134 | - |
|
| 135 | - $newPath = $parentPath . '/' . $newName; |
|
| 136 | - |
|
| 137 | - $this->fileView->rename($this->path, $newPath); |
|
| 138 | - |
|
| 139 | - $this->path = $newPath; |
|
| 140 | - |
|
| 141 | - $this->refreshInfo(); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - public function setPropertyCache($property_cache) { |
|
| 145 | - $this->property_cache = $property_cache; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Returns the last modification time, as a unix timestamp |
|
| 150 | - * |
|
| 151 | - * @return int timestamp as integer |
|
| 152 | - */ |
|
| 153 | - public function getLastModified() { |
|
| 154 | - $timestamp = $this->info->getMtime(); |
|
| 155 | - if (!empty($timestamp)) { |
|
| 156 | - return (int)$timestamp; |
|
| 157 | - } |
|
| 158 | - return $timestamp; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * sets the last modification time of the file (mtime) to the value given |
|
| 163 | - * in the second parameter or to now if the second param is empty. |
|
| 164 | - * Even if the modification time is set to a custom value the access time is set to now. |
|
| 165 | - */ |
|
| 166 | - public function touch($mtime) { |
|
| 167 | - $this->fileView->touch($this->path, $mtime); |
|
| 168 | - $this->refreshInfo(); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Returns the ETag for a file |
|
| 173 | - * |
|
| 174 | - * An ETag is a unique identifier representing the current version of the |
|
| 175 | - * file. If the file changes, the ETag MUST change. The ETag is an |
|
| 176 | - * arbitrary string, but MUST be surrounded by double-quotes. |
|
| 177 | - * |
|
| 178 | - * Return null if the ETag can not effectively be determined |
|
| 179 | - * |
|
| 180 | - * @return string |
|
| 181 | - */ |
|
| 182 | - public function getETag() { |
|
| 183 | - return '"' . $this->info->getEtag() . '"'; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Sets the ETag |
|
| 188 | - * |
|
| 189 | - * @param string $etag |
|
| 190 | - * |
|
| 191 | - * @return int file id of updated file or -1 on failure |
|
| 192 | - */ |
|
| 193 | - public function setETag($etag) { |
|
| 194 | - return $this->fileView->putFileInfo($this->path, array('etag' => $etag)); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Returns the size of the node, in bytes |
|
| 199 | - * |
|
| 200 | - * @return integer |
|
| 201 | - */ |
|
| 202 | - public function getSize() { |
|
| 203 | - return $this->info->getSize(); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Returns the cache's file id |
|
| 208 | - * |
|
| 209 | - * @return int |
|
| 210 | - */ |
|
| 211 | - public function getId() { |
|
| 212 | - return $this->info->getId(); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @return string|null |
|
| 217 | - */ |
|
| 218 | - public function getFileId() { |
|
| 219 | - if ($this->info->getId()) { |
|
| 220 | - $instanceId = \OC_Util::getInstanceId(); |
|
| 221 | - $id = sprintf('%08d', $this->info->getId()); |
|
| 222 | - return $id . $instanceId; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - return null; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * @return integer |
|
| 230 | - */ |
|
| 231 | - public function getInternalFileId() { |
|
| 232 | - return $this->info->getId(); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * @param string $user |
|
| 237 | - * @return int |
|
| 238 | - */ |
|
| 239 | - public function getSharePermissions($user) { |
|
| 240 | - |
|
| 241 | - // check of we access a federated share |
|
| 242 | - if ($user !== null) { |
|
| 243 | - try { |
|
| 244 | - $share = $this->shareManager->getShareByToken($user); |
|
| 245 | - return $share->getPermissions(); |
|
| 246 | - } catch (ShareNotFound $e) { |
|
| 247 | - // ignore |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - $storage = $this->info->getStorage(); |
|
| 252 | - |
|
| 253 | - $path = $this->info->getInternalPath(); |
|
| 254 | - |
|
| 255 | - if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
| 256 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
| 257 | - $permissions = (int)$storage->getShare()->getPermissions(); |
|
| 258 | - } else { |
|
| 259 | - $permissions = $storage->getPermissions($path); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /* |
|
| 46 | + /** |
|
| 47 | + * @var \OC\Files\View |
|
| 48 | + */ |
|
| 49 | + protected $fileView; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * The path to the current node |
|
| 53 | + * |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + protected $path; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * node properties cache |
|
| 60 | + * |
|
| 61 | + * @var array |
|
| 62 | + */ |
|
| 63 | + protected $property_cache = null; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @var \OCP\Files\FileInfo |
|
| 67 | + */ |
|
| 68 | + protected $info; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @var IManager |
|
| 72 | + */ |
|
| 73 | + protected $shareManager; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Sets up the node, expects a full path name |
|
| 77 | + * |
|
| 78 | + * @param \OC\Files\View $view |
|
| 79 | + * @param \OCP\Files\FileInfo $info |
|
| 80 | + * @param IManager $shareManager |
|
| 81 | + */ |
|
| 82 | + public function __construct(View $view, FileInfo $info, IManager $shareManager = null) { |
|
| 83 | + $this->fileView = $view; |
|
| 84 | + $this->path = $this->fileView->getRelativePath($info->getPath()); |
|
| 85 | + $this->info = $info; |
|
| 86 | + if ($shareManager) { |
|
| 87 | + $this->shareManager = $shareManager; |
|
| 88 | + } else { |
|
| 89 | + $this->shareManager = \OC::$server->getShareManager(); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + protected function refreshInfo() { |
|
| 94 | + $this->info = $this->fileView->getFileInfo($this->path); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Returns the name of the node |
|
| 99 | + * |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + public function getName() { |
|
| 103 | + return $this->info->getName(); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Returns the full path |
|
| 108 | + * |
|
| 109 | + * @return string |
|
| 110 | + */ |
|
| 111 | + public function getPath() { |
|
| 112 | + return $this->path; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Renames the node |
|
| 117 | + * |
|
| 118 | + * @param string $name The new name |
|
| 119 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
| 120 | + * @throws \Sabre\DAV\Exception\Forbidden |
|
| 121 | + */ |
|
| 122 | + public function setName($name) { |
|
| 123 | + |
|
| 124 | + // rename is only allowed if the update privilege is granted |
|
| 125 | + if (!$this->info->isUpdateable()) { |
|
| 126 | + throw new \Sabre\DAV\Exception\Forbidden(); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + list($parentPath,) = \Sabre\Uri\split($this->path); |
|
| 130 | + list(, $newName) = \Sabre\Uri\split($name); |
|
| 131 | + |
|
| 132 | + // verify path of the target |
|
| 133 | + $this->verifyPath(); |
|
| 134 | + |
|
| 135 | + $newPath = $parentPath . '/' . $newName; |
|
| 136 | + |
|
| 137 | + $this->fileView->rename($this->path, $newPath); |
|
| 138 | + |
|
| 139 | + $this->path = $newPath; |
|
| 140 | + |
|
| 141 | + $this->refreshInfo(); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + public function setPropertyCache($property_cache) { |
|
| 145 | + $this->property_cache = $property_cache; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Returns the last modification time, as a unix timestamp |
|
| 150 | + * |
|
| 151 | + * @return int timestamp as integer |
|
| 152 | + */ |
|
| 153 | + public function getLastModified() { |
|
| 154 | + $timestamp = $this->info->getMtime(); |
|
| 155 | + if (!empty($timestamp)) { |
|
| 156 | + return (int)$timestamp; |
|
| 157 | + } |
|
| 158 | + return $timestamp; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * sets the last modification time of the file (mtime) to the value given |
|
| 163 | + * in the second parameter or to now if the second param is empty. |
|
| 164 | + * Even if the modification time is set to a custom value the access time is set to now. |
|
| 165 | + */ |
|
| 166 | + public function touch($mtime) { |
|
| 167 | + $this->fileView->touch($this->path, $mtime); |
|
| 168 | + $this->refreshInfo(); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Returns the ETag for a file |
|
| 173 | + * |
|
| 174 | + * An ETag is a unique identifier representing the current version of the |
|
| 175 | + * file. If the file changes, the ETag MUST change. The ETag is an |
|
| 176 | + * arbitrary string, but MUST be surrounded by double-quotes. |
|
| 177 | + * |
|
| 178 | + * Return null if the ETag can not effectively be determined |
|
| 179 | + * |
|
| 180 | + * @return string |
|
| 181 | + */ |
|
| 182 | + public function getETag() { |
|
| 183 | + return '"' . $this->info->getEtag() . '"'; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Sets the ETag |
|
| 188 | + * |
|
| 189 | + * @param string $etag |
|
| 190 | + * |
|
| 191 | + * @return int file id of updated file or -1 on failure |
|
| 192 | + */ |
|
| 193 | + public function setETag($etag) { |
|
| 194 | + return $this->fileView->putFileInfo($this->path, array('etag' => $etag)); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Returns the size of the node, in bytes |
|
| 199 | + * |
|
| 200 | + * @return integer |
|
| 201 | + */ |
|
| 202 | + public function getSize() { |
|
| 203 | + return $this->info->getSize(); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Returns the cache's file id |
|
| 208 | + * |
|
| 209 | + * @return int |
|
| 210 | + */ |
|
| 211 | + public function getId() { |
|
| 212 | + return $this->info->getId(); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @return string|null |
|
| 217 | + */ |
|
| 218 | + public function getFileId() { |
|
| 219 | + if ($this->info->getId()) { |
|
| 220 | + $instanceId = \OC_Util::getInstanceId(); |
|
| 221 | + $id = sprintf('%08d', $this->info->getId()); |
|
| 222 | + return $id . $instanceId; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + return null; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * @return integer |
|
| 230 | + */ |
|
| 231 | + public function getInternalFileId() { |
|
| 232 | + return $this->info->getId(); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * @param string $user |
|
| 237 | + * @return int |
|
| 238 | + */ |
|
| 239 | + public function getSharePermissions($user) { |
|
| 240 | + |
|
| 241 | + // check of we access a federated share |
|
| 242 | + if ($user !== null) { |
|
| 243 | + try { |
|
| 244 | + $share = $this->shareManager->getShareByToken($user); |
|
| 245 | + return $share->getPermissions(); |
|
| 246 | + } catch (ShareNotFound $e) { |
|
| 247 | + // ignore |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + $storage = $this->info->getStorage(); |
|
| 252 | + |
|
| 253 | + $path = $this->info->getInternalPath(); |
|
| 254 | + |
|
| 255 | + if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
| 256 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
| 257 | + $permissions = (int)$storage->getShare()->getPermissions(); |
|
| 258 | + } else { |
|
| 259 | + $permissions = $storage->getPermissions($path); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /* |
|
| 263 | 263 | * We can always share non moveable mount points with DELETE and UPDATE |
| 264 | 264 | * Eventually we need to do this properly |
| 265 | 265 | */ |
| 266 | - $mountpoint = $this->info->getMountPoint(); |
|
| 267 | - if (!($mountpoint instanceof MoveableMount)) { |
|
| 268 | - $mountpointpath = $mountpoint->getMountPoint(); |
|
| 269 | - if (substr($mountpointpath, -1) === '/') { |
|
| 270 | - $mountpointpath = substr($mountpointpath, 0, -1); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - if ($mountpointpath === $this->info->getPath()) { |
|
| 274 | - $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /* |
|
| 266 | + $mountpoint = $this->info->getMountPoint(); |
|
| 267 | + if (!($mountpoint instanceof MoveableMount)) { |
|
| 268 | + $mountpointpath = $mountpoint->getMountPoint(); |
|
| 269 | + if (substr($mountpointpath, -1) === '/') { |
|
| 270 | + $mountpointpath = substr($mountpointpath, 0, -1); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + if ($mountpointpath === $this->info->getPath()) { |
|
| 274 | + $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /* |
|
| 279 | 279 | * Files can't have create or delete permissions |
| 280 | 280 | */ |
| 281 | - if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
| 282 | - $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - return $permissions; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * @return string |
|
| 290 | - */ |
|
| 291 | - public function getDavPermissions() { |
|
| 292 | - $p = ''; |
|
| 293 | - if ($this->info->isShared()) { |
|
| 294 | - $p .= 'S'; |
|
| 295 | - } |
|
| 296 | - if ($this->info->isShareable()) { |
|
| 297 | - $p .= 'R'; |
|
| 298 | - } |
|
| 299 | - if ($this->info->isMounted()) { |
|
| 300 | - $p .= 'M'; |
|
| 301 | - } |
|
| 302 | - if ($this->info->isDeletable()) { |
|
| 303 | - $p .= 'D'; |
|
| 304 | - } |
|
| 305 | - if ($this->info->isUpdateable()) { |
|
| 306 | - $p .= 'NV'; // Renameable, Moveable |
|
| 307 | - } |
|
| 308 | - if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
| 309 | - if ($this->info->isUpdateable()) { |
|
| 310 | - $p .= 'W'; |
|
| 311 | - } |
|
| 312 | - } else { |
|
| 313 | - if ($this->info->isCreatable()) { |
|
| 314 | - $p .= 'CK'; |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - return $p; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - public function getOwner() { |
|
| 321 | - return $this->info->getOwner(); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - protected function verifyPath() { |
|
| 325 | - try { |
|
| 326 | - $fileName = basename($this->info->getPath()); |
|
| 327 | - $this->fileView->verifyPath($this->path, $fileName); |
|
| 328 | - } catch (\OCP\Files\InvalidPathException $ex) { |
|
| 329 | - throw new InvalidPath($ex->getMessage()); |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 335 | - */ |
|
| 336 | - public function acquireLock($type) { |
|
| 337 | - $this->fileView->lockFile($this->path, $type); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 342 | - */ |
|
| 343 | - public function releaseLock($type) { |
|
| 344 | - $this->fileView->unlockFile($this->path, $type); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 349 | - */ |
|
| 350 | - public function changeLock($type) { |
|
| 351 | - $this->fileView->changeLock($this->path, $type); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - public function getFileInfo() { |
|
| 355 | - return $this->info; |
|
| 356 | - } |
|
| 281 | + if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
| 282 | + $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + return $permissions; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * @return string |
|
| 290 | + */ |
|
| 291 | + public function getDavPermissions() { |
|
| 292 | + $p = ''; |
|
| 293 | + if ($this->info->isShared()) { |
|
| 294 | + $p .= 'S'; |
|
| 295 | + } |
|
| 296 | + if ($this->info->isShareable()) { |
|
| 297 | + $p .= 'R'; |
|
| 298 | + } |
|
| 299 | + if ($this->info->isMounted()) { |
|
| 300 | + $p .= 'M'; |
|
| 301 | + } |
|
| 302 | + if ($this->info->isDeletable()) { |
|
| 303 | + $p .= 'D'; |
|
| 304 | + } |
|
| 305 | + if ($this->info->isUpdateable()) { |
|
| 306 | + $p .= 'NV'; // Renameable, Moveable |
|
| 307 | + } |
|
| 308 | + if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
| 309 | + if ($this->info->isUpdateable()) { |
|
| 310 | + $p .= 'W'; |
|
| 311 | + } |
|
| 312 | + } else { |
|
| 313 | + if ($this->info->isCreatable()) { |
|
| 314 | + $p .= 'CK'; |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + return $p; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + public function getOwner() { |
|
| 321 | + return $this->info->getOwner(); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + protected function verifyPath() { |
|
| 325 | + try { |
|
| 326 | + $fileName = basename($this->info->getPath()); |
|
| 327 | + $this->fileView->verifyPath($this->path, $fileName); |
|
| 328 | + } catch (\OCP\Files\InvalidPathException $ex) { |
|
| 329 | + throw new InvalidPath($ex->getMessage()); |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 335 | + */ |
|
| 336 | + public function acquireLock($type) { |
|
| 337 | + $this->fileView->lockFile($this->path, $type); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 342 | + */ |
|
| 343 | + public function releaseLock($type) { |
|
| 344 | + $this->fileView->unlockFile($this->path, $type); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 349 | + */ |
|
| 350 | + public function changeLock($type) { |
|
| 351 | + $this->fileView->changeLock($this->path, $type); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + public function getFileInfo() { |
|
| 355 | + return $this->info; |
|
| 356 | + } |
|
| 357 | 357 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | $shareTypesByFileId = []; |
| 150 | 150 | |
| 151 | - foreach($shares as $fileId => $sharesForFile) { |
|
| 151 | + foreach ($shares as $fileId => $sharesForFile) { |
|
| 152 | 152 | $types = array_map(function(IShare $share) { |
| 153 | 153 | return $share->getShareType(); |
| 154 | 154 | }, $sharesForFile); |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - $propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) { |
|
| 192 | + $propFind->handle(self::SHARETYPES_PROPERTYNAME, function() use ($sabreNode) { |
|
| 193 | 193 | if (isset($this->cachedShareTypes[$sabreNode->getId()])) { |
| 194 | 194 | $shareTypes = $this->cachedShareTypes[$sabreNode->getId()]; |
| 195 | 195 | } else { |
@@ -32,181 +32,181 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | class SharesPlugin extends \Sabre\DAV\ServerPlugin { |
| 34 | 34 | |
| 35 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 36 | - const SHARETYPES_PROPERTYNAME = '{http://owncloud.org/ns}share-types'; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Reference to main server object |
|
| 40 | - * |
|
| 41 | - * @var \Sabre\DAV\Server |
|
| 42 | - */ |
|
| 43 | - private $server; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var \OCP\Share\IManager |
|
| 47 | - */ |
|
| 48 | - private $shareManager; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var \Sabre\DAV\Tree |
|
| 52 | - */ |
|
| 53 | - private $tree; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var string |
|
| 57 | - */ |
|
| 58 | - private $userId; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @var \OCP\Files\Folder |
|
| 62 | - */ |
|
| 63 | - private $userFolder; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var IShare[] |
|
| 67 | - */ |
|
| 68 | - private $cachedShareTypes; |
|
| 69 | - |
|
| 70 | - private $cachedFolders = []; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @param \Sabre\DAV\Tree $tree tree |
|
| 74 | - * @param IUserSession $userSession user session |
|
| 75 | - * @param \OCP\Files\Folder $userFolder user home folder |
|
| 76 | - * @param \OCP\Share\IManager $shareManager share manager |
|
| 77 | - */ |
|
| 78 | - public function __construct( |
|
| 79 | - \Sabre\DAV\Tree $tree, |
|
| 80 | - IUserSession $userSession, |
|
| 81 | - \OCP\Files\Folder $userFolder, |
|
| 82 | - \OCP\Share\IManager $shareManager |
|
| 83 | - ) { |
|
| 84 | - $this->tree = $tree; |
|
| 85 | - $this->shareManager = $shareManager; |
|
| 86 | - $this->userFolder = $userFolder; |
|
| 87 | - $this->userId = $userSession->getUser()->getUID(); |
|
| 88 | - $this->cachedShareTypes = []; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * This initializes the plugin. |
|
| 93 | - * |
|
| 94 | - * This function is called by \Sabre\DAV\Server, after |
|
| 95 | - * addPlugin is called. |
|
| 96 | - * |
|
| 97 | - * This method should set up the required event subscriptions. |
|
| 98 | - * |
|
| 99 | - * @param \Sabre\DAV\Server $server |
|
| 100 | - */ |
|
| 101 | - public function initialize(\Sabre\DAV\Server $server) { |
|
| 102 | - $server->xml->namespacesMap[self::NS_OWNCLOUD] = 'oc'; |
|
| 103 | - $server->xml->elementMap[self::SHARETYPES_PROPERTYNAME] = 'OCA\\DAV\\Connector\\Sabre\\ShareTypeList'; |
|
| 104 | - $server->protectedProperties[] = self::SHARETYPES_PROPERTYNAME; |
|
| 105 | - |
|
| 106 | - $this->server = $server; |
|
| 107 | - $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Return a list of share types for outgoing shares |
|
| 112 | - * |
|
| 113 | - * @param \OCP\Files\Node $node file node |
|
| 114 | - * |
|
| 115 | - * @return int[] array of share types |
|
| 116 | - */ |
|
| 117 | - private function getShareTypes(\OCP\Files\Node $node) { |
|
| 118 | - $shareTypes = []; |
|
| 119 | - $requestedShareTypes = [ |
|
| 120 | - \OCP\Share::SHARE_TYPE_USER, |
|
| 121 | - \OCP\Share::SHARE_TYPE_GROUP, |
|
| 122 | - \OCP\Share::SHARE_TYPE_LINK, |
|
| 123 | - \OCP\Share::SHARE_TYPE_REMOTE, |
|
| 124 | - \OCP\Share::SHARE_TYPE_EMAIL, |
|
| 125 | - ]; |
|
| 126 | - foreach ($requestedShareTypes as $requestedShareType) { |
|
| 127 | - // one of each type is enough to find out about the types |
|
| 128 | - $shares = $this->shareManager->getSharesBy( |
|
| 129 | - $this->userId, |
|
| 130 | - $requestedShareType, |
|
| 131 | - $node, |
|
| 132 | - false, |
|
| 133 | - 1 |
|
| 134 | - ); |
|
| 135 | - if (!empty($shares)) { |
|
| 136 | - $shareTypes[] = $requestedShareType; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - return $shareTypes; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - private function getSharesTypesInFolder(\OCP\Files\Folder $node) { |
|
| 143 | - $shares = $this->shareManager->getSharesInFolder( |
|
| 144 | - $this->userId, |
|
| 145 | - $node, |
|
| 146 | - true |
|
| 147 | - ); |
|
| 148 | - |
|
| 149 | - $shareTypesByFileId = []; |
|
| 150 | - |
|
| 151 | - foreach($shares as $fileId => $sharesForFile) { |
|
| 152 | - $types = array_map(function(IShare $share) { |
|
| 153 | - return $share->getShareType(); |
|
| 154 | - }, $sharesForFile); |
|
| 155 | - $types = array_unique($types); |
|
| 156 | - sort($types); |
|
| 157 | - $shareTypesByFileId[$fileId] = $types; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - return $shareTypesByFileId; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Adds shares to propfind response |
|
| 165 | - * |
|
| 166 | - * @param PropFind $propFind propfind object |
|
| 167 | - * @param \Sabre\DAV\INode $sabreNode sabre node |
|
| 168 | - */ |
|
| 169 | - public function handleGetProperties( |
|
| 170 | - PropFind $propFind, |
|
| 171 | - \Sabre\DAV\INode $sabreNode |
|
| 172 | - ) { |
|
| 173 | - if (!($sabreNode instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
| 174 | - return; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - // need prefetch ? |
|
| 178 | - if ($sabreNode instanceof \OCA\DAV\Connector\Sabre\Directory |
|
| 179 | - && $propFind->getDepth() !== 0 |
|
| 180 | - && !is_null($propFind->getStatus(self::SHARETYPES_PROPERTYNAME)) |
|
| 181 | - ) { |
|
| 182 | - $folderNode = $this->userFolder->get($sabreNode->getPath()); |
|
| 183 | - |
|
| 184 | - $childShares = $this->getSharesTypesInFolder($folderNode); |
|
| 185 | - $this->cachedFolders[] = $sabreNode->getPath(); |
|
| 186 | - $this->cachedShareTypes[$folderNode->getId()] = $this->getShareTypes($folderNode); |
|
| 187 | - foreach ($childShares as $id => $shares) { |
|
| 188 | - $this->cachedShareTypes[$id] = $shares; |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - $propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) { |
|
| 193 | - if (isset($this->cachedShareTypes[$sabreNode->getId()])) { |
|
| 194 | - $shareTypes = $this->cachedShareTypes[$sabreNode->getId()]; |
|
| 195 | - } else { |
|
| 196 | - list($parentPath,) = \Sabre\Uri\split($sabreNode->getPath()); |
|
| 197 | - if ($parentPath === '') { |
|
| 198 | - $parentPath = '/'; |
|
| 199 | - } |
|
| 200 | - // if we already cached the folder this file is in we know there are no shares for this file |
|
| 201 | - if (array_search($parentPath, $this->cachedFolders) === false) { |
|
| 202 | - $node = $this->userFolder->get($sabreNode->getPath()); |
|
| 203 | - $shareTypes = $this->getShareTypes($node); |
|
| 204 | - } else { |
|
| 205 | - return []; |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - return new ShareTypeList($shareTypes); |
|
| 210 | - }); |
|
| 211 | - } |
|
| 35 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 36 | + const SHARETYPES_PROPERTYNAME = '{http://owncloud.org/ns}share-types'; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Reference to main server object |
|
| 40 | + * |
|
| 41 | + * @var \Sabre\DAV\Server |
|
| 42 | + */ |
|
| 43 | + private $server; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var \OCP\Share\IManager |
|
| 47 | + */ |
|
| 48 | + private $shareManager; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var \Sabre\DAV\Tree |
|
| 52 | + */ |
|
| 53 | + private $tree; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var string |
|
| 57 | + */ |
|
| 58 | + private $userId; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @var \OCP\Files\Folder |
|
| 62 | + */ |
|
| 63 | + private $userFolder; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @var IShare[] |
|
| 67 | + */ |
|
| 68 | + private $cachedShareTypes; |
|
| 69 | + |
|
| 70 | + private $cachedFolders = []; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @param \Sabre\DAV\Tree $tree tree |
|
| 74 | + * @param IUserSession $userSession user session |
|
| 75 | + * @param \OCP\Files\Folder $userFolder user home folder |
|
| 76 | + * @param \OCP\Share\IManager $shareManager share manager |
|
| 77 | + */ |
|
| 78 | + public function __construct( |
|
| 79 | + \Sabre\DAV\Tree $tree, |
|
| 80 | + IUserSession $userSession, |
|
| 81 | + \OCP\Files\Folder $userFolder, |
|
| 82 | + \OCP\Share\IManager $shareManager |
|
| 83 | + ) { |
|
| 84 | + $this->tree = $tree; |
|
| 85 | + $this->shareManager = $shareManager; |
|
| 86 | + $this->userFolder = $userFolder; |
|
| 87 | + $this->userId = $userSession->getUser()->getUID(); |
|
| 88 | + $this->cachedShareTypes = []; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * This initializes the plugin. |
|
| 93 | + * |
|
| 94 | + * This function is called by \Sabre\DAV\Server, after |
|
| 95 | + * addPlugin is called. |
|
| 96 | + * |
|
| 97 | + * This method should set up the required event subscriptions. |
|
| 98 | + * |
|
| 99 | + * @param \Sabre\DAV\Server $server |
|
| 100 | + */ |
|
| 101 | + public function initialize(\Sabre\DAV\Server $server) { |
|
| 102 | + $server->xml->namespacesMap[self::NS_OWNCLOUD] = 'oc'; |
|
| 103 | + $server->xml->elementMap[self::SHARETYPES_PROPERTYNAME] = 'OCA\\DAV\\Connector\\Sabre\\ShareTypeList'; |
|
| 104 | + $server->protectedProperties[] = self::SHARETYPES_PROPERTYNAME; |
|
| 105 | + |
|
| 106 | + $this->server = $server; |
|
| 107 | + $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Return a list of share types for outgoing shares |
|
| 112 | + * |
|
| 113 | + * @param \OCP\Files\Node $node file node |
|
| 114 | + * |
|
| 115 | + * @return int[] array of share types |
|
| 116 | + */ |
|
| 117 | + private function getShareTypes(\OCP\Files\Node $node) { |
|
| 118 | + $shareTypes = []; |
|
| 119 | + $requestedShareTypes = [ |
|
| 120 | + \OCP\Share::SHARE_TYPE_USER, |
|
| 121 | + \OCP\Share::SHARE_TYPE_GROUP, |
|
| 122 | + \OCP\Share::SHARE_TYPE_LINK, |
|
| 123 | + \OCP\Share::SHARE_TYPE_REMOTE, |
|
| 124 | + \OCP\Share::SHARE_TYPE_EMAIL, |
|
| 125 | + ]; |
|
| 126 | + foreach ($requestedShareTypes as $requestedShareType) { |
|
| 127 | + // one of each type is enough to find out about the types |
|
| 128 | + $shares = $this->shareManager->getSharesBy( |
|
| 129 | + $this->userId, |
|
| 130 | + $requestedShareType, |
|
| 131 | + $node, |
|
| 132 | + false, |
|
| 133 | + 1 |
|
| 134 | + ); |
|
| 135 | + if (!empty($shares)) { |
|
| 136 | + $shareTypes[] = $requestedShareType; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + return $shareTypes; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + private function getSharesTypesInFolder(\OCP\Files\Folder $node) { |
|
| 143 | + $shares = $this->shareManager->getSharesInFolder( |
|
| 144 | + $this->userId, |
|
| 145 | + $node, |
|
| 146 | + true |
|
| 147 | + ); |
|
| 148 | + |
|
| 149 | + $shareTypesByFileId = []; |
|
| 150 | + |
|
| 151 | + foreach($shares as $fileId => $sharesForFile) { |
|
| 152 | + $types = array_map(function(IShare $share) { |
|
| 153 | + return $share->getShareType(); |
|
| 154 | + }, $sharesForFile); |
|
| 155 | + $types = array_unique($types); |
|
| 156 | + sort($types); |
|
| 157 | + $shareTypesByFileId[$fileId] = $types; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + return $shareTypesByFileId; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Adds shares to propfind response |
|
| 165 | + * |
|
| 166 | + * @param PropFind $propFind propfind object |
|
| 167 | + * @param \Sabre\DAV\INode $sabreNode sabre node |
|
| 168 | + */ |
|
| 169 | + public function handleGetProperties( |
|
| 170 | + PropFind $propFind, |
|
| 171 | + \Sabre\DAV\INode $sabreNode |
|
| 172 | + ) { |
|
| 173 | + if (!($sabreNode instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
| 174 | + return; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + // need prefetch ? |
|
| 178 | + if ($sabreNode instanceof \OCA\DAV\Connector\Sabre\Directory |
|
| 179 | + && $propFind->getDepth() !== 0 |
|
| 180 | + && !is_null($propFind->getStatus(self::SHARETYPES_PROPERTYNAME)) |
|
| 181 | + ) { |
|
| 182 | + $folderNode = $this->userFolder->get($sabreNode->getPath()); |
|
| 183 | + |
|
| 184 | + $childShares = $this->getSharesTypesInFolder($folderNode); |
|
| 185 | + $this->cachedFolders[] = $sabreNode->getPath(); |
|
| 186 | + $this->cachedShareTypes[$folderNode->getId()] = $this->getShareTypes($folderNode); |
|
| 187 | + foreach ($childShares as $id => $shares) { |
|
| 188 | + $this->cachedShareTypes[$id] = $shares; |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + $propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) { |
|
| 193 | + if (isset($this->cachedShareTypes[$sabreNode->getId()])) { |
|
| 194 | + $shareTypes = $this->cachedShareTypes[$sabreNode->getId()]; |
|
| 195 | + } else { |
|
| 196 | + list($parentPath,) = \Sabre\Uri\split($sabreNode->getPath()); |
|
| 197 | + if ($parentPath === '') { |
|
| 198 | + $parentPath = '/'; |
|
| 199 | + } |
|
| 200 | + // if we already cached the folder this file is in we know there are no shares for this file |
|
| 201 | + if (array_search($parentPath, $this->cachedFolders) === false) { |
|
| 202 | + $node = $this->userFolder->get($sabreNode->getPath()); |
|
| 203 | + $shareTypes = $this->getShareTypes($node); |
|
| 204 | + } else { |
|
| 205 | + return []; |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + return new ShareTypeList($shareTypes); |
|
| 210 | + }); |
|
| 211 | + } |
|
| 212 | 212 | } |