@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -27,165 +27,165 @@ |
||
27 | 27 | |
28 | 28 | class SystemPrincipalBackend extends AbstractBackend { |
29 | 29 | |
30 | - /** |
|
31 | - * Returns a list of principals based on a prefix. |
|
32 | - * |
|
33 | - * This prefix will often contain something like 'principals'. You are only |
|
34 | - * expected to return principals that are in this base path. |
|
35 | - * |
|
36 | - * You are expected to return at least a 'uri' for every user, you can |
|
37 | - * return any additional properties if you wish so. Common properties are: |
|
38 | - * {DAV:}displayname |
|
39 | - * {http://sabredav.org/ns}email-address - This is a custom SabreDAV |
|
40 | - * field that's actually injected in a number of other properties. If |
|
41 | - * you have an email address, use this property. |
|
42 | - * |
|
43 | - * @param string $prefixPath |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - function getPrincipalsByPrefix($prefixPath) { |
|
47 | - $principals = []; |
|
48 | - |
|
49 | - if ($prefixPath === 'principals/system') { |
|
50 | - $principals[] = [ |
|
51 | - 'uri' => 'principals/system/system', |
|
52 | - '{DAV:}displayname' => 'system', |
|
53 | - ]; |
|
54 | - $principals[] = [ |
|
55 | - 'uri' => 'principals/system/public', |
|
56 | - '{DAV:}displayname' => 'public', |
|
57 | - ]; |
|
58 | - } |
|
59 | - |
|
60 | - return $principals; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Returns a specific principal, specified by it's path. |
|
65 | - * The returned structure should be the exact same as from |
|
66 | - * getPrincipalsByPrefix. |
|
67 | - * |
|
68 | - * @param string $path |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - function getPrincipalByPath($path) { |
|
72 | - |
|
73 | - if ($path === 'principals/system/system') { |
|
74 | - $principal = [ |
|
75 | - 'uri' => 'principals/system/system', |
|
76 | - '{DAV:}displayname' => 'system', |
|
77 | - ]; |
|
78 | - return $principal; |
|
79 | - } |
|
80 | - if ($path === 'principals/system/public') { |
|
81 | - $principal = [ |
|
82 | - 'uri' => 'principals/system/public', |
|
83 | - '{DAV:}displayname' => 'public', |
|
84 | - ]; |
|
85 | - return $principal; |
|
86 | - } |
|
87 | - |
|
88 | - return null; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Updates one ore more webdav properties on a principal. |
|
93 | - * |
|
94 | - * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
95 | - * To do the actual updates, you must tell this object which properties |
|
96 | - * you're going to process with the handle() method. |
|
97 | - * |
|
98 | - * Calling the handle method is like telling the PropPatch object "I |
|
99 | - * promise I can handle updating this property". |
|
100 | - * |
|
101 | - * Read the PropPatch documentation for more info and examples. |
|
102 | - * |
|
103 | - * @param string $path |
|
104 | - * @param \Sabre\DAV\PropPatch $propPatch |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - function updatePrincipal($path, \Sabre\DAV\PropPatch $propPatch) { |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * This method is used to search for principals matching a set of |
|
112 | - * properties. |
|
113 | - * |
|
114 | - * This search is specifically used by RFC3744's principal-property-search |
|
115 | - * REPORT. |
|
116 | - * |
|
117 | - * The actual search should be a unicode-non-case-sensitive search. The |
|
118 | - * keys in searchProperties are the WebDAV property names, while the values |
|
119 | - * are the property values to search on. |
|
120 | - * |
|
121 | - * By default, if multiple properties are submitted to this method, the |
|
122 | - * various properties should be combined with 'AND'. If $test is set to |
|
123 | - * 'anyof', it should be combined using 'OR'. |
|
124 | - * |
|
125 | - * This method should simply return an array with full principal uri's. |
|
126 | - * |
|
127 | - * If somebody attempted to search on a property the backend does not |
|
128 | - * support, you should simply return 0 results. |
|
129 | - * |
|
130 | - * You can also just return 0 results if you choose to not support |
|
131 | - * searching at all, but keep in mind that this may stop certain features |
|
132 | - * from working. |
|
133 | - * |
|
134 | - * @param string $prefixPath |
|
135 | - * @param array $searchProperties |
|
136 | - * @param string $test |
|
137 | - * @return array |
|
138 | - */ |
|
139 | - function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
140 | - return []; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Returns the list of members for a group-principal |
|
145 | - * |
|
146 | - * @param string $principal |
|
147 | - * @return array |
|
148 | - */ |
|
149 | - function getGroupMemberSet($principal) { |
|
150 | - // TODO: for now the group principal has only one member, the user itself |
|
151 | - $principal = $this->getPrincipalByPath($principal); |
|
152 | - if (!$principal) { |
|
153 | - throw new \Sabre\DAV\Exception('Principal not found'); |
|
154 | - } |
|
155 | - |
|
156 | - return [$principal['uri']]; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Returns the list of groups a principal is a member of |
|
161 | - * |
|
162 | - * @param string $principal |
|
163 | - * @return array |
|
164 | - */ |
|
165 | - function getGroupMembership($principal) { |
|
166 | - list($prefix, $name) = URLUtil::splitPath($principal); |
|
167 | - |
|
168 | - if ($prefix === 'principals/system') { |
|
169 | - $principal = $this->getPrincipalByPath($principal); |
|
170 | - if (!$principal) { |
|
171 | - throw new \Sabre\DAV\Exception('Principal not found'); |
|
172 | - } |
|
173 | - |
|
174 | - return []; |
|
175 | - } |
|
176 | - return []; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Updates the list of group members for a group principal. |
|
181 | - * |
|
182 | - * The principals should be passed as a list of uri's. |
|
183 | - * |
|
184 | - * @param string $principal |
|
185 | - * @param array $members |
|
186 | - * @return void |
|
187 | - */ |
|
188 | - function setGroupMemberSet($principal, array $members) { |
|
189 | - throw new \Sabre\DAV\Exception('Setting members of the group is not supported yet'); |
|
190 | - } |
|
30 | + /** |
|
31 | + * Returns a list of principals based on a prefix. |
|
32 | + * |
|
33 | + * This prefix will often contain something like 'principals'. You are only |
|
34 | + * expected to return principals that are in this base path. |
|
35 | + * |
|
36 | + * You are expected to return at least a 'uri' for every user, you can |
|
37 | + * return any additional properties if you wish so. Common properties are: |
|
38 | + * {DAV:}displayname |
|
39 | + * {http://sabredav.org/ns}email-address - This is a custom SabreDAV |
|
40 | + * field that's actually injected in a number of other properties. If |
|
41 | + * you have an email address, use this property. |
|
42 | + * |
|
43 | + * @param string $prefixPath |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + function getPrincipalsByPrefix($prefixPath) { |
|
47 | + $principals = []; |
|
48 | + |
|
49 | + if ($prefixPath === 'principals/system') { |
|
50 | + $principals[] = [ |
|
51 | + 'uri' => 'principals/system/system', |
|
52 | + '{DAV:}displayname' => 'system', |
|
53 | + ]; |
|
54 | + $principals[] = [ |
|
55 | + 'uri' => 'principals/system/public', |
|
56 | + '{DAV:}displayname' => 'public', |
|
57 | + ]; |
|
58 | + } |
|
59 | + |
|
60 | + return $principals; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Returns a specific principal, specified by it's path. |
|
65 | + * The returned structure should be the exact same as from |
|
66 | + * getPrincipalsByPrefix. |
|
67 | + * |
|
68 | + * @param string $path |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + function getPrincipalByPath($path) { |
|
72 | + |
|
73 | + if ($path === 'principals/system/system') { |
|
74 | + $principal = [ |
|
75 | + 'uri' => 'principals/system/system', |
|
76 | + '{DAV:}displayname' => 'system', |
|
77 | + ]; |
|
78 | + return $principal; |
|
79 | + } |
|
80 | + if ($path === 'principals/system/public') { |
|
81 | + $principal = [ |
|
82 | + 'uri' => 'principals/system/public', |
|
83 | + '{DAV:}displayname' => 'public', |
|
84 | + ]; |
|
85 | + return $principal; |
|
86 | + } |
|
87 | + |
|
88 | + return null; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Updates one ore more webdav properties on a principal. |
|
93 | + * |
|
94 | + * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
95 | + * To do the actual updates, you must tell this object which properties |
|
96 | + * you're going to process with the handle() method. |
|
97 | + * |
|
98 | + * Calling the handle method is like telling the PropPatch object "I |
|
99 | + * promise I can handle updating this property". |
|
100 | + * |
|
101 | + * Read the PropPatch documentation for more info and examples. |
|
102 | + * |
|
103 | + * @param string $path |
|
104 | + * @param \Sabre\DAV\PropPatch $propPatch |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + function updatePrincipal($path, \Sabre\DAV\PropPatch $propPatch) { |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * This method is used to search for principals matching a set of |
|
112 | + * properties. |
|
113 | + * |
|
114 | + * This search is specifically used by RFC3744's principal-property-search |
|
115 | + * REPORT. |
|
116 | + * |
|
117 | + * The actual search should be a unicode-non-case-sensitive search. The |
|
118 | + * keys in searchProperties are the WebDAV property names, while the values |
|
119 | + * are the property values to search on. |
|
120 | + * |
|
121 | + * By default, if multiple properties are submitted to this method, the |
|
122 | + * various properties should be combined with 'AND'. If $test is set to |
|
123 | + * 'anyof', it should be combined using 'OR'. |
|
124 | + * |
|
125 | + * This method should simply return an array with full principal uri's. |
|
126 | + * |
|
127 | + * If somebody attempted to search on a property the backend does not |
|
128 | + * support, you should simply return 0 results. |
|
129 | + * |
|
130 | + * You can also just return 0 results if you choose to not support |
|
131 | + * searching at all, but keep in mind that this may stop certain features |
|
132 | + * from working. |
|
133 | + * |
|
134 | + * @param string $prefixPath |
|
135 | + * @param array $searchProperties |
|
136 | + * @param string $test |
|
137 | + * @return array |
|
138 | + */ |
|
139 | + function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
140 | + return []; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Returns the list of members for a group-principal |
|
145 | + * |
|
146 | + * @param string $principal |
|
147 | + * @return array |
|
148 | + */ |
|
149 | + function getGroupMemberSet($principal) { |
|
150 | + // TODO: for now the group principal has only one member, the user itself |
|
151 | + $principal = $this->getPrincipalByPath($principal); |
|
152 | + if (!$principal) { |
|
153 | + throw new \Sabre\DAV\Exception('Principal not found'); |
|
154 | + } |
|
155 | + |
|
156 | + return [$principal['uri']]; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Returns the list of groups a principal is a member of |
|
161 | + * |
|
162 | + * @param string $principal |
|
163 | + * @return array |
|
164 | + */ |
|
165 | + function getGroupMembership($principal) { |
|
166 | + list($prefix, $name) = URLUtil::splitPath($principal); |
|
167 | + |
|
168 | + if ($prefix === 'principals/system') { |
|
169 | + $principal = $this->getPrincipalByPath($principal); |
|
170 | + if (!$principal) { |
|
171 | + throw new \Sabre\DAV\Exception('Principal not found'); |
|
172 | + } |
|
173 | + |
|
174 | + return []; |
|
175 | + } |
|
176 | + return []; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Updates the list of group members for a group principal. |
|
181 | + * |
|
182 | + * The principals should be passed as a list of uri's. |
|
183 | + * |
|
184 | + * @param string $principal |
|
185 | + * @param array $members |
|
186 | + * @return void |
|
187 | + */ |
|
188 | + function setGroupMemberSet($principal, array $members) { |
|
189 | + throw new \Sabre\DAV\Exception('Setting members of the group is not supported yet'); |
|
190 | + } |
|
191 | 191 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -36,270 +36,270 @@ |
||
36 | 36 | use Sabre\DAV\PropPatch; |
37 | 37 | |
38 | 38 | class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties { |
39 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
39 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
40 | 40 | |
41 | - const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}isUnread'; |
|
42 | - const PROPERTY_NAME_MESSAGE = '{http://owncloud.org/ns}message'; |
|
43 | - const PROPERTY_NAME_ACTOR_DISPLAYNAME = '{http://owncloud.org/ns}actorDisplayName'; |
|
44 | - const PROPERTY_NAME_MENTIONS = '{http://owncloud.org/ns}mentions'; |
|
45 | - const PROPERTY_NAME_MENTION = '{http://owncloud.org/ns}mention'; |
|
46 | - const PROPERTY_NAME_MENTION_TYPE = '{http://owncloud.org/ns}mentionType'; |
|
47 | - const PROPERTY_NAME_MENTION_ID = '{http://owncloud.org/ns}mentionId'; |
|
48 | - const PROPERTY_NAME_MENTION_DISPLAYNAME = '{http://owncloud.org/ns}mentionDisplayName'; |
|
41 | + const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}isUnread'; |
|
42 | + const PROPERTY_NAME_MESSAGE = '{http://owncloud.org/ns}message'; |
|
43 | + const PROPERTY_NAME_ACTOR_DISPLAYNAME = '{http://owncloud.org/ns}actorDisplayName'; |
|
44 | + const PROPERTY_NAME_MENTIONS = '{http://owncloud.org/ns}mentions'; |
|
45 | + const PROPERTY_NAME_MENTION = '{http://owncloud.org/ns}mention'; |
|
46 | + const PROPERTY_NAME_MENTION_TYPE = '{http://owncloud.org/ns}mentionType'; |
|
47 | + const PROPERTY_NAME_MENTION_ID = '{http://owncloud.org/ns}mentionId'; |
|
48 | + const PROPERTY_NAME_MENTION_DISPLAYNAME = '{http://owncloud.org/ns}mentionDisplayName'; |
|
49 | 49 | |
50 | - /** @var IComment */ |
|
51 | - public $comment; |
|
50 | + /** @var IComment */ |
|
51 | + public $comment; |
|
52 | 52 | |
53 | - /** @var ICommentsManager */ |
|
54 | - protected $commentsManager; |
|
53 | + /** @var ICommentsManager */ |
|
54 | + protected $commentsManager; |
|
55 | 55 | |
56 | - /** @var ILogger */ |
|
57 | - protected $logger; |
|
56 | + /** @var ILogger */ |
|
57 | + protected $logger; |
|
58 | 58 | |
59 | - /** @var array list of properties with key being their name and value their setter */ |
|
60 | - protected $properties = []; |
|
59 | + /** @var array list of properties with key being their name and value their setter */ |
|
60 | + protected $properties = []; |
|
61 | 61 | |
62 | - /** @var IUserManager */ |
|
63 | - protected $userManager; |
|
62 | + /** @var IUserManager */ |
|
63 | + protected $userManager; |
|
64 | 64 | |
65 | - /** @var IUserSession */ |
|
66 | - protected $userSession; |
|
65 | + /** @var IUserSession */ |
|
66 | + protected $userSession; |
|
67 | 67 | |
68 | - /** |
|
69 | - * CommentNode constructor. |
|
70 | - * |
|
71 | - * @param ICommentsManager $commentsManager |
|
72 | - * @param IComment $comment |
|
73 | - * @param IUserManager $userManager |
|
74 | - * @param IUserSession $userSession |
|
75 | - * @param ILogger $logger |
|
76 | - */ |
|
77 | - public function __construct( |
|
78 | - ICommentsManager $commentsManager, |
|
79 | - IComment $comment, |
|
80 | - IUserManager $userManager, |
|
81 | - IUserSession $userSession, |
|
82 | - ILogger $logger |
|
83 | - ) { |
|
84 | - $this->commentsManager = $commentsManager; |
|
85 | - $this->comment = $comment; |
|
86 | - $this->logger = $logger; |
|
68 | + /** |
|
69 | + * CommentNode constructor. |
|
70 | + * |
|
71 | + * @param ICommentsManager $commentsManager |
|
72 | + * @param IComment $comment |
|
73 | + * @param IUserManager $userManager |
|
74 | + * @param IUserSession $userSession |
|
75 | + * @param ILogger $logger |
|
76 | + */ |
|
77 | + public function __construct( |
|
78 | + ICommentsManager $commentsManager, |
|
79 | + IComment $comment, |
|
80 | + IUserManager $userManager, |
|
81 | + IUserSession $userSession, |
|
82 | + ILogger $logger |
|
83 | + ) { |
|
84 | + $this->commentsManager = $commentsManager; |
|
85 | + $this->comment = $comment; |
|
86 | + $this->logger = $logger; |
|
87 | 87 | |
88 | - $methods = get_class_methods($this->comment); |
|
89 | - $methods = array_filter($methods, function($name){ |
|
90 | - return strpos($name, 'get') === 0; |
|
91 | - }); |
|
92 | - foreach($methods as $getter) { |
|
93 | - if($getter === 'getMentions') { |
|
94 | - continue; // special treatment |
|
95 | - } |
|
96 | - $name = '{'.self::NS_OWNCLOUD.'}' . lcfirst(substr($getter, 3)); |
|
97 | - $this->properties[$name] = $getter; |
|
98 | - } |
|
99 | - $this->userManager = $userManager; |
|
100 | - $this->userSession = $userSession; |
|
101 | - } |
|
88 | + $methods = get_class_methods($this->comment); |
|
89 | + $methods = array_filter($methods, function($name){ |
|
90 | + return strpos($name, 'get') === 0; |
|
91 | + }); |
|
92 | + foreach($methods as $getter) { |
|
93 | + if($getter === 'getMentions') { |
|
94 | + continue; // special treatment |
|
95 | + } |
|
96 | + $name = '{'.self::NS_OWNCLOUD.'}' . lcfirst(substr($getter, 3)); |
|
97 | + $this->properties[$name] = $getter; |
|
98 | + } |
|
99 | + $this->userManager = $userManager; |
|
100 | + $this->userSession = $userSession; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * returns a list of all possible property names |
|
105 | - * |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - static public function getPropertyNames() { |
|
109 | - return [ |
|
110 | - '{http://owncloud.org/ns}id', |
|
111 | - '{http://owncloud.org/ns}parentId', |
|
112 | - '{http://owncloud.org/ns}topmostParentId', |
|
113 | - '{http://owncloud.org/ns}childrenCount', |
|
114 | - '{http://owncloud.org/ns}verb', |
|
115 | - '{http://owncloud.org/ns}actorType', |
|
116 | - '{http://owncloud.org/ns}actorId', |
|
117 | - '{http://owncloud.org/ns}creationDateTime', |
|
118 | - '{http://owncloud.org/ns}latestChildDateTime', |
|
119 | - '{http://owncloud.org/ns}objectType', |
|
120 | - '{http://owncloud.org/ns}objectId', |
|
121 | - // re-used property names are defined as constants |
|
122 | - self::PROPERTY_NAME_MESSAGE, |
|
123 | - self::PROPERTY_NAME_ACTOR_DISPLAYNAME, |
|
124 | - self::PROPERTY_NAME_UNREAD, |
|
125 | - self::PROPERTY_NAME_MENTIONS, |
|
126 | - self::PROPERTY_NAME_MENTION, |
|
127 | - self::PROPERTY_NAME_MENTION_TYPE, |
|
128 | - self::PROPERTY_NAME_MENTION_ID, |
|
129 | - self::PROPERTY_NAME_MENTION_DISPLAYNAME, |
|
130 | - ]; |
|
131 | - } |
|
103 | + /** |
|
104 | + * returns a list of all possible property names |
|
105 | + * |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + static public function getPropertyNames() { |
|
109 | + return [ |
|
110 | + '{http://owncloud.org/ns}id', |
|
111 | + '{http://owncloud.org/ns}parentId', |
|
112 | + '{http://owncloud.org/ns}topmostParentId', |
|
113 | + '{http://owncloud.org/ns}childrenCount', |
|
114 | + '{http://owncloud.org/ns}verb', |
|
115 | + '{http://owncloud.org/ns}actorType', |
|
116 | + '{http://owncloud.org/ns}actorId', |
|
117 | + '{http://owncloud.org/ns}creationDateTime', |
|
118 | + '{http://owncloud.org/ns}latestChildDateTime', |
|
119 | + '{http://owncloud.org/ns}objectType', |
|
120 | + '{http://owncloud.org/ns}objectId', |
|
121 | + // re-used property names are defined as constants |
|
122 | + self::PROPERTY_NAME_MESSAGE, |
|
123 | + self::PROPERTY_NAME_ACTOR_DISPLAYNAME, |
|
124 | + self::PROPERTY_NAME_UNREAD, |
|
125 | + self::PROPERTY_NAME_MENTIONS, |
|
126 | + self::PROPERTY_NAME_MENTION, |
|
127 | + self::PROPERTY_NAME_MENTION_TYPE, |
|
128 | + self::PROPERTY_NAME_MENTION_ID, |
|
129 | + self::PROPERTY_NAME_MENTION_DISPLAYNAME, |
|
130 | + ]; |
|
131 | + } |
|
132 | 132 | |
133 | - protected function checkWriteAccessOnComment() { |
|
134 | - $user = $this->userSession->getUser(); |
|
135 | - if( $this->comment->getActorType() !== 'users' |
|
136 | - || is_null($user) |
|
137 | - || $this->comment->getActorId() !== $user->getUID() |
|
138 | - ) { |
|
139 | - throw new Forbidden('Only authors are allowed to edit their comment.'); |
|
140 | - } |
|
141 | - } |
|
133 | + protected function checkWriteAccessOnComment() { |
|
134 | + $user = $this->userSession->getUser(); |
|
135 | + if( $this->comment->getActorType() !== 'users' |
|
136 | + || is_null($user) |
|
137 | + || $this->comment->getActorId() !== $user->getUID() |
|
138 | + ) { |
|
139 | + throw new Forbidden('Only authors are allowed to edit their comment.'); |
|
140 | + } |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * Deleted the current node |
|
145 | - * |
|
146 | - * @return void |
|
147 | - */ |
|
148 | - function delete() { |
|
149 | - $this->checkWriteAccessOnComment(); |
|
150 | - $this->commentsManager->delete($this->comment->getId()); |
|
151 | - } |
|
143 | + /** |
|
144 | + * Deleted the current node |
|
145 | + * |
|
146 | + * @return void |
|
147 | + */ |
|
148 | + function delete() { |
|
149 | + $this->checkWriteAccessOnComment(); |
|
150 | + $this->commentsManager->delete($this->comment->getId()); |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * Returns the name of the node. |
|
155 | - * |
|
156 | - * This is used to generate the url. |
|
157 | - * |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - function getName() { |
|
161 | - return $this->comment->getId(); |
|
162 | - } |
|
153 | + /** |
|
154 | + * Returns the name of the node. |
|
155 | + * |
|
156 | + * This is used to generate the url. |
|
157 | + * |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + function getName() { |
|
161 | + return $this->comment->getId(); |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
165 | - * Renames the node |
|
166 | - * |
|
167 | - * @param string $name The new name |
|
168 | - * @throws MethodNotAllowed |
|
169 | - */ |
|
170 | - function setName($name) { |
|
171 | - throw new MethodNotAllowed(); |
|
172 | - } |
|
164 | + /** |
|
165 | + * Renames the node |
|
166 | + * |
|
167 | + * @param string $name The new name |
|
168 | + * @throws MethodNotAllowed |
|
169 | + */ |
|
170 | + function setName($name) { |
|
171 | + throw new MethodNotAllowed(); |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * Returns the last modification time, as a unix timestamp |
|
176 | - * |
|
177 | - * @return int |
|
178 | - */ |
|
179 | - function getLastModified() { |
|
180 | - return null; |
|
181 | - } |
|
174 | + /** |
|
175 | + * Returns the last modification time, as a unix timestamp |
|
176 | + * |
|
177 | + * @return int |
|
178 | + */ |
|
179 | + function getLastModified() { |
|
180 | + return null; |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * update the comment's message |
|
185 | - * |
|
186 | - * @param $propertyValue |
|
187 | - * @return bool |
|
188 | - * @throws BadRequest |
|
189 | - * @throws \Exception |
|
190 | - */ |
|
191 | - public function updateComment($propertyValue) { |
|
192 | - $this->checkWriteAccessOnComment(); |
|
193 | - try { |
|
194 | - $this->comment->setMessage($propertyValue); |
|
195 | - $this->commentsManager->save($this->comment); |
|
196 | - return true; |
|
197 | - } catch (\Exception $e) { |
|
198 | - $this->logger->logException($e, ['app' => 'dav/comments']); |
|
199 | - if($e instanceof MessageTooLongException) { |
|
200 | - $msg = 'Message exceeds allowed character limit of '; |
|
201 | - throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e); |
|
202 | - } |
|
203 | - throw $e; |
|
204 | - } |
|
205 | - } |
|
183 | + /** |
|
184 | + * update the comment's message |
|
185 | + * |
|
186 | + * @param $propertyValue |
|
187 | + * @return bool |
|
188 | + * @throws BadRequest |
|
189 | + * @throws \Exception |
|
190 | + */ |
|
191 | + public function updateComment($propertyValue) { |
|
192 | + $this->checkWriteAccessOnComment(); |
|
193 | + try { |
|
194 | + $this->comment->setMessage($propertyValue); |
|
195 | + $this->commentsManager->save($this->comment); |
|
196 | + return true; |
|
197 | + } catch (\Exception $e) { |
|
198 | + $this->logger->logException($e, ['app' => 'dav/comments']); |
|
199 | + if($e instanceof MessageTooLongException) { |
|
200 | + $msg = 'Message exceeds allowed character limit of '; |
|
201 | + throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e); |
|
202 | + } |
|
203 | + throw $e; |
|
204 | + } |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * Updates properties on this node. |
|
209 | - * |
|
210 | - * This method received a PropPatch object, which contains all the |
|
211 | - * information about the update. |
|
212 | - * |
|
213 | - * To update specific properties, call the 'handle' method on this object. |
|
214 | - * Read the PropPatch documentation for more information. |
|
215 | - * |
|
216 | - * @param PropPatch $propPatch |
|
217 | - * @return void |
|
218 | - */ |
|
219 | - function propPatch(PropPatch $propPatch) { |
|
220 | - // other properties than 'message' are read only |
|
221 | - $propPatch->handle(self::PROPERTY_NAME_MESSAGE, [$this, 'updateComment']); |
|
222 | - } |
|
207 | + /** |
|
208 | + * Updates properties on this node. |
|
209 | + * |
|
210 | + * This method received a PropPatch object, which contains all the |
|
211 | + * information about the update. |
|
212 | + * |
|
213 | + * To update specific properties, call the 'handle' method on this object. |
|
214 | + * Read the PropPatch documentation for more information. |
|
215 | + * |
|
216 | + * @param PropPatch $propPatch |
|
217 | + * @return void |
|
218 | + */ |
|
219 | + function propPatch(PropPatch $propPatch) { |
|
220 | + // other properties than 'message' are read only |
|
221 | + $propPatch->handle(self::PROPERTY_NAME_MESSAGE, [$this, 'updateComment']); |
|
222 | + } |
|
223 | 223 | |
224 | - /** |
|
225 | - * Returns a list of properties for this nodes. |
|
226 | - * |
|
227 | - * The properties list is a list of propertynames the client requested, |
|
228 | - * encoded in clark-notation {xmlnamespace}tagname |
|
229 | - * |
|
230 | - * If the array is empty, it means 'all properties' were requested. |
|
231 | - * |
|
232 | - * Note that it's fine to liberally give properties back, instead of |
|
233 | - * conforming to the list of requested properties. |
|
234 | - * The Server class will filter out the extra. |
|
235 | - * |
|
236 | - * @param array $properties |
|
237 | - * @return array |
|
238 | - */ |
|
239 | - function getProperties($properties) { |
|
240 | - $properties = array_keys($this->properties); |
|
224 | + /** |
|
225 | + * Returns a list of properties for this nodes. |
|
226 | + * |
|
227 | + * The properties list is a list of propertynames the client requested, |
|
228 | + * encoded in clark-notation {xmlnamespace}tagname |
|
229 | + * |
|
230 | + * If the array is empty, it means 'all properties' were requested. |
|
231 | + * |
|
232 | + * Note that it's fine to liberally give properties back, instead of |
|
233 | + * conforming to the list of requested properties. |
|
234 | + * The Server class will filter out the extra. |
|
235 | + * |
|
236 | + * @param array $properties |
|
237 | + * @return array |
|
238 | + */ |
|
239 | + function getProperties($properties) { |
|
240 | + $properties = array_keys($this->properties); |
|
241 | 241 | |
242 | - $result = []; |
|
243 | - foreach($properties as $property) { |
|
244 | - $getter = $this->properties[$property]; |
|
245 | - if(method_exists($this->comment, $getter)) { |
|
246 | - $result[$property] = $this->comment->$getter(); |
|
247 | - } |
|
248 | - } |
|
242 | + $result = []; |
|
243 | + foreach($properties as $property) { |
|
244 | + $getter = $this->properties[$property]; |
|
245 | + if(method_exists($this->comment, $getter)) { |
|
246 | + $result[$property] = $this->comment->$getter(); |
|
247 | + } |
|
248 | + } |
|
249 | 249 | |
250 | - if($this->comment->getActorType() === 'users') { |
|
251 | - $user = $this->userManager->get($this->comment->getActorId()); |
|
252 | - $displayName = is_null($user) ? null : $user->getDisplayName(); |
|
253 | - $result[self::PROPERTY_NAME_ACTOR_DISPLAYNAME] = $displayName; |
|
254 | - } |
|
250 | + if($this->comment->getActorType() === 'users') { |
|
251 | + $user = $this->userManager->get($this->comment->getActorId()); |
|
252 | + $displayName = is_null($user) ? null : $user->getDisplayName(); |
|
253 | + $result[self::PROPERTY_NAME_ACTOR_DISPLAYNAME] = $displayName; |
|
254 | + } |
|
255 | 255 | |
256 | - $result[self::PROPERTY_NAME_MENTIONS] = $this->composeMentionsPropertyValue(); |
|
256 | + $result[self::PROPERTY_NAME_MENTIONS] = $this->composeMentionsPropertyValue(); |
|
257 | 257 | |
258 | - $unread = null; |
|
259 | - $user = $this->userSession->getUser(); |
|
260 | - if(!is_null($user)) { |
|
261 | - $readUntil = $this->commentsManager->getReadMark( |
|
262 | - $this->comment->getObjectType(), |
|
263 | - $this->comment->getObjectId(), |
|
264 | - $user |
|
265 | - ); |
|
266 | - if(is_null($readUntil)) { |
|
267 | - $unread = 'true'; |
|
268 | - } else { |
|
269 | - $unread = $this->comment->getCreationDateTime() > $readUntil; |
|
270 | - // re-format for output |
|
271 | - $unread = $unread ? 'true' : 'false'; |
|
272 | - } |
|
273 | - } |
|
274 | - $result[self::PROPERTY_NAME_UNREAD] = $unread; |
|
258 | + $unread = null; |
|
259 | + $user = $this->userSession->getUser(); |
|
260 | + if(!is_null($user)) { |
|
261 | + $readUntil = $this->commentsManager->getReadMark( |
|
262 | + $this->comment->getObjectType(), |
|
263 | + $this->comment->getObjectId(), |
|
264 | + $user |
|
265 | + ); |
|
266 | + if(is_null($readUntil)) { |
|
267 | + $unread = 'true'; |
|
268 | + } else { |
|
269 | + $unread = $this->comment->getCreationDateTime() > $readUntil; |
|
270 | + // re-format for output |
|
271 | + $unread = $unread ? 'true' : 'false'; |
|
272 | + } |
|
273 | + } |
|
274 | + $result[self::PROPERTY_NAME_UNREAD] = $unread; |
|
275 | 275 | |
276 | - return $result; |
|
277 | - } |
|
276 | + return $result; |
|
277 | + } |
|
278 | 278 | |
279 | - /** |
|
280 | - * transforms a mentions array as returned from IComment->getMentions to an |
|
281 | - * array with DAV-compatible structure that can be assigned to the |
|
282 | - * PROPERTY_NAME_MENTION property. |
|
283 | - * |
|
284 | - * @return array |
|
285 | - */ |
|
286 | - protected function composeMentionsPropertyValue() { |
|
287 | - return array_map(function($mention) { |
|
288 | - try { |
|
289 | - $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']); |
|
290 | - } catch (\OutOfBoundsException $e) { |
|
291 | - $this->logger->logException($e); |
|
292 | - // No displayname, upon client's discretion what to display. |
|
293 | - $displayName = ''; |
|
294 | - } |
|
279 | + /** |
|
280 | + * transforms a mentions array as returned from IComment->getMentions to an |
|
281 | + * array with DAV-compatible structure that can be assigned to the |
|
282 | + * PROPERTY_NAME_MENTION property. |
|
283 | + * |
|
284 | + * @return array |
|
285 | + */ |
|
286 | + protected function composeMentionsPropertyValue() { |
|
287 | + return array_map(function($mention) { |
|
288 | + try { |
|
289 | + $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']); |
|
290 | + } catch (\OutOfBoundsException $e) { |
|
291 | + $this->logger->logException($e); |
|
292 | + // No displayname, upon client's discretion what to display. |
|
293 | + $displayName = ''; |
|
294 | + } |
|
295 | 295 | |
296 | - return [ |
|
297 | - self::PROPERTY_NAME_MENTION => [ |
|
298 | - self::PROPERTY_NAME_MENTION_TYPE => $mention['type'], |
|
299 | - self::PROPERTY_NAME_MENTION_ID => $mention['id'], |
|
300 | - self::PROPERTY_NAME_MENTION_DISPLAYNAME => $displayName, |
|
301 | - ] |
|
302 | - ]; |
|
303 | - }, $this->comment->getMentions()); |
|
304 | - } |
|
296 | + return [ |
|
297 | + self::PROPERTY_NAME_MENTION => [ |
|
298 | + self::PROPERTY_NAME_MENTION_TYPE => $mention['type'], |
|
299 | + self::PROPERTY_NAME_MENTION_ID => $mention['id'], |
|
300 | + self::PROPERTY_NAME_MENTION_DISPLAYNAME => $displayName, |
|
301 | + ] |
|
302 | + ]; |
|
303 | + }, $this->comment->getMentions()); |
|
304 | + } |
|
305 | 305 | } |