@@ -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 | } |
@@ -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,318 +43,318 @@ |
||
| 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->isReadable()) { |
|
| 303 | - $p .= 'G'; |
|
| 304 | - } |
|
| 305 | - if ($this->info->isDeletable()) { |
|
| 306 | - $p .= 'D'; |
|
| 307 | - } |
|
| 308 | - if ($this->info->isUpdateable()) { |
|
| 309 | - $p .= 'NV'; // Renameable, Moveable |
|
| 310 | - } |
|
| 311 | - if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
| 312 | - if ($this->info->isUpdateable()) { |
|
| 313 | - $p .= 'W'; |
|
| 314 | - } |
|
| 315 | - } else { |
|
| 316 | - if ($this->info->isCreatable()) { |
|
| 317 | - $p .= 'CK'; |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - return $p; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - public function getOwner() { |
|
| 324 | - return $this->info->getOwner(); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - protected function verifyPath() { |
|
| 328 | - try { |
|
| 329 | - $fileName = basename($this->info->getPath()); |
|
| 330 | - $this->fileView->verifyPath($this->path, $fileName); |
|
| 331 | - } catch (\OCP\Files\InvalidPathException $ex) { |
|
| 332 | - throw new InvalidPath($ex->getMessage()); |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 338 | - */ |
|
| 339 | - public function acquireLock($type) { |
|
| 340 | - $this->fileView->lockFile($this->path, $type); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 345 | - */ |
|
| 346 | - public function releaseLock($type) { |
|
| 347 | - $this->fileView->unlockFile($this->path, $type); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 352 | - */ |
|
| 353 | - public function changeLock($type) { |
|
| 354 | - $this->fileView->changeLock($this->path, $type); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - public function getFileInfo() { |
|
| 358 | - return $this->info; |
|
| 359 | - } |
|
| 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->isReadable()) { |
|
| 303 | + $p .= 'G'; |
|
| 304 | + } |
|
| 305 | + if ($this->info->isDeletable()) { |
|
| 306 | + $p .= 'D'; |
|
| 307 | + } |
|
| 308 | + if ($this->info->isUpdateable()) { |
|
| 309 | + $p .= 'NV'; // Renameable, Moveable |
|
| 310 | + } |
|
| 311 | + if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
| 312 | + if ($this->info->isUpdateable()) { |
|
| 313 | + $p .= 'W'; |
|
| 314 | + } |
|
| 315 | + } else { |
|
| 316 | + if ($this->info->isCreatable()) { |
|
| 317 | + $p .= 'CK'; |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + return $p; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + public function getOwner() { |
|
| 324 | + return $this->info->getOwner(); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + protected function verifyPath() { |
|
| 328 | + try { |
|
| 329 | + $fileName = basename($this->info->getPath()); |
|
| 330 | + $this->fileView->verifyPath($this->path, $fileName); |
|
| 331 | + } catch (\OCP\Files\InvalidPathException $ex) { |
|
| 332 | + throw new InvalidPath($ex->getMessage()); |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 338 | + */ |
|
| 339 | + public function acquireLock($type) { |
|
| 340 | + $this->fileView->lockFile($this->path, $type); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 345 | + */ |
|
| 346 | + public function releaseLock($type) { |
|
| 347 | + $this->fileView->unlockFile($this->path, $type); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 352 | + */ |
|
| 353 | + public function changeLock($type) { |
|
| 354 | + $this->fileView->changeLock($this->path, $type); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + public function getFileInfo() { |
|
| 358 | + return $this->info; |
|
| 359 | + } |
|
| 360 | 360 | } |
@@ -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 | } |
@@ -245,7 +245,9 @@ |
||
| 245 | 245 | function httpGet(RequestInterface $request, ResponseInterface $response) { |
| 246 | 246 | // Only handle valid files |
| 247 | 247 | $node = $this->tree->getNodeForPath($request->getPath()); |
| 248 | - if (!($node instanceof IFile)) return; |
|
| 248 | + if (!($node instanceof IFile)) { |
|
| 249 | + return; |
|
| 250 | + } |
|
| 249 | 251 | |
| 250 | 252 | // adds a 'Content-Disposition: attachment' header in case no disposition |
| 251 | 253 | // header has been set before |
@@ -448,7 +448,7 @@ |
||
| 448 | 448 | * |
| 449 | 449 | * @param string $path source path |
| 450 | 450 | * @param string $destination destination path |
| 451 | - * @return bool|void false to stop handling, void to skip this handler |
|
| 451 | + * @return null|false false to stop handling, void to skip this handler |
|
| 452 | 452 | */ |
| 453 | 453 | public function beforeMoveFutureFile($path, $destination) { |
| 454 | 454 | $sourceNode = $this->tree->getNodeForPath($path); |
@@ -49,453 +49,453 @@ |
||
| 49 | 49 | |
| 50 | 50 | class FilesPlugin extends ServerPlugin { |
| 51 | 51 | |
| 52 | - // namespace |
|
| 53 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 54 | - const NS_NEXTCLOUD = 'http://nextcloud.org/ns'; |
|
| 55 | - const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id'; |
|
| 56 | - const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid'; |
|
| 57 | - const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions'; |
|
| 58 | - const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions'; |
|
| 59 | - const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL'; |
|
| 60 | - const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size'; |
|
| 61 | - const GETETAG_PROPERTYNAME = '{DAV:}getetag'; |
|
| 62 | - const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified'; |
|
| 63 | - const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id'; |
|
| 64 | - const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name'; |
|
| 65 | - const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums'; |
|
| 66 | - const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint'; |
|
| 67 | - const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview'; |
|
| 68 | - const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type'; |
|
| 69 | - const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted'; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Reference to main server object |
|
| 73 | - * |
|
| 74 | - * @var \Sabre\DAV\Server |
|
| 75 | - */ |
|
| 76 | - private $server; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @var Tree |
|
| 80 | - */ |
|
| 81 | - private $tree; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Whether this is public webdav. |
|
| 85 | - * If true, some returned information will be stripped off. |
|
| 86 | - * |
|
| 87 | - * @var bool |
|
| 88 | - */ |
|
| 89 | - private $isPublic; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @var View |
|
| 93 | - */ |
|
| 94 | - private $fileView; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @var bool |
|
| 98 | - */ |
|
| 99 | - private $downloadAttachment; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @var IConfig |
|
| 103 | - */ |
|
| 104 | - private $config; |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @var IRequest |
|
| 108 | - */ |
|
| 109 | - private $request; |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @var IPreview |
|
| 113 | - */ |
|
| 114 | - private $previewManager; |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @param Tree $tree |
|
| 118 | - * @param IConfig $config |
|
| 119 | - * @param IRequest $request |
|
| 120 | - * @param IPreview $previewManager |
|
| 121 | - * @param bool $isPublic |
|
| 122 | - * @param bool $downloadAttachment |
|
| 123 | - */ |
|
| 124 | - public function __construct(Tree $tree, |
|
| 125 | - IConfig $config, |
|
| 126 | - IRequest $request, |
|
| 127 | - IPreview $previewManager, |
|
| 128 | - $isPublic = false, |
|
| 129 | - $downloadAttachment = true) { |
|
| 130 | - $this->tree = $tree; |
|
| 131 | - $this->config = $config; |
|
| 132 | - $this->request = $request; |
|
| 133 | - $this->isPublic = $isPublic; |
|
| 134 | - $this->downloadAttachment = $downloadAttachment; |
|
| 135 | - $this->previewManager = $previewManager; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * This initializes the plugin. |
|
| 140 | - * |
|
| 141 | - * This function is called by \Sabre\DAV\Server, after |
|
| 142 | - * addPlugin is called. |
|
| 143 | - * |
|
| 144 | - * This method should set up the required event subscriptions. |
|
| 145 | - * |
|
| 146 | - * @param \Sabre\DAV\Server $server |
|
| 147 | - * @return void |
|
| 148 | - */ |
|
| 149 | - public function initialize(\Sabre\DAV\Server $server) { |
|
| 150 | - $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
| 151 | - $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc'; |
|
| 152 | - $server->protectedProperties[] = self::FILEID_PROPERTYNAME; |
|
| 153 | - $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME; |
|
| 154 | - $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME; |
|
| 155 | - $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME; |
|
| 156 | - $server->protectedProperties[] = self::SIZE_PROPERTYNAME; |
|
| 157 | - $server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME; |
|
| 158 | - $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME; |
|
| 159 | - $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME; |
|
| 160 | - $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME; |
|
| 161 | - $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME; |
|
| 162 | - $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME; |
|
| 163 | - $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME; |
|
| 164 | - $server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME; |
|
| 165 | - |
|
| 166 | - // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH |
|
| 167 | - $allowedProperties = ['{DAV:}getetag']; |
|
| 168 | - $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties); |
|
| 169 | - |
|
| 170 | - $this->server = $server; |
|
| 171 | - $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
| 172 | - $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
|
| 173 | - $this->server->on('afterBind', array($this, 'sendFileIdHeader')); |
|
| 174 | - $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader')); |
|
| 175 | - $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
| 176 | - $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken')); |
|
| 177 | - $this->server->on('afterResponse', function($request, ResponseInterface $response) { |
|
| 178 | - $body = $response->getBody(); |
|
| 179 | - if (is_resource($body)) { |
|
| 180 | - fclose($body); |
|
| 181 | - } |
|
| 182 | - }); |
|
| 183 | - $this->server->on('beforeMove', [$this, 'checkMove']); |
|
| 184 | - $this->server->on('beforeMove', [$this, 'beforeMoveFutureFile']); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Plugin that checks if a move can actually be performed. |
|
| 189 | - * |
|
| 190 | - * @param string $source source path |
|
| 191 | - * @param string $destination destination path |
|
| 192 | - * @throws Forbidden |
|
| 193 | - * @throws NotFound |
|
| 194 | - */ |
|
| 195 | - function checkMove($source, $destination) { |
|
| 196 | - $sourceNode = $this->tree->getNodeForPath($source); |
|
| 197 | - if (!$sourceNode instanceof Node) { |
|
| 198 | - return; |
|
| 199 | - } |
|
| 200 | - list($sourceDir,) = \Sabre\Uri\split($source); |
|
| 201 | - list($destinationDir,) = \Sabre\Uri\split($destination); |
|
| 202 | - |
|
| 203 | - if ($sourceDir !== $destinationDir) { |
|
| 204 | - $sourceNodeFileInfo = $sourceNode->getFileInfo(); |
|
| 205 | - if ($sourceNodeFileInfo === null) { |
|
| 206 | - throw new NotFound($source . ' does not exist'); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - if (!$sourceNodeFileInfo->isDeletable()) { |
|
| 210 | - throw new Forbidden($source . " cannot be deleted"); |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * This sets a cookie to be able to recognize the start of the download |
|
| 217 | - * the content must not be longer than 32 characters and must only contain |
|
| 218 | - * alphanumeric characters |
|
| 219 | - * |
|
| 220 | - * @param RequestInterface $request |
|
| 221 | - * @param ResponseInterface $response |
|
| 222 | - */ |
|
| 223 | - function handleDownloadToken(RequestInterface $request, ResponseInterface $response) { |
|
| 224 | - $queryParams = $request->getQueryParameters(); |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * this sets a cookie to be able to recognize the start of the download |
|
| 228 | - * the content must not be longer than 32 characters and must only contain |
|
| 229 | - * alphanumeric characters |
|
| 230 | - */ |
|
| 231 | - if (isset($queryParams['downloadStartSecret'])) { |
|
| 232 | - $token = $queryParams['downloadStartSecret']; |
|
| 233 | - if (!isset($token[32]) |
|
| 234 | - && preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) { |
|
| 235 | - // FIXME: use $response->setHeader() instead |
|
| 236 | - setcookie('ocDownloadStarted', $token, time() + 20, '/'); |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Add headers to file download |
|
| 243 | - * |
|
| 244 | - * @param RequestInterface $request |
|
| 245 | - * @param ResponseInterface $response |
|
| 246 | - */ |
|
| 247 | - function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
| 248 | - // Only handle valid files |
|
| 249 | - $node = $this->tree->getNodeForPath($request->getPath()); |
|
| 250 | - if (!($node instanceof IFile)) return; |
|
| 251 | - |
|
| 252 | - // adds a 'Content-Disposition: attachment' header in case no disposition |
|
| 253 | - // header has been set before |
|
| 254 | - if ($this->downloadAttachment && |
|
| 255 | - $response->getHeader('Content-Disposition') === null) { |
|
| 256 | - $filename = $node->getName(); |
|
| 257 | - if ($this->request->isUserAgent( |
|
| 258 | - [ |
|
| 259 | - \OC\AppFramework\Http\Request::USER_AGENT_IE, |
|
| 260 | - \OC\AppFramework\Http\Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
| 261 | - \OC\AppFramework\Http\Request::USER_AGENT_FREEBOX, |
|
| 262 | - ])) { |
|
| 263 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
| 264 | - } else { |
|
| 265 | - $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
| 266 | - . '; filename="' . rawurlencode($filename) . '"'); |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
| 271 | - //Add OC-Checksum header |
|
| 272 | - /** @var $node File */ |
|
| 273 | - $checksum = $node->getChecksum(); |
|
| 274 | - if ($checksum !== null && $checksum !== '') { |
|
| 275 | - $response->addHeader('OC-Checksum', $checksum); |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Adds all ownCloud-specific properties |
|
| 282 | - * |
|
| 283 | - * @param PropFind $propFind |
|
| 284 | - * @param \Sabre\DAV\INode $node |
|
| 285 | - * @return void |
|
| 286 | - */ |
|
| 287 | - public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) { |
|
| 288 | - |
|
| 289 | - $httpRequest = $this->server->httpRequest; |
|
| 290 | - |
|
| 291 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
| 292 | - /** |
|
| 293 | - * This was disabled, because it made dir listing throw an exception, |
|
| 294 | - * so users were unable to navigate into folders where one subitem |
|
| 295 | - * is blocked by the files_accesscontrol app, see: |
|
| 296 | - * https://github.com/nextcloud/files_accesscontrol/issues/65 |
|
| 52 | + // namespace |
|
| 53 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 54 | + const NS_NEXTCLOUD = 'http://nextcloud.org/ns'; |
|
| 55 | + const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id'; |
|
| 56 | + const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid'; |
|
| 57 | + const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions'; |
|
| 58 | + const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions'; |
|
| 59 | + const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL'; |
|
| 60 | + const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size'; |
|
| 61 | + const GETETAG_PROPERTYNAME = '{DAV:}getetag'; |
|
| 62 | + const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified'; |
|
| 63 | + const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id'; |
|
| 64 | + const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name'; |
|
| 65 | + const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums'; |
|
| 66 | + const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint'; |
|
| 67 | + const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview'; |
|
| 68 | + const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type'; |
|
| 69 | + const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted'; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Reference to main server object |
|
| 73 | + * |
|
| 74 | + * @var \Sabre\DAV\Server |
|
| 75 | + */ |
|
| 76 | + private $server; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @var Tree |
|
| 80 | + */ |
|
| 81 | + private $tree; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Whether this is public webdav. |
|
| 85 | + * If true, some returned information will be stripped off. |
|
| 86 | + * |
|
| 87 | + * @var bool |
|
| 88 | + */ |
|
| 89 | + private $isPublic; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @var View |
|
| 93 | + */ |
|
| 94 | + private $fileView; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @var bool |
|
| 98 | + */ |
|
| 99 | + private $downloadAttachment; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @var IConfig |
|
| 103 | + */ |
|
| 104 | + private $config; |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @var IRequest |
|
| 108 | + */ |
|
| 109 | + private $request; |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @var IPreview |
|
| 113 | + */ |
|
| 114 | + private $previewManager; |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @param Tree $tree |
|
| 118 | + * @param IConfig $config |
|
| 119 | + * @param IRequest $request |
|
| 120 | + * @param IPreview $previewManager |
|
| 121 | + * @param bool $isPublic |
|
| 122 | + * @param bool $downloadAttachment |
|
| 123 | + */ |
|
| 124 | + public function __construct(Tree $tree, |
|
| 125 | + IConfig $config, |
|
| 126 | + IRequest $request, |
|
| 127 | + IPreview $previewManager, |
|
| 128 | + $isPublic = false, |
|
| 129 | + $downloadAttachment = true) { |
|
| 130 | + $this->tree = $tree; |
|
| 131 | + $this->config = $config; |
|
| 132 | + $this->request = $request; |
|
| 133 | + $this->isPublic = $isPublic; |
|
| 134 | + $this->downloadAttachment = $downloadAttachment; |
|
| 135 | + $this->previewManager = $previewManager; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * This initializes the plugin. |
|
| 140 | + * |
|
| 141 | + * This function is called by \Sabre\DAV\Server, after |
|
| 142 | + * addPlugin is called. |
|
| 143 | + * |
|
| 144 | + * This method should set up the required event subscriptions. |
|
| 145 | + * |
|
| 146 | + * @param \Sabre\DAV\Server $server |
|
| 147 | + * @return void |
|
| 148 | + */ |
|
| 149 | + public function initialize(\Sabre\DAV\Server $server) { |
|
| 150 | + $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
| 151 | + $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc'; |
|
| 152 | + $server->protectedProperties[] = self::FILEID_PROPERTYNAME; |
|
| 153 | + $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME; |
|
| 154 | + $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME; |
|
| 155 | + $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME; |
|
| 156 | + $server->protectedProperties[] = self::SIZE_PROPERTYNAME; |
|
| 157 | + $server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME; |
|
| 158 | + $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME; |
|
| 159 | + $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME; |
|
| 160 | + $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME; |
|
| 161 | + $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME; |
|
| 162 | + $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME; |
|
| 163 | + $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME; |
|
| 164 | + $server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME; |
|
| 165 | + |
|
| 166 | + // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH |
|
| 167 | + $allowedProperties = ['{DAV:}getetag']; |
|
| 168 | + $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties); |
|
| 169 | + |
|
| 170 | + $this->server = $server; |
|
| 171 | + $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
| 172 | + $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
|
| 173 | + $this->server->on('afterBind', array($this, 'sendFileIdHeader')); |
|
| 174 | + $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader')); |
|
| 175 | + $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
| 176 | + $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken')); |
|
| 177 | + $this->server->on('afterResponse', function($request, ResponseInterface $response) { |
|
| 178 | + $body = $response->getBody(); |
|
| 179 | + if (is_resource($body)) { |
|
| 180 | + fclose($body); |
|
| 181 | + } |
|
| 182 | + }); |
|
| 183 | + $this->server->on('beforeMove', [$this, 'checkMove']); |
|
| 184 | + $this->server->on('beforeMove', [$this, 'beforeMoveFutureFile']); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Plugin that checks if a move can actually be performed. |
|
| 189 | + * |
|
| 190 | + * @param string $source source path |
|
| 191 | + * @param string $destination destination path |
|
| 192 | + * @throws Forbidden |
|
| 193 | + * @throws NotFound |
|
| 194 | + */ |
|
| 195 | + function checkMove($source, $destination) { |
|
| 196 | + $sourceNode = $this->tree->getNodeForPath($source); |
|
| 197 | + if (!$sourceNode instanceof Node) { |
|
| 198 | + return; |
|
| 199 | + } |
|
| 200 | + list($sourceDir,) = \Sabre\Uri\split($source); |
|
| 201 | + list($destinationDir,) = \Sabre\Uri\split($destination); |
|
| 202 | + |
|
| 203 | + if ($sourceDir !== $destinationDir) { |
|
| 204 | + $sourceNodeFileInfo = $sourceNode->getFileInfo(); |
|
| 205 | + if ($sourceNodeFileInfo === null) { |
|
| 206 | + throw new NotFound($source . ' does not exist'); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + if (!$sourceNodeFileInfo->isDeletable()) { |
|
| 210 | + throw new Forbidden($source . " cannot be deleted"); |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * This sets a cookie to be able to recognize the start of the download |
|
| 217 | + * the content must not be longer than 32 characters and must only contain |
|
| 218 | + * alphanumeric characters |
|
| 219 | + * |
|
| 220 | + * @param RequestInterface $request |
|
| 221 | + * @param ResponseInterface $response |
|
| 222 | + */ |
|
| 223 | + function handleDownloadToken(RequestInterface $request, ResponseInterface $response) { |
|
| 224 | + $queryParams = $request->getQueryParameters(); |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * this sets a cookie to be able to recognize the start of the download |
|
| 228 | + * the content must not be longer than 32 characters and must only contain |
|
| 229 | + * alphanumeric characters |
|
| 230 | + */ |
|
| 231 | + if (isset($queryParams['downloadStartSecret'])) { |
|
| 232 | + $token = $queryParams['downloadStartSecret']; |
|
| 233 | + if (!isset($token[32]) |
|
| 234 | + && preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) { |
|
| 235 | + // FIXME: use $response->setHeader() instead |
|
| 236 | + setcookie('ocDownloadStarted', $token, time() + 20, '/'); |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Add headers to file download |
|
| 243 | + * |
|
| 244 | + * @param RequestInterface $request |
|
| 245 | + * @param ResponseInterface $response |
|
| 246 | + */ |
|
| 247 | + function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
| 248 | + // Only handle valid files |
|
| 249 | + $node = $this->tree->getNodeForPath($request->getPath()); |
|
| 250 | + if (!($node instanceof IFile)) return; |
|
| 251 | + |
|
| 252 | + // adds a 'Content-Disposition: attachment' header in case no disposition |
|
| 253 | + // header has been set before |
|
| 254 | + if ($this->downloadAttachment && |
|
| 255 | + $response->getHeader('Content-Disposition') === null) { |
|
| 256 | + $filename = $node->getName(); |
|
| 257 | + if ($this->request->isUserAgent( |
|
| 258 | + [ |
|
| 259 | + \OC\AppFramework\Http\Request::USER_AGENT_IE, |
|
| 260 | + \OC\AppFramework\Http\Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
| 261 | + \OC\AppFramework\Http\Request::USER_AGENT_FREEBOX, |
|
| 262 | + ])) { |
|
| 263 | + $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
| 264 | + } else { |
|
| 265 | + $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
| 266 | + . '; filename="' . rawurlencode($filename) . '"'); |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
| 271 | + //Add OC-Checksum header |
|
| 272 | + /** @var $node File */ |
|
| 273 | + $checksum = $node->getChecksum(); |
|
| 274 | + if ($checksum !== null && $checksum !== '') { |
|
| 275 | + $response->addHeader('OC-Checksum', $checksum); |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Adds all ownCloud-specific properties |
|
| 282 | + * |
|
| 283 | + * @param PropFind $propFind |
|
| 284 | + * @param \Sabre\DAV\INode $node |
|
| 285 | + * @return void |
|
| 286 | + */ |
|
| 287 | + public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) { |
|
| 288 | + |
|
| 289 | + $httpRequest = $this->server->httpRequest; |
|
| 290 | + |
|
| 291 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
| 292 | + /** |
|
| 293 | + * This was disabled, because it made dir listing throw an exception, |
|
| 294 | + * so users were unable to navigate into folders where one subitem |
|
| 295 | + * is blocked by the files_accesscontrol app, see: |
|
| 296 | + * https://github.com/nextcloud/files_accesscontrol/issues/65 |
|
| 297 | 297 | if (!$node->getFileInfo()->isReadable()) { |
| 298 | 298 | // avoid detecting files through this means |
| 299 | 299 | throw new NotFound(); |
| 300 | 300 | } |
| 301 | - */ |
|
| 302 | - |
|
| 303 | - $propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) { |
|
| 304 | - return $node->getFileId(); |
|
| 305 | - }); |
|
| 306 | - |
|
| 307 | - $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) { |
|
| 308 | - return $node->getInternalFileId(); |
|
| 309 | - }); |
|
| 310 | - |
|
| 311 | - $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) { |
|
| 312 | - $perms = $node->getDavPermissions(); |
|
| 313 | - if ($this->isPublic) { |
|
| 314 | - // remove mount information |
|
| 315 | - $perms = str_replace(['S', 'M'], '', $perms); |
|
| 316 | - } |
|
| 317 | - return $perms; |
|
| 318 | - }); |
|
| 319 | - |
|
| 320 | - $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) { |
|
| 321 | - return $node->getSharePermissions( |
|
| 322 | - $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
| 323 | - ); |
|
| 324 | - }); |
|
| 325 | - |
|
| 326 | - $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) { |
|
| 327 | - return $node->getETag(); |
|
| 328 | - }); |
|
| 329 | - |
|
| 330 | - $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) { |
|
| 331 | - $owner = $node->getOwner(); |
|
| 332 | - if (!$owner) { |
|
| 333 | - return null; |
|
| 334 | - } else { |
|
| 335 | - return $owner->getUID(); |
|
| 336 | - } |
|
| 337 | - }); |
|
| 338 | - $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) { |
|
| 339 | - $owner = $node->getOwner(); |
|
| 340 | - if (!$owner) { |
|
| 341 | - return null; |
|
| 342 | - } else { |
|
| 343 | - return $owner->getDisplayName(); |
|
| 344 | - } |
|
| 345 | - }); |
|
| 346 | - |
|
| 347 | - $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) { |
|
| 348 | - $result = $node->getFileInfo()->isEncrypted() ? '1' : '0'; |
|
| 349 | - return $result; |
|
| 350 | - }); |
|
| 351 | - |
|
| 352 | - $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
| 353 | - return json_encode($this->previewManager->isAvailable($node->getFileInfo())); |
|
| 354 | - }); |
|
| 355 | - $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
| 356 | - return $node->getSize(); |
|
| 357 | - }); |
|
| 358 | - $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
| 359 | - return $node->getFileInfo()->getMountPoint()->getMountType(); |
|
| 360 | - }); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
| 364 | - $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) { |
|
| 365 | - return $this->config->getSystemValue('data-fingerprint', ''); |
|
| 366 | - }); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
| 370 | - $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) { |
|
| 371 | - /** @var $node \OCA\DAV\Connector\Sabre\File */ |
|
| 372 | - try { |
|
| 373 | - $directDownloadUrl = $node->getDirectDownload(); |
|
| 374 | - if (isset($directDownloadUrl['url'])) { |
|
| 375 | - return $directDownloadUrl['url']; |
|
| 376 | - } |
|
| 377 | - } catch (StorageNotAvailableException $e) { |
|
| 378 | - return false; |
|
| 379 | - } catch (ForbiddenException $e) { |
|
| 380 | - return false; |
|
| 381 | - } |
|
| 382 | - return false; |
|
| 383 | - }); |
|
| 384 | - |
|
| 385 | - $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) { |
|
| 386 | - $checksum = $node->getChecksum(); |
|
| 387 | - if ($checksum === NULL || $checksum === '') { |
|
| 388 | - return null; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - return new ChecksumList($checksum); |
|
| 392 | - }); |
|
| 393 | - |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) { |
|
| 397 | - $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
| 398 | - return $node->getSize(); |
|
| 399 | - }); |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * Update ownCloud-specific properties |
|
| 405 | - * |
|
| 406 | - * @param string $path |
|
| 407 | - * @param PropPatch $propPatch |
|
| 408 | - * |
|
| 409 | - * @return void |
|
| 410 | - */ |
|
| 411 | - public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
| 412 | - $node = $this->tree->getNodeForPath($path); |
|
| 413 | - if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
| 414 | - return; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) { |
|
| 418 | - if (empty($time)) { |
|
| 419 | - return false; |
|
| 420 | - } |
|
| 421 | - $node->touch($time); |
|
| 422 | - return true; |
|
| 423 | - }); |
|
| 424 | - $propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) { |
|
| 425 | - if (empty($etag)) { |
|
| 426 | - return false; |
|
| 427 | - } |
|
| 428 | - if ($node->setEtag($etag) !== -1) { |
|
| 429 | - return true; |
|
| 430 | - } |
|
| 431 | - return false; |
|
| 432 | - }); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * @param string $filePath |
|
| 437 | - * @param \Sabre\DAV\INode $node |
|
| 438 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
| 439 | - */ |
|
| 440 | - public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) { |
|
| 441 | - // chunked upload handling |
|
| 442 | - if (isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
| 443 | - list($path, $name) = \Sabre\Uri\split($filePath); |
|
| 444 | - $info = \OC_FileChunking::decodeName($name); |
|
| 445 | - if (!empty($info)) { |
|
| 446 | - $filePath = $path . '/' . $info['name']; |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder |
|
| 451 | - if (!$this->server->tree->nodeExists($filePath)) { |
|
| 452 | - return; |
|
| 453 | - } |
|
| 454 | - $node = $this->server->tree->getNodeForPath($filePath); |
|
| 455 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
| 456 | - $fileId = $node->getFileId(); |
|
| 457 | - if (!is_null($fileId)) { |
|
| 458 | - $this->server->httpResponse->setHeader('OC-FileId', $fileId); |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Move handler for future file. |
|
| 465 | - * |
|
| 466 | - * This overrides the default move behavior to prevent Sabre |
|
| 467 | - * to delete the target file before moving. Because deleting would |
|
| 468 | - * lose the file id and metadata. |
|
| 469 | - * |
|
| 470 | - * @param string $path source path |
|
| 471 | - * @param string $destination destination path |
|
| 472 | - * @return bool|void false to stop handling, void to skip this handler |
|
| 473 | - */ |
|
| 474 | - public function beforeMoveFutureFile($path, $destination) { |
|
| 475 | - $sourceNode = $this->tree->getNodeForPath($path); |
|
| 476 | - if (!$sourceNode instanceof FutureFile) { |
|
| 477 | - // skip handling as the source is not a chunked FutureFile |
|
| 478 | - return; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - if (!$this->tree->nodeExists($destination)) { |
|
| 482 | - // skip and let the default handler do its work |
|
| 483 | - return; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - // do a move manually, skipping Sabre's default "delete" for existing nodes |
|
| 487 | - $this->tree->move($path, $destination); |
|
| 488 | - |
|
| 489 | - // trigger all default events (copied from CorePlugin::move) |
|
| 490 | - $this->server->emit('afterMove', [$path, $destination]); |
|
| 491 | - $this->server->emit('afterUnbind', [$path]); |
|
| 492 | - $this->server->emit('afterBind', [$destination]); |
|
| 493 | - |
|
| 494 | - $response = $this->server->httpResponse; |
|
| 495 | - $response->setHeader('Content-Length', '0'); |
|
| 496 | - $response->setStatus(204); |
|
| 497 | - |
|
| 498 | - return false; |
|
| 499 | - } |
|
| 301 | + */ |
|
| 302 | + |
|
| 303 | + $propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) { |
|
| 304 | + return $node->getFileId(); |
|
| 305 | + }); |
|
| 306 | + |
|
| 307 | + $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) { |
|
| 308 | + return $node->getInternalFileId(); |
|
| 309 | + }); |
|
| 310 | + |
|
| 311 | + $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) { |
|
| 312 | + $perms = $node->getDavPermissions(); |
|
| 313 | + if ($this->isPublic) { |
|
| 314 | + // remove mount information |
|
| 315 | + $perms = str_replace(['S', 'M'], '', $perms); |
|
| 316 | + } |
|
| 317 | + return $perms; |
|
| 318 | + }); |
|
| 319 | + |
|
| 320 | + $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) { |
|
| 321 | + return $node->getSharePermissions( |
|
| 322 | + $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
| 323 | + ); |
|
| 324 | + }); |
|
| 325 | + |
|
| 326 | + $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) { |
|
| 327 | + return $node->getETag(); |
|
| 328 | + }); |
|
| 329 | + |
|
| 330 | + $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) { |
|
| 331 | + $owner = $node->getOwner(); |
|
| 332 | + if (!$owner) { |
|
| 333 | + return null; |
|
| 334 | + } else { |
|
| 335 | + return $owner->getUID(); |
|
| 336 | + } |
|
| 337 | + }); |
|
| 338 | + $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) { |
|
| 339 | + $owner = $node->getOwner(); |
|
| 340 | + if (!$owner) { |
|
| 341 | + return null; |
|
| 342 | + } else { |
|
| 343 | + return $owner->getDisplayName(); |
|
| 344 | + } |
|
| 345 | + }); |
|
| 346 | + |
|
| 347 | + $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) { |
|
| 348 | + $result = $node->getFileInfo()->isEncrypted() ? '1' : '0'; |
|
| 349 | + return $result; |
|
| 350 | + }); |
|
| 351 | + |
|
| 352 | + $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
| 353 | + return json_encode($this->previewManager->isAvailable($node->getFileInfo())); |
|
| 354 | + }); |
|
| 355 | + $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
| 356 | + return $node->getSize(); |
|
| 357 | + }); |
|
| 358 | + $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
| 359 | + return $node->getFileInfo()->getMountPoint()->getMountType(); |
|
| 360 | + }); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
| 364 | + $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) { |
|
| 365 | + return $this->config->getSystemValue('data-fingerprint', ''); |
|
| 366 | + }); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
| 370 | + $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) { |
|
| 371 | + /** @var $node \OCA\DAV\Connector\Sabre\File */ |
|
| 372 | + try { |
|
| 373 | + $directDownloadUrl = $node->getDirectDownload(); |
|
| 374 | + if (isset($directDownloadUrl['url'])) { |
|
| 375 | + return $directDownloadUrl['url']; |
|
| 376 | + } |
|
| 377 | + } catch (StorageNotAvailableException $e) { |
|
| 378 | + return false; |
|
| 379 | + } catch (ForbiddenException $e) { |
|
| 380 | + return false; |
|
| 381 | + } |
|
| 382 | + return false; |
|
| 383 | + }); |
|
| 384 | + |
|
| 385 | + $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) { |
|
| 386 | + $checksum = $node->getChecksum(); |
|
| 387 | + if ($checksum === NULL || $checksum === '') { |
|
| 388 | + return null; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + return new ChecksumList($checksum); |
|
| 392 | + }); |
|
| 393 | + |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) { |
|
| 397 | + $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
| 398 | + return $node->getSize(); |
|
| 399 | + }); |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * Update ownCloud-specific properties |
|
| 405 | + * |
|
| 406 | + * @param string $path |
|
| 407 | + * @param PropPatch $propPatch |
|
| 408 | + * |
|
| 409 | + * @return void |
|
| 410 | + */ |
|
| 411 | + public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
| 412 | + $node = $this->tree->getNodeForPath($path); |
|
| 413 | + if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
| 414 | + return; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) { |
|
| 418 | + if (empty($time)) { |
|
| 419 | + return false; |
|
| 420 | + } |
|
| 421 | + $node->touch($time); |
|
| 422 | + return true; |
|
| 423 | + }); |
|
| 424 | + $propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) { |
|
| 425 | + if (empty($etag)) { |
|
| 426 | + return false; |
|
| 427 | + } |
|
| 428 | + if ($node->setEtag($etag) !== -1) { |
|
| 429 | + return true; |
|
| 430 | + } |
|
| 431 | + return false; |
|
| 432 | + }); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * @param string $filePath |
|
| 437 | + * @param \Sabre\DAV\INode $node |
|
| 438 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
| 439 | + */ |
|
| 440 | + public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) { |
|
| 441 | + // chunked upload handling |
|
| 442 | + if (isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
| 443 | + list($path, $name) = \Sabre\Uri\split($filePath); |
|
| 444 | + $info = \OC_FileChunking::decodeName($name); |
|
| 445 | + if (!empty($info)) { |
|
| 446 | + $filePath = $path . '/' . $info['name']; |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder |
|
| 451 | + if (!$this->server->tree->nodeExists($filePath)) { |
|
| 452 | + return; |
|
| 453 | + } |
|
| 454 | + $node = $this->server->tree->getNodeForPath($filePath); |
|
| 455 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
| 456 | + $fileId = $node->getFileId(); |
|
| 457 | + if (!is_null($fileId)) { |
|
| 458 | + $this->server->httpResponse->setHeader('OC-FileId', $fileId); |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Move handler for future file. |
|
| 465 | + * |
|
| 466 | + * This overrides the default move behavior to prevent Sabre |
|
| 467 | + * to delete the target file before moving. Because deleting would |
|
| 468 | + * lose the file id and metadata. |
|
| 469 | + * |
|
| 470 | + * @param string $path source path |
|
| 471 | + * @param string $destination destination path |
|
| 472 | + * @return bool|void false to stop handling, void to skip this handler |
|
| 473 | + */ |
|
| 474 | + public function beforeMoveFutureFile($path, $destination) { |
|
| 475 | + $sourceNode = $this->tree->getNodeForPath($path); |
|
| 476 | + if (!$sourceNode instanceof FutureFile) { |
|
| 477 | + // skip handling as the source is not a chunked FutureFile |
|
| 478 | + return; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + if (!$this->tree->nodeExists($destination)) { |
|
| 482 | + // skip and let the default handler do its work |
|
| 483 | + return; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + // do a move manually, skipping Sabre's default "delete" for existing nodes |
|
| 487 | + $this->tree->move($path, $destination); |
|
| 488 | + |
|
| 489 | + // trigger all default events (copied from CorePlugin::move) |
|
| 490 | + $this->server->emit('afterMove', [$path, $destination]); |
|
| 491 | + $this->server->emit('afterUnbind', [$path]); |
|
| 492 | + $this->server->emit('afterBind', [$destination]); |
|
| 493 | + |
|
| 494 | + $response = $this->server->httpResponse; |
|
| 495 | + $response->setHeader('Content-Length', '0'); |
|
| 496 | + $response->setStatus(204); |
|
| 497 | + |
|
| 498 | + return false; |
|
| 499 | + } |
|
| 500 | 500 | |
| 501 | 501 | } |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
| 173 | 173 | $this->server->on('afterBind', array($this, 'sendFileIdHeader')); |
| 174 | 174 | $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader')); |
| 175 | - $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
| 175 | + $this->server->on('afterMethod:GET', [$this, 'httpGet']); |
|
| 176 | 176 | $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken')); |
| 177 | 177 | $this->server->on('afterResponse', function($request, ResponseInterface $response) { |
| 178 | 178 | $body = $response->getBody(); |
@@ -203,11 +203,11 @@ discard block |
||
| 203 | 203 | if ($sourceDir !== $destinationDir) { |
| 204 | 204 | $sourceNodeFileInfo = $sourceNode->getFileInfo(); |
| 205 | 205 | if ($sourceNodeFileInfo === null) { |
| 206 | - throw new NotFound($source . ' does not exist'); |
|
| 206 | + throw new NotFound($source.' does not exist'); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | if (!$sourceNodeFileInfo->isDeletable()) { |
| 210 | - throw new Forbidden($source . " cannot be deleted"); |
|
| 210 | + throw new Forbidden($source." cannot be deleted"); |
|
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | } |
@@ -260,10 +260,10 @@ discard block |
||
| 260 | 260 | \OC\AppFramework\Http\Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
| 261 | 261 | \OC\AppFramework\Http\Request::USER_AGENT_FREEBOX, |
| 262 | 262 | ])) { |
| 263 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
| 263 | + $response->addHeader('Content-Disposition', 'attachment; filename="'.rawurlencode($filename).'"'); |
|
| 264 | 264 | } else { |
| 265 | - $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
| 266 | - . '; filename="' . rawurlencode($filename) . '"'); |
|
| 265 | + $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\''.rawurlencode($filename) |
|
| 266 | + . '; filename="'.rawurlencode($filename).'"'); |
|
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | |
@@ -349,13 +349,13 @@ discard block |
||
| 349 | 349 | return $result; |
| 350 | 350 | }); |
| 351 | 351 | |
| 352 | - $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
| 352 | + $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function() use ($node) { |
|
| 353 | 353 | return json_encode($this->previewManager->isAvailable($node->getFileInfo())); |
| 354 | 354 | }); |
| 355 | 355 | $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
| 356 | 356 | return $node->getSize(); |
| 357 | 357 | }); |
| 358 | - $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
| 358 | + $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function() use ($node) { |
|
| 359 | 359 | return $node->getFileInfo()->getMountPoint()->getMountType(); |
| 360 | 360 | }); |
| 361 | 361 | } |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | list($path, $name) = \Sabre\Uri\split($filePath); |
| 444 | 444 | $info = \OC_FileChunking::decodeName($name); |
| 445 | 445 | if (!empty($info)) { |
| 446 | - $filePath = $path . '/' . $info['name']; |
|
| 446 | + $filePath = $path.'/'.$info['name']; |
|
| 447 | 447 | } |
| 448 | 448 | } |
| 449 | 449 | |
@@ -60,9 +60,9 @@ |
||
| 60 | 60 | |
| 61 | 61 | public function propFind(PropFind $propFind, INode $node) { |
| 62 | 62 | /* Overload current-user-principal */ |
| 63 | - $propFind->handle('{DAV:}current-user-principal', function () { |
|
| 63 | + $propFind->handle('{DAV:}current-user-principal', function() { |
|
| 64 | 64 | if ($url = parent::getCurrentUserPrincipal()) { |
| 65 | - return new Principal(Principal::HREF, $url . '/'); |
|
| 65 | + return new Principal(Principal::HREF, $url.'/'); |
|
| 66 | 66 | } else { |
| 67 | 67 | return new Principal(Principal::UNAUTHENTICATED); |
| 68 | 68 | } |
@@ -38,7 +38,9 @@ |
||
| 38 | 38 | public function getCurrentUserPrincipals() { |
| 39 | 39 | $principalV2 = $this->getCurrentUserPrincipal(); |
| 40 | 40 | |
| 41 | - if (is_null($principalV2)) return []; |
|
| 41 | + if (is_null($principalV2)) { |
|
| 42 | + return []; |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | $principalV1 = $this->convertPrincipal($principalV2, false); |
| 44 | 46 | return array_merge( |
@@ -32,42 +32,42 @@ |
||
| 32 | 32 | |
| 33 | 33 | class LegacyDAVACL extends DavAclPlugin { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @inheritdoc |
|
| 37 | - */ |
|
| 38 | - public function getCurrentUserPrincipals() { |
|
| 39 | - $principalV2 = $this->getCurrentUserPrincipal(); |
|
| 35 | + /** |
|
| 36 | + * @inheritdoc |
|
| 37 | + */ |
|
| 38 | + public function getCurrentUserPrincipals() { |
|
| 39 | + $principalV2 = $this->getCurrentUserPrincipal(); |
|
| 40 | 40 | |
| 41 | - if (is_null($principalV2)) return []; |
|
| 41 | + if (is_null($principalV2)) return []; |
|
| 42 | 42 | |
| 43 | - $principalV1 = $this->convertPrincipal($principalV2, false); |
|
| 44 | - return array_merge( |
|
| 45 | - [ |
|
| 46 | - $principalV2, |
|
| 47 | - $principalV1 |
|
| 48 | - ], |
|
| 49 | - $this->getPrincipalMembership($principalV1) |
|
| 50 | - ); |
|
| 51 | - } |
|
| 43 | + $principalV1 = $this->convertPrincipal($principalV2, false); |
|
| 44 | + return array_merge( |
|
| 45 | + [ |
|
| 46 | + $principalV2, |
|
| 47 | + $principalV1 |
|
| 48 | + ], |
|
| 49 | + $this->getPrincipalMembership($principalV1) |
|
| 50 | + ); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - private function convertPrincipal($principal, $toV2) { |
|
| 54 | - list(, $name) = \Sabre\Uri\split($principal); |
|
| 55 | - if ($toV2) { |
|
| 56 | - return "principals/users/$name"; |
|
| 57 | - } |
|
| 58 | - return "principals/$name"; |
|
| 59 | - } |
|
| 53 | + private function convertPrincipal($principal, $toV2) { |
|
| 54 | + list(, $name) = \Sabre\Uri\split($principal); |
|
| 55 | + if ($toV2) { |
|
| 56 | + return "principals/users/$name"; |
|
| 57 | + } |
|
| 58 | + return "principals/$name"; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - public function propFind(PropFind $propFind, INode $node) { |
|
| 62 | - /* Overload current-user-principal */ |
|
| 63 | - $propFind->handle('{DAV:}current-user-principal', function () { |
|
| 64 | - if ($url = parent::getCurrentUserPrincipal()) { |
|
| 65 | - return new Principal(Principal::HREF, $url . '/'); |
|
| 66 | - } else { |
|
| 67 | - return new Principal(Principal::UNAUTHENTICATED); |
|
| 68 | - } |
|
| 69 | - }); |
|
| 61 | + public function propFind(PropFind $propFind, INode $node) { |
|
| 62 | + /* Overload current-user-principal */ |
|
| 63 | + $propFind->handle('{DAV:}current-user-principal', function () { |
|
| 64 | + if ($url = parent::getCurrentUserPrincipal()) { |
|
| 65 | + return new Principal(Principal::HREF, $url . '/'); |
|
| 66 | + } else { |
|
| 67 | + return new Principal(Principal::UNAUTHENTICATED); |
|
| 68 | + } |
|
| 69 | + }); |
|
| 70 | 70 | |
| 71 | - return parent::propFind($propFind, $node); |
|
| 72 | - } |
|
| 71 | + return parent::propFind($propFind, $node); |
|
| 72 | + } |
|
| 73 | 73 | } |
@@ -70,7 +70,7 @@ |
||
| 70 | 70 | $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
| 71 | 71 | |
| 72 | 72 | // first time login event setup |
| 73 | - $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { |
|
| 73 | + $dispatcher->addListener(IUser::class.'::firstLogin', function($event) use ($hm) { |
|
| 74 | 74 | if ($event instanceof GenericEvent) { |
| 75 | 75 | $hm->firstLogin($event->getSubject()); |
| 76 | 76 | } |
@@ -76,7 +76,7 @@ |
||
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | - * @param IManager $contactsManager |
|
| 79 | + * @param IContactsManager $contactsManager |
|
| 80 | 80 | */ |
| 81 | 81 | public function setupSystemContactsProvider(IContactsManager $contactsManager) { |
| 82 | 82 | /** @var ContactsManager $cm */ |
@@ -43,175 +43,175 @@ |
||
| 43 | 43 | |
| 44 | 44 | class Application extends App { |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Application constructor. |
|
| 48 | - */ |
|
| 49 | - public function __construct() { |
|
| 50 | - parent::__construct('dav'); |
|
| 51 | - |
|
| 52 | - $container = $this->getContainer(); |
|
| 53 | - $server = $container->getServer(); |
|
| 54 | - |
|
| 55 | - $container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) { |
|
| 56 | - return new PhotoCache( |
|
| 57 | - $server->getAppDataDir('dav-photocache') |
|
| 58 | - ); |
|
| 59 | - }); |
|
| 60 | - |
|
| 61 | - /* |
|
| 46 | + /** |
|
| 47 | + * Application constructor. |
|
| 48 | + */ |
|
| 49 | + public function __construct() { |
|
| 50 | + parent::__construct('dav'); |
|
| 51 | + |
|
| 52 | + $container = $this->getContainer(); |
|
| 53 | + $server = $container->getServer(); |
|
| 54 | + |
|
| 55 | + $container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) { |
|
| 56 | + return new PhotoCache( |
|
| 57 | + $server->getAppDataDir('dav-photocache') |
|
| 58 | + ); |
|
| 59 | + }); |
|
| 60 | + |
|
| 61 | + /* |
|
| 62 | 62 | * Register capabilities |
| 63 | 63 | */ |
| 64 | - $container->registerCapability(Capabilities::class); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @param IContactsManager $contactsManager |
|
| 69 | - * @param string $userID |
|
| 70 | - */ |
|
| 71 | - public function setupContactsProvider(IContactsManager $contactsManager, $userID) { |
|
| 72 | - /** @var ContactsManager $cm */ |
|
| 73 | - $cm = $this->getContainer()->query(ContactsManager::class); |
|
| 74 | - $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
| 75 | - $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param IManager $contactsManager |
|
| 80 | - */ |
|
| 81 | - public function setupSystemContactsProvider(IContactsManager $contactsManager) { |
|
| 82 | - /** @var ContactsManager $cm */ |
|
| 83 | - $cm = $this->getContainer()->query(ContactsManager::class); |
|
| 84 | - $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
| 85 | - $cm->setupSystemContactsProvider($contactsManager, $urlGenerator); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @param ICalendarManager $calendarManager |
|
| 90 | - * @param string $userId |
|
| 91 | - */ |
|
| 92 | - public function setupCalendarProvider(ICalendarManager $calendarManager, $userId) { |
|
| 93 | - $cm = $this->getContainer()->query(CalendarManager::class); |
|
| 94 | - $cm->setupCalendarProvider($calendarManager, $userId); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - public function registerHooks() { |
|
| 98 | - /** @var HookManager $hm */ |
|
| 99 | - $hm = $this->getContainer()->query(HookManager::class); |
|
| 100 | - $hm->setup(); |
|
| 101 | - |
|
| 102 | - $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
| 103 | - |
|
| 104 | - // first time login event setup |
|
| 105 | - $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { |
|
| 106 | - if ($event instanceof GenericEvent) { |
|
| 107 | - $hm->firstLogin($event->getSubject()); |
|
| 108 | - } |
|
| 109 | - }); |
|
| 110 | - |
|
| 111 | - // carddav/caldav sync event setup |
|
| 112 | - $listener = function($event) { |
|
| 113 | - if ($event instanceof GenericEvent) { |
|
| 114 | - /** @var BirthdayService $b */ |
|
| 115 | - $b = $this->getContainer()->query(BirthdayService::class); |
|
| 116 | - $b->onCardChanged( |
|
| 117 | - $event->getArgument('addressBookId'), |
|
| 118 | - $event->getArgument('cardUri'), |
|
| 119 | - $event->getArgument('cardData') |
|
| 120 | - ); |
|
| 121 | - } |
|
| 122 | - }; |
|
| 123 | - |
|
| 124 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener); |
|
| 125 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener); |
|
| 126 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) { |
|
| 127 | - if ($event instanceof GenericEvent) { |
|
| 128 | - /** @var BirthdayService $b */ |
|
| 129 | - $b = $this->getContainer()->query(BirthdayService::class); |
|
| 130 | - $b->onCardDeleted( |
|
| 131 | - $event->getArgument('addressBookId'), |
|
| 132 | - $event->getArgument('cardUri') |
|
| 133 | - ); |
|
| 134 | - } |
|
| 135 | - }); |
|
| 136 | - |
|
| 137 | - $clearPhotoCache = function($event) { |
|
| 138 | - if ($event instanceof GenericEvent) { |
|
| 139 | - /** @var PhotoCache $p */ |
|
| 140 | - $p = $this->getContainer()->query(PhotoCache::class); |
|
| 141 | - $p->delete( |
|
| 142 | - $event->getArgument('addressBookId'), |
|
| 143 | - $event->getArgument('cardUri') |
|
| 144 | - ); |
|
| 145 | - } |
|
| 146 | - }; |
|
| 147 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache); |
|
| 148 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache); |
|
| 149 | - |
|
| 150 | - $dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) { |
|
| 151 | - $user = $event->getSubject(); |
|
| 152 | - $syncService = $this->getContainer()->query(SyncService::class); |
|
| 153 | - $syncService->updateUser($user); |
|
| 154 | - }); |
|
| 155 | - |
|
| 156 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) { |
|
| 157 | - /** @var Backend $backend */ |
|
| 158 | - $backend = $this->getContainer()->query(Backend::class); |
|
| 159 | - $backend->onCalendarAdd( |
|
| 160 | - $event->getArgument('calendarData') |
|
| 161 | - ); |
|
| 162 | - }); |
|
| 163 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) { |
|
| 164 | - /** @var Backend $backend */ |
|
| 165 | - $backend = $this->getContainer()->query(Backend::class); |
|
| 166 | - $backend->onCalendarUpdate( |
|
| 167 | - $event->getArgument('calendarData'), |
|
| 168 | - $event->getArgument('shares'), |
|
| 169 | - $event->getArgument('propertyMutations') |
|
| 170 | - ); |
|
| 171 | - }); |
|
| 172 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) { |
|
| 173 | - /** @var Backend $backend */ |
|
| 174 | - $backend = $this->getContainer()->query(Backend::class); |
|
| 175 | - $backend->onCalendarDelete( |
|
| 176 | - $event->getArgument('calendarData'), |
|
| 177 | - $event->getArgument('shares') |
|
| 178 | - ); |
|
| 179 | - }); |
|
| 180 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) { |
|
| 181 | - /** @var Backend $backend */ |
|
| 182 | - $backend = $this->getContainer()->query(Backend::class); |
|
| 183 | - $backend->onCalendarUpdateShares( |
|
| 184 | - $event->getArgument('calendarData'), |
|
| 185 | - $event->getArgument('shares'), |
|
| 186 | - $event->getArgument('add'), |
|
| 187 | - $event->getArgument('remove') |
|
| 188 | - ); |
|
| 189 | - }); |
|
| 190 | - |
|
| 191 | - $listener = function(GenericEvent $event, $eventName) { |
|
| 192 | - /** @var Backend $backend */ |
|
| 193 | - $backend = $this->getContainer()->query(Backend::class); |
|
| 194 | - |
|
| 195 | - $subject = Event::SUBJECT_OBJECT_ADD; |
|
| 196 | - if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') { |
|
| 197 | - $subject = Event::SUBJECT_OBJECT_UPDATE; |
|
| 198 | - } else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') { |
|
| 199 | - $subject = Event::SUBJECT_OBJECT_DELETE; |
|
| 200 | - } |
|
| 201 | - $backend->onTouchCalendarObject( |
|
| 202 | - $subject, |
|
| 203 | - $event->getArgument('calendarData'), |
|
| 204 | - $event->getArgument('shares'), |
|
| 205 | - $event->getArgument('objectData') |
|
| 206 | - ); |
|
| 207 | - }; |
|
| 208 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener); |
|
| 209 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); |
|
| 210 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - public function getSyncService() { |
|
| 214 | - return $this->getContainer()->query(SyncService::class); |
|
| 215 | - } |
|
| 64 | + $container->registerCapability(Capabilities::class); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @param IContactsManager $contactsManager |
|
| 69 | + * @param string $userID |
|
| 70 | + */ |
|
| 71 | + public function setupContactsProvider(IContactsManager $contactsManager, $userID) { |
|
| 72 | + /** @var ContactsManager $cm */ |
|
| 73 | + $cm = $this->getContainer()->query(ContactsManager::class); |
|
| 74 | + $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
| 75 | + $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param IManager $contactsManager |
|
| 80 | + */ |
|
| 81 | + public function setupSystemContactsProvider(IContactsManager $contactsManager) { |
|
| 82 | + /** @var ContactsManager $cm */ |
|
| 83 | + $cm = $this->getContainer()->query(ContactsManager::class); |
|
| 84 | + $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
| 85 | + $cm->setupSystemContactsProvider($contactsManager, $urlGenerator); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @param ICalendarManager $calendarManager |
|
| 90 | + * @param string $userId |
|
| 91 | + */ |
|
| 92 | + public function setupCalendarProvider(ICalendarManager $calendarManager, $userId) { |
|
| 93 | + $cm = $this->getContainer()->query(CalendarManager::class); |
|
| 94 | + $cm->setupCalendarProvider($calendarManager, $userId); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + public function registerHooks() { |
|
| 98 | + /** @var HookManager $hm */ |
|
| 99 | + $hm = $this->getContainer()->query(HookManager::class); |
|
| 100 | + $hm->setup(); |
|
| 101 | + |
|
| 102 | + $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
| 103 | + |
|
| 104 | + // first time login event setup |
|
| 105 | + $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { |
|
| 106 | + if ($event instanceof GenericEvent) { |
|
| 107 | + $hm->firstLogin($event->getSubject()); |
|
| 108 | + } |
|
| 109 | + }); |
|
| 110 | + |
|
| 111 | + // carddav/caldav sync event setup |
|
| 112 | + $listener = function($event) { |
|
| 113 | + if ($event instanceof GenericEvent) { |
|
| 114 | + /** @var BirthdayService $b */ |
|
| 115 | + $b = $this->getContainer()->query(BirthdayService::class); |
|
| 116 | + $b->onCardChanged( |
|
| 117 | + $event->getArgument('addressBookId'), |
|
| 118 | + $event->getArgument('cardUri'), |
|
| 119 | + $event->getArgument('cardData') |
|
| 120 | + ); |
|
| 121 | + } |
|
| 122 | + }; |
|
| 123 | + |
|
| 124 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener); |
|
| 125 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener); |
|
| 126 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) { |
|
| 127 | + if ($event instanceof GenericEvent) { |
|
| 128 | + /** @var BirthdayService $b */ |
|
| 129 | + $b = $this->getContainer()->query(BirthdayService::class); |
|
| 130 | + $b->onCardDeleted( |
|
| 131 | + $event->getArgument('addressBookId'), |
|
| 132 | + $event->getArgument('cardUri') |
|
| 133 | + ); |
|
| 134 | + } |
|
| 135 | + }); |
|
| 136 | + |
|
| 137 | + $clearPhotoCache = function($event) { |
|
| 138 | + if ($event instanceof GenericEvent) { |
|
| 139 | + /** @var PhotoCache $p */ |
|
| 140 | + $p = $this->getContainer()->query(PhotoCache::class); |
|
| 141 | + $p->delete( |
|
| 142 | + $event->getArgument('addressBookId'), |
|
| 143 | + $event->getArgument('cardUri') |
|
| 144 | + ); |
|
| 145 | + } |
|
| 146 | + }; |
|
| 147 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache); |
|
| 148 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache); |
|
| 149 | + |
|
| 150 | + $dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) { |
|
| 151 | + $user = $event->getSubject(); |
|
| 152 | + $syncService = $this->getContainer()->query(SyncService::class); |
|
| 153 | + $syncService->updateUser($user); |
|
| 154 | + }); |
|
| 155 | + |
|
| 156 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) { |
|
| 157 | + /** @var Backend $backend */ |
|
| 158 | + $backend = $this->getContainer()->query(Backend::class); |
|
| 159 | + $backend->onCalendarAdd( |
|
| 160 | + $event->getArgument('calendarData') |
|
| 161 | + ); |
|
| 162 | + }); |
|
| 163 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) { |
|
| 164 | + /** @var Backend $backend */ |
|
| 165 | + $backend = $this->getContainer()->query(Backend::class); |
|
| 166 | + $backend->onCalendarUpdate( |
|
| 167 | + $event->getArgument('calendarData'), |
|
| 168 | + $event->getArgument('shares'), |
|
| 169 | + $event->getArgument('propertyMutations') |
|
| 170 | + ); |
|
| 171 | + }); |
|
| 172 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) { |
|
| 173 | + /** @var Backend $backend */ |
|
| 174 | + $backend = $this->getContainer()->query(Backend::class); |
|
| 175 | + $backend->onCalendarDelete( |
|
| 176 | + $event->getArgument('calendarData'), |
|
| 177 | + $event->getArgument('shares') |
|
| 178 | + ); |
|
| 179 | + }); |
|
| 180 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) { |
|
| 181 | + /** @var Backend $backend */ |
|
| 182 | + $backend = $this->getContainer()->query(Backend::class); |
|
| 183 | + $backend->onCalendarUpdateShares( |
|
| 184 | + $event->getArgument('calendarData'), |
|
| 185 | + $event->getArgument('shares'), |
|
| 186 | + $event->getArgument('add'), |
|
| 187 | + $event->getArgument('remove') |
|
| 188 | + ); |
|
| 189 | + }); |
|
| 190 | + |
|
| 191 | + $listener = function(GenericEvent $event, $eventName) { |
|
| 192 | + /** @var Backend $backend */ |
|
| 193 | + $backend = $this->getContainer()->query(Backend::class); |
|
| 194 | + |
|
| 195 | + $subject = Event::SUBJECT_OBJECT_ADD; |
|
| 196 | + if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') { |
|
| 197 | + $subject = Event::SUBJECT_OBJECT_UPDATE; |
|
| 198 | + } else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') { |
|
| 199 | + $subject = Event::SUBJECT_OBJECT_DELETE; |
|
| 200 | + } |
|
| 201 | + $backend->onTouchCalendarObject( |
|
| 202 | + $subject, |
|
| 203 | + $event->getArgument('calendarData'), |
|
| 204 | + $event->getArgument('shares'), |
|
| 205 | + $event->getArgument('objectData') |
|
| 206 | + ); |
|
| 207 | + }; |
|
| 208 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener); |
|
| 209 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); |
|
| 210 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + public function getSyncService() { |
|
| 214 | + return $this->getContainer()->query(SyncService::class); |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | 217 | } |