@@ -42,280 +42,280 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | class DbHandler { |
| 44 | 44 | |
| 45 | - /** @var IDBConnection */ |
|
| 46 | - private $connection; |
|
| 47 | - |
|
| 48 | - /** @var IL10N */ |
|
| 49 | - private $IL10N; |
|
| 50 | - |
|
| 51 | - /** @var string */ |
|
| 52 | - private $dbTable = 'trusted_servers'; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @param IDBConnection $connection |
|
| 56 | - * @param IL10N $il10n |
|
| 57 | - */ |
|
| 58 | - public function __construct( |
|
| 59 | - IDBConnection $connection, |
|
| 60 | - IL10N $il10n |
|
| 61 | - ) { |
|
| 62 | - $this->connection = $connection; |
|
| 63 | - $this->IL10N = $il10n; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * add server to the list of trusted servers |
|
| 68 | - * |
|
| 69 | - * @param string $url |
|
| 70 | - * @return int |
|
| 71 | - * @throws HintException |
|
| 72 | - */ |
|
| 73 | - public function addServer($url) { |
|
| 74 | - $hash = $this->hash($url); |
|
| 75 | - $url = rtrim($url, '/'); |
|
| 76 | - $query = $this->connection->getQueryBuilder(); |
|
| 77 | - $query->insert($this->dbTable) |
|
| 78 | - ->values( |
|
| 79 | - [ |
|
| 80 | - 'url' => $query->createParameter('url'), |
|
| 81 | - 'url_hash' => $query->createParameter('url_hash'), |
|
| 82 | - ] |
|
| 83 | - ) |
|
| 84 | - ->setParameter('url', $url) |
|
| 85 | - ->setParameter('url_hash', $hash); |
|
| 86 | - |
|
| 87 | - $result = $query->execute(); |
|
| 88 | - |
|
| 89 | - if ($result) { |
|
| 90 | - return (int)$this->connection->lastInsertId('*PREFIX*'.$this->dbTable); |
|
| 91 | - } else { |
|
| 92 | - $message = 'Internal failure, Could not add trusted server: ' . $url; |
|
| 93 | - $message_t = $this->IL10N->t('Could not add server'); |
|
| 94 | - throw new HintException($message, $message_t); |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * remove server from the list of trusted servers |
|
| 100 | - * |
|
| 101 | - * @param int $id |
|
| 102 | - */ |
|
| 103 | - public function removeServer($id) { |
|
| 104 | - $query = $this->connection->getQueryBuilder(); |
|
| 105 | - $query->delete($this->dbTable) |
|
| 106 | - ->where($query->expr()->eq('id', $query->createParameter('id'))) |
|
| 107 | - ->setParameter('id', $id); |
|
| 108 | - $query->execute(); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * get trusted server with given ID |
|
| 113 | - * |
|
| 114 | - * @param int $id |
|
| 115 | - * @return array |
|
| 116 | - * @throws \Exception |
|
| 117 | - */ |
|
| 118 | - public function getServerById($id) { |
|
| 119 | - $query = $this->connection->getQueryBuilder(); |
|
| 120 | - $query->select('*')->from($this->dbTable) |
|
| 121 | - ->where($query->expr()->eq('id', $query->createParameter('id'))) |
|
| 122 | - ->setParameter('id', $id); |
|
| 123 | - $query->execute(); |
|
| 124 | - $result = $query->execute()->fetchAll(); |
|
| 125 | - |
|
| 126 | - if (empty($result)) { |
|
| 127 | - throw new \Exception('No Server found with ID: ' . $id); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - return $result[0]; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * get all trusted servers |
|
| 135 | - * |
|
| 136 | - * @return array |
|
| 137 | - */ |
|
| 138 | - public function getAllServer() { |
|
| 139 | - $query = $this->connection->getQueryBuilder(); |
|
| 140 | - $query->select(['url', 'url_hash', 'id', 'status', 'shared_secret', 'sync_token'])->from($this->dbTable); |
|
| 141 | - $result = $query->execute()->fetchAll(); |
|
| 142 | - return $result; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * check if server already exists in the database table |
|
| 147 | - * |
|
| 148 | - * @param string $url |
|
| 149 | - * @return bool |
|
| 150 | - */ |
|
| 151 | - public function serverExists($url) { |
|
| 152 | - $hash = $this->hash($url); |
|
| 153 | - $query = $this->connection->getQueryBuilder(); |
|
| 154 | - $query->select('url')->from($this->dbTable) |
|
| 155 | - ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash'))) |
|
| 156 | - ->setParameter('url_hash', $hash); |
|
| 157 | - $result = $query->execute()->fetchAll(); |
|
| 158 | - |
|
| 159 | - return !empty($result); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * write token to database. Token is used to exchange the secret |
|
| 164 | - * |
|
| 165 | - * @param string $url |
|
| 166 | - * @param string $token |
|
| 167 | - */ |
|
| 168 | - public function addToken($url, $token) { |
|
| 169 | - $hash = $this->hash($url); |
|
| 170 | - $query = $this->connection->getQueryBuilder(); |
|
| 171 | - $query->update($this->dbTable) |
|
| 172 | - ->set('token', $query->createParameter('token')) |
|
| 173 | - ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash'))) |
|
| 174 | - ->setParameter('url_hash', $hash) |
|
| 175 | - ->setParameter('token', $token); |
|
| 176 | - $query->execute(); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * get token stored in database |
|
| 181 | - * |
|
| 182 | - * @param string $url |
|
| 183 | - * @return string |
|
| 184 | - * @throws \Exception |
|
| 185 | - */ |
|
| 186 | - public function getToken($url) { |
|
| 187 | - $hash = $this->hash($url); |
|
| 188 | - $query = $this->connection->getQueryBuilder(); |
|
| 189 | - $query->select('token')->from($this->dbTable) |
|
| 190 | - ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash'))) |
|
| 191 | - ->setParameter('url_hash', $hash); |
|
| 192 | - |
|
| 193 | - $result = $query->execute()->fetch(); |
|
| 194 | - |
|
| 195 | - if (!isset($result['token'])) { |
|
| 196 | - throw new \Exception('No token found for: ' . $url); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $result['token']; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * add shared Secret to database |
|
| 204 | - * |
|
| 205 | - * @param string $url |
|
| 206 | - * @param string $sharedSecret |
|
| 207 | - */ |
|
| 208 | - public function addSharedSecret($url, $sharedSecret) { |
|
| 209 | - $hash = $this->hash($url); |
|
| 210 | - $query = $this->connection->getQueryBuilder(); |
|
| 211 | - $query->update($this->dbTable) |
|
| 212 | - ->set('shared_secret', $query->createParameter('sharedSecret')) |
|
| 213 | - ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash'))) |
|
| 214 | - ->setParameter('url_hash', $hash) |
|
| 215 | - ->setParameter('sharedSecret', $sharedSecret); |
|
| 216 | - $query->execute(); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * get shared secret from database |
|
| 221 | - * |
|
| 222 | - * @param string $url |
|
| 223 | - * @return string |
|
| 224 | - */ |
|
| 225 | - public function getSharedSecret($url) { |
|
| 226 | - $hash = $this->hash($url); |
|
| 227 | - $query = $this->connection->getQueryBuilder(); |
|
| 228 | - $query->select('shared_secret')->from($this->dbTable) |
|
| 229 | - ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash'))) |
|
| 230 | - ->setParameter('url_hash', $hash); |
|
| 231 | - |
|
| 232 | - $result = $query->execute()->fetch(); |
|
| 233 | - return $result['shared_secret']; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * set server status |
|
| 238 | - * |
|
| 239 | - * @param string $url |
|
| 240 | - * @param int $status |
|
| 241 | - * @param string|null $token |
|
| 242 | - */ |
|
| 243 | - public function setServerStatus($url, $status, $token = null) { |
|
| 244 | - $hash = $this->hash($url); |
|
| 245 | - $query = $this->connection->getQueryBuilder(); |
|
| 246 | - $query->update($this->dbTable) |
|
| 247 | - ->set('status', $query->createNamedParameter($status)) |
|
| 248 | - ->where($query->expr()->eq('url_hash', $query->createNamedParameter($hash))); |
|
| 249 | - if (!is_null($token)) { |
|
| 250 | - $query->set('sync_token', $query->createNamedParameter($token)); |
|
| 251 | - } |
|
| 252 | - $query->execute(); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * get server status |
|
| 257 | - * |
|
| 258 | - * @param string $url |
|
| 259 | - * @return int |
|
| 260 | - */ |
|
| 261 | - public function getServerStatus($url) { |
|
| 262 | - $hash = $this->hash($url); |
|
| 263 | - $query = $this->connection->getQueryBuilder(); |
|
| 264 | - $query->select('status')->from($this->dbTable) |
|
| 265 | - ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash'))) |
|
| 266 | - ->setParameter('url_hash', $hash); |
|
| 267 | - |
|
| 268 | - $result = $query->execute()->fetch(); |
|
| 269 | - return (int)$result['status']; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * create hash from URL |
|
| 274 | - * |
|
| 275 | - * @param string $url |
|
| 276 | - * @return string |
|
| 277 | - */ |
|
| 278 | - protected function hash($url) { |
|
| 279 | - $normalized = $this->normalizeUrl($url); |
|
| 280 | - return sha1($normalized); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * normalize URL, used to create the sha1 hash |
|
| 285 | - * |
|
| 286 | - * @param string $url |
|
| 287 | - * @return string |
|
| 288 | - */ |
|
| 289 | - protected function normalizeUrl($url) { |
|
| 290 | - $normalized = $url; |
|
| 291 | - |
|
| 292 | - if (strpos($url, 'https://') === 0) { |
|
| 293 | - $normalized = substr($url, strlen('https://')); |
|
| 294 | - } else if (strpos($url, 'http://') === 0) { |
|
| 295 | - $normalized = substr($url, strlen('http://')); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - $normalized = Filesystem::normalizePath($normalized); |
|
| 299 | - $normalized = trim($normalized, '/'); |
|
| 300 | - |
|
| 301 | - return $normalized; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * @param $username |
|
| 306 | - * @param $password |
|
| 307 | - * @return bool |
|
| 308 | - */ |
|
| 309 | - public function auth($username, $password) { |
|
| 310 | - if ($username !== 'system') { |
|
| 311 | - return false; |
|
| 312 | - } |
|
| 313 | - $query = $this->connection->getQueryBuilder(); |
|
| 314 | - $query->select('url')->from($this->dbTable) |
|
| 315 | - ->where($query->expr()->eq('shared_secret', $query->createNamedParameter($password))); |
|
| 316 | - |
|
| 317 | - $result = $query->execute()->fetch(); |
|
| 318 | - return !empty($result); |
|
| 319 | - } |
|
| 45 | + /** @var IDBConnection */ |
|
| 46 | + private $connection; |
|
| 47 | + |
|
| 48 | + /** @var IL10N */ |
|
| 49 | + private $IL10N; |
|
| 50 | + |
|
| 51 | + /** @var string */ |
|
| 52 | + private $dbTable = 'trusted_servers'; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @param IDBConnection $connection |
|
| 56 | + * @param IL10N $il10n |
|
| 57 | + */ |
|
| 58 | + public function __construct( |
|
| 59 | + IDBConnection $connection, |
|
| 60 | + IL10N $il10n |
|
| 61 | + ) { |
|
| 62 | + $this->connection = $connection; |
|
| 63 | + $this->IL10N = $il10n; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * add server to the list of trusted servers |
|
| 68 | + * |
|
| 69 | + * @param string $url |
|
| 70 | + * @return int |
|
| 71 | + * @throws HintException |
|
| 72 | + */ |
|
| 73 | + public function addServer($url) { |
|
| 74 | + $hash = $this->hash($url); |
|
| 75 | + $url = rtrim($url, '/'); |
|
| 76 | + $query = $this->connection->getQueryBuilder(); |
|
| 77 | + $query->insert($this->dbTable) |
|
| 78 | + ->values( |
|
| 79 | + [ |
|
| 80 | + 'url' => $query->createParameter('url'), |
|
| 81 | + 'url_hash' => $query->createParameter('url_hash'), |
|
| 82 | + ] |
|
| 83 | + ) |
|
| 84 | + ->setParameter('url', $url) |
|
| 85 | + ->setParameter('url_hash', $hash); |
|
| 86 | + |
|
| 87 | + $result = $query->execute(); |
|
| 88 | + |
|
| 89 | + if ($result) { |
|
| 90 | + return (int)$this->connection->lastInsertId('*PREFIX*'.$this->dbTable); |
|
| 91 | + } else { |
|
| 92 | + $message = 'Internal failure, Could not add trusted server: ' . $url; |
|
| 93 | + $message_t = $this->IL10N->t('Could not add server'); |
|
| 94 | + throw new HintException($message, $message_t); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * remove server from the list of trusted servers |
|
| 100 | + * |
|
| 101 | + * @param int $id |
|
| 102 | + */ |
|
| 103 | + public function removeServer($id) { |
|
| 104 | + $query = $this->connection->getQueryBuilder(); |
|
| 105 | + $query->delete($this->dbTable) |
|
| 106 | + ->where($query->expr()->eq('id', $query->createParameter('id'))) |
|
| 107 | + ->setParameter('id', $id); |
|
| 108 | + $query->execute(); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * get trusted server with given ID |
|
| 113 | + * |
|
| 114 | + * @param int $id |
|
| 115 | + * @return array |
|
| 116 | + * @throws \Exception |
|
| 117 | + */ |
|
| 118 | + public function getServerById($id) { |
|
| 119 | + $query = $this->connection->getQueryBuilder(); |
|
| 120 | + $query->select('*')->from($this->dbTable) |
|
| 121 | + ->where($query->expr()->eq('id', $query->createParameter('id'))) |
|
| 122 | + ->setParameter('id', $id); |
|
| 123 | + $query->execute(); |
|
| 124 | + $result = $query->execute()->fetchAll(); |
|
| 125 | + |
|
| 126 | + if (empty($result)) { |
|
| 127 | + throw new \Exception('No Server found with ID: ' . $id); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + return $result[0]; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * get all trusted servers |
|
| 135 | + * |
|
| 136 | + * @return array |
|
| 137 | + */ |
|
| 138 | + public function getAllServer() { |
|
| 139 | + $query = $this->connection->getQueryBuilder(); |
|
| 140 | + $query->select(['url', 'url_hash', 'id', 'status', 'shared_secret', 'sync_token'])->from($this->dbTable); |
|
| 141 | + $result = $query->execute()->fetchAll(); |
|
| 142 | + return $result; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * check if server already exists in the database table |
|
| 147 | + * |
|
| 148 | + * @param string $url |
|
| 149 | + * @return bool |
|
| 150 | + */ |
|
| 151 | + public function serverExists($url) { |
|
| 152 | + $hash = $this->hash($url); |
|
| 153 | + $query = $this->connection->getQueryBuilder(); |
|
| 154 | + $query->select('url')->from($this->dbTable) |
|
| 155 | + ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash'))) |
|
| 156 | + ->setParameter('url_hash', $hash); |
|
| 157 | + $result = $query->execute()->fetchAll(); |
|
| 158 | + |
|
| 159 | + return !empty($result); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * write token to database. Token is used to exchange the secret |
|
| 164 | + * |
|
| 165 | + * @param string $url |
|
| 166 | + * @param string $token |
|
| 167 | + */ |
|
| 168 | + public function addToken($url, $token) { |
|
| 169 | + $hash = $this->hash($url); |
|
| 170 | + $query = $this->connection->getQueryBuilder(); |
|
| 171 | + $query->update($this->dbTable) |
|
| 172 | + ->set('token', $query->createParameter('token')) |
|
| 173 | + ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash'))) |
|
| 174 | + ->setParameter('url_hash', $hash) |
|
| 175 | + ->setParameter('token', $token); |
|
| 176 | + $query->execute(); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * get token stored in database |
|
| 181 | + * |
|
| 182 | + * @param string $url |
|
| 183 | + * @return string |
|
| 184 | + * @throws \Exception |
|
| 185 | + */ |
|
| 186 | + public function getToken($url) { |
|
| 187 | + $hash = $this->hash($url); |
|
| 188 | + $query = $this->connection->getQueryBuilder(); |
|
| 189 | + $query->select('token')->from($this->dbTable) |
|
| 190 | + ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash'))) |
|
| 191 | + ->setParameter('url_hash', $hash); |
|
| 192 | + |
|
| 193 | + $result = $query->execute()->fetch(); |
|
| 194 | + |
|
| 195 | + if (!isset($result['token'])) { |
|
| 196 | + throw new \Exception('No token found for: ' . $url); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $result['token']; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * add shared Secret to database |
|
| 204 | + * |
|
| 205 | + * @param string $url |
|
| 206 | + * @param string $sharedSecret |
|
| 207 | + */ |
|
| 208 | + public function addSharedSecret($url, $sharedSecret) { |
|
| 209 | + $hash = $this->hash($url); |
|
| 210 | + $query = $this->connection->getQueryBuilder(); |
|
| 211 | + $query->update($this->dbTable) |
|
| 212 | + ->set('shared_secret', $query->createParameter('sharedSecret')) |
|
| 213 | + ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash'))) |
|
| 214 | + ->setParameter('url_hash', $hash) |
|
| 215 | + ->setParameter('sharedSecret', $sharedSecret); |
|
| 216 | + $query->execute(); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * get shared secret from database |
|
| 221 | + * |
|
| 222 | + * @param string $url |
|
| 223 | + * @return string |
|
| 224 | + */ |
|
| 225 | + public function getSharedSecret($url) { |
|
| 226 | + $hash = $this->hash($url); |
|
| 227 | + $query = $this->connection->getQueryBuilder(); |
|
| 228 | + $query->select('shared_secret')->from($this->dbTable) |
|
| 229 | + ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash'))) |
|
| 230 | + ->setParameter('url_hash', $hash); |
|
| 231 | + |
|
| 232 | + $result = $query->execute()->fetch(); |
|
| 233 | + return $result['shared_secret']; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * set server status |
|
| 238 | + * |
|
| 239 | + * @param string $url |
|
| 240 | + * @param int $status |
|
| 241 | + * @param string|null $token |
|
| 242 | + */ |
|
| 243 | + public function setServerStatus($url, $status, $token = null) { |
|
| 244 | + $hash = $this->hash($url); |
|
| 245 | + $query = $this->connection->getQueryBuilder(); |
|
| 246 | + $query->update($this->dbTable) |
|
| 247 | + ->set('status', $query->createNamedParameter($status)) |
|
| 248 | + ->where($query->expr()->eq('url_hash', $query->createNamedParameter($hash))); |
|
| 249 | + if (!is_null($token)) { |
|
| 250 | + $query->set('sync_token', $query->createNamedParameter($token)); |
|
| 251 | + } |
|
| 252 | + $query->execute(); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * get server status |
|
| 257 | + * |
|
| 258 | + * @param string $url |
|
| 259 | + * @return int |
|
| 260 | + */ |
|
| 261 | + public function getServerStatus($url) { |
|
| 262 | + $hash = $this->hash($url); |
|
| 263 | + $query = $this->connection->getQueryBuilder(); |
|
| 264 | + $query->select('status')->from($this->dbTable) |
|
| 265 | + ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash'))) |
|
| 266 | + ->setParameter('url_hash', $hash); |
|
| 267 | + |
|
| 268 | + $result = $query->execute()->fetch(); |
|
| 269 | + return (int)$result['status']; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * create hash from URL |
|
| 274 | + * |
|
| 275 | + * @param string $url |
|
| 276 | + * @return string |
|
| 277 | + */ |
|
| 278 | + protected function hash($url) { |
|
| 279 | + $normalized = $this->normalizeUrl($url); |
|
| 280 | + return sha1($normalized); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * normalize URL, used to create the sha1 hash |
|
| 285 | + * |
|
| 286 | + * @param string $url |
|
| 287 | + * @return string |
|
| 288 | + */ |
|
| 289 | + protected function normalizeUrl($url) { |
|
| 290 | + $normalized = $url; |
|
| 291 | + |
|
| 292 | + if (strpos($url, 'https://') === 0) { |
|
| 293 | + $normalized = substr($url, strlen('https://')); |
|
| 294 | + } else if (strpos($url, 'http://') === 0) { |
|
| 295 | + $normalized = substr($url, strlen('http://')); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + $normalized = Filesystem::normalizePath($normalized); |
|
| 299 | + $normalized = trim($normalized, '/'); |
|
| 300 | + |
|
| 301 | + return $normalized; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * @param $username |
|
| 306 | + * @param $password |
|
| 307 | + * @return bool |
|
| 308 | + */ |
|
| 309 | + public function auth($username, $password) { |
|
| 310 | + if ($username !== 'system') { |
|
| 311 | + return false; |
|
| 312 | + } |
|
| 313 | + $query = $this->connection->getQueryBuilder(); |
|
| 314 | + $query->select('url')->from($this->dbTable) |
|
| 315 | + ->where($query->expr()->eq('shared_secret', $query->createNamedParameter($password))); |
|
| 316 | + |
|
| 317 | + $result = $query->execute()->fetch(); |
|
| 318 | + return !empty($result); |
|
| 319 | + } |
|
| 320 | 320 | |
| 321 | 321 | } |
@@ -87,9 +87,9 @@ discard block |
||
| 87 | 87 | $result = $query->execute(); |
| 88 | 88 | |
| 89 | 89 | if ($result) { |
| 90 | - return (int)$this->connection->lastInsertId('*PREFIX*'.$this->dbTable); |
|
| 90 | + return (int) $this->connection->lastInsertId('*PREFIX*'.$this->dbTable); |
|
| 91 | 91 | } else { |
| 92 | - $message = 'Internal failure, Could not add trusted server: ' . $url; |
|
| 92 | + $message = 'Internal failure, Could not add trusted server: '.$url; |
|
| 93 | 93 | $message_t = $this->IL10N->t('Could not add server'); |
| 94 | 94 | throw new HintException($message, $message_t); |
| 95 | 95 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | $result = $query->execute()->fetchAll(); |
| 125 | 125 | |
| 126 | 126 | if (empty($result)) { |
| 127 | - throw new \Exception('No Server found with ID: ' . $id); |
|
| 127 | + throw new \Exception('No Server found with ID: '.$id); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | return $result[0]; |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | $result = $query->execute()->fetch(); |
| 194 | 194 | |
| 195 | 195 | if (!isset($result['token'])) { |
| 196 | - throw new \Exception('No token found for: ' . $url); |
|
| 196 | + throw new \Exception('No token found for: '.$url); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | return $result['token']; |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | ->setParameter('url_hash', $hash); |
| 267 | 267 | |
| 268 | 268 | $result = $query->execute()->fetch(); |
| 269 | - return (int)$result['status']; |
|
| 269 | + return (int) $result['status']; |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -27,18 +27,18 @@ |
||
| 27 | 27 | |
| 28 | 28 | class SyncJob extends TimedJob { |
| 29 | 29 | |
| 30 | - public function __construct() { |
|
| 31 | - // Run once a day |
|
| 32 | - $this->setInterval(24 * 60 * 60); |
|
| 33 | - } |
|
| 30 | + public function __construct() { |
|
| 31 | + // Run once a day |
|
| 32 | + $this->setInterval(24 * 60 * 60); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - protected function run($argument) { |
|
| 36 | - $app = new Application(); |
|
| 37 | - $ss = $app->getSyncService(); |
|
| 38 | - $ss->syncThemAll(function($url, $ex) { |
|
| 39 | - if ($ex instanceof \Exception) { |
|
| 40 | - \OC::$server->getLogger()->error("Error while syncing $url : " . $ex->getMessage(), ['app' => 'fed-sync']); |
|
| 41 | - } |
|
| 42 | - }); |
|
| 43 | - } |
|
| 35 | + protected function run($argument) { |
|
| 36 | + $app = new Application(); |
|
| 37 | + $ss = $app->getSyncService(); |
|
| 38 | + $ss->syncThemAll(function($url, $ex) { |
|
| 39 | + if ($ex instanceof \Exception) { |
|
| 40 | + \OC::$server->getLogger()->error("Error while syncing $url : " . $ex->getMessage(), ['app' => 'fed-sync']); |
|
| 41 | + } |
|
| 42 | + }); |
|
| 43 | + } |
|
| 44 | 44 | } |
@@ -37,7 +37,7 @@ |
||
| 37 | 37 | $ss = $app->getSyncService(); |
| 38 | 38 | $ss->syncThemAll(function($url, $ex) { |
| 39 | 39 | if ($ex instanceof \Exception) { |
| 40 | - \OC::$server->getLogger()->error("Error while syncing $url : " . $ex->getMessage(), ['app' => 'fed-sync']); |
|
| 40 | + \OC::$server->getLogger()->error("Error while syncing $url : ".$ex->getMessage(), ['app' => 'fed-sync']); |
|
| 41 | 41 | } |
| 42 | 42 | }); |
| 43 | 43 | } |
@@ -26,67 +26,67 @@ |
||
| 26 | 26 | |
| 27 | 27 | class PublicAuth implements BackendInterface { |
| 28 | 28 | |
| 29 | - /** @var string[] */ |
|
| 30 | - private $publicURLs; |
|
| 29 | + /** @var string[] */ |
|
| 30 | + private $publicURLs; |
|
| 31 | 31 | |
| 32 | - public function __construct() { |
|
| 33 | - $this->publicURLs = [ |
|
| 34 | - 'public-calendars', |
|
| 35 | - 'principals/system/public' |
|
| 36 | - ]; |
|
| 37 | - } |
|
| 32 | + public function __construct() { |
|
| 33 | + $this->publicURLs = [ |
|
| 34 | + 'public-calendars', |
|
| 35 | + 'principals/system/public' |
|
| 36 | + ]; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * When this method is called, the backend must check if authentication was |
|
| 41 | - * successful. |
|
| 42 | - * |
|
| 43 | - * The returned value must be one of the following |
|
| 44 | - * |
|
| 45 | - * [true, "principals/username"] |
|
| 46 | - * [false, "reason for failure"] |
|
| 47 | - * |
|
| 48 | - * If authentication was successful, it's expected that the authentication |
|
| 49 | - * backend returns a so-called principal url. |
|
| 50 | - * |
|
| 51 | - * Examples of a principal url: |
|
| 52 | - * |
|
| 53 | - * principals/admin |
|
| 54 | - * principals/user1 |
|
| 55 | - * principals/users/joe |
|
| 56 | - * principals/uid/123457 |
|
| 57 | - * |
|
| 58 | - * If you don't use WebDAV ACL (RFC3744) we recommend that you simply |
|
| 59 | - * return a string such as: |
|
| 60 | - * |
|
| 61 | - * principals/users/[username] |
|
| 62 | - * |
|
| 63 | - * @param RequestInterface $request |
|
| 64 | - * @param ResponseInterface $response |
|
| 65 | - * @return array |
|
| 66 | - */ |
|
| 67 | - function check(RequestInterface $request, ResponseInterface $response) { |
|
| 39 | + /** |
|
| 40 | + * When this method is called, the backend must check if authentication was |
|
| 41 | + * successful. |
|
| 42 | + * |
|
| 43 | + * The returned value must be one of the following |
|
| 44 | + * |
|
| 45 | + * [true, "principals/username"] |
|
| 46 | + * [false, "reason for failure"] |
|
| 47 | + * |
|
| 48 | + * If authentication was successful, it's expected that the authentication |
|
| 49 | + * backend returns a so-called principal url. |
|
| 50 | + * |
|
| 51 | + * Examples of a principal url: |
|
| 52 | + * |
|
| 53 | + * principals/admin |
|
| 54 | + * principals/user1 |
|
| 55 | + * principals/users/joe |
|
| 56 | + * principals/uid/123457 |
|
| 57 | + * |
|
| 58 | + * If you don't use WebDAV ACL (RFC3744) we recommend that you simply |
|
| 59 | + * return a string such as: |
|
| 60 | + * |
|
| 61 | + * principals/users/[username] |
|
| 62 | + * |
|
| 63 | + * @param RequestInterface $request |
|
| 64 | + * @param ResponseInterface $response |
|
| 65 | + * @return array |
|
| 66 | + */ |
|
| 67 | + function check(RequestInterface $request, ResponseInterface $response) { |
|
| 68 | 68 | |
| 69 | - if ($this->isRequestPublic($request)) { |
|
| 70 | - return [true, "principals/system/public"]; |
|
| 71 | - } |
|
| 72 | - return [false, "No public access to this resource."]; |
|
| 73 | - } |
|
| 69 | + if ($this->isRequestPublic($request)) { |
|
| 70 | + return [true, "principals/system/public"]; |
|
| 71 | + } |
|
| 72 | + return [false, "No public access to this resource."]; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @inheritdoc |
|
| 77 | - */ |
|
| 78 | - function challenge(RequestInterface $request, ResponseInterface $response) { |
|
| 79 | - } |
|
| 75 | + /** |
|
| 76 | + * @inheritdoc |
|
| 77 | + */ |
|
| 78 | + function challenge(RequestInterface $request, ResponseInterface $response) { |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @param RequestInterface $request |
|
| 83 | - * @return bool |
|
| 84 | - */ |
|
| 85 | - private function isRequestPublic(RequestInterface $request) { |
|
| 86 | - $url = $request->getPath(); |
|
| 87 | - $matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) { |
|
| 88 | - return strpos($url, $publicUrl, 0) === 0; |
|
| 89 | - }); |
|
| 90 | - return !empty($matchingUrls); |
|
| 91 | - } |
|
| 81 | + /** |
|
| 82 | + * @param RequestInterface $request |
|
| 83 | + * @return bool |
|
| 84 | + */ |
|
| 85 | + private function isRequestPublic(RequestInterface $request) { |
|
| 86 | + $url = $request->getPath(); |
|
| 87 | + $matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) { |
|
| 88 | + return strpos($url, $publicUrl, 0) === 0; |
|
| 89 | + }); |
|
| 90 | + return !empty($matchingUrls); |
|
| 91 | + } |
|
| 92 | 92 | } |
@@ -84,7 +84,7 @@ |
||
| 84 | 84 | */ |
| 85 | 85 | private function isRequestPublic(RequestInterface $request) { |
| 86 | 86 | $url = $request->getPath(); |
| 87 | - $matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) { |
|
| 87 | + $matchingUrls = array_filter($this->publicURLs, function($publicUrl) use ($url) { |
|
| 88 | 88 | return strpos($url, $publicUrl, 0) === 0; |
| 89 | 89 | }); |
| 90 | 90 | return !empty($matchingUrls); |
@@ -47,8 +47,8 @@ discard block |
||
| 47 | 47 | static function xmlDeserialize(Reader $reader) { |
| 48 | 48 | |
| 49 | 49 | $elements = $reader->parseInnerTree([ |
| 50 | - '{' . Plugin::NS_OWNCLOUD. '}set' => 'Sabre\\Xml\\Element\\KeyValue', |
|
| 51 | - '{' . Plugin::NS_OWNCLOUD . '}remove' => 'Sabre\\Xml\\Element\\KeyValue', |
|
| 50 | + '{'.Plugin::NS_OWNCLOUD.'}set' => 'Sabre\\Xml\\Element\\KeyValue', |
|
| 51 | + '{'.Plugin::NS_OWNCLOUD.'}remove' => 'Sabre\\Xml\\Element\\KeyValue', |
|
| 52 | 52 | ]); |
| 53 | 53 | |
| 54 | 54 | $set = []; |
@@ -57,21 +57,21 @@ discard block |
||
| 57 | 57 | foreach ($elements as $elem) { |
| 58 | 58 | switch ($elem['name']) { |
| 59 | 59 | |
| 60 | - case '{' . Plugin::NS_OWNCLOUD . '}set' : |
|
| 60 | + case '{'.Plugin::NS_OWNCLOUD.'}set' : |
|
| 61 | 61 | $sharee = $elem['value']; |
| 62 | 62 | |
| 63 | - $sumElem = '{' . Plugin::NS_OWNCLOUD . '}summary'; |
|
| 64 | - $commonName = '{' . Plugin::NS_OWNCLOUD . '}common-name'; |
|
| 63 | + $sumElem = '{'.Plugin::NS_OWNCLOUD.'}summary'; |
|
| 64 | + $commonName = '{'.Plugin::NS_OWNCLOUD.'}common-name'; |
|
| 65 | 65 | |
| 66 | 66 | $set[] = [ |
| 67 | 67 | 'href' => $sharee['{DAV:}href'], |
| 68 | 68 | 'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null, |
| 69 | 69 | 'summary' => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null, |
| 70 | - 'readOnly' => !array_key_exists('{' . Plugin::NS_OWNCLOUD . '}read-write', $sharee), |
|
| 70 | + 'readOnly' => !array_key_exists('{'.Plugin::NS_OWNCLOUD.'}read-write', $sharee), |
|
| 71 | 71 | ]; |
| 72 | 72 | break; |
| 73 | 73 | |
| 74 | - case '{' . Plugin::NS_OWNCLOUD . '}remove' : |
|
| 74 | + case '{'.Plugin::NS_OWNCLOUD.'}remove' : |
|
| 75 | 75 | $remove[] = $elem['value']['{DAV:}href']; |
| 76 | 76 | break; |
| 77 | 77 | |
@@ -41,130 +41,130 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | class Invite implements XmlSerializable { |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * The list of users a calendar has been shared to. |
|
| 46 | - * |
|
| 47 | - * @var array |
|
| 48 | - */ |
|
| 49 | - protected $users; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * The organizer contains information about the person who shared the |
|
| 53 | - * object. |
|
| 54 | - * |
|
| 55 | - * @var array|null |
|
| 56 | - */ |
|
| 57 | - protected $organizer; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Creates the property. |
|
| 61 | - * |
|
| 62 | - * Users is an array. Each element of the array has the following |
|
| 63 | - * properties: |
|
| 64 | - * |
|
| 65 | - * * href - Often a mailto: address |
|
| 66 | - * * commonName - Optional, for example a first and lastname for a user. |
|
| 67 | - * * status - One of the SharingPlugin::STATUS_* constants. |
|
| 68 | - * * readOnly - true or false |
|
| 69 | - * * summary - Optional, description of the share |
|
| 70 | - * |
|
| 71 | - * The organizer key is optional to specify. It's only useful when a |
|
| 72 | - * 'sharee' requests the sharing information. |
|
| 73 | - * |
|
| 74 | - * The organizer may have the following properties: |
|
| 75 | - * * href - Often a mailto: address. |
|
| 76 | - * * commonName - Optional human-readable name. |
|
| 77 | - * * firstName - Optional first name. |
|
| 78 | - * * lastName - Optional last name. |
|
| 79 | - * |
|
| 80 | - * If you wonder why these two structures are so different, I guess a |
|
| 81 | - * valid answer is that the current spec is still a draft. |
|
| 82 | - * |
|
| 83 | - * @param array $users |
|
| 84 | - */ |
|
| 85 | - function __construct(array $users, array $organizer = null) { |
|
| 86 | - |
|
| 87 | - $this->users = $users; |
|
| 88 | - $this->organizer = $organizer; |
|
| 89 | - |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Returns the list of users, as it was passed to the constructor. |
|
| 94 | - * |
|
| 95 | - * @return array |
|
| 96 | - */ |
|
| 97 | - function getValue() { |
|
| 98 | - |
|
| 99 | - return $this->users; |
|
| 100 | - |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * The xmlSerialize metod is called during xml writing. |
|
| 105 | - * |
|
| 106 | - * Use the $writer argument to write its own xml serialization. |
|
| 107 | - * |
|
| 108 | - * An important note: do _not_ create a parent element. Any element |
|
| 109 | - * implementing XmlSerializble should only ever write what's considered |
|
| 110 | - * its 'inner xml'. |
|
| 111 | - * |
|
| 112 | - * The parent of the current element is responsible for writing a |
|
| 113 | - * containing element. |
|
| 114 | - * |
|
| 115 | - * This allows serializers to be re-used for different element names. |
|
| 116 | - * |
|
| 117 | - * If you are opening new elements, you must also close them again. |
|
| 118 | - * |
|
| 119 | - * @param Writer $writer |
|
| 120 | - * @return void |
|
| 121 | - */ |
|
| 122 | - function xmlSerialize(Writer $writer) { |
|
| 123 | - |
|
| 124 | - $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
| 125 | - |
|
| 126 | - if (!is_null($this->organizer)) { |
|
| 127 | - |
|
| 128 | - $writer->startElement($cs . 'organizer'); |
|
| 129 | - $writer->writeElement('{DAV:}href', $this->organizer['href']); |
|
| 130 | - |
|
| 131 | - if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
|
| 132 | - $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
| 133 | - } |
|
| 134 | - if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
|
| 135 | - $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
| 136 | - } |
|
| 137 | - if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
|
| 138 | - $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
| 139 | - } |
|
| 140 | - $writer->endElement(); // organizer |
|
| 141 | - |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - foreach ($this->users as $user) { |
|
| 145 | - |
|
| 146 | - $writer->startElement($cs . 'user'); |
|
| 147 | - $writer->writeElement('{DAV:}href', $user['href']); |
|
| 148 | - if (isset($user['commonName']) && $user['commonName']) { |
|
| 149 | - $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
| 150 | - } |
|
| 151 | - $writer->writeElement($cs . 'invite-accepted'); |
|
| 152 | - |
|
| 153 | - $writer->startElement($cs . 'access'); |
|
| 154 | - if ($user['readOnly']) { |
|
| 155 | - $writer->writeElement($cs . 'read'); |
|
| 156 | - } else { |
|
| 157 | - $writer->writeElement($cs . 'read-write'); |
|
| 158 | - } |
|
| 159 | - $writer->endElement(); // access |
|
| 160 | - |
|
| 161 | - if (isset($user['summary']) && $user['summary']) { |
|
| 162 | - $writer->writeElement($cs . 'summary', $user['summary']); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - $writer->endElement(); //user |
|
| 166 | - |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - } |
|
| 44 | + /** |
|
| 45 | + * The list of users a calendar has been shared to. |
|
| 46 | + * |
|
| 47 | + * @var array |
|
| 48 | + */ |
|
| 49 | + protected $users; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * The organizer contains information about the person who shared the |
|
| 53 | + * object. |
|
| 54 | + * |
|
| 55 | + * @var array|null |
|
| 56 | + */ |
|
| 57 | + protected $organizer; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Creates the property. |
|
| 61 | + * |
|
| 62 | + * Users is an array. Each element of the array has the following |
|
| 63 | + * properties: |
|
| 64 | + * |
|
| 65 | + * * href - Often a mailto: address |
|
| 66 | + * * commonName - Optional, for example a first and lastname for a user. |
|
| 67 | + * * status - One of the SharingPlugin::STATUS_* constants. |
|
| 68 | + * * readOnly - true or false |
|
| 69 | + * * summary - Optional, description of the share |
|
| 70 | + * |
|
| 71 | + * The organizer key is optional to specify. It's only useful when a |
|
| 72 | + * 'sharee' requests the sharing information. |
|
| 73 | + * |
|
| 74 | + * The organizer may have the following properties: |
|
| 75 | + * * href - Often a mailto: address. |
|
| 76 | + * * commonName - Optional human-readable name. |
|
| 77 | + * * firstName - Optional first name. |
|
| 78 | + * * lastName - Optional last name. |
|
| 79 | + * |
|
| 80 | + * If you wonder why these two structures are so different, I guess a |
|
| 81 | + * valid answer is that the current spec is still a draft. |
|
| 82 | + * |
|
| 83 | + * @param array $users |
|
| 84 | + */ |
|
| 85 | + function __construct(array $users, array $organizer = null) { |
|
| 86 | + |
|
| 87 | + $this->users = $users; |
|
| 88 | + $this->organizer = $organizer; |
|
| 89 | + |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Returns the list of users, as it was passed to the constructor. |
|
| 94 | + * |
|
| 95 | + * @return array |
|
| 96 | + */ |
|
| 97 | + function getValue() { |
|
| 98 | + |
|
| 99 | + return $this->users; |
|
| 100 | + |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * The xmlSerialize metod is called during xml writing. |
|
| 105 | + * |
|
| 106 | + * Use the $writer argument to write its own xml serialization. |
|
| 107 | + * |
|
| 108 | + * An important note: do _not_ create a parent element. Any element |
|
| 109 | + * implementing XmlSerializble should only ever write what's considered |
|
| 110 | + * its 'inner xml'. |
|
| 111 | + * |
|
| 112 | + * The parent of the current element is responsible for writing a |
|
| 113 | + * containing element. |
|
| 114 | + * |
|
| 115 | + * This allows serializers to be re-used for different element names. |
|
| 116 | + * |
|
| 117 | + * If you are opening new elements, you must also close them again. |
|
| 118 | + * |
|
| 119 | + * @param Writer $writer |
|
| 120 | + * @return void |
|
| 121 | + */ |
|
| 122 | + function xmlSerialize(Writer $writer) { |
|
| 123 | + |
|
| 124 | + $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
| 125 | + |
|
| 126 | + if (!is_null($this->organizer)) { |
|
| 127 | + |
|
| 128 | + $writer->startElement($cs . 'organizer'); |
|
| 129 | + $writer->writeElement('{DAV:}href', $this->organizer['href']); |
|
| 130 | + |
|
| 131 | + if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
|
| 132 | + $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
| 133 | + } |
|
| 134 | + if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
|
| 135 | + $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
| 136 | + } |
|
| 137 | + if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
|
| 138 | + $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
| 139 | + } |
|
| 140 | + $writer->endElement(); // organizer |
|
| 141 | + |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + foreach ($this->users as $user) { |
|
| 145 | + |
|
| 146 | + $writer->startElement($cs . 'user'); |
|
| 147 | + $writer->writeElement('{DAV:}href', $user['href']); |
|
| 148 | + if (isset($user['commonName']) && $user['commonName']) { |
|
| 149 | + $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
| 150 | + } |
|
| 151 | + $writer->writeElement($cs . 'invite-accepted'); |
|
| 152 | + |
|
| 153 | + $writer->startElement($cs . 'access'); |
|
| 154 | + if ($user['readOnly']) { |
|
| 155 | + $writer->writeElement($cs . 'read'); |
|
| 156 | + } else { |
|
| 157 | + $writer->writeElement($cs . 'read-write'); |
|
| 158 | + } |
|
| 159 | + $writer->endElement(); // access |
|
| 160 | + |
|
| 161 | + if (isset($user['summary']) && $user['summary']) { |
|
| 162 | + $writer->writeElement($cs . 'summary', $user['summary']); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + $writer->endElement(); //user |
|
| 166 | + |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + } |
|
| 170 | 170 | } |
@@ -121,21 +121,21 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | function xmlSerialize(Writer $writer) { |
| 123 | 123 | |
| 124 | - $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
| 124 | + $cs = '{'.Plugin::NS_OWNCLOUD.'}'; |
|
| 125 | 125 | |
| 126 | 126 | if (!is_null($this->organizer)) { |
| 127 | 127 | |
| 128 | - $writer->startElement($cs . 'organizer'); |
|
| 128 | + $writer->startElement($cs.'organizer'); |
|
| 129 | 129 | $writer->writeElement('{DAV:}href', $this->organizer['href']); |
| 130 | 130 | |
| 131 | 131 | if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
| 132 | - $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
| 132 | + $writer->writeElement($cs.'common-name', $this->organizer['commonName']); |
|
| 133 | 133 | } |
| 134 | 134 | if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
| 135 | - $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
| 135 | + $writer->writeElement($cs.'first-name', $this->organizer['firstName']); |
|
| 136 | 136 | } |
| 137 | 137 | if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
| 138 | - $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
| 138 | + $writer->writeElement($cs.'last-name', $this->organizer['lastName']); |
|
| 139 | 139 | } |
| 140 | 140 | $writer->endElement(); // organizer |
| 141 | 141 | |
@@ -143,23 +143,23 @@ discard block |
||
| 143 | 143 | |
| 144 | 144 | foreach ($this->users as $user) { |
| 145 | 145 | |
| 146 | - $writer->startElement($cs . 'user'); |
|
| 146 | + $writer->startElement($cs.'user'); |
|
| 147 | 147 | $writer->writeElement('{DAV:}href', $user['href']); |
| 148 | 148 | if (isset($user['commonName']) && $user['commonName']) { |
| 149 | - $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
| 149 | + $writer->writeElement($cs.'common-name', $user['commonName']); |
|
| 150 | 150 | } |
| 151 | - $writer->writeElement($cs . 'invite-accepted'); |
|
| 151 | + $writer->writeElement($cs.'invite-accepted'); |
|
| 152 | 152 | |
| 153 | - $writer->startElement($cs . 'access'); |
|
| 153 | + $writer->startElement($cs.'access'); |
|
| 154 | 154 | if ($user['readOnly']) { |
| 155 | - $writer->writeElement($cs . 'read'); |
|
| 155 | + $writer->writeElement($cs.'read'); |
|
| 156 | 156 | } else { |
| 157 | - $writer->writeElement($cs . 'read-write'); |
|
| 157 | + $writer->writeElement($cs.'read-write'); |
|
| 158 | 158 | } |
| 159 | 159 | $writer->endElement(); // access |
| 160 | 160 | |
| 161 | 161 | if (isset($user['summary']) && $user['summary']) { |
| 162 | - $writer->writeElement($cs . 'summary', $user['summary']); |
|
| 162 | + $writer->writeElement($cs.'summary', $user['summary']); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | $writer->endElement(); //user |
@@ -99,11 +99,11 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | function initialize(Server $server) { |
| 101 | 101 | $this->server = $server; |
| 102 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest'; |
|
| 103 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\Invite'; |
|
| 102 | + $this->server->xml->elementMap['{'.Plugin::NS_OWNCLOUD.'}share'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest'; |
|
| 103 | + $this->server->xml->elementMap['{'.Plugin::NS_OWNCLOUD.'}invite'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\Invite'; |
|
| 104 | 104 | |
| 105 | 105 | $this->server->on('method:POST', [$this, 'httpPost']); |
| 106 | - $this->server->on('propFind', [$this, 'propFind']); |
|
| 106 | + $this->server->on('propFind', [$this, 'propFind']); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | // Dealing with the 'share' document, which modified invitees on a |
| 148 | 148 | // calendar. |
| 149 | - case '{' . self::NS_OWNCLOUD . '}share' : |
|
| 149 | + case '{'.self::NS_OWNCLOUD.'}share' : |
|
| 150 | 150 | |
| 151 | 151 | // We can only deal with IShareableCalendar objects |
| 152 | 152 | if (!$node instanceof IShareable) { |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | function propFind(PropFind $propFind, INode $node) { |
| 190 | 190 | if ($node instanceof IShareable) { |
| 191 | 191 | |
| 192 | - $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function() use ($node) { |
|
| 192 | + $propFind->handle('{'.Plugin::NS_OWNCLOUD.'}invite', function() use ($node) { |
|
| 193 | 193 | return new Invite( |
| 194 | 194 | $node->getShares() |
| 195 | 195 | ); |
@@ -119,8 +119,9 @@ |
||
| 119 | 119 | |
| 120 | 120 | // Only handling xml |
| 121 | 121 | $contentType = $request->getHeader('Content-Type'); |
| 122 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
| 123 | - return; |
|
| 122 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
| 123 | + return; |
|
| 124 | + } |
|
| 124 | 125 | |
| 125 | 126 | // Making sure the node exists |
| 126 | 127 | try { |
@@ -36,167 +36,167 @@ |
||
| 36 | 36 | |
| 37 | 37 | class Plugin extends ServerPlugin { |
| 38 | 38 | |
| 39 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 40 | - const NS_NEXTCLOUD = 'http://nextcloud.com/ns'; |
|
| 41 | - |
|
| 42 | - /** @var Auth */ |
|
| 43 | - private $auth; |
|
| 44 | - |
|
| 45 | - /** @var IRequest */ |
|
| 46 | - private $request; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Plugin constructor. |
|
| 50 | - * |
|
| 51 | - * @param Auth $authBackEnd |
|
| 52 | - * @param IRequest $request |
|
| 53 | - */ |
|
| 54 | - public function __construct(Auth $authBackEnd, IRequest $request) { |
|
| 55 | - $this->auth = $authBackEnd; |
|
| 56 | - $this->request = $request; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Reference to SabreDAV server object. |
|
| 61 | - * |
|
| 62 | - * @var \Sabre\DAV\Server |
|
| 63 | - */ |
|
| 64 | - protected $server; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * This method should return a list of server-features. |
|
| 68 | - * |
|
| 69 | - * This is for example 'versioning' and is added to the DAV: header |
|
| 70 | - * in an OPTIONS response. |
|
| 71 | - * |
|
| 72 | - * @return string[] |
|
| 73 | - */ |
|
| 74 | - function getFeatures() { |
|
| 75 | - return ['oc-resource-sharing']; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Returns a plugin name. |
|
| 80 | - * |
|
| 81 | - * Using this name other plugins will be able to access other plugins |
|
| 82 | - * using Sabre\DAV\Server::getPlugin |
|
| 83 | - * |
|
| 84 | - * @return string |
|
| 85 | - */ |
|
| 86 | - function getPluginName() { |
|
| 87 | - return 'oc-resource-sharing'; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * This initializes the plugin. |
|
| 92 | - * |
|
| 93 | - * This function is called by Sabre\DAV\Server, after |
|
| 94 | - * addPlugin is called. |
|
| 95 | - * |
|
| 96 | - * This method should set up the required event subscriptions. |
|
| 97 | - * |
|
| 98 | - * @param Server $server |
|
| 99 | - * @return void |
|
| 100 | - */ |
|
| 101 | - function initialize(Server $server) { |
|
| 102 | - $this->server = $server; |
|
| 103 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest'; |
|
| 104 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\Invite'; |
|
| 105 | - |
|
| 106 | - $this->server->on('method:POST', [$this, 'httpPost']); |
|
| 107 | - $this->server->on('propFind', [$this, 'propFind']); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * We intercept this to handle POST requests on a dav resource. |
|
| 112 | - * |
|
| 113 | - * @param RequestInterface $request |
|
| 114 | - * @param ResponseInterface $response |
|
| 115 | - * @return null|false |
|
| 116 | - */ |
|
| 117 | - function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
| 118 | - |
|
| 119 | - $path = $request->getPath(); |
|
| 120 | - |
|
| 121 | - // Only handling xml |
|
| 122 | - $contentType = $request->getHeader('Content-Type'); |
|
| 123 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
| 124 | - return; |
|
| 125 | - |
|
| 126 | - // Making sure the node exists |
|
| 127 | - try { |
|
| 128 | - $node = $this->server->tree->getNodeForPath($path); |
|
| 129 | - } catch (NotFound $e) { |
|
| 130 | - return; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - $requestBody = $request->getBodyAsString(); |
|
| 134 | - |
|
| 135 | - // If this request handler could not deal with this POST request, it |
|
| 136 | - // will return 'null' and other plugins get a chance to handle the |
|
| 137 | - // request. |
|
| 138 | - // |
|
| 139 | - // However, we already requested the full body. This is a problem, |
|
| 140 | - // because a body can only be read once. This is why we preemptively |
|
| 141 | - // re-populated the request body with the existing data. |
|
| 142 | - $request->setBody($requestBody); |
|
| 143 | - |
|
| 144 | - $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
| 145 | - |
|
| 146 | - switch ($documentType) { |
|
| 147 | - |
|
| 148 | - // Dealing with the 'share' document, which modified invitees on a |
|
| 149 | - // calendar. |
|
| 150 | - case '{' . self::NS_OWNCLOUD . '}share' : |
|
| 151 | - |
|
| 152 | - // We can only deal with IShareableCalendar objects |
|
| 153 | - if (!$node instanceof IShareable) { |
|
| 154 | - return; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - $this->server->transactionType = 'post-oc-resource-share'; |
|
| 158 | - |
|
| 159 | - // Getting ACL info |
|
| 160 | - $acl = $this->server->getPlugin('acl'); |
|
| 161 | - |
|
| 162 | - // If there's no ACL support, we allow everything |
|
| 163 | - if ($acl) { |
|
| 164 | - /** @var \Sabre\DAVACL\Plugin $acl */ |
|
| 165 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - $node->updateShares($message->set, $message->remove); |
|
| 169 | - |
|
| 170 | - $response->setStatus(200); |
|
| 171 | - // Adding this because sending a response body may cause issues, |
|
| 172 | - // and I wanted some type of indicator the response was handled. |
|
| 173 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 174 | - |
|
| 175 | - // Breaking the event chain |
|
| 176 | - return false; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * This event is triggered when properties are requested for a certain |
|
| 182 | - * node. |
|
| 183 | - * |
|
| 184 | - * This allows us to inject any properties early. |
|
| 185 | - * |
|
| 186 | - * @param PropFind $propFind |
|
| 187 | - * @param INode $node |
|
| 188 | - * @return void |
|
| 189 | - */ |
|
| 190 | - function propFind(PropFind $propFind, INode $node) { |
|
| 191 | - if ($node instanceof IShareable) { |
|
| 192 | - |
|
| 193 | - $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function() use ($node) { |
|
| 194 | - return new Invite( |
|
| 195 | - $node->getShares() |
|
| 196 | - ); |
|
| 197 | - }); |
|
| 198 | - |
|
| 199 | - } |
|
| 200 | - } |
|
| 39 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 40 | + const NS_NEXTCLOUD = 'http://nextcloud.com/ns'; |
|
| 41 | + |
|
| 42 | + /** @var Auth */ |
|
| 43 | + private $auth; |
|
| 44 | + |
|
| 45 | + /** @var IRequest */ |
|
| 46 | + private $request; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Plugin constructor. |
|
| 50 | + * |
|
| 51 | + * @param Auth $authBackEnd |
|
| 52 | + * @param IRequest $request |
|
| 53 | + */ |
|
| 54 | + public function __construct(Auth $authBackEnd, IRequest $request) { |
|
| 55 | + $this->auth = $authBackEnd; |
|
| 56 | + $this->request = $request; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Reference to SabreDAV server object. |
|
| 61 | + * |
|
| 62 | + * @var \Sabre\DAV\Server |
|
| 63 | + */ |
|
| 64 | + protected $server; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * This method should return a list of server-features. |
|
| 68 | + * |
|
| 69 | + * This is for example 'versioning' and is added to the DAV: header |
|
| 70 | + * in an OPTIONS response. |
|
| 71 | + * |
|
| 72 | + * @return string[] |
|
| 73 | + */ |
|
| 74 | + function getFeatures() { |
|
| 75 | + return ['oc-resource-sharing']; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Returns a plugin name. |
|
| 80 | + * |
|
| 81 | + * Using this name other plugins will be able to access other plugins |
|
| 82 | + * using Sabre\DAV\Server::getPlugin |
|
| 83 | + * |
|
| 84 | + * @return string |
|
| 85 | + */ |
|
| 86 | + function getPluginName() { |
|
| 87 | + return 'oc-resource-sharing'; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * This initializes the plugin. |
|
| 92 | + * |
|
| 93 | + * This function is called by Sabre\DAV\Server, after |
|
| 94 | + * addPlugin is called. |
|
| 95 | + * |
|
| 96 | + * This method should set up the required event subscriptions. |
|
| 97 | + * |
|
| 98 | + * @param Server $server |
|
| 99 | + * @return void |
|
| 100 | + */ |
|
| 101 | + function initialize(Server $server) { |
|
| 102 | + $this->server = $server; |
|
| 103 | + $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest'; |
|
| 104 | + $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\Invite'; |
|
| 105 | + |
|
| 106 | + $this->server->on('method:POST', [$this, 'httpPost']); |
|
| 107 | + $this->server->on('propFind', [$this, 'propFind']); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * We intercept this to handle POST requests on a dav resource. |
|
| 112 | + * |
|
| 113 | + * @param RequestInterface $request |
|
| 114 | + * @param ResponseInterface $response |
|
| 115 | + * @return null|false |
|
| 116 | + */ |
|
| 117 | + function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
| 118 | + |
|
| 119 | + $path = $request->getPath(); |
|
| 120 | + |
|
| 121 | + // Only handling xml |
|
| 122 | + $contentType = $request->getHeader('Content-Type'); |
|
| 123 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
| 124 | + return; |
|
| 125 | + |
|
| 126 | + // Making sure the node exists |
|
| 127 | + try { |
|
| 128 | + $node = $this->server->tree->getNodeForPath($path); |
|
| 129 | + } catch (NotFound $e) { |
|
| 130 | + return; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + $requestBody = $request->getBodyAsString(); |
|
| 134 | + |
|
| 135 | + // If this request handler could not deal with this POST request, it |
|
| 136 | + // will return 'null' and other plugins get a chance to handle the |
|
| 137 | + // request. |
|
| 138 | + // |
|
| 139 | + // However, we already requested the full body. This is a problem, |
|
| 140 | + // because a body can only be read once. This is why we preemptively |
|
| 141 | + // re-populated the request body with the existing data. |
|
| 142 | + $request->setBody($requestBody); |
|
| 143 | + |
|
| 144 | + $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
| 145 | + |
|
| 146 | + switch ($documentType) { |
|
| 147 | + |
|
| 148 | + // Dealing with the 'share' document, which modified invitees on a |
|
| 149 | + // calendar. |
|
| 150 | + case '{' . self::NS_OWNCLOUD . '}share' : |
|
| 151 | + |
|
| 152 | + // We can only deal with IShareableCalendar objects |
|
| 153 | + if (!$node instanceof IShareable) { |
|
| 154 | + return; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + $this->server->transactionType = 'post-oc-resource-share'; |
|
| 158 | + |
|
| 159 | + // Getting ACL info |
|
| 160 | + $acl = $this->server->getPlugin('acl'); |
|
| 161 | + |
|
| 162 | + // If there's no ACL support, we allow everything |
|
| 163 | + if ($acl) { |
|
| 164 | + /** @var \Sabre\DAVACL\Plugin $acl */ |
|
| 165 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + $node->updateShares($message->set, $message->remove); |
|
| 169 | + |
|
| 170 | + $response->setStatus(200); |
|
| 171 | + // Adding this because sending a response body may cause issues, |
|
| 172 | + // and I wanted some type of indicator the response was handled. |
|
| 173 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 174 | + |
|
| 175 | + // Breaking the event chain |
|
| 176 | + return false; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * This event is triggered when properties are requested for a certain |
|
| 182 | + * node. |
|
| 183 | + * |
|
| 184 | + * This allows us to inject any properties early. |
|
| 185 | + * |
|
| 186 | + * @param PropFind $propFind |
|
| 187 | + * @param INode $node |
|
| 188 | + * @return void |
|
| 189 | + */ |
|
| 190 | + function propFind(PropFind $propFind, INode $node) { |
|
| 191 | + if ($node instanceof IShareable) { |
|
| 192 | + |
|
| 193 | + $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function() use ($node) { |
|
| 194 | + return new Invite( |
|
| 195 | + $node->getShares() |
|
| 196 | + ); |
|
| 197 | + }); |
|
| 198 | + |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | 202 | } |
@@ -29,188 +29,188 @@ |
||
| 29 | 29 | |
| 30 | 30 | class Backend { |
| 31 | 31 | |
| 32 | - /** @var IDBConnection */ |
|
| 33 | - private $db; |
|
| 34 | - /** @var Principal */ |
|
| 35 | - private $principalBackend; |
|
| 36 | - /** @var string */ |
|
| 37 | - private $resourceType; |
|
| 38 | - |
|
| 39 | - const ACCESS_OWNER = 1; |
|
| 40 | - const ACCESS_READ_WRITE = 2; |
|
| 41 | - const ACCESS_READ = 3; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @param IDBConnection $db |
|
| 45 | - * @param Principal $principalBackend |
|
| 46 | - * @param string $resourceType |
|
| 47 | - */ |
|
| 48 | - public function __construct(IDBConnection $db, Principal $principalBackend, $resourceType) { |
|
| 49 | - $this->db = $db; |
|
| 50 | - $this->principalBackend = $principalBackend; |
|
| 51 | - $this->resourceType = $resourceType; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @param IShareable $shareable |
|
| 56 | - * @param string[] $add |
|
| 57 | - * @param string[] $remove |
|
| 58 | - */ |
|
| 59 | - public function updateShares($shareable, $add, $remove) { |
|
| 60 | - foreach($add as $element) { |
|
| 61 | - $this->shareWith($shareable, $element); |
|
| 62 | - } |
|
| 63 | - foreach($remove as $element) { |
|
| 64 | - $this->unshare($shareable, $element); |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @param IShareable $shareable |
|
| 70 | - * @param string $element |
|
| 71 | - */ |
|
| 72 | - private function shareWith($shareable, $element) { |
|
| 73 | - $user = $element['href']; |
|
| 74 | - $parts = explode(':', $user, 2); |
|
| 75 | - if ($parts[0] !== 'principal') { |
|
| 76 | - return; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // don't share with owner |
|
| 80 | - if ($shareable->getOwner() === $parts[1]) { |
|
| 81 | - return; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - // remove the share if it already exists |
|
| 85 | - $this->unshare($shareable, $element['href']); |
|
| 86 | - $access = self::ACCESS_READ; |
|
| 87 | - if (isset($element['readOnly'])) { |
|
| 88 | - $access = $element['readOnly'] ? self::ACCESS_READ : self::ACCESS_READ_WRITE; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $query = $this->db->getQueryBuilder(); |
|
| 92 | - $query->insert('dav_shares') |
|
| 93 | - ->values([ |
|
| 94 | - 'principaluri' => $query->createNamedParameter($parts[1]), |
|
| 95 | - 'type' => $query->createNamedParameter($this->resourceType), |
|
| 96 | - 'access' => $query->createNamedParameter($access), |
|
| 97 | - 'resourceid' => $query->createNamedParameter($shareable->getResourceId()) |
|
| 98 | - ]); |
|
| 99 | - $query->execute(); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param $resourceId |
|
| 104 | - */ |
|
| 105 | - public function deleteAllShares($resourceId) { |
|
| 106 | - $query = $this->db->getQueryBuilder(); |
|
| 107 | - $query->delete('dav_shares') |
|
| 108 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId))) |
|
| 109 | - ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
| 110 | - ->execute(); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - public function deleteAllSharesByUser($principaluri) { |
|
| 114 | - $query = $this->db->getQueryBuilder(); |
|
| 115 | - $query->delete('dav_shares') |
|
| 116 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principaluri))) |
|
| 117 | - ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
| 118 | - ->execute(); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @param IShareable $shareable |
|
| 123 | - * @param string $element |
|
| 124 | - */ |
|
| 125 | - private function unshare($shareable, $element) { |
|
| 126 | - $parts = explode(':', $element, 2); |
|
| 127 | - if ($parts[0] !== 'principal') { |
|
| 128 | - return; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - // don't share with owner |
|
| 132 | - if ($shareable->getOwner() === $parts[1]) { |
|
| 133 | - return; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - $query = $this->db->getQueryBuilder(); |
|
| 137 | - $query->delete('dav_shares') |
|
| 138 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($shareable->getResourceId()))) |
|
| 139 | - ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
| 140 | - ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($parts[1]))) |
|
| 141 | - ; |
|
| 142 | - $query->execute(); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Returns the list of people whom this resource is shared with. |
|
| 147 | - * |
|
| 148 | - * Every element in this array should have the following properties: |
|
| 149 | - * * href - Often a mailto: address |
|
| 150 | - * * commonName - Optional, for example a first + last name |
|
| 151 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 152 | - * * readOnly - boolean |
|
| 153 | - * * summary - Optional, a description for the share |
|
| 154 | - * |
|
| 155 | - * @param int $resourceId |
|
| 156 | - * @return array |
|
| 157 | - */ |
|
| 158 | - public function getShares($resourceId) { |
|
| 159 | - $query = $this->db->getQueryBuilder(); |
|
| 160 | - $result = $query->select(['principaluri', 'access']) |
|
| 161 | - ->from('dav_shares') |
|
| 162 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId))) |
|
| 163 | - ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
| 164 | - ->execute(); |
|
| 165 | - |
|
| 166 | - $shares = []; |
|
| 167 | - while($row = $result->fetch()) { |
|
| 168 | - $p = $this->principalBackend->getPrincipalByPath($row['principaluri']); |
|
| 169 | - $shares[]= [ |
|
| 170 | - 'href' => "principal:${row['principaluri']}", |
|
| 171 | - 'commonName' => isset($p['{DAV:}displayname']) ? $p['{DAV:}displayname'] : '', |
|
| 172 | - 'status' => 1, |
|
| 173 | - 'readOnly' => ($row['access'] == self::ACCESS_READ), |
|
| 174 | - '{http://owncloud.org/ns}principal' => $row['principaluri'], |
|
| 175 | - '{http://owncloud.org/ns}group-share' => is_null($p) |
|
| 176 | - ]; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return $shares; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * For shared resources the sharee is set in the ACL of the resource |
|
| 184 | - * |
|
| 185 | - * @param int $resourceId |
|
| 186 | - * @param array $acl |
|
| 187 | - * @return array |
|
| 188 | - */ |
|
| 189 | - public function applyShareAcl($resourceId, $acl) { |
|
| 190 | - |
|
| 191 | - $shares = $this->getShares($resourceId); |
|
| 192 | - foreach ($shares as $share) { |
|
| 193 | - $acl[] = [ |
|
| 194 | - 'privilege' => '{DAV:}read', |
|
| 195 | - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
| 196 | - 'protected' => true, |
|
| 197 | - ]; |
|
| 198 | - if (!$share['readOnly']) { |
|
| 199 | - $acl[] = [ |
|
| 200 | - 'privilege' => '{DAV:}write', |
|
| 201 | - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
| 202 | - 'protected' => true, |
|
| 203 | - ]; |
|
| 204 | - } else if ($this->resourceType === 'calendar') { |
|
| 205 | - // Allow changing the properties of read only calendars, |
|
| 206 | - // so users can change the visibility. |
|
| 207 | - $acl[] = [ |
|
| 208 | - 'privilege' => '{DAV:}write-properties', |
|
| 209 | - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
| 210 | - 'protected' => true, |
|
| 211 | - ]; |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - return $acl; |
|
| 215 | - } |
|
| 32 | + /** @var IDBConnection */ |
|
| 33 | + private $db; |
|
| 34 | + /** @var Principal */ |
|
| 35 | + private $principalBackend; |
|
| 36 | + /** @var string */ |
|
| 37 | + private $resourceType; |
|
| 38 | + |
|
| 39 | + const ACCESS_OWNER = 1; |
|
| 40 | + const ACCESS_READ_WRITE = 2; |
|
| 41 | + const ACCESS_READ = 3; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @param IDBConnection $db |
|
| 45 | + * @param Principal $principalBackend |
|
| 46 | + * @param string $resourceType |
|
| 47 | + */ |
|
| 48 | + public function __construct(IDBConnection $db, Principal $principalBackend, $resourceType) { |
|
| 49 | + $this->db = $db; |
|
| 50 | + $this->principalBackend = $principalBackend; |
|
| 51 | + $this->resourceType = $resourceType; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @param IShareable $shareable |
|
| 56 | + * @param string[] $add |
|
| 57 | + * @param string[] $remove |
|
| 58 | + */ |
|
| 59 | + public function updateShares($shareable, $add, $remove) { |
|
| 60 | + foreach($add as $element) { |
|
| 61 | + $this->shareWith($shareable, $element); |
|
| 62 | + } |
|
| 63 | + foreach($remove as $element) { |
|
| 64 | + $this->unshare($shareable, $element); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @param IShareable $shareable |
|
| 70 | + * @param string $element |
|
| 71 | + */ |
|
| 72 | + private function shareWith($shareable, $element) { |
|
| 73 | + $user = $element['href']; |
|
| 74 | + $parts = explode(':', $user, 2); |
|
| 75 | + if ($parts[0] !== 'principal') { |
|
| 76 | + return; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // don't share with owner |
|
| 80 | + if ($shareable->getOwner() === $parts[1]) { |
|
| 81 | + return; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + // remove the share if it already exists |
|
| 85 | + $this->unshare($shareable, $element['href']); |
|
| 86 | + $access = self::ACCESS_READ; |
|
| 87 | + if (isset($element['readOnly'])) { |
|
| 88 | + $access = $element['readOnly'] ? self::ACCESS_READ : self::ACCESS_READ_WRITE; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $query = $this->db->getQueryBuilder(); |
|
| 92 | + $query->insert('dav_shares') |
|
| 93 | + ->values([ |
|
| 94 | + 'principaluri' => $query->createNamedParameter($parts[1]), |
|
| 95 | + 'type' => $query->createNamedParameter($this->resourceType), |
|
| 96 | + 'access' => $query->createNamedParameter($access), |
|
| 97 | + 'resourceid' => $query->createNamedParameter($shareable->getResourceId()) |
|
| 98 | + ]); |
|
| 99 | + $query->execute(); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param $resourceId |
|
| 104 | + */ |
|
| 105 | + public function deleteAllShares($resourceId) { |
|
| 106 | + $query = $this->db->getQueryBuilder(); |
|
| 107 | + $query->delete('dav_shares') |
|
| 108 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId))) |
|
| 109 | + ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
| 110 | + ->execute(); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + public function deleteAllSharesByUser($principaluri) { |
|
| 114 | + $query = $this->db->getQueryBuilder(); |
|
| 115 | + $query->delete('dav_shares') |
|
| 116 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principaluri))) |
|
| 117 | + ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
| 118 | + ->execute(); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @param IShareable $shareable |
|
| 123 | + * @param string $element |
|
| 124 | + */ |
|
| 125 | + private function unshare($shareable, $element) { |
|
| 126 | + $parts = explode(':', $element, 2); |
|
| 127 | + if ($parts[0] !== 'principal') { |
|
| 128 | + return; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + // don't share with owner |
|
| 132 | + if ($shareable->getOwner() === $parts[1]) { |
|
| 133 | + return; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + $query = $this->db->getQueryBuilder(); |
|
| 137 | + $query->delete('dav_shares') |
|
| 138 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($shareable->getResourceId()))) |
|
| 139 | + ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
| 140 | + ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($parts[1]))) |
|
| 141 | + ; |
|
| 142 | + $query->execute(); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Returns the list of people whom this resource is shared with. |
|
| 147 | + * |
|
| 148 | + * Every element in this array should have the following properties: |
|
| 149 | + * * href - Often a mailto: address |
|
| 150 | + * * commonName - Optional, for example a first + last name |
|
| 151 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 152 | + * * readOnly - boolean |
|
| 153 | + * * summary - Optional, a description for the share |
|
| 154 | + * |
|
| 155 | + * @param int $resourceId |
|
| 156 | + * @return array |
|
| 157 | + */ |
|
| 158 | + public function getShares($resourceId) { |
|
| 159 | + $query = $this->db->getQueryBuilder(); |
|
| 160 | + $result = $query->select(['principaluri', 'access']) |
|
| 161 | + ->from('dav_shares') |
|
| 162 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId))) |
|
| 163 | + ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
| 164 | + ->execute(); |
|
| 165 | + |
|
| 166 | + $shares = []; |
|
| 167 | + while($row = $result->fetch()) { |
|
| 168 | + $p = $this->principalBackend->getPrincipalByPath($row['principaluri']); |
|
| 169 | + $shares[]= [ |
|
| 170 | + 'href' => "principal:${row['principaluri']}", |
|
| 171 | + 'commonName' => isset($p['{DAV:}displayname']) ? $p['{DAV:}displayname'] : '', |
|
| 172 | + 'status' => 1, |
|
| 173 | + 'readOnly' => ($row['access'] == self::ACCESS_READ), |
|
| 174 | + '{http://owncloud.org/ns}principal' => $row['principaluri'], |
|
| 175 | + '{http://owncloud.org/ns}group-share' => is_null($p) |
|
| 176 | + ]; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return $shares; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * For shared resources the sharee is set in the ACL of the resource |
|
| 184 | + * |
|
| 185 | + * @param int $resourceId |
|
| 186 | + * @param array $acl |
|
| 187 | + * @return array |
|
| 188 | + */ |
|
| 189 | + public function applyShareAcl($resourceId, $acl) { |
|
| 190 | + |
|
| 191 | + $shares = $this->getShares($resourceId); |
|
| 192 | + foreach ($shares as $share) { |
|
| 193 | + $acl[] = [ |
|
| 194 | + 'privilege' => '{DAV:}read', |
|
| 195 | + 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
| 196 | + 'protected' => true, |
|
| 197 | + ]; |
|
| 198 | + if (!$share['readOnly']) { |
|
| 199 | + $acl[] = [ |
|
| 200 | + 'privilege' => '{DAV:}write', |
|
| 201 | + 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
| 202 | + 'protected' => true, |
|
| 203 | + ]; |
|
| 204 | + } else if ($this->resourceType === 'calendar') { |
|
| 205 | + // Allow changing the properties of read only calendars, |
|
| 206 | + // so users can change the visibility. |
|
| 207 | + $acl[] = [ |
|
| 208 | + 'privilege' => '{DAV:}write-properties', |
|
| 209 | + 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
| 210 | + 'protected' => true, |
|
| 211 | + ]; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + return $acl; |
|
| 215 | + } |
|
| 216 | 216 | } |
@@ -57,10 +57,10 @@ discard block |
||
| 57 | 57 | * @param string[] $remove |
| 58 | 58 | */ |
| 59 | 59 | public function updateShares($shareable, $add, $remove) { |
| 60 | - foreach($add as $element) { |
|
| 60 | + foreach ($add as $element) { |
|
| 61 | 61 | $this->shareWith($shareable, $element); |
| 62 | 62 | } |
| 63 | - foreach($remove as $element) { |
|
| 63 | + foreach ($remove as $element) { |
|
| 64 | 64 | $this->unshare($shareable, $element); |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -164,9 +164,9 @@ discard block |
||
| 164 | 164 | ->execute(); |
| 165 | 165 | |
| 166 | 166 | $shares = []; |
| 167 | - while($row = $result->fetch()) { |
|
| 167 | + while ($row = $result->fetch()) { |
|
| 168 | 168 | $p = $this->principalBackend->getPrincipalByPath($row['principaluri']); |
| 169 | - $shares[]= [ |
|
| 169 | + $shares[] = [ |
|
| 170 | 170 | 'href' => "principal:${row['principaluri']}", |
| 171 | 171 | 'commonName' => isset($p['{DAV:}displayname']) ? $p['{DAV:}displayname'] : '', |
| 172 | 172 | 'status' => 1, |
@@ -192,13 +192,13 @@ discard block |
||
| 192 | 192 | foreach ($shares as $share) { |
| 193 | 193 | $acl[] = [ |
| 194 | 194 | 'privilege' => '{DAV:}read', |
| 195 | - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
| 195 | + 'principal' => $share['{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}principal'], |
|
| 196 | 196 | 'protected' => true, |
| 197 | 197 | ]; |
| 198 | 198 | if (!$share['readOnly']) { |
| 199 | 199 | $acl[] = [ |
| 200 | 200 | 'privilege' => '{DAV:}write', |
| 201 | - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
| 201 | + 'principal' => $share['{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}principal'], |
|
| 202 | 202 | 'protected' => true, |
| 203 | 203 | ]; |
| 204 | 204 | } else if ($this->resourceType === 'calendar') { |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | // so users can change the visibility. |
| 207 | 207 | $acl[] = [ |
| 208 | 208 | 'privilege' => '{DAV:}write-properties', |
| 209 | - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
| 209 | + 'principal' => $share['{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}principal'], |
|
| 210 | 210 | 'protected' => true, |
| 211 | 211 | ]; |
| 212 | 212 | } |
@@ -28,48 +28,48 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | interface IShareable extends INode { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Updates the list of shares. |
|
| 33 | - * |
|
| 34 | - * The first array is a list of people that are to be added to the |
|
| 35 | - * resource. |
|
| 36 | - * |
|
| 37 | - * Every element in the add array has the following properties: |
|
| 38 | - * * href - A url. Usually a mailto: address |
|
| 39 | - * * commonName - Usually a first and last name, or false |
|
| 40 | - * * summary - A description of the share, can also be false |
|
| 41 | - * * readOnly - A boolean value |
|
| 42 | - * |
|
| 43 | - * Every element in the remove array is just the address string. |
|
| 44 | - * |
|
| 45 | - * @param array $add |
|
| 46 | - * @param array $remove |
|
| 47 | - * @return void |
|
| 48 | - */ |
|
| 49 | - function updateShares(array $add, array $remove); |
|
| 31 | + /** |
|
| 32 | + * Updates the list of shares. |
|
| 33 | + * |
|
| 34 | + * The first array is a list of people that are to be added to the |
|
| 35 | + * resource. |
|
| 36 | + * |
|
| 37 | + * Every element in the add array has the following properties: |
|
| 38 | + * * href - A url. Usually a mailto: address |
|
| 39 | + * * commonName - Usually a first and last name, or false |
|
| 40 | + * * summary - A description of the share, can also be false |
|
| 41 | + * * readOnly - A boolean value |
|
| 42 | + * |
|
| 43 | + * Every element in the remove array is just the address string. |
|
| 44 | + * |
|
| 45 | + * @param array $add |
|
| 46 | + * @param array $remove |
|
| 47 | + * @return void |
|
| 48 | + */ |
|
| 49 | + function updateShares(array $add, array $remove); |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Returns the list of people whom this resource is shared with. |
|
| 53 | - * |
|
| 54 | - * Every element in this array should have the following properties: |
|
| 55 | - * * href - Often a mailto: address |
|
| 56 | - * * commonName - Optional, for example a first + last name |
|
| 57 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 58 | - * * readOnly - boolean |
|
| 59 | - * * summary - Optional, a description for the share |
|
| 60 | - * |
|
| 61 | - * @return array |
|
| 62 | - */ |
|
| 63 | - function getShares(); |
|
| 51 | + /** |
|
| 52 | + * Returns the list of people whom this resource is shared with. |
|
| 53 | + * |
|
| 54 | + * Every element in this array should have the following properties: |
|
| 55 | + * * href - Often a mailto: address |
|
| 56 | + * * commonName - Optional, for example a first + last name |
|
| 57 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 58 | + * * readOnly - boolean |
|
| 59 | + * * summary - Optional, a description for the share |
|
| 60 | + * |
|
| 61 | + * @return array |
|
| 62 | + */ |
|
| 63 | + function getShares(); |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @return int |
|
| 67 | - */ |
|
| 68 | - public function getResourceId(); |
|
| 65 | + /** |
|
| 66 | + * @return int |
|
| 67 | + */ |
|
| 68 | + public function getResourceId(); |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - public function getOwner(); |
|
| 70 | + /** |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + public function getOwner(); |
|
| 74 | 74 | |
| 75 | 75 | } |
| 76 | 76 | \ No newline at end of file |
@@ -43,85 +43,85 @@ |
||
| 43 | 43 | */ |
| 44 | 44 | class EntityTypeCollection extends RootCollection { |
| 45 | 45 | |
| 46 | - /** @var ILogger */ |
|
| 47 | - protected $logger; |
|
| 46 | + /** @var ILogger */ |
|
| 47 | + protected $logger; |
|
| 48 | 48 | |
| 49 | - /** @var IUserManager */ |
|
| 50 | - protected $userManager; |
|
| 49 | + /** @var IUserManager */ |
|
| 50 | + protected $userManager; |
|
| 51 | 51 | |
| 52 | - /** @var \Closure */ |
|
| 53 | - protected $childExistsFunction; |
|
| 52 | + /** @var \Closure */ |
|
| 53 | + protected $childExistsFunction; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @param string $name |
|
| 57 | - * @param ICommentsManager $commentsManager |
|
| 58 | - * @param IUserManager $userManager |
|
| 59 | - * @param IUserSession $userSession |
|
| 60 | - * @param ILogger $logger |
|
| 61 | - * @param \Closure $childExistsFunction |
|
| 62 | - */ |
|
| 63 | - public function __construct( |
|
| 64 | - $name, |
|
| 65 | - ICommentsManager $commentsManager, |
|
| 66 | - IUserManager $userManager, |
|
| 67 | - IUserSession $userSession, |
|
| 68 | - ILogger $logger, |
|
| 69 | - \Closure $childExistsFunction |
|
| 70 | - ) { |
|
| 71 | - $name = trim($name); |
|
| 72 | - if(empty($name) || !is_string($name)) { |
|
| 73 | - throw new \InvalidArgumentException('"name" parameter must be non-empty string'); |
|
| 74 | - } |
|
| 75 | - $this->name = $name; |
|
| 76 | - $this->commentsManager = $commentsManager; |
|
| 77 | - $this->logger = $logger; |
|
| 78 | - $this->userManager = $userManager; |
|
| 79 | - $this->userSession = $userSession; |
|
| 80 | - $this->childExistsFunction = $childExistsFunction; |
|
| 81 | - } |
|
| 55 | + /** |
|
| 56 | + * @param string $name |
|
| 57 | + * @param ICommentsManager $commentsManager |
|
| 58 | + * @param IUserManager $userManager |
|
| 59 | + * @param IUserSession $userSession |
|
| 60 | + * @param ILogger $logger |
|
| 61 | + * @param \Closure $childExistsFunction |
|
| 62 | + */ |
|
| 63 | + public function __construct( |
|
| 64 | + $name, |
|
| 65 | + ICommentsManager $commentsManager, |
|
| 66 | + IUserManager $userManager, |
|
| 67 | + IUserSession $userSession, |
|
| 68 | + ILogger $logger, |
|
| 69 | + \Closure $childExistsFunction |
|
| 70 | + ) { |
|
| 71 | + $name = trim($name); |
|
| 72 | + if(empty($name) || !is_string($name)) { |
|
| 73 | + throw new \InvalidArgumentException('"name" parameter must be non-empty string'); |
|
| 74 | + } |
|
| 75 | + $this->name = $name; |
|
| 76 | + $this->commentsManager = $commentsManager; |
|
| 77 | + $this->logger = $logger; |
|
| 78 | + $this->userManager = $userManager; |
|
| 79 | + $this->userSession = $userSession; |
|
| 80 | + $this->childExistsFunction = $childExistsFunction; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Returns a specific child node, referenced by its name |
|
| 85 | - * |
|
| 86 | - * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
| 87 | - * exist. |
|
| 88 | - * |
|
| 89 | - * @param string $name |
|
| 90 | - * @return \Sabre\DAV\INode |
|
| 91 | - * @throws NotFound |
|
| 92 | - */ |
|
| 93 | - function getChild($name) { |
|
| 94 | - if(!$this->childExists($name)) { |
|
| 95 | - throw new NotFound('Entity does not exist or is not available'); |
|
| 96 | - } |
|
| 97 | - return new EntityCollection( |
|
| 98 | - $name, |
|
| 99 | - $this->name, |
|
| 100 | - $this->commentsManager, |
|
| 101 | - $this->userManager, |
|
| 102 | - $this->userSession, |
|
| 103 | - $this->logger |
|
| 104 | - ); |
|
| 105 | - } |
|
| 83 | + /** |
|
| 84 | + * Returns a specific child node, referenced by its name |
|
| 85 | + * |
|
| 86 | + * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
| 87 | + * exist. |
|
| 88 | + * |
|
| 89 | + * @param string $name |
|
| 90 | + * @return \Sabre\DAV\INode |
|
| 91 | + * @throws NotFound |
|
| 92 | + */ |
|
| 93 | + function getChild($name) { |
|
| 94 | + if(!$this->childExists($name)) { |
|
| 95 | + throw new NotFound('Entity does not exist or is not available'); |
|
| 96 | + } |
|
| 97 | + return new EntityCollection( |
|
| 98 | + $name, |
|
| 99 | + $this->name, |
|
| 100 | + $this->commentsManager, |
|
| 101 | + $this->userManager, |
|
| 102 | + $this->userSession, |
|
| 103 | + $this->logger |
|
| 104 | + ); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Returns an array with all the child nodes |
|
| 109 | - * |
|
| 110 | - * @return \Sabre\DAV\INode[] |
|
| 111 | - * @throws MethodNotAllowed |
|
| 112 | - */ |
|
| 113 | - function getChildren() { |
|
| 114 | - throw new MethodNotAllowed('No permission to list folder contents'); |
|
| 115 | - } |
|
| 107 | + /** |
|
| 108 | + * Returns an array with all the child nodes |
|
| 109 | + * |
|
| 110 | + * @return \Sabre\DAV\INode[] |
|
| 111 | + * @throws MethodNotAllowed |
|
| 112 | + */ |
|
| 113 | + function getChildren() { |
|
| 114 | + throw new MethodNotAllowed('No permission to list folder contents'); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Checks if a child-node with the specified name exists |
|
| 119 | - * |
|
| 120 | - * @param string $name |
|
| 121 | - * @return bool |
|
| 122 | - */ |
|
| 123 | - function childExists($name) { |
|
| 124 | - return call_user_func($this->childExistsFunction, $name); |
|
| 125 | - } |
|
| 117 | + /** |
|
| 118 | + * Checks if a child-node with the specified name exists |
|
| 119 | + * |
|
| 120 | + * @param string $name |
|
| 121 | + * @return bool |
|
| 122 | + */ |
|
| 123 | + function childExists($name) { |
|
| 124 | + return call_user_func($this->childExistsFunction, $name); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | 127 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | \Closure $childExistsFunction |
| 70 | 70 | ) { |
| 71 | 71 | $name = trim($name); |
| 72 | - if(empty($name) || !is_string($name)) { |
|
| 72 | + if (empty($name) || !is_string($name)) { |
|
| 73 | 73 | throw new \InvalidArgumentException('"name" parameter must be non-empty string'); |
| 74 | 74 | } |
| 75 | 75 | $this->name = $name; |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @throws NotFound |
| 92 | 92 | */ |
| 93 | 93 | function getChild($name) { |
| 94 | - if(!$this->childExists($name)) { |
|
| 94 | + if (!$this->childExists($name)) { |
|
| 95 | 95 | throw new NotFound('Entity does not exist or is not available'); |
| 96 | 96 | } |
| 97 | 97 | return new EntityCollection( |