@@ -26,16 +26,16 @@ |
||
26 | 26 | |
27 | 27 | // Migration OC8.2 -> OC9 |
28 | 28 | if (version_compare($installedVersion, '0.9.1', '<')) { |
29 | - $m = new Migration(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()); |
|
30 | - $m->removeReShares(); |
|
31 | - $m->updateInitiatorInfo(); |
|
29 | + $m = new Migration(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()); |
|
30 | + $m->removeReShares(); |
|
31 | + $m->updateInitiatorInfo(); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | if (version_compare($installedVersion, '1.1.1', '<')) { |
35 | - $m = new Migration(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()); |
|
35 | + $m = new Migration(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | if (version_compare($installedVersion, '1.4.0', '<')) { |
39 | - $m = new Migration(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()); |
|
40 | - $m->addPasswordColumn(); |
|
39 | + $m = new Migration(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()); |
|
40 | + $m->addPasswordColumn(); |
|
41 | 41 | } |
@@ -6,5 +6,5 @@ |
||
6 | 6 | ?> |
7 | 7 | |
8 | 8 | -- |
9 | -<?php p($theme->getName() . ' - ' . $theme->getSlogan()); ?> |
|
9 | +<?php p($theme->getName().' - '.$theme->getSlogan()); ?> |
|
10 | 10 | <?php print_unescaped("\n".$theme->getBaseUrl()); |
@@ -36,10 +36,10 @@ |
||
36 | 36 | <td width="20px"> </td> |
37 | 37 | <td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;"> |
38 | 38 | <?php |
39 | - print_unescaped($l->t('Hey there,<br><br>%s shared <i>%s</i> with you.<br>You should have already received a separate mail with a link to access it.<br><br>It is protected with the following password: %s<br><br>', [$_['initiator'], $_['filename'], $_['password']])); |
|
40 | - // TRANSLATORS term at the end of a mail |
|
41 | - p($l->t('Cheers!')); |
|
42 | - ?> |
|
39 | + print_unescaped($l->t('Hey there,<br><br>%s shared <i>%s</i> with you.<br>You should have already received a separate mail with a link to access it.<br><br>It is protected with the following password: %s<br><br>', [$_['initiator'], $_['filename'], $_['password']])); |
|
40 | + // TRANSLATORS term at the end of a mail |
|
41 | + p($l->t('Cheers!')); |
|
42 | + ?> |
|
43 | 43 | </td> |
44 | 44 | </tr> |
45 | 45 | <tr><td colspan="2"> </td></tr> |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | <tr><td> |
28 | 28 | <table cellspacing="0" cellpadding="0" border="0" width="600px"> |
29 | 29 | <tr> |
30 | - <td colspan="2" bgcolor="<?php p($theme->getColorPrimary());?>"> |
|
30 | + <td colspan="2" bgcolor="<?php p($theme->getColorPrimary()); ?>"> |
|
31 | 31 | <img src="<?php p(\OC::$server->getURLGenerator()->getAbsoluteURL(image_path('', 'logo-mail.png'))); ?>" alt="<?php p($theme->getName()); ?>"/> |
32 | 32 | </td> |
33 | 33 | </tr> |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | <td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">--<br> |
53 | 53 | <?php p($theme->getName()); ?> - |
54 | 54 | <?php p($theme->getSlogan()); ?> |
55 | - <br><a href="<?php p($theme->getBaseUrl()); ?>"><?php p($theme->getBaseUrl());?></a> |
|
55 | + <br><a href="<?php p($theme->getBaseUrl()); ?>"><?php p($theme->getBaseUrl()); ?></a> |
|
56 | 56 | </td> |
57 | 57 | </tr> |
58 | 58 | <tr> |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered |
217 | 217 | $result = \OC::$server->getContactsManager()->search($query, [$property]); |
218 | 218 | foreach ($result as $r) { |
219 | - foreach($r[$property] as $value) { |
|
219 | + foreach ($r[$property] as $value) { |
|
220 | 220 | if ($value === $query) { |
221 | 221 | return $r['FN']; |
222 | 222 | } |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | |
495 | 495 | $shares = array_merge($userShares, $groupShares, $circleShares); |
496 | 496 | |
497 | - $shares = array_filter($shares, function (IShare $share) { |
|
497 | + $shares = array_filter($shares, function(IShare $share) { |
|
498 | 498 | return $share->getShareOwner() !== $this->currentUser; |
499 | 499 | }); |
500 | 500 | |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); |
530 | 530 | $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); |
531 | 531 | $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); |
532 | - if($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
532 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
533 | 533 | $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $node, false, -1, 0)); |
534 | 534 | } |
535 | 535 | if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | } |
686 | 686 | |
687 | 687 | if ($permissions !== null) { |
688 | - $newPermissions = (int)$permissions; |
|
688 | + $newPermissions = (int) $permissions; |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | if ($newPermissions !== null && |
@@ -742,7 +742,7 @@ discard block |
||
742 | 742 | |
743 | 743 | } else { |
744 | 744 | if ($permissions !== null) { |
745 | - $permissions = (int)$permissions; |
|
745 | + $permissions = (int) $permissions; |
|
746 | 746 | $share->setPermissions($permissions); |
747 | 747 | } |
748 | 748 | |
@@ -874,7 +874,7 @@ discard block |
||
874 | 874 | |
875 | 875 | // First check if it is an internal share. |
876 | 876 | try { |
877 | - $share = $this->shareManager->getShareById('ocinternal:' . $id); |
|
877 | + $share = $this->shareManager->getShareById('ocinternal:'.$id); |
|
878 | 878 | return $share; |
879 | 879 | } catch (ShareNotFound $e) { |
880 | 880 | // Do nothing, just try the other share type |
@@ -883,7 +883,7 @@ discard block |
||
883 | 883 | |
884 | 884 | try { |
885 | 885 | if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
886 | - $share = $this->shareManager->getShareById('ocCircleShare:' . $id); |
|
886 | + $share = $this->shareManager->getShareById('ocCircleShare:'.$id); |
|
887 | 887 | return $share; |
888 | 888 | } |
889 | 889 | } catch (ShareNotFound $e) { |
@@ -892,7 +892,7 @@ discard block |
||
892 | 892 | |
893 | 893 | try { |
894 | 894 | if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
895 | - $share = $this->shareManager->getShareById('ocMailShare:' . $id); |
|
895 | + $share = $this->shareManager->getShareById('ocMailShare:'.$id); |
|
896 | 896 | return $share; |
897 | 897 | } |
898 | 898 | } catch (ShareNotFound $e) { |
@@ -902,7 +902,7 @@ discard block |
||
902 | 902 | if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
903 | 903 | throw new ShareNotFound(); |
904 | 904 | } |
905 | - $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id); |
|
905 | + $share = $this->shareManager->getShareById('ocFederatedSharing:'.$id); |
|
906 | 906 | |
907 | 907 | return $share; |
908 | 908 | } |
@@ -51,879 +51,879 @@ |
||
51 | 51 | */ |
52 | 52 | class ShareAPIController extends OCSController { |
53 | 53 | |
54 | - /** @var IManager */ |
|
55 | - private $shareManager; |
|
56 | - /** @var IGroupManager */ |
|
57 | - private $groupManager; |
|
58 | - /** @var IUserManager */ |
|
59 | - private $userManager; |
|
60 | - /** @var IRequest */ |
|
61 | - protected $request; |
|
62 | - /** @var IRootFolder */ |
|
63 | - private $rootFolder; |
|
64 | - /** @var IURLGenerator */ |
|
65 | - private $urlGenerator; |
|
66 | - /** @var string */ |
|
67 | - private $currentUser; |
|
68 | - /** @var IL10N */ |
|
69 | - private $l; |
|
70 | - /** @var \OCP\Files\Node */ |
|
71 | - private $lockedNode; |
|
72 | - |
|
73 | - /** |
|
74 | - * Share20OCS constructor. |
|
75 | - * |
|
76 | - * @param string $appName |
|
77 | - * @param IRequest $request |
|
78 | - * @param IManager $shareManager |
|
79 | - * @param IGroupManager $groupManager |
|
80 | - * @param IUserManager $userManager |
|
81 | - * @param IRootFolder $rootFolder |
|
82 | - * @param IURLGenerator $urlGenerator |
|
83 | - * @param string $userId |
|
84 | - * @param IL10N $l10n |
|
85 | - */ |
|
86 | - public function __construct( |
|
87 | - $appName, |
|
88 | - IRequest $request, |
|
89 | - IManager $shareManager, |
|
90 | - IGroupManager $groupManager, |
|
91 | - IUserManager $userManager, |
|
92 | - IRootFolder $rootFolder, |
|
93 | - IURLGenerator $urlGenerator, |
|
94 | - $userId, |
|
95 | - IL10N $l10n |
|
96 | - ) { |
|
97 | - parent::__construct($appName, $request); |
|
98 | - |
|
99 | - $this->shareManager = $shareManager; |
|
100 | - $this->userManager = $userManager; |
|
101 | - $this->groupManager = $groupManager; |
|
102 | - $this->request = $request; |
|
103 | - $this->rootFolder = $rootFolder; |
|
104 | - $this->urlGenerator = $urlGenerator; |
|
105 | - $this->currentUser = $userId; |
|
106 | - $this->l = $l10n; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Convert an IShare to an array for OCS output |
|
111 | - * |
|
112 | - * @param \OCP\Share\IShare $share |
|
113 | - * @param Node|null $recipientNode |
|
114 | - * @return array |
|
115 | - * @throws NotFoundException In case the node can't be resolved. |
|
116 | - */ |
|
117 | - protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null) { |
|
118 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
119 | - $shareOwner = $this->userManager->get($share->getShareOwner()); |
|
120 | - |
|
121 | - $result = [ |
|
122 | - 'id' => $share->getId(), |
|
123 | - 'share_type' => $share->getShareType(), |
|
124 | - 'uid_owner' => $share->getSharedBy(), |
|
125 | - 'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(), |
|
126 | - 'permissions' => $share->getPermissions(), |
|
127 | - 'stime' => $share->getShareTime()->getTimestamp(), |
|
128 | - 'parent' => null, |
|
129 | - 'expiration' => null, |
|
130 | - 'token' => null, |
|
131 | - 'uid_file_owner' => $share->getShareOwner(), |
|
132 | - 'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(), |
|
133 | - ]; |
|
134 | - |
|
135 | - $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
136 | - if ($recipientNode) { |
|
137 | - $node = $recipientNode; |
|
138 | - } else { |
|
139 | - $nodes = $userFolder->getById($share->getNodeId()); |
|
140 | - |
|
141 | - if (empty($nodes)) { |
|
142 | - // fallback to guessing the path |
|
143 | - $node = $userFolder->get($share->getTarget()); |
|
144 | - if ($node === null) { |
|
145 | - throw new NotFoundException(); |
|
146 | - } |
|
147 | - } else { |
|
148 | - $node = $nodes[0]; |
|
149 | - } |
|
150 | - } |
|
151 | - |
|
152 | - $result['path'] = $userFolder->getRelativePath($node->getPath()); |
|
153 | - if ($node instanceOf \OCP\Files\Folder) { |
|
154 | - $result['item_type'] = 'folder'; |
|
155 | - } else { |
|
156 | - $result['item_type'] = 'file'; |
|
157 | - } |
|
158 | - $result['mimetype'] = $node->getMimetype(); |
|
159 | - $result['storage_id'] = $node->getStorage()->getId(); |
|
160 | - $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId(); |
|
161 | - $result['item_source'] = $node->getId(); |
|
162 | - $result['file_source'] = $node->getId(); |
|
163 | - $result['file_parent'] = $node->getParent()->getId(); |
|
164 | - $result['file_target'] = $share->getTarget(); |
|
165 | - |
|
166 | - $expiration = $share->getExpirationDate(); |
|
167 | - if ($expiration !== null) { |
|
168 | - $result['expiration'] = $expiration->format('Y-m-d 00:00:00'); |
|
169 | - } |
|
170 | - |
|
171 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
172 | - $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
173 | - $result['share_with'] = $share->getSharedWith(); |
|
174 | - $result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith(); |
|
175 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
176 | - $group = $this->groupManager->get($share->getSharedWith()); |
|
177 | - $result['share_with'] = $share->getSharedWith(); |
|
178 | - $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith(); |
|
179 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
180 | - |
|
181 | - $result['share_with'] = $share->getPassword(); |
|
182 | - $result['share_with_displayname'] = $share->getPassword(); |
|
183 | - |
|
184 | - $result['token'] = $share->getToken(); |
|
185 | - $result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]); |
|
186 | - |
|
187 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
188 | - $result['share_with'] = $share->getSharedWith(); |
|
189 | - $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD'); |
|
190 | - $result['token'] = $share->getToken(); |
|
191 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
192 | - $result['share_with'] = $share->getSharedWith(); |
|
193 | - $result['password'] = $share->getPassword(); |
|
194 | - $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL'); |
|
195 | - $result['token'] = $share->getToken(); |
|
196 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
197 | - $result['share_with_displayname'] = $share->getSharedWith(); |
|
198 | - $result['share_with'] = explode(' ', $share->getSharedWith(), 2)[0]; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - $result['mail_send'] = $share->getMailSend() ? 1 : 0; |
|
203 | - |
|
204 | - return $result; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Check if one of the users address books knows the exact property, if |
|
209 | - * yes we return the full name. |
|
210 | - * |
|
211 | - * @param string $query |
|
212 | - * @param string $property |
|
213 | - * @return string |
|
214 | - */ |
|
215 | - private function getDisplayNameFromAddressBook($query, $property) { |
|
216 | - // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered |
|
217 | - $result = \OC::$server->getContactsManager()->search($query, [$property]); |
|
218 | - foreach ($result as $r) { |
|
219 | - foreach($r[$property] as $value) { |
|
220 | - if ($value === $query) { |
|
221 | - return $r['FN']; |
|
222 | - } |
|
223 | - } |
|
224 | - } |
|
225 | - |
|
226 | - return $query; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Get a specific share by id |
|
231 | - * |
|
232 | - * @NoAdminRequired |
|
233 | - * |
|
234 | - * @param string $id |
|
235 | - * @return DataResponse |
|
236 | - * @throws OCSNotFoundException |
|
237 | - */ |
|
238 | - public function getShare($id) { |
|
239 | - try { |
|
240 | - $share = $this->getShareById($id); |
|
241 | - } catch (ShareNotFound $e) { |
|
242 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
243 | - } |
|
244 | - |
|
245 | - if ($this->canAccessShare($share)) { |
|
246 | - try { |
|
247 | - $share = $this->formatShare($share); |
|
248 | - return new DataResponse([$share]); |
|
249 | - } catch (NotFoundException $e) { |
|
250 | - //Fall trough |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Delete a share |
|
259 | - * |
|
260 | - * @NoAdminRequired |
|
261 | - * |
|
262 | - * @param string $id |
|
263 | - * @return DataResponse |
|
264 | - * @throws OCSNotFoundException |
|
265 | - */ |
|
266 | - public function deleteShare($id) { |
|
267 | - try { |
|
268 | - $share = $this->getShareById($id); |
|
269 | - } catch (ShareNotFound $e) { |
|
270 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
271 | - } |
|
272 | - |
|
273 | - try { |
|
274 | - $this->lock($share->getNode()); |
|
275 | - } catch (LockedException $e) { |
|
276 | - throw new OCSNotFoundException($this->l->t('could not delete share')); |
|
277 | - } |
|
278 | - |
|
279 | - if (!$this->canAccessShare($share)) { |
|
280 | - throw new OCSNotFoundException($this->l->t('Could not delete share')); |
|
281 | - } |
|
282 | - |
|
283 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && |
|
284 | - $share->getShareOwner() !== $this->currentUser && |
|
285 | - $share->getSharedBy() !== $this->currentUser) { |
|
286 | - $this->shareManager->deleteFromSelf($share, $this->currentUser); |
|
287 | - } else { |
|
288 | - $this->shareManager->deleteShare($share); |
|
289 | - } |
|
290 | - |
|
291 | - return new DataResponse(); |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * @NoAdminRequired |
|
296 | - * |
|
297 | - * @param string $path |
|
298 | - * @param int $permissions |
|
299 | - * @param int $shareType |
|
300 | - * @param string $shareWith |
|
301 | - * @param string $publicUpload |
|
302 | - * @param string $password |
|
303 | - * @param string $expireDate |
|
304 | - * |
|
305 | - * @return DataResponse |
|
306 | - * @throws OCSNotFoundException |
|
307 | - * @throws OCSForbiddenException |
|
308 | - * @throws OCSBadRequestException |
|
309 | - * @throws OCSException |
|
310 | - */ |
|
311 | - public function createShare( |
|
312 | - $path = null, |
|
313 | - $permissions = \OCP\Constants::PERMISSION_ALL, |
|
314 | - $shareType = -1, |
|
315 | - $shareWith = null, |
|
316 | - $publicUpload = 'false', |
|
317 | - $password = '', |
|
318 | - $expireDate = '' |
|
319 | - ) { |
|
320 | - $share = $this->shareManager->newShare(); |
|
321 | - |
|
322 | - // Verify path |
|
323 | - if ($path === null) { |
|
324 | - throw new OCSNotFoundException($this->l->t('Please specify a file or folder path')); |
|
325 | - } |
|
326 | - |
|
327 | - $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
328 | - try { |
|
329 | - $path = $userFolder->get($path); |
|
330 | - } catch (NotFoundException $e) { |
|
331 | - throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
332 | - } |
|
333 | - |
|
334 | - $share->setNode($path); |
|
335 | - |
|
336 | - try { |
|
337 | - $this->lock($share->getNode()); |
|
338 | - } catch (LockedException $e) { |
|
339 | - throw new OCSNotFoundException($this->l->t('Could not create share')); |
|
340 | - } |
|
341 | - |
|
342 | - if ($permissions < 0 || $permissions > \OCP\Constants::PERMISSION_ALL) { |
|
343 | - throw new OCSNotFoundException($this->l->t('invalid permissions')); |
|
344 | - } |
|
345 | - |
|
346 | - // Shares always require read permissions |
|
347 | - $permissions |= \OCP\Constants::PERMISSION_READ; |
|
348 | - |
|
349 | - if ($path instanceof \OCP\Files\File) { |
|
350 | - // Single file shares should never have delete or create permissions |
|
351 | - $permissions &= ~\OCP\Constants::PERMISSION_DELETE; |
|
352 | - $permissions &= ~\OCP\Constants::PERMISSION_CREATE; |
|
353 | - } |
|
354 | - |
|
355 | - /* |
|
54 | + /** @var IManager */ |
|
55 | + private $shareManager; |
|
56 | + /** @var IGroupManager */ |
|
57 | + private $groupManager; |
|
58 | + /** @var IUserManager */ |
|
59 | + private $userManager; |
|
60 | + /** @var IRequest */ |
|
61 | + protected $request; |
|
62 | + /** @var IRootFolder */ |
|
63 | + private $rootFolder; |
|
64 | + /** @var IURLGenerator */ |
|
65 | + private $urlGenerator; |
|
66 | + /** @var string */ |
|
67 | + private $currentUser; |
|
68 | + /** @var IL10N */ |
|
69 | + private $l; |
|
70 | + /** @var \OCP\Files\Node */ |
|
71 | + private $lockedNode; |
|
72 | + |
|
73 | + /** |
|
74 | + * Share20OCS constructor. |
|
75 | + * |
|
76 | + * @param string $appName |
|
77 | + * @param IRequest $request |
|
78 | + * @param IManager $shareManager |
|
79 | + * @param IGroupManager $groupManager |
|
80 | + * @param IUserManager $userManager |
|
81 | + * @param IRootFolder $rootFolder |
|
82 | + * @param IURLGenerator $urlGenerator |
|
83 | + * @param string $userId |
|
84 | + * @param IL10N $l10n |
|
85 | + */ |
|
86 | + public function __construct( |
|
87 | + $appName, |
|
88 | + IRequest $request, |
|
89 | + IManager $shareManager, |
|
90 | + IGroupManager $groupManager, |
|
91 | + IUserManager $userManager, |
|
92 | + IRootFolder $rootFolder, |
|
93 | + IURLGenerator $urlGenerator, |
|
94 | + $userId, |
|
95 | + IL10N $l10n |
|
96 | + ) { |
|
97 | + parent::__construct($appName, $request); |
|
98 | + |
|
99 | + $this->shareManager = $shareManager; |
|
100 | + $this->userManager = $userManager; |
|
101 | + $this->groupManager = $groupManager; |
|
102 | + $this->request = $request; |
|
103 | + $this->rootFolder = $rootFolder; |
|
104 | + $this->urlGenerator = $urlGenerator; |
|
105 | + $this->currentUser = $userId; |
|
106 | + $this->l = $l10n; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Convert an IShare to an array for OCS output |
|
111 | + * |
|
112 | + * @param \OCP\Share\IShare $share |
|
113 | + * @param Node|null $recipientNode |
|
114 | + * @return array |
|
115 | + * @throws NotFoundException In case the node can't be resolved. |
|
116 | + */ |
|
117 | + protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null) { |
|
118 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
119 | + $shareOwner = $this->userManager->get($share->getShareOwner()); |
|
120 | + |
|
121 | + $result = [ |
|
122 | + 'id' => $share->getId(), |
|
123 | + 'share_type' => $share->getShareType(), |
|
124 | + 'uid_owner' => $share->getSharedBy(), |
|
125 | + 'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(), |
|
126 | + 'permissions' => $share->getPermissions(), |
|
127 | + 'stime' => $share->getShareTime()->getTimestamp(), |
|
128 | + 'parent' => null, |
|
129 | + 'expiration' => null, |
|
130 | + 'token' => null, |
|
131 | + 'uid_file_owner' => $share->getShareOwner(), |
|
132 | + 'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(), |
|
133 | + ]; |
|
134 | + |
|
135 | + $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
136 | + if ($recipientNode) { |
|
137 | + $node = $recipientNode; |
|
138 | + } else { |
|
139 | + $nodes = $userFolder->getById($share->getNodeId()); |
|
140 | + |
|
141 | + if (empty($nodes)) { |
|
142 | + // fallback to guessing the path |
|
143 | + $node = $userFolder->get($share->getTarget()); |
|
144 | + if ($node === null) { |
|
145 | + throw new NotFoundException(); |
|
146 | + } |
|
147 | + } else { |
|
148 | + $node = $nodes[0]; |
|
149 | + } |
|
150 | + } |
|
151 | + |
|
152 | + $result['path'] = $userFolder->getRelativePath($node->getPath()); |
|
153 | + if ($node instanceOf \OCP\Files\Folder) { |
|
154 | + $result['item_type'] = 'folder'; |
|
155 | + } else { |
|
156 | + $result['item_type'] = 'file'; |
|
157 | + } |
|
158 | + $result['mimetype'] = $node->getMimetype(); |
|
159 | + $result['storage_id'] = $node->getStorage()->getId(); |
|
160 | + $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId(); |
|
161 | + $result['item_source'] = $node->getId(); |
|
162 | + $result['file_source'] = $node->getId(); |
|
163 | + $result['file_parent'] = $node->getParent()->getId(); |
|
164 | + $result['file_target'] = $share->getTarget(); |
|
165 | + |
|
166 | + $expiration = $share->getExpirationDate(); |
|
167 | + if ($expiration !== null) { |
|
168 | + $result['expiration'] = $expiration->format('Y-m-d 00:00:00'); |
|
169 | + } |
|
170 | + |
|
171 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
172 | + $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
173 | + $result['share_with'] = $share->getSharedWith(); |
|
174 | + $result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith(); |
|
175 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
176 | + $group = $this->groupManager->get($share->getSharedWith()); |
|
177 | + $result['share_with'] = $share->getSharedWith(); |
|
178 | + $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith(); |
|
179 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
180 | + |
|
181 | + $result['share_with'] = $share->getPassword(); |
|
182 | + $result['share_with_displayname'] = $share->getPassword(); |
|
183 | + |
|
184 | + $result['token'] = $share->getToken(); |
|
185 | + $result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]); |
|
186 | + |
|
187 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
188 | + $result['share_with'] = $share->getSharedWith(); |
|
189 | + $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD'); |
|
190 | + $result['token'] = $share->getToken(); |
|
191 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
192 | + $result['share_with'] = $share->getSharedWith(); |
|
193 | + $result['password'] = $share->getPassword(); |
|
194 | + $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL'); |
|
195 | + $result['token'] = $share->getToken(); |
|
196 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
197 | + $result['share_with_displayname'] = $share->getSharedWith(); |
|
198 | + $result['share_with'] = explode(' ', $share->getSharedWith(), 2)[0]; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + $result['mail_send'] = $share->getMailSend() ? 1 : 0; |
|
203 | + |
|
204 | + return $result; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Check if one of the users address books knows the exact property, if |
|
209 | + * yes we return the full name. |
|
210 | + * |
|
211 | + * @param string $query |
|
212 | + * @param string $property |
|
213 | + * @return string |
|
214 | + */ |
|
215 | + private function getDisplayNameFromAddressBook($query, $property) { |
|
216 | + // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered |
|
217 | + $result = \OC::$server->getContactsManager()->search($query, [$property]); |
|
218 | + foreach ($result as $r) { |
|
219 | + foreach($r[$property] as $value) { |
|
220 | + if ($value === $query) { |
|
221 | + return $r['FN']; |
|
222 | + } |
|
223 | + } |
|
224 | + } |
|
225 | + |
|
226 | + return $query; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Get a specific share by id |
|
231 | + * |
|
232 | + * @NoAdminRequired |
|
233 | + * |
|
234 | + * @param string $id |
|
235 | + * @return DataResponse |
|
236 | + * @throws OCSNotFoundException |
|
237 | + */ |
|
238 | + public function getShare($id) { |
|
239 | + try { |
|
240 | + $share = $this->getShareById($id); |
|
241 | + } catch (ShareNotFound $e) { |
|
242 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
243 | + } |
|
244 | + |
|
245 | + if ($this->canAccessShare($share)) { |
|
246 | + try { |
|
247 | + $share = $this->formatShare($share); |
|
248 | + return new DataResponse([$share]); |
|
249 | + } catch (NotFoundException $e) { |
|
250 | + //Fall trough |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Delete a share |
|
259 | + * |
|
260 | + * @NoAdminRequired |
|
261 | + * |
|
262 | + * @param string $id |
|
263 | + * @return DataResponse |
|
264 | + * @throws OCSNotFoundException |
|
265 | + */ |
|
266 | + public function deleteShare($id) { |
|
267 | + try { |
|
268 | + $share = $this->getShareById($id); |
|
269 | + } catch (ShareNotFound $e) { |
|
270 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
271 | + } |
|
272 | + |
|
273 | + try { |
|
274 | + $this->lock($share->getNode()); |
|
275 | + } catch (LockedException $e) { |
|
276 | + throw new OCSNotFoundException($this->l->t('could not delete share')); |
|
277 | + } |
|
278 | + |
|
279 | + if (!$this->canAccessShare($share)) { |
|
280 | + throw new OCSNotFoundException($this->l->t('Could not delete share')); |
|
281 | + } |
|
282 | + |
|
283 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && |
|
284 | + $share->getShareOwner() !== $this->currentUser && |
|
285 | + $share->getSharedBy() !== $this->currentUser) { |
|
286 | + $this->shareManager->deleteFromSelf($share, $this->currentUser); |
|
287 | + } else { |
|
288 | + $this->shareManager->deleteShare($share); |
|
289 | + } |
|
290 | + |
|
291 | + return new DataResponse(); |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * @NoAdminRequired |
|
296 | + * |
|
297 | + * @param string $path |
|
298 | + * @param int $permissions |
|
299 | + * @param int $shareType |
|
300 | + * @param string $shareWith |
|
301 | + * @param string $publicUpload |
|
302 | + * @param string $password |
|
303 | + * @param string $expireDate |
|
304 | + * |
|
305 | + * @return DataResponse |
|
306 | + * @throws OCSNotFoundException |
|
307 | + * @throws OCSForbiddenException |
|
308 | + * @throws OCSBadRequestException |
|
309 | + * @throws OCSException |
|
310 | + */ |
|
311 | + public function createShare( |
|
312 | + $path = null, |
|
313 | + $permissions = \OCP\Constants::PERMISSION_ALL, |
|
314 | + $shareType = -1, |
|
315 | + $shareWith = null, |
|
316 | + $publicUpload = 'false', |
|
317 | + $password = '', |
|
318 | + $expireDate = '' |
|
319 | + ) { |
|
320 | + $share = $this->shareManager->newShare(); |
|
321 | + |
|
322 | + // Verify path |
|
323 | + if ($path === null) { |
|
324 | + throw new OCSNotFoundException($this->l->t('Please specify a file or folder path')); |
|
325 | + } |
|
326 | + |
|
327 | + $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
328 | + try { |
|
329 | + $path = $userFolder->get($path); |
|
330 | + } catch (NotFoundException $e) { |
|
331 | + throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
332 | + } |
|
333 | + |
|
334 | + $share->setNode($path); |
|
335 | + |
|
336 | + try { |
|
337 | + $this->lock($share->getNode()); |
|
338 | + } catch (LockedException $e) { |
|
339 | + throw new OCSNotFoundException($this->l->t('Could not create share')); |
|
340 | + } |
|
341 | + |
|
342 | + if ($permissions < 0 || $permissions > \OCP\Constants::PERMISSION_ALL) { |
|
343 | + throw new OCSNotFoundException($this->l->t('invalid permissions')); |
|
344 | + } |
|
345 | + |
|
346 | + // Shares always require read permissions |
|
347 | + $permissions |= \OCP\Constants::PERMISSION_READ; |
|
348 | + |
|
349 | + if ($path instanceof \OCP\Files\File) { |
|
350 | + // Single file shares should never have delete or create permissions |
|
351 | + $permissions &= ~\OCP\Constants::PERMISSION_DELETE; |
|
352 | + $permissions &= ~\OCP\Constants::PERMISSION_CREATE; |
|
353 | + } |
|
354 | + |
|
355 | + /* |
|
356 | 356 | * Hack for https://github.com/owncloud/core/issues/22587 |
357 | 357 | * We check the permissions via webdav. But the permissions of the mount point |
358 | 358 | * do not equal the share permissions. Here we fix that for federated mounts. |
359 | 359 | */ |
360 | - if ($path->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
361 | - $permissions &= ~($permissions & ~$path->getPermissions()); |
|
362 | - } |
|
363 | - |
|
364 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
365 | - // Valid user is required to share |
|
366 | - if ($shareWith === null || !$this->userManager->userExists($shareWith)) { |
|
367 | - throw new OCSNotFoundException($this->l->t('Please specify a valid user')); |
|
368 | - } |
|
369 | - $share->setSharedWith($shareWith); |
|
370 | - $share->setPermissions($permissions); |
|
371 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
372 | - if (!$this->shareManager->allowGroupSharing()) { |
|
373 | - throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator')); |
|
374 | - } |
|
375 | - |
|
376 | - // Valid group is required to share |
|
377 | - if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) { |
|
378 | - throw new OCSNotFoundException($this->l->t('Please specify a valid group')); |
|
379 | - } |
|
380 | - $share->setSharedWith($shareWith); |
|
381 | - $share->setPermissions($permissions); |
|
382 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
383 | - //Can we even share links? |
|
384 | - if (!$this->shareManager->shareApiAllowLinks()) { |
|
385 | - throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator')); |
|
386 | - } |
|
387 | - |
|
388 | - /* |
|
360 | + if ($path->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
361 | + $permissions &= ~($permissions & ~$path->getPermissions()); |
|
362 | + } |
|
363 | + |
|
364 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
365 | + // Valid user is required to share |
|
366 | + if ($shareWith === null || !$this->userManager->userExists($shareWith)) { |
|
367 | + throw new OCSNotFoundException($this->l->t('Please specify a valid user')); |
|
368 | + } |
|
369 | + $share->setSharedWith($shareWith); |
|
370 | + $share->setPermissions($permissions); |
|
371 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
372 | + if (!$this->shareManager->allowGroupSharing()) { |
|
373 | + throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator')); |
|
374 | + } |
|
375 | + |
|
376 | + // Valid group is required to share |
|
377 | + if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) { |
|
378 | + throw new OCSNotFoundException($this->l->t('Please specify a valid group')); |
|
379 | + } |
|
380 | + $share->setSharedWith($shareWith); |
|
381 | + $share->setPermissions($permissions); |
|
382 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
383 | + //Can we even share links? |
|
384 | + if (!$this->shareManager->shareApiAllowLinks()) { |
|
385 | + throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator')); |
|
386 | + } |
|
387 | + |
|
388 | + /* |
|
389 | 389 | * For now we only allow 1 link share. |
390 | 390 | * Return the existing link share if this is a duplicate |
391 | 391 | */ |
392 | - $existingShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0); |
|
393 | - if (!empty($existingShares)) { |
|
394 | - return new DataResponse($this->formatShare($existingShares[0])); |
|
395 | - } |
|
396 | - |
|
397 | - if ($publicUpload === 'true') { |
|
398 | - // Check if public upload is allowed |
|
399 | - if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
400 | - throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
401 | - } |
|
402 | - |
|
403 | - // Public upload can only be set for folders |
|
404 | - if ($path instanceof \OCP\Files\File) { |
|
405 | - throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
406 | - } |
|
407 | - |
|
408 | - $share->setPermissions( |
|
409 | - \OCP\Constants::PERMISSION_READ | |
|
410 | - \OCP\Constants::PERMISSION_CREATE | |
|
411 | - \OCP\Constants::PERMISSION_UPDATE | |
|
412 | - \OCP\Constants::PERMISSION_DELETE |
|
413 | - ); |
|
414 | - } else { |
|
415 | - $share->setPermissions(\OCP\Constants::PERMISSION_READ); |
|
416 | - } |
|
417 | - |
|
418 | - // Set password |
|
419 | - if ($password !== '') { |
|
420 | - $share->setPassword($password); |
|
421 | - } |
|
422 | - |
|
423 | - //Expire date |
|
424 | - if ($expireDate !== '') { |
|
425 | - try { |
|
426 | - $expireDate = $this->parseDate($expireDate); |
|
427 | - $share->setExpirationDate($expireDate); |
|
428 | - } catch (\Exception $e) { |
|
429 | - throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); |
|
430 | - } |
|
431 | - } |
|
432 | - |
|
433 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
434 | - if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
435 | - throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType])); |
|
436 | - } |
|
437 | - |
|
438 | - $share->setSharedWith($shareWith); |
|
439 | - $share->setPermissions($permissions); |
|
440 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
441 | - if ($share->getNodeType() === 'file') { |
|
442 | - $share->setPermissions(\OCP\Constants::PERMISSION_READ); |
|
443 | - } else { |
|
444 | - $share->setPermissions( |
|
445 | - \OCP\Constants::PERMISSION_READ | |
|
446 | - \OCP\Constants::PERMISSION_CREATE | |
|
447 | - \OCP\Constants::PERMISSION_UPDATE | |
|
448 | - \OCP\Constants::PERMISSION_DELETE); |
|
449 | - } |
|
450 | - $share->setSharedWith($shareWith); |
|
451 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
452 | - if (!\OCP\App::isEnabled('circles')) { |
|
453 | - throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled')); |
|
454 | - } |
|
455 | - |
|
456 | - $circle = \OCA\Circles\Api\Circles::detailsCircle($shareWith); |
|
457 | - |
|
458 | - // Valid circle is required to share |
|
459 | - if ($circle === null) { |
|
460 | - throw new OCSNotFoundException($this->l->t('Please specify a valid circle')); |
|
461 | - } |
|
462 | - $share->setSharedWith($shareWith); |
|
463 | - $share->setPermissions($permissions); |
|
464 | - } else { |
|
465 | - throw new OCSBadRequestException($this->l->t('Unknown share type')); |
|
466 | - } |
|
467 | - |
|
468 | - $share->setShareType($shareType); |
|
469 | - $share->setSharedBy($this->currentUser); |
|
470 | - |
|
471 | - try { |
|
472 | - $share = $this->shareManager->createShare($share); |
|
473 | - } catch (GenericShareException $e) { |
|
474 | - $code = $e->getCode() === 0 ? 403 : $e->getCode(); |
|
475 | - throw new OCSException($e->getHint(), $code); |
|
476 | - } catch (\Exception $e) { |
|
477 | - throw new OCSForbiddenException($e->getMessage()); |
|
478 | - } |
|
479 | - |
|
480 | - $output = $this->formatShare($share); |
|
481 | - |
|
482 | - return new DataResponse($output); |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * @param \OCP\Files\File|\OCP\Files\Folder $node |
|
487 | - * @return DataResponse |
|
488 | - */ |
|
489 | - private function getSharedWithMe($node = null) { |
|
490 | - |
|
491 | - $userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0); |
|
492 | - $groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0); |
|
493 | - $circleShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $node, -1, 0); |
|
494 | - |
|
495 | - $shares = array_merge($userShares, $groupShares, $circleShares); |
|
496 | - |
|
497 | - $shares = array_filter($shares, function (IShare $share) { |
|
498 | - return $share->getShareOwner() !== $this->currentUser; |
|
499 | - }); |
|
500 | - |
|
501 | - $formatted = []; |
|
502 | - foreach ($shares as $share) { |
|
503 | - if ($this->canAccessShare($share)) { |
|
504 | - try { |
|
505 | - $formatted[] = $this->formatShare($share); |
|
506 | - } catch (NotFoundException $e) { |
|
507 | - // Ignore this share |
|
508 | - } |
|
509 | - } |
|
510 | - } |
|
511 | - |
|
512 | - return new DataResponse($formatted); |
|
513 | - } |
|
514 | - |
|
515 | - /** |
|
516 | - * @param \OCP\Files\Folder $folder |
|
517 | - * @return DataResponse |
|
518 | - * @throws OCSBadRequestException |
|
519 | - */ |
|
520 | - private function getSharesInDir($folder) { |
|
521 | - if (!($folder instanceof \OCP\Files\Folder)) { |
|
522 | - throw new OCSBadRequestException($this->l->t('Not a directory')); |
|
523 | - } |
|
524 | - |
|
525 | - $nodes = $folder->getDirectoryListing(); |
|
526 | - /** @var \OCP\Share\IShare[] $shares */ |
|
527 | - $shares = []; |
|
528 | - foreach ($nodes as $node) { |
|
529 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); |
|
530 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); |
|
531 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); |
|
532 | - if($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
533 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $node, false, -1, 0)); |
|
534 | - } |
|
535 | - if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
536 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $node, false, -1, 0)); |
|
537 | - } |
|
538 | - } |
|
539 | - |
|
540 | - $formatted = []; |
|
541 | - foreach ($shares as $share) { |
|
542 | - try { |
|
543 | - $formatted[] = $this->formatShare($share); |
|
544 | - } catch (NotFoundException $e) { |
|
545 | - //Ignore this share |
|
546 | - } |
|
547 | - } |
|
548 | - |
|
549 | - return new DataResponse($formatted); |
|
550 | - } |
|
551 | - |
|
552 | - /** |
|
553 | - * The getShares function. |
|
554 | - * |
|
555 | - * @NoAdminRequired |
|
556 | - * |
|
557 | - * @param string $shared_with_me |
|
558 | - * @param string $reshares |
|
559 | - * @param string $subfiles |
|
560 | - * @param string $path |
|
561 | - * |
|
562 | - * - Get shares by the current user |
|
563 | - * - Get shares by the current user and reshares (?reshares=true) |
|
564 | - * - Get shares with the current user (?shared_with_me=true) |
|
565 | - * - Get shares for a specific path (?path=...) |
|
566 | - * - Get all shares in a folder (?subfiles=true&path=..) |
|
567 | - * |
|
568 | - * @return DataResponse |
|
569 | - * @throws OCSNotFoundException |
|
570 | - */ |
|
571 | - public function getShares( |
|
572 | - $shared_with_me = 'false', |
|
573 | - $reshares = 'false', |
|
574 | - $subfiles = 'false', |
|
575 | - $path = null |
|
576 | - ) { |
|
577 | - |
|
578 | - if ($path !== null) { |
|
579 | - $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
580 | - try { |
|
581 | - $path = $userFolder->get($path); |
|
582 | - $this->lock($path); |
|
583 | - } catch (\OCP\Files\NotFoundException $e) { |
|
584 | - throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
585 | - } catch (LockedException $e) { |
|
586 | - throw new OCSNotFoundException($this->l->t('Could not lock path')); |
|
587 | - } |
|
588 | - } |
|
589 | - |
|
590 | - if ($shared_with_me === 'true') { |
|
591 | - $result = $this->getSharedWithMe($path); |
|
592 | - return $result; |
|
593 | - } |
|
594 | - |
|
595 | - if ($subfiles === 'true') { |
|
596 | - $result = $this->getSharesInDir($path); |
|
597 | - return $result; |
|
598 | - } |
|
599 | - |
|
600 | - if ($reshares === 'true') { |
|
601 | - $reshares = true; |
|
602 | - } else { |
|
603 | - $reshares = false; |
|
604 | - } |
|
605 | - |
|
606 | - // Get all shares |
|
607 | - $userShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0); |
|
608 | - $groupShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0); |
|
609 | - $linkShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0); |
|
610 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
611 | - $mailShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0); |
|
612 | - } else { |
|
613 | - $mailShares = []; |
|
614 | - } |
|
615 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
616 | - $circleShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0); |
|
617 | - } else { |
|
618 | - $circleShares = []; |
|
619 | - } |
|
620 | - |
|
621 | - $shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares); |
|
622 | - |
|
623 | - if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
624 | - $federatedShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0); |
|
625 | - $shares = array_merge($shares, $federatedShares); |
|
626 | - } |
|
627 | - |
|
628 | - $formatted = []; |
|
629 | - foreach ($shares as $share) { |
|
630 | - try { |
|
631 | - $formatted[] = $this->formatShare($share, $path); |
|
632 | - } catch (NotFoundException $e) { |
|
633 | - //Ignore share |
|
634 | - } |
|
635 | - } |
|
636 | - |
|
637 | - return new DataResponse($formatted); |
|
638 | - } |
|
639 | - |
|
640 | - /** |
|
641 | - * @NoAdminRequired |
|
642 | - * |
|
643 | - * @param int $id |
|
644 | - * @param int $permissions |
|
645 | - * @param string $password |
|
646 | - * @param string $publicUpload |
|
647 | - * @param string $expireDate |
|
648 | - * @return DataResponse |
|
649 | - * @throws OCSNotFoundException |
|
650 | - * @throws OCSBadRequestException |
|
651 | - * @throws OCSForbiddenException |
|
652 | - */ |
|
653 | - public function updateShare( |
|
654 | - $id, |
|
655 | - $permissions = null, |
|
656 | - $password = null, |
|
657 | - $publicUpload = null, |
|
658 | - $expireDate = null |
|
659 | - ) { |
|
660 | - try { |
|
661 | - $share = $this->getShareById($id); |
|
662 | - } catch (ShareNotFound $e) { |
|
663 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
664 | - } |
|
665 | - |
|
666 | - $this->lock($share->getNode()); |
|
667 | - |
|
668 | - if (!$this->canAccessShare($share, false)) { |
|
669 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
670 | - } |
|
671 | - |
|
672 | - if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) { |
|
673 | - throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given')); |
|
674 | - } |
|
675 | - |
|
676 | - /* |
|
392 | + $existingShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0); |
|
393 | + if (!empty($existingShares)) { |
|
394 | + return new DataResponse($this->formatShare($existingShares[0])); |
|
395 | + } |
|
396 | + |
|
397 | + if ($publicUpload === 'true') { |
|
398 | + // Check if public upload is allowed |
|
399 | + if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
400 | + throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
401 | + } |
|
402 | + |
|
403 | + // Public upload can only be set for folders |
|
404 | + if ($path instanceof \OCP\Files\File) { |
|
405 | + throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
406 | + } |
|
407 | + |
|
408 | + $share->setPermissions( |
|
409 | + \OCP\Constants::PERMISSION_READ | |
|
410 | + \OCP\Constants::PERMISSION_CREATE | |
|
411 | + \OCP\Constants::PERMISSION_UPDATE | |
|
412 | + \OCP\Constants::PERMISSION_DELETE |
|
413 | + ); |
|
414 | + } else { |
|
415 | + $share->setPermissions(\OCP\Constants::PERMISSION_READ); |
|
416 | + } |
|
417 | + |
|
418 | + // Set password |
|
419 | + if ($password !== '') { |
|
420 | + $share->setPassword($password); |
|
421 | + } |
|
422 | + |
|
423 | + //Expire date |
|
424 | + if ($expireDate !== '') { |
|
425 | + try { |
|
426 | + $expireDate = $this->parseDate($expireDate); |
|
427 | + $share->setExpirationDate($expireDate); |
|
428 | + } catch (\Exception $e) { |
|
429 | + throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); |
|
430 | + } |
|
431 | + } |
|
432 | + |
|
433 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
434 | + if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
435 | + throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType])); |
|
436 | + } |
|
437 | + |
|
438 | + $share->setSharedWith($shareWith); |
|
439 | + $share->setPermissions($permissions); |
|
440 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
441 | + if ($share->getNodeType() === 'file') { |
|
442 | + $share->setPermissions(\OCP\Constants::PERMISSION_READ); |
|
443 | + } else { |
|
444 | + $share->setPermissions( |
|
445 | + \OCP\Constants::PERMISSION_READ | |
|
446 | + \OCP\Constants::PERMISSION_CREATE | |
|
447 | + \OCP\Constants::PERMISSION_UPDATE | |
|
448 | + \OCP\Constants::PERMISSION_DELETE); |
|
449 | + } |
|
450 | + $share->setSharedWith($shareWith); |
|
451 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
452 | + if (!\OCP\App::isEnabled('circles')) { |
|
453 | + throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled')); |
|
454 | + } |
|
455 | + |
|
456 | + $circle = \OCA\Circles\Api\Circles::detailsCircle($shareWith); |
|
457 | + |
|
458 | + // Valid circle is required to share |
|
459 | + if ($circle === null) { |
|
460 | + throw new OCSNotFoundException($this->l->t('Please specify a valid circle')); |
|
461 | + } |
|
462 | + $share->setSharedWith($shareWith); |
|
463 | + $share->setPermissions($permissions); |
|
464 | + } else { |
|
465 | + throw new OCSBadRequestException($this->l->t('Unknown share type')); |
|
466 | + } |
|
467 | + |
|
468 | + $share->setShareType($shareType); |
|
469 | + $share->setSharedBy($this->currentUser); |
|
470 | + |
|
471 | + try { |
|
472 | + $share = $this->shareManager->createShare($share); |
|
473 | + } catch (GenericShareException $e) { |
|
474 | + $code = $e->getCode() === 0 ? 403 : $e->getCode(); |
|
475 | + throw new OCSException($e->getHint(), $code); |
|
476 | + } catch (\Exception $e) { |
|
477 | + throw new OCSForbiddenException($e->getMessage()); |
|
478 | + } |
|
479 | + |
|
480 | + $output = $this->formatShare($share); |
|
481 | + |
|
482 | + return new DataResponse($output); |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * @param \OCP\Files\File|\OCP\Files\Folder $node |
|
487 | + * @return DataResponse |
|
488 | + */ |
|
489 | + private function getSharedWithMe($node = null) { |
|
490 | + |
|
491 | + $userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0); |
|
492 | + $groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0); |
|
493 | + $circleShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $node, -1, 0); |
|
494 | + |
|
495 | + $shares = array_merge($userShares, $groupShares, $circleShares); |
|
496 | + |
|
497 | + $shares = array_filter($shares, function (IShare $share) { |
|
498 | + return $share->getShareOwner() !== $this->currentUser; |
|
499 | + }); |
|
500 | + |
|
501 | + $formatted = []; |
|
502 | + foreach ($shares as $share) { |
|
503 | + if ($this->canAccessShare($share)) { |
|
504 | + try { |
|
505 | + $formatted[] = $this->formatShare($share); |
|
506 | + } catch (NotFoundException $e) { |
|
507 | + // Ignore this share |
|
508 | + } |
|
509 | + } |
|
510 | + } |
|
511 | + |
|
512 | + return new DataResponse($formatted); |
|
513 | + } |
|
514 | + |
|
515 | + /** |
|
516 | + * @param \OCP\Files\Folder $folder |
|
517 | + * @return DataResponse |
|
518 | + * @throws OCSBadRequestException |
|
519 | + */ |
|
520 | + private function getSharesInDir($folder) { |
|
521 | + if (!($folder instanceof \OCP\Files\Folder)) { |
|
522 | + throw new OCSBadRequestException($this->l->t('Not a directory')); |
|
523 | + } |
|
524 | + |
|
525 | + $nodes = $folder->getDirectoryListing(); |
|
526 | + /** @var \OCP\Share\IShare[] $shares */ |
|
527 | + $shares = []; |
|
528 | + foreach ($nodes as $node) { |
|
529 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); |
|
530 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); |
|
531 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); |
|
532 | + if($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
533 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $node, false, -1, 0)); |
|
534 | + } |
|
535 | + if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
536 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $node, false, -1, 0)); |
|
537 | + } |
|
538 | + } |
|
539 | + |
|
540 | + $formatted = []; |
|
541 | + foreach ($shares as $share) { |
|
542 | + try { |
|
543 | + $formatted[] = $this->formatShare($share); |
|
544 | + } catch (NotFoundException $e) { |
|
545 | + //Ignore this share |
|
546 | + } |
|
547 | + } |
|
548 | + |
|
549 | + return new DataResponse($formatted); |
|
550 | + } |
|
551 | + |
|
552 | + /** |
|
553 | + * The getShares function. |
|
554 | + * |
|
555 | + * @NoAdminRequired |
|
556 | + * |
|
557 | + * @param string $shared_with_me |
|
558 | + * @param string $reshares |
|
559 | + * @param string $subfiles |
|
560 | + * @param string $path |
|
561 | + * |
|
562 | + * - Get shares by the current user |
|
563 | + * - Get shares by the current user and reshares (?reshares=true) |
|
564 | + * - Get shares with the current user (?shared_with_me=true) |
|
565 | + * - Get shares for a specific path (?path=...) |
|
566 | + * - Get all shares in a folder (?subfiles=true&path=..) |
|
567 | + * |
|
568 | + * @return DataResponse |
|
569 | + * @throws OCSNotFoundException |
|
570 | + */ |
|
571 | + public function getShares( |
|
572 | + $shared_with_me = 'false', |
|
573 | + $reshares = 'false', |
|
574 | + $subfiles = 'false', |
|
575 | + $path = null |
|
576 | + ) { |
|
577 | + |
|
578 | + if ($path !== null) { |
|
579 | + $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
580 | + try { |
|
581 | + $path = $userFolder->get($path); |
|
582 | + $this->lock($path); |
|
583 | + } catch (\OCP\Files\NotFoundException $e) { |
|
584 | + throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
585 | + } catch (LockedException $e) { |
|
586 | + throw new OCSNotFoundException($this->l->t('Could not lock path')); |
|
587 | + } |
|
588 | + } |
|
589 | + |
|
590 | + if ($shared_with_me === 'true') { |
|
591 | + $result = $this->getSharedWithMe($path); |
|
592 | + return $result; |
|
593 | + } |
|
594 | + |
|
595 | + if ($subfiles === 'true') { |
|
596 | + $result = $this->getSharesInDir($path); |
|
597 | + return $result; |
|
598 | + } |
|
599 | + |
|
600 | + if ($reshares === 'true') { |
|
601 | + $reshares = true; |
|
602 | + } else { |
|
603 | + $reshares = false; |
|
604 | + } |
|
605 | + |
|
606 | + // Get all shares |
|
607 | + $userShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0); |
|
608 | + $groupShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0); |
|
609 | + $linkShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0); |
|
610 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
611 | + $mailShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0); |
|
612 | + } else { |
|
613 | + $mailShares = []; |
|
614 | + } |
|
615 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
616 | + $circleShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0); |
|
617 | + } else { |
|
618 | + $circleShares = []; |
|
619 | + } |
|
620 | + |
|
621 | + $shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares); |
|
622 | + |
|
623 | + if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
624 | + $federatedShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0); |
|
625 | + $shares = array_merge($shares, $federatedShares); |
|
626 | + } |
|
627 | + |
|
628 | + $formatted = []; |
|
629 | + foreach ($shares as $share) { |
|
630 | + try { |
|
631 | + $formatted[] = $this->formatShare($share, $path); |
|
632 | + } catch (NotFoundException $e) { |
|
633 | + //Ignore share |
|
634 | + } |
|
635 | + } |
|
636 | + |
|
637 | + return new DataResponse($formatted); |
|
638 | + } |
|
639 | + |
|
640 | + /** |
|
641 | + * @NoAdminRequired |
|
642 | + * |
|
643 | + * @param int $id |
|
644 | + * @param int $permissions |
|
645 | + * @param string $password |
|
646 | + * @param string $publicUpload |
|
647 | + * @param string $expireDate |
|
648 | + * @return DataResponse |
|
649 | + * @throws OCSNotFoundException |
|
650 | + * @throws OCSBadRequestException |
|
651 | + * @throws OCSForbiddenException |
|
652 | + */ |
|
653 | + public function updateShare( |
|
654 | + $id, |
|
655 | + $permissions = null, |
|
656 | + $password = null, |
|
657 | + $publicUpload = null, |
|
658 | + $expireDate = null |
|
659 | + ) { |
|
660 | + try { |
|
661 | + $share = $this->getShareById($id); |
|
662 | + } catch (ShareNotFound $e) { |
|
663 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
664 | + } |
|
665 | + |
|
666 | + $this->lock($share->getNode()); |
|
667 | + |
|
668 | + if (!$this->canAccessShare($share, false)) { |
|
669 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
670 | + } |
|
671 | + |
|
672 | + if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) { |
|
673 | + throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given')); |
|
674 | + } |
|
675 | + |
|
676 | + /* |
|
677 | 677 | * expirationdate, password and publicUpload only make sense for link shares |
678 | 678 | */ |
679 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
680 | - |
|
681 | - $newPermissions = null; |
|
682 | - if ($publicUpload === 'true') { |
|
683 | - $newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE; |
|
684 | - } else if ($publicUpload === 'false') { |
|
685 | - $newPermissions = \OCP\Constants::PERMISSION_READ; |
|
686 | - } |
|
687 | - |
|
688 | - if ($permissions !== null) { |
|
689 | - $newPermissions = (int)$permissions; |
|
690 | - } |
|
691 | - |
|
692 | - if ($newPermissions !== null && |
|
693 | - !in_array($newPermissions, [ |
|
694 | - \OCP\Constants::PERMISSION_READ, |
|
695 | - \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE, // legacy |
|
696 | - \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE, // correct |
|
697 | - \OCP\Constants::PERMISSION_CREATE, // hidden file list |
|
698 | - \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE, // allow to edit single files |
|
699 | - ]) |
|
700 | - ) { |
|
701 | - throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links')); |
|
702 | - } |
|
703 | - |
|
704 | - if ( |
|
705 | - // legacy |
|
706 | - $newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE) || |
|
707 | - // correct |
|
708 | - $newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE) |
|
709 | - ) { |
|
710 | - if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
711 | - throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
712 | - } |
|
713 | - |
|
714 | - if (!($share->getNode() instanceof \OCP\Files\Folder)) { |
|
715 | - throw new OCSBadRequestException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
716 | - } |
|
717 | - |
|
718 | - // normalize to correct public upload permissions |
|
719 | - $newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE; |
|
720 | - } |
|
721 | - |
|
722 | - if ($newPermissions !== null) { |
|
723 | - $share->setPermissions($newPermissions); |
|
724 | - $permissions = $newPermissions; |
|
725 | - } |
|
726 | - |
|
727 | - if ($expireDate === '') { |
|
728 | - $share->setExpirationDate(null); |
|
729 | - } else if ($expireDate !== null) { |
|
730 | - try { |
|
731 | - $expireDate = $this->parseDate($expireDate); |
|
732 | - } catch (\Exception $e) { |
|
733 | - throw new OCSBadRequestException($e->getMessage()); |
|
734 | - } |
|
735 | - $share->setExpirationDate($expireDate); |
|
736 | - } |
|
737 | - |
|
738 | - if ($password === '') { |
|
739 | - $share->setPassword(null); |
|
740 | - } else if ($password !== null) { |
|
741 | - $share->setPassword($password); |
|
742 | - } |
|
743 | - |
|
744 | - } else { |
|
745 | - if ($permissions !== null) { |
|
746 | - $permissions = (int)$permissions; |
|
747 | - $share->setPermissions($permissions); |
|
748 | - } |
|
749 | - |
|
750 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
751 | - if ($password === '') { |
|
752 | - $share->setPassword(null); |
|
753 | - } else if ($password !== null) { |
|
754 | - $share->setPassword($password); |
|
755 | - } |
|
756 | - } |
|
757 | - |
|
758 | - if ($expireDate === '') { |
|
759 | - $share->setExpirationDate(null); |
|
760 | - } else if ($expireDate !== null) { |
|
761 | - try { |
|
762 | - $expireDate = $this->parseDate($expireDate); |
|
763 | - } catch (\Exception $e) { |
|
764 | - throw new OCSBadRequestException($e->getMessage()); |
|
765 | - } |
|
766 | - $share->setExpirationDate($expireDate); |
|
767 | - } |
|
768 | - |
|
769 | - } |
|
770 | - |
|
771 | - if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) { |
|
772 | - /* Check if this is an incomming share */ |
|
773 | - $incomingShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0); |
|
774 | - $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0)); |
|
775 | - |
|
776 | - /** @var \OCP\Share\IShare[] $incomingShares */ |
|
777 | - if (!empty($incomingShares)) { |
|
778 | - $maxPermissions = 0; |
|
779 | - foreach ($incomingShares as $incomingShare) { |
|
780 | - $maxPermissions |= $incomingShare->getPermissions(); |
|
781 | - } |
|
782 | - |
|
783 | - if ($share->getPermissions() & ~$maxPermissions) { |
|
784 | - throw new OCSNotFoundException($this->l->t('Cannot increase permissions')); |
|
785 | - } |
|
786 | - } |
|
787 | - } |
|
788 | - |
|
789 | - |
|
790 | - try { |
|
791 | - $share = $this->shareManager->updateShare($share); |
|
792 | - } catch (\Exception $e) { |
|
793 | - throw new OCSBadRequestException($e->getMessage()); |
|
794 | - } |
|
795 | - |
|
796 | - return new DataResponse($this->formatShare($share)); |
|
797 | - } |
|
798 | - |
|
799 | - /** |
|
800 | - * @param \OCP\Share\IShare $share |
|
801 | - * @return bool |
|
802 | - */ |
|
803 | - protected function canAccessShare(\OCP\Share\IShare $share, $checkGroups = true) { |
|
804 | - // A file with permissions 0 can't be accessed by us. So Don't show it |
|
805 | - if ($share->getPermissions() === 0) { |
|
806 | - return false; |
|
807 | - } |
|
808 | - |
|
809 | - // Owner of the file and the sharer of the file can always get share |
|
810 | - if ($share->getShareOwner() === $this->currentUser || |
|
811 | - $share->getSharedBy() === $this->currentUser |
|
812 | - ) { |
|
813 | - return true; |
|
814 | - } |
|
815 | - |
|
816 | - // If the share is shared with you (or a group you are a member of) |
|
817 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
818 | - $share->getSharedWith() === $this->currentUser |
|
819 | - ) { |
|
820 | - return true; |
|
821 | - } |
|
822 | - |
|
823 | - if ($checkGroups && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
824 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
825 | - $user = $this->userManager->get($this->currentUser); |
|
826 | - if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) { |
|
827 | - return true; |
|
828 | - } |
|
829 | - } |
|
830 | - |
|
831 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
832 | - // TODO: have a sanity check like above? |
|
833 | - return true; |
|
834 | - } |
|
835 | - |
|
836 | - return false; |
|
837 | - } |
|
838 | - |
|
839 | - /** |
|
840 | - * Make sure that the passed date is valid ISO 8601 |
|
841 | - * So YYYY-MM-DD |
|
842 | - * If not throw an exception |
|
843 | - * |
|
844 | - * @param string $expireDate |
|
845 | - * |
|
846 | - * @throws \Exception |
|
847 | - * @return \DateTime |
|
848 | - */ |
|
849 | - private function parseDate($expireDate) { |
|
850 | - try { |
|
851 | - $date = new \DateTime($expireDate); |
|
852 | - } catch (\Exception $e) { |
|
853 | - throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
854 | - } |
|
855 | - |
|
856 | - if ($date === false) { |
|
857 | - throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
858 | - } |
|
859 | - |
|
860 | - $date->setTime(0, 0, 0); |
|
861 | - |
|
862 | - return $date; |
|
863 | - } |
|
864 | - |
|
865 | - /** |
|
866 | - * Since we have multiple providers but the OCS Share API v1 does |
|
867 | - * not support this we need to check all backends. |
|
868 | - * |
|
869 | - * @param string $id |
|
870 | - * @return \OCP\Share\IShare |
|
871 | - * @throws ShareNotFound |
|
872 | - */ |
|
873 | - private function getShareById($id) { |
|
874 | - $share = null; |
|
875 | - |
|
876 | - // First check if it is an internal share. |
|
877 | - try { |
|
878 | - $share = $this->shareManager->getShareById('ocinternal:' . $id); |
|
879 | - return $share; |
|
880 | - } catch (ShareNotFound $e) { |
|
881 | - // Do nothing, just try the other share type |
|
882 | - } |
|
883 | - |
|
884 | - |
|
885 | - try { |
|
886 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
887 | - $share = $this->shareManager->getShareById('ocCircleShare:' . $id); |
|
888 | - return $share; |
|
889 | - } |
|
890 | - } catch (ShareNotFound $e) { |
|
891 | - // Do nothing, just try the other share type |
|
892 | - } |
|
893 | - |
|
894 | - try { |
|
895 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
896 | - $share = $this->shareManager->getShareById('ocMailShare:' . $id); |
|
897 | - return $share; |
|
898 | - } |
|
899 | - } catch (ShareNotFound $e) { |
|
900 | - // Do nothing, just try the other share type |
|
901 | - } |
|
902 | - |
|
903 | - if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
904 | - throw new ShareNotFound(); |
|
905 | - } |
|
906 | - $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id); |
|
907 | - |
|
908 | - return $share; |
|
909 | - } |
|
910 | - |
|
911 | - /** |
|
912 | - * Lock a Node |
|
913 | - * |
|
914 | - * @param \OCP\Files\Node $node |
|
915 | - */ |
|
916 | - private function lock(\OCP\Files\Node $node) { |
|
917 | - $node->lock(ILockingProvider::LOCK_SHARED); |
|
918 | - $this->lockedNode = $node; |
|
919 | - } |
|
920 | - |
|
921 | - /** |
|
922 | - * Cleanup the remaining locks |
|
923 | - */ |
|
924 | - public function cleanup() { |
|
925 | - if ($this->lockedNode !== null) { |
|
926 | - $this->lockedNode->unlock(ILockingProvider::LOCK_SHARED); |
|
927 | - } |
|
928 | - } |
|
679 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
680 | + |
|
681 | + $newPermissions = null; |
|
682 | + if ($publicUpload === 'true') { |
|
683 | + $newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE; |
|
684 | + } else if ($publicUpload === 'false') { |
|
685 | + $newPermissions = \OCP\Constants::PERMISSION_READ; |
|
686 | + } |
|
687 | + |
|
688 | + if ($permissions !== null) { |
|
689 | + $newPermissions = (int)$permissions; |
|
690 | + } |
|
691 | + |
|
692 | + if ($newPermissions !== null && |
|
693 | + !in_array($newPermissions, [ |
|
694 | + \OCP\Constants::PERMISSION_READ, |
|
695 | + \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE, // legacy |
|
696 | + \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE, // correct |
|
697 | + \OCP\Constants::PERMISSION_CREATE, // hidden file list |
|
698 | + \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE, // allow to edit single files |
|
699 | + ]) |
|
700 | + ) { |
|
701 | + throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links')); |
|
702 | + } |
|
703 | + |
|
704 | + if ( |
|
705 | + // legacy |
|
706 | + $newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE) || |
|
707 | + // correct |
|
708 | + $newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE) |
|
709 | + ) { |
|
710 | + if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
711 | + throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
712 | + } |
|
713 | + |
|
714 | + if (!($share->getNode() instanceof \OCP\Files\Folder)) { |
|
715 | + throw new OCSBadRequestException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
716 | + } |
|
717 | + |
|
718 | + // normalize to correct public upload permissions |
|
719 | + $newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE; |
|
720 | + } |
|
721 | + |
|
722 | + if ($newPermissions !== null) { |
|
723 | + $share->setPermissions($newPermissions); |
|
724 | + $permissions = $newPermissions; |
|
725 | + } |
|
726 | + |
|
727 | + if ($expireDate === '') { |
|
728 | + $share->setExpirationDate(null); |
|
729 | + } else if ($expireDate !== null) { |
|
730 | + try { |
|
731 | + $expireDate = $this->parseDate($expireDate); |
|
732 | + } catch (\Exception $e) { |
|
733 | + throw new OCSBadRequestException($e->getMessage()); |
|
734 | + } |
|
735 | + $share->setExpirationDate($expireDate); |
|
736 | + } |
|
737 | + |
|
738 | + if ($password === '') { |
|
739 | + $share->setPassword(null); |
|
740 | + } else if ($password !== null) { |
|
741 | + $share->setPassword($password); |
|
742 | + } |
|
743 | + |
|
744 | + } else { |
|
745 | + if ($permissions !== null) { |
|
746 | + $permissions = (int)$permissions; |
|
747 | + $share->setPermissions($permissions); |
|
748 | + } |
|
749 | + |
|
750 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
751 | + if ($password === '') { |
|
752 | + $share->setPassword(null); |
|
753 | + } else if ($password !== null) { |
|
754 | + $share->setPassword($password); |
|
755 | + } |
|
756 | + } |
|
757 | + |
|
758 | + if ($expireDate === '') { |
|
759 | + $share->setExpirationDate(null); |
|
760 | + } else if ($expireDate !== null) { |
|
761 | + try { |
|
762 | + $expireDate = $this->parseDate($expireDate); |
|
763 | + } catch (\Exception $e) { |
|
764 | + throw new OCSBadRequestException($e->getMessage()); |
|
765 | + } |
|
766 | + $share->setExpirationDate($expireDate); |
|
767 | + } |
|
768 | + |
|
769 | + } |
|
770 | + |
|
771 | + if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) { |
|
772 | + /* Check if this is an incomming share */ |
|
773 | + $incomingShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0); |
|
774 | + $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0)); |
|
775 | + |
|
776 | + /** @var \OCP\Share\IShare[] $incomingShares */ |
|
777 | + if (!empty($incomingShares)) { |
|
778 | + $maxPermissions = 0; |
|
779 | + foreach ($incomingShares as $incomingShare) { |
|
780 | + $maxPermissions |= $incomingShare->getPermissions(); |
|
781 | + } |
|
782 | + |
|
783 | + if ($share->getPermissions() & ~$maxPermissions) { |
|
784 | + throw new OCSNotFoundException($this->l->t('Cannot increase permissions')); |
|
785 | + } |
|
786 | + } |
|
787 | + } |
|
788 | + |
|
789 | + |
|
790 | + try { |
|
791 | + $share = $this->shareManager->updateShare($share); |
|
792 | + } catch (\Exception $e) { |
|
793 | + throw new OCSBadRequestException($e->getMessage()); |
|
794 | + } |
|
795 | + |
|
796 | + return new DataResponse($this->formatShare($share)); |
|
797 | + } |
|
798 | + |
|
799 | + /** |
|
800 | + * @param \OCP\Share\IShare $share |
|
801 | + * @return bool |
|
802 | + */ |
|
803 | + protected function canAccessShare(\OCP\Share\IShare $share, $checkGroups = true) { |
|
804 | + // A file with permissions 0 can't be accessed by us. So Don't show it |
|
805 | + if ($share->getPermissions() === 0) { |
|
806 | + return false; |
|
807 | + } |
|
808 | + |
|
809 | + // Owner of the file and the sharer of the file can always get share |
|
810 | + if ($share->getShareOwner() === $this->currentUser || |
|
811 | + $share->getSharedBy() === $this->currentUser |
|
812 | + ) { |
|
813 | + return true; |
|
814 | + } |
|
815 | + |
|
816 | + // If the share is shared with you (or a group you are a member of) |
|
817 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
818 | + $share->getSharedWith() === $this->currentUser |
|
819 | + ) { |
|
820 | + return true; |
|
821 | + } |
|
822 | + |
|
823 | + if ($checkGroups && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
824 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
825 | + $user = $this->userManager->get($this->currentUser); |
|
826 | + if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) { |
|
827 | + return true; |
|
828 | + } |
|
829 | + } |
|
830 | + |
|
831 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
832 | + // TODO: have a sanity check like above? |
|
833 | + return true; |
|
834 | + } |
|
835 | + |
|
836 | + return false; |
|
837 | + } |
|
838 | + |
|
839 | + /** |
|
840 | + * Make sure that the passed date is valid ISO 8601 |
|
841 | + * So YYYY-MM-DD |
|
842 | + * If not throw an exception |
|
843 | + * |
|
844 | + * @param string $expireDate |
|
845 | + * |
|
846 | + * @throws \Exception |
|
847 | + * @return \DateTime |
|
848 | + */ |
|
849 | + private function parseDate($expireDate) { |
|
850 | + try { |
|
851 | + $date = new \DateTime($expireDate); |
|
852 | + } catch (\Exception $e) { |
|
853 | + throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
854 | + } |
|
855 | + |
|
856 | + if ($date === false) { |
|
857 | + throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
858 | + } |
|
859 | + |
|
860 | + $date->setTime(0, 0, 0); |
|
861 | + |
|
862 | + return $date; |
|
863 | + } |
|
864 | + |
|
865 | + /** |
|
866 | + * Since we have multiple providers but the OCS Share API v1 does |
|
867 | + * not support this we need to check all backends. |
|
868 | + * |
|
869 | + * @param string $id |
|
870 | + * @return \OCP\Share\IShare |
|
871 | + * @throws ShareNotFound |
|
872 | + */ |
|
873 | + private function getShareById($id) { |
|
874 | + $share = null; |
|
875 | + |
|
876 | + // First check if it is an internal share. |
|
877 | + try { |
|
878 | + $share = $this->shareManager->getShareById('ocinternal:' . $id); |
|
879 | + return $share; |
|
880 | + } catch (ShareNotFound $e) { |
|
881 | + // Do nothing, just try the other share type |
|
882 | + } |
|
883 | + |
|
884 | + |
|
885 | + try { |
|
886 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
887 | + $share = $this->shareManager->getShareById('ocCircleShare:' . $id); |
|
888 | + return $share; |
|
889 | + } |
|
890 | + } catch (ShareNotFound $e) { |
|
891 | + // Do nothing, just try the other share type |
|
892 | + } |
|
893 | + |
|
894 | + try { |
|
895 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
896 | + $share = $this->shareManager->getShareById('ocMailShare:' . $id); |
|
897 | + return $share; |
|
898 | + } |
|
899 | + } catch (ShareNotFound $e) { |
|
900 | + // Do nothing, just try the other share type |
|
901 | + } |
|
902 | + |
|
903 | + if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
904 | + throw new ShareNotFound(); |
|
905 | + } |
|
906 | + $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id); |
|
907 | + |
|
908 | + return $share; |
|
909 | + } |
|
910 | + |
|
911 | + /** |
|
912 | + * Lock a Node |
|
913 | + * |
|
914 | + * @param \OCP\Files\Node $node |
|
915 | + */ |
|
916 | + private function lock(\OCP\Files\Node $node) { |
|
917 | + $node->lock(ILockingProvider::LOCK_SHARED); |
|
918 | + $this->lockedNode = $node; |
|
919 | + } |
|
920 | + |
|
921 | + /** |
|
922 | + * Cleanup the remaining locks |
|
923 | + */ |
|
924 | + public function cleanup() { |
|
925 | + if ($this->lockedNode !== null) { |
|
926 | + $this->lockedNode->unlock(ILockingProvider::LOCK_SHARED); |
|
927 | + } |
|
928 | + } |
|
929 | 929 | } |
@@ -39,270 +39,270 @@ |
||
39 | 39 | */ |
40 | 40 | class Migration { |
41 | 41 | |
42 | - /** @var IDBConnection */ |
|
43 | - private $connection; |
|
44 | - |
|
45 | - /** @var IConfig */ |
|
46 | - private $config; |
|
47 | - |
|
48 | - /** @var ICache with all shares we already saw */ |
|
49 | - private $shareCache; |
|
50 | - |
|
51 | - /** @var string */ |
|
52 | - private $table = 'share'; |
|
53 | - |
|
54 | - public function __construct(IDBConnection $connection, IConfig $config) { |
|
55 | - $this->connection = $connection; |
|
56 | - $this->config = $config; |
|
57 | - |
|
58 | - // We cache up to 10k share items (~20MB) |
|
59 | - $this->shareCache = new CappedMemoryCache(10000); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * move all re-shares to the owner in order to have a flat list of shares |
|
64 | - * upgrade from oC 8.2 to 9.0 with the new sharing |
|
65 | - */ |
|
66 | - public function removeReShares() { |
|
67 | - |
|
68 | - $stmt = $this->getReShares(); |
|
69 | - |
|
70 | - $owners = []; |
|
71 | - while($share = $stmt->fetch()) { |
|
72 | - |
|
73 | - $this->shareCache[$share['id']] = $share; |
|
74 | - |
|
75 | - $owners[$share['id']] = [ |
|
76 | - 'owner' => $this->findOwner($share), |
|
77 | - 'initiator' => $share['uid_owner'], |
|
78 | - 'type' => $share['share_type'], |
|
79 | - ]; |
|
80 | - |
|
81 | - if (count($owners) === 1000) { |
|
82 | - $this->updateOwners($owners); |
|
83 | - $owners = []; |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - $stmt->closeCursor(); |
|
88 | - |
|
89 | - if (count($owners)) { |
|
90 | - $this->updateOwners($owners); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * update all owner information so that all shares have an owner |
|
96 | - * and an initiator for the upgrade from oC 8.2 to 9.0 with the new sharing |
|
97 | - */ |
|
98 | - public function updateInitiatorInfo() { |
|
99 | - while (true) { |
|
100 | - $shares = $this->getMissingInitiator(1000); |
|
101 | - |
|
102 | - if (empty($shares)) { |
|
103 | - break; |
|
104 | - } |
|
105 | - |
|
106 | - $owners = []; |
|
107 | - foreach ($shares as $share) { |
|
108 | - $owners[$share['id']] = [ |
|
109 | - 'owner' => $share['uid_owner'], |
|
110 | - 'initiator' => $share['uid_owner'], |
|
111 | - 'type' => $share['share_type'], |
|
112 | - ]; |
|
113 | - } |
|
114 | - $this->updateOwners($owners); |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * this was dropped for Nextcloud 11 in favour of share by mail |
|
120 | - */ |
|
121 | - public function removeSendMailOption() { |
|
122 | - $this->config->deleteAppValue('core', 'shareapi_allow_mail_notification'); |
|
123 | - $this->config->deleteAppValue('core', 'shareapi_allow_public_notification'); |
|
124 | - } |
|
125 | - |
|
126 | - public function addPasswordColumn() { |
|
127 | - $query = $this->connection->getQueryBuilder(); |
|
128 | - $query |
|
129 | - ->update('share') |
|
130 | - ->set('password', 'share_with') |
|
131 | - ->where($query->expr()->eq('share_type', $query->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))) |
|
132 | - ->andWhere($query->expr()->isNotNull('share_with')); |
|
133 | - $query->execute(); |
|
134 | - |
|
135 | - $clearQuery = $this->connection->getQueryBuilder(); |
|
136 | - $clearQuery |
|
137 | - ->update('share')->set('share_with', $clearQuery->createNamedParameter(null)) |
|
138 | - ->where($clearQuery->expr()->eq('share_type', $clearQuery->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))); |
|
139 | - |
|
140 | - $clearQuery->execute(); |
|
141 | - |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * find the owner of a re-shared file/folder |
|
146 | - * |
|
147 | - * @param array $share |
|
148 | - * @return array |
|
149 | - */ |
|
150 | - private function findOwner($share) { |
|
151 | - $currentShare = $share; |
|
152 | - while(!is_null($currentShare['parent'])) { |
|
153 | - if (isset($this->shareCache[$currentShare['parent']])) { |
|
154 | - $currentShare = $this->shareCache[$currentShare['parent']]; |
|
155 | - } else { |
|
156 | - $currentShare = $this->getShare((int)$currentShare['parent']); |
|
157 | - $this->shareCache[$currentShare['id']] = $currentShare; |
|
158 | - } |
|
159 | - } |
|
160 | - |
|
161 | - return $currentShare['uid_owner']; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Get $n re-shares from the database |
|
166 | - * |
|
167 | - * @param int $n The max number of shares to fetch |
|
168 | - * @return \Doctrine\DBAL\Driver\Statement |
|
169 | - */ |
|
170 | - private function getReShares() { |
|
171 | - $query = $this->connection->getQueryBuilder(); |
|
172 | - $query->select(['id', 'parent', 'uid_owner', 'share_type']) |
|
173 | - ->from($this->table) |
|
174 | - ->where($query->expr()->in( |
|
175 | - 'share_type', |
|
176 | - $query->createNamedParameter( |
|
177 | - [ |
|
178 | - \OCP\Share::SHARE_TYPE_USER, |
|
179 | - \OCP\Share::SHARE_TYPE_GROUP, |
|
180 | - \OCP\Share::SHARE_TYPE_LINK, |
|
181 | - \OCP\Share::SHARE_TYPE_REMOTE, |
|
182 | - ], |
|
183 | - Connection::PARAM_INT_ARRAY |
|
184 | - ) |
|
185 | - )) |
|
186 | - ->andWhere($query->expr()->in( |
|
187 | - 'item_type', |
|
188 | - $query->createNamedParameter( |
|
189 | - ['file', 'folder'], |
|
190 | - Connection::PARAM_STR_ARRAY |
|
191 | - ) |
|
192 | - )) |
|
193 | - ->andWhere($query->expr()->isNotNull('parent')) |
|
194 | - ->orderBy('id', 'asc'); |
|
195 | - return $query->execute(); |
|
196 | - |
|
197 | - |
|
198 | - $shares = $result->fetchAll(); |
|
199 | - $result->closeCursor(); |
|
200 | - |
|
201 | - $ordered = []; |
|
202 | - foreach ($shares as $share) { |
|
203 | - $ordered[(int)$share['id']] = $share; |
|
204 | - } |
|
205 | - |
|
206 | - return $ordered; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Get $n re-shares from the database |
|
211 | - * |
|
212 | - * @param int $n The max number of shares to fetch |
|
213 | - * @return array |
|
214 | - */ |
|
215 | - private function getMissingInitiator($n = 1000) { |
|
216 | - $query = $this->connection->getQueryBuilder(); |
|
217 | - $query->select(['id', 'uid_owner', 'share_type']) |
|
218 | - ->from($this->table) |
|
219 | - ->where($query->expr()->in( |
|
220 | - 'share_type', |
|
221 | - $query->createNamedParameter( |
|
222 | - [ |
|
223 | - \OCP\Share::SHARE_TYPE_USER, |
|
224 | - \OCP\Share::SHARE_TYPE_GROUP, |
|
225 | - \OCP\Share::SHARE_TYPE_LINK, |
|
226 | - \OCP\Share::SHARE_TYPE_REMOTE, |
|
227 | - ], |
|
228 | - Connection::PARAM_INT_ARRAY |
|
229 | - ) |
|
230 | - )) |
|
231 | - ->andWhere($query->expr()->in( |
|
232 | - 'item_type', |
|
233 | - $query->createNamedParameter( |
|
234 | - ['file', 'folder'], |
|
235 | - Connection::PARAM_STR_ARRAY |
|
236 | - ) |
|
237 | - )) |
|
238 | - ->andWhere($query->expr()->isNull('uid_initiator')) |
|
239 | - ->orderBy('id', 'asc') |
|
240 | - ->setMaxResults($n); |
|
241 | - $result = $query->execute(); |
|
242 | - $shares = $result->fetchAll(); |
|
243 | - $result->closeCursor(); |
|
244 | - |
|
245 | - $ordered = []; |
|
246 | - foreach ($shares as $share) { |
|
247 | - $ordered[(int)$share['id']] = $share; |
|
248 | - } |
|
249 | - |
|
250 | - return $ordered; |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * get a specific share |
|
255 | - * |
|
256 | - * @param int $id |
|
257 | - * @return array |
|
258 | - */ |
|
259 | - private function getShare($id) { |
|
260 | - $query = $this->connection->getQueryBuilder(); |
|
261 | - $query->select(['id', 'parent', 'uid_owner']) |
|
262 | - ->from($this->table) |
|
263 | - ->where($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
264 | - $result = $query->execute(); |
|
265 | - $share = $result->fetchAll(); |
|
266 | - $result->closeCursor(); |
|
267 | - |
|
268 | - return $share[0]; |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * update database with the new owners |
|
273 | - * |
|
274 | - * @param array $owners |
|
275 | - * @throws \Exception |
|
276 | - */ |
|
277 | - private function updateOwners($owners) { |
|
278 | - |
|
279 | - $this->connection->beginTransaction(); |
|
280 | - |
|
281 | - try { |
|
282 | - |
|
283 | - foreach ($owners as $id => $owner) { |
|
284 | - $query = $this->connection->getQueryBuilder(); |
|
285 | - $query->update($this->table) |
|
286 | - ->set('uid_owner', $query->createNamedParameter($owner['owner'])) |
|
287 | - ->set('uid_initiator', $query->createNamedParameter($owner['initiator'])); |
|
288 | - |
|
289 | - |
|
290 | - if ((int)$owner['type'] !== \OCP\Share::SHARE_TYPE_LINK) { |
|
291 | - $query->set('parent', $query->createNamedParameter(null)); |
|
292 | - } |
|
293 | - |
|
294 | - $query->where($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
295 | - |
|
296 | - $query->execute(); |
|
297 | - } |
|
298 | - |
|
299 | - $this->connection->commit(); |
|
300 | - |
|
301 | - } catch (\Exception $e) { |
|
302 | - $this->connection->rollBack(); |
|
303 | - throw $e; |
|
304 | - } |
|
305 | - |
|
306 | - } |
|
42 | + /** @var IDBConnection */ |
|
43 | + private $connection; |
|
44 | + |
|
45 | + /** @var IConfig */ |
|
46 | + private $config; |
|
47 | + |
|
48 | + /** @var ICache with all shares we already saw */ |
|
49 | + private $shareCache; |
|
50 | + |
|
51 | + /** @var string */ |
|
52 | + private $table = 'share'; |
|
53 | + |
|
54 | + public function __construct(IDBConnection $connection, IConfig $config) { |
|
55 | + $this->connection = $connection; |
|
56 | + $this->config = $config; |
|
57 | + |
|
58 | + // We cache up to 10k share items (~20MB) |
|
59 | + $this->shareCache = new CappedMemoryCache(10000); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * move all re-shares to the owner in order to have a flat list of shares |
|
64 | + * upgrade from oC 8.2 to 9.0 with the new sharing |
|
65 | + */ |
|
66 | + public function removeReShares() { |
|
67 | + |
|
68 | + $stmt = $this->getReShares(); |
|
69 | + |
|
70 | + $owners = []; |
|
71 | + while($share = $stmt->fetch()) { |
|
72 | + |
|
73 | + $this->shareCache[$share['id']] = $share; |
|
74 | + |
|
75 | + $owners[$share['id']] = [ |
|
76 | + 'owner' => $this->findOwner($share), |
|
77 | + 'initiator' => $share['uid_owner'], |
|
78 | + 'type' => $share['share_type'], |
|
79 | + ]; |
|
80 | + |
|
81 | + if (count($owners) === 1000) { |
|
82 | + $this->updateOwners($owners); |
|
83 | + $owners = []; |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + $stmt->closeCursor(); |
|
88 | + |
|
89 | + if (count($owners)) { |
|
90 | + $this->updateOwners($owners); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * update all owner information so that all shares have an owner |
|
96 | + * and an initiator for the upgrade from oC 8.2 to 9.0 with the new sharing |
|
97 | + */ |
|
98 | + public function updateInitiatorInfo() { |
|
99 | + while (true) { |
|
100 | + $shares = $this->getMissingInitiator(1000); |
|
101 | + |
|
102 | + if (empty($shares)) { |
|
103 | + break; |
|
104 | + } |
|
105 | + |
|
106 | + $owners = []; |
|
107 | + foreach ($shares as $share) { |
|
108 | + $owners[$share['id']] = [ |
|
109 | + 'owner' => $share['uid_owner'], |
|
110 | + 'initiator' => $share['uid_owner'], |
|
111 | + 'type' => $share['share_type'], |
|
112 | + ]; |
|
113 | + } |
|
114 | + $this->updateOwners($owners); |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * this was dropped for Nextcloud 11 in favour of share by mail |
|
120 | + */ |
|
121 | + public function removeSendMailOption() { |
|
122 | + $this->config->deleteAppValue('core', 'shareapi_allow_mail_notification'); |
|
123 | + $this->config->deleteAppValue('core', 'shareapi_allow_public_notification'); |
|
124 | + } |
|
125 | + |
|
126 | + public function addPasswordColumn() { |
|
127 | + $query = $this->connection->getQueryBuilder(); |
|
128 | + $query |
|
129 | + ->update('share') |
|
130 | + ->set('password', 'share_with') |
|
131 | + ->where($query->expr()->eq('share_type', $query->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))) |
|
132 | + ->andWhere($query->expr()->isNotNull('share_with')); |
|
133 | + $query->execute(); |
|
134 | + |
|
135 | + $clearQuery = $this->connection->getQueryBuilder(); |
|
136 | + $clearQuery |
|
137 | + ->update('share')->set('share_with', $clearQuery->createNamedParameter(null)) |
|
138 | + ->where($clearQuery->expr()->eq('share_type', $clearQuery->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))); |
|
139 | + |
|
140 | + $clearQuery->execute(); |
|
141 | + |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * find the owner of a re-shared file/folder |
|
146 | + * |
|
147 | + * @param array $share |
|
148 | + * @return array |
|
149 | + */ |
|
150 | + private function findOwner($share) { |
|
151 | + $currentShare = $share; |
|
152 | + while(!is_null($currentShare['parent'])) { |
|
153 | + if (isset($this->shareCache[$currentShare['parent']])) { |
|
154 | + $currentShare = $this->shareCache[$currentShare['parent']]; |
|
155 | + } else { |
|
156 | + $currentShare = $this->getShare((int)$currentShare['parent']); |
|
157 | + $this->shareCache[$currentShare['id']] = $currentShare; |
|
158 | + } |
|
159 | + } |
|
160 | + |
|
161 | + return $currentShare['uid_owner']; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Get $n re-shares from the database |
|
166 | + * |
|
167 | + * @param int $n The max number of shares to fetch |
|
168 | + * @return \Doctrine\DBAL\Driver\Statement |
|
169 | + */ |
|
170 | + private function getReShares() { |
|
171 | + $query = $this->connection->getQueryBuilder(); |
|
172 | + $query->select(['id', 'parent', 'uid_owner', 'share_type']) |
|
173 | + ->from($this->table) |
|
174 | + ->where($query->expr()->in( |
|
175 | + 'share_type', |
|
176 | + $query->createNamedParameter( |
|
177 | + [ |
|
178 | + \OCP\Share::SHARE_TYPE_USER, |
|
179 | + \OCP\Share::SHARE_TYPE_GROUP, |
|
180 | + \OCP\Share::SHARE_TYPE_LINK, |
|
181 | + \OCP\Share::SHARE_TYPE_REMOTE, |
|
182 | + ], |
|
183 | + Connection::PARAM_INT_ARRAY |
|
184 | + ) |
|
185 | + )) |
|
186 | + ->andWhere($query->expr()->in( |
|
187 | + 'item_type', |
|
188 | + $query->createNamedParameter( |
|
189 | + ['file', 'folder'], |
|
190 | + Connection::PARAM_STR_ARRAY |
|
191 | + ) |
|
192 | + )) |
|
193 | + ->andWhere($query->expr()->isNotNull('parent')) |
|
194 | + ->orderBy('id', 'asc'); |
|
195 | + return $query->execute(); |
|
196 | + |
|
197 | + |
|
198 | + $shares = $result->fetchAll(); |
|
199 | + $result->closeCursor(); |
|
200 | + |
|
201 | + $ordered = []; |
|
202 | + foreach ($shares as $share) { |
|
203 | + $ordered[(int)$share['id']] = $share; |
|
204 | + } |
|
205 | + |
|
206 | + return $ordered; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Get $n re-shares from the database |
|
211 | + * |
|
212 | + * @param int $n The max number of shares to fetch |
|
213 | + * @return array |
|
214 | + */ |
|
215 | + private function getMissingInitiator($n = 1000) { |
|
216 | + $query = $this->connection->getQueryBuilder(); |
|
217 | + $query->select(['id', 'uid_owner', 'share_type']) |
|
218 | + ->from($this->table) |
|
219 | + ->where($query->expr()->in( |
|
220 | + 'share_type', |
|
221 | + $query->createNamedParameter( |
|
222 | + [ |
|
223 | + \OCP\Share::SHARE_TYPE_USER, |
|
224 | + \OCP\Share::SHARE_TYPE_GROUP, |
|
225 | + \OCP\Share::SHARE_TYPE_LINK, |
|
226 | + \OCP\Share::SHARE_TYPE_REMOTE, |
|
227 | + ], |
|
228 | + Connection::PARAM_INT_ARRAY |
|
229 | + ) |
|
230 | + )) |
|
231 | + ->andWhere($query->expr()->in( |
|
232 | + 'item_type', |
|
233 | + $query->createNamedParameter( |
|
234 | + ['file', 'folder'], |
|
235 | + Connection::PARAM_STR_ARRAY |
|
236 | + ) |
|
237 | + )) |
|
238 | + ->andWhere($query->expr()->isNull('uid_initiator')) |
|
239 | + ->orderBy('id', 'asc') |
|
240 | + ->setMaxResults($n); |
|
241 | + $result = $query->execute(); |
|
242 | + $shares = $result->fetchAll(); |
|
243 | + $result->closeCursor(); |
|
244 | + |
|
245 | + $ordered = []; |
|
246 | + foreach ($shares as $share) { |
|
247 | + $ordered[(int)$share['id']] = $share; |
|
248 | + } |
|
249 | + |
|
250 | + return $ordered; |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * get a specific share |
|
255 | + * |
|
256 | + * @param int $id |
|
257 | + * @return array |
|
258 | + */ |
|
259 | + private function getShare($id) { |
|
260 | + $query = $this->connection->getQueryBuilder(); |
|
261 | + $query->select(['id', 'parent', 'uid_owner']) |
|
262 | + ->from($this->table) |
|
263 | + ->where($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
264 | + $result = $query->execute(); |
|
265 | + $share = $result->fetchAll(); |
|
266 | + $result->closeCursor(); |
|
267 | + |
|
268 | + return $share[0]; |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * update database with the new owners |
|
273 | + * |
|
274 | + * @param array $owners |
|
275 | + * @throws \Exception |
|
276 | + */ |
|
277 | + private function updateOwners($owners) { |
|
278 | + |
|
279 | + $this->connection->beginTransaction(); |
|
280 | + |
|
281 | + try { |
|
282 | + |
|
283 | + foreach ($owners as $id => $owner) { |
|
284 | + $query = $this->connection->getQueryBuilder(); |
|
285 | + $query->update($this->table) |
|
286 | + ->set('uid_owner', $query->createNamedParameter($owner['owner'])) |
|
287 | + ->set('uid_initiator', $query->createNamedParameter($owner['initiator'])); |
|
288 | + |
|
289 | + |
|
290 | + if ((int)$owner['type'] !== \OCP\Share::SHARE_TYPE_LINK) { |
|
291 | + $query->set('parent', $query->createNamedParameter(null)); |
|
292 | + } |
|
293 | + |
|
294 | + $query->where($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
295 | + |
|
296 | + $query->execute(); |
|
297 | + } |
|
298 | + |
|
299 | + $this->connection->commit(); |
|
300 | + |
|
301 | + } catch (\Exception $e) { |
|
302 | + $this->connection->rollBack(); |
|
303 | + throw $e; |
|
304 | + } |
|
305 | + |
|
306 | + } |
|
307 | 307 | |
308 | 308 | } |
@@ -193,10 +193,10 @@ discard block |
||
193 | 193 | * publish activity if a file/folder was shared by mail |
194 | 194 | * |
195 | 195 | * @param $subject |
196 | - * @param $parameters |
|
197 | - * @param $affectedUser |
|
196 | + * @param string[] $parameters |
|
197 | + * @param string $affectedUser |
|
198 | 198 | * @param $fileId |
199 | - * @param $filePath |
|
199 | + * @param string $filePath |
|
200 | 200 | */ |
201 | 201 | protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
202 | 202 | $event = $this->activityManager->generateEvent(); |
@@ -248,6 +248,12 @@ discard block |
||
248 | 248 | |
249 | 249 | } |
250 | 250 | |
251 | + /** |
|
252 | + * @param string $link |
|
253 | + * @param string $owner |
|
254 | + * @param string $initiator |
|
255 | + * @param string $shareWith |
|
256 | + */ |
|
251 | 257 | protected function sendMailNotification($filename, $link, $owner, $initiator, $shareWith) { |
252 | 258 | $ownerUser = $this->userManager->get($owner); |
253 | 259 | $initiatorUser = $this->userManager->get($initiator); |
@@ -277,6 +283,7 @@ discard block |
||
277 | 283 | * @param $link |
278 | 284 | * @param $owner |
279 | 285 | * @param $initiator |
286 | + * @param string $template |
|
280 | 287 | * @return string plain text mail |
281 | 288 | * @throws HintException |
282 | 289 | */ |
@@ -304,6 +311,7 @@ discard block |
||
304 | 311 | * @param string $filename |
305 | 312 | * @param string $initiator |
306 | 313 | * @param string $shareWith |
314 | + * @param string $password |
|
307 | 315 | */ |
308 | 316 | protected function sendPassword($filename, $initiator, $shareWith, $password) { |
309 | 317 | |
@@ -332,6 +340,7 @@ discard block |
||
332 | 340 | * @param string $filename |
333 | 341 | * @param string $initiator |
334 | 342 | * @param string $password |
343 | + * @param string $template |
|
335 | 344 | * @return string plain text mail |
336 | 345 | * @throws HintException |
337 | 346 | */ |
@@ -790,7 +799,7 @@ discard block |
||
790 | 799 | /** |
791 | 800 | * get database row of a give share |
792 | 801 | * |
793 | - * @param $id |
|
802 | + * @param integer $id |
|
794 | 803 | * @return array |
795 | 804 | * @throws ShareNotFound |
796 | 805 | */ |
@@ -50,808 +50,808 @@ |
||
50 | 50 | */ |
51 | 51 | class ShareByMailProvider implements IShareProvider { |
52 | 52 | |
53 | - /** @var IDBConnection */ |
|
54 | - private $dbConnection; |
|
55 | - |
|
56 | - /** @var ILogger */ |
|
57 | - private $logger; |
|
58 | - |
|
59 | - /** @var ISecureRandom */ |
|
60 | - private $secureRandom; |
|
61 | - |
|
62 | - /** @var IUserManager */ |
|
63 | - private $userManager; |
|
64 | - |
|
65 | - /** @var IRootFolder */ |
|
66 | - private $rootFolder; |
|
67 | - |
|
68 | - /** @var IL10N */ |
|
69 | - private $l; |
|
70 | - |
|
71 | - /** @var IMailer */ |
|
72 | - private $mailer; |
|
73 | - |
|
74 | - /** @var IURLGenerator */ |
|
75 | - private $urlGenerator; |
|
76 | - |
|
77 | - /** @var IManager */ |
|
78 | - private $activityManager; |
|
79 | - |
|
80 | - /** @var SettingsManager */ |
|
81 | - private $settingsManager; |
|
82 | - |
|
83 | - /** |
|
84 | - * Return the identifier of this provider. |
|
85 | - * |
|
86 | - * @return string Containing only [a-zA-Z0-9] |
|
87 | - */ |
|
88 | - public function identifier() { |
|
89 | - return 'ocMailShare'; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * DefaultShareProvider constructor. |
|
94 | - * |
|
95 | - * @param IDBConnection $connection |
|
96 | - * @param ISecureRandom $secureRandom |
|
97 | - * @param IUserManager $userManager |
|
98 | - * @param IRootFolder $rootFolder |
|
99 | - * @param IL10N $l |
|
100 | - * @param ILogger $logger |
|
101 | - * @param IMailer $mailer |
|
102 | - * @param IURLGenerator $urlGenerator |
|
103 | - * @param IManager $activityManager |
|
104 | - * @param SettingsManager $settingsManager |
|
105 | - */ |
|
106 | - public function __construct( |
|
107 | - IDBConnection $connection, |
|
108 | - ISecureRandom $secureRandom, |
|
109 | - IUserManager $userManager, |
|
110 | - IRootFolder $rootFolder, |
|
111 | - IL10N $l, |
|
112 | - ILogger $logger, |
|
113 | - IMailer $mailer, |
|
114 | - IURLGenerator $urlGenerator, |
|
115 | - IManager $activityManager, |
|
116 | - SettingsManager $settingsManager |
|
117 | - ) { |
|
118 | - $this->dbConnection = $connection; |
|
119 | - $this->secureRandom = $secureRandom; |
|
120 | - $this->userManager = $userManager; |
|
121 | - $this->rootFolder = $rootFolder; |
|
122 | - $this->l = $l; |
|
123 | - $this->logger = $logger; |
|
124 | - $this->mailer = $mailer; |
|
125 | - $this->urlGenerator = $urlGenerator; |
|
126 | - $this->activityManager = $activityManager; |
|
127 | - $this->settingsManager = $settingsManager; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Share a path |
|
132 | - * |
|
133 | - * @param IShare $share |
|
134 | - * @return IShare The share object |
|
135 | - * @throws ShareNotFound |
|
136 | - * @throws \Exception |
|
137 | - */ |
|
138 | - public function create(IShare $share) { |
|
139 | - |
|
140 | - $shareWith = $share->getSharedWith(); |
|
141 | - /* |
|
53 | + /** @var IDBConnection */ |
|
54 | + private $dbConnection; |
|
55 | + |
|
56 | + /** @var ILogger */ |
|
57 | + private $logger; |
|
58 | + |
|
59 | + /** @var ISecureRandom */ |
|
60 | + private $secureRandom; |
|
61 | + |
|
62 | + /** @var IUserManager */ |
|
63 | + private $userManager; |
|
64 | + |
|
65 | + /** @var IRootFolder */ |
|
66 | + private $rootFolder; |
|
67 | + |
|
68 | + /** @var IL10N */ |
|
69 | + private $l; |
|
70 | + |
|
71 | + /** @var IMailer */ |
|
72 | + private $mailer; |
|
73 | + |
|
74 | + /** @var IURLGenerator */ |
|
75 | + private $urlGenerator; |
|
76 | + |
|
77 | + /** @var IManager */ |
|
78 | + private $activityManager; |
|
79 | + |
|
80 | + /** @var SettingsManager */ |
|
81 | + private $settingsManager; |
|
82 | + |
|
83 | + /** |
|
84 | + * Return the identifier of this provider. |
|
85 | + * |
|
86 | + * @return string Containing only [a-zA-Z0-9] |
|
87 | + */ |
|
88 | + public function identifier() { |
|
89 | + return 'ocMailShare'; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * DefaultShareProvider constructor. |
|
94 | + * |
|
95 | + * @param IDBConnection $connection |
|
96 | + * @param ISecureRandom $secureRandom |
|
97 | + * @param IUserManager $userManager |
|
98 | + * @param IRootFolder $rootFolder |
|
99 | + * @param IL10N $l |
|
100 | + * @param ILogger $logger |
|
101 | + * @param IMailer $mailer |
|
102 | + * @param IURLGenerator $urlGenerator |
|
103 | + * @param IManager $activityManager |
|
104 | + * @param SettingsManager $settingsManager |
|
105 | + */ |
|
106 | + public function __construct( |
|
107 | + IDBConnection $connection, |
|
108 | + ISecureRandom $secureRandom, |
|
109 | + IUserManager $userManager, |
|
110 | + IRootFolder $rootFolder, |
|
111 | + IL10N $l, |
|
112 | + ILogger $logger, |
|
113 | + IMailer $mailer, |
|
114 | + IURLGenerator $urlGenerator, |
|
115 | + IManager $activityManager, |
|
116 | + SettingsManager $settingsManager |
|
117 | + ) { |
|
118 | + $this->dbConnection = $connection; |
|
119 | + $this->secureRandom = $secureRandom; |
|
120 | + $this->userManager = $userManager; |
|
121 | + $this->rootFolder = $rootFolder; |
|
122 | + $this->l = $l; |
|
123 | + $this->logger = $logger; |
|
124 | + $this->mailer = $mailer; |
|
125 | + $this->urlGenerator = $urlGenerator; |
|
126 | + $this->activityManager = $activityManager; |
|
127 | + $this->settingsManager = $settingsManager; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Share a path |
|
132 | + * |
|
133 | + * @param IShare $share |
|
134 | + * @return IShare The share object |
|
135 | + * @throws ShareNotFound |
|
136 | + * @throws \Exception |
|
137 | + */ |
|
138 | + public function create(IShare $share) { |
|
139 | + |
|
140 | + $shareWith = $share->getSharedWith(); |
|
141 | + /* |
|
142 | 142 | * Check if file is not already shared with the remote user |
143 | 143 | */ |
144 | - $alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0); |
|
145 | - if (!empty($alreadyShared)) { |
|
146 | - $message = 'Sharing %s failed, this item is already shared with %s'; |
|
147 | - $message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
148 | - $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
149 | - throw new \Exception($message_t); |
|
150 | - } |
|
151 | - |
|
152 | - $shareId = $this->createMailShare($share); |
|
153 | - $this->createActivity($share); |
|
154 | - $data = $this->getRawShare($shareId); |
|
155 | - return $this->createShareObject($data); |
|
156 | - |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * create activity if a file/folder was shared by mail |
|
161 | - * |
|
162 | - * @param IShare $share |
|
163 | - */ |
|
164 | - protected function createActivity(IShare $share) { |
|
165 | - |
|
166 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
167 | - |
|
168 | - $this->publishActivity( |
|
169 | - Activity::SUBJECT_SHARED_EMAIL_SELF, |
|
170 | - [$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()], |
|
171 | - $share->getSharedBy(), |
|
172 | - $share->getNode()->getId(), |
|
173 | - $userFolder->getRelativePath($share->getNode()->getPath()) |
|
174 | - ); |
|
175 | - |
|
176 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
177 | - $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
178 | - $fileId = $share->getNode()->getId(); |
|
179 | - $nodes = $ownerFolder->getById($fileId); |
|
180 | - $ownerPath = $nodes[0]->getPath(); |
|
181 | - $this->publishActivity( |
|
182 | - Activity::SUBJECT_SHARED_EMAIL_BY, |
|
183 | - [$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()], |
|
184 | - $share->getShareOwner(), |
|
185 | - $fileId, |
|
186 | - $ownerFolder->getRelativePath($ownerPath) |
|
187 | - ); |
|
188 | - } |
|
189 | - |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * publish activity if a file/folder was shared by mail |
|
194 | - * |
|
195 | - * @param $subject |
|
196 | - * @param $parameters |
|
197 | - * @param $affectedUser |
|
198 | - * @param $fileId |
|
199 | - * @param $filePath |
|
200 | - */ |
|
201 | - protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
|
202 | - $event = $this->activityManager->generateEvent(); |
|
203 | - $event->setApp('sharebymail') |
|
204 | - ->setType('shared') |
|
205 | - ->setSubject($subject, $parameters) |
|
206 | - ->setAffectedUser($affectedUser) |
|
207 | - ->setObject('files', $fileId, $filePath); |
|
208 | - $this->activityManager->publish($event); |
|
209 | - |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * @param IShare $share |
|
214 | - * @return int |
|
215 | - * @throws \Exception |
|
216 | - */ |
|
217 | - protected function createMailShare(IShare $share) { |
|
218 | - $share->setToken($this->generateToken()); |
|
219 | - $shareId = $this->addShareToDB( |
|
220 | - $share->getNodeId(), |
|
221 | - $share->getNodeType(), |
|
222 | - $share->getSharedWith(), |
|
223 | - $share->getSharedBy(), |
|
224 | - $share->getShareOwner(), |
|
225 | - $share->getPermissions(), |
|
226 | - $share->getToken() |
|
227 | - ); |
|
228 | - |
|
229 | - try { |
|
230 | - $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', |
|
231 | - ['token' => $share->getToken()]); |
|
232 | - $this->sendMailNotification($share->getNode()->getName(), |
|
233 | - $link, |
|
234 | - $share->getShareOwner(), |
|
235 | - $share->getSharedBy(), $share->getSharedWith()); |
|
236 | - } catch (HintException $hintException) { |
|
237 | - $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); |
|
238 | - $this->removeShareFromTable($shareId); |
|
239 | - throw $hintException; |
|
240 | - } catch (\Exception $e) { |
|
241 | - $this->logger->error('Failed to send share by mail: ' . $e->getMessage()); |
|
242 | - $this->removeShareFromTable($shareId); |
|
243 | - throw new HintException('Failed to send share by mail', |
|
244 | - $this->l->t('Failed to send share by E-mail')); |
|
245 | - } |
|
246 | - |
|
247 | - return $shareId; |
|
248 | - |
|
249 | - } |
|
250 | - |
|
251 | - protected function sendMailNotification($filename, $link, $owner, $initiator, $shareWith) { |
|
252 | - $ownerUser = $this->userManager->get($owner); |
|
253 | - $initiatorUser = $this->userManager->get($initiator); |
|
254 | - $ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner; |
|
255 | - $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
256 | - if ($owner === $initiator) { |
|
257 | - $subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); |
|
258 | - } else { |
|
259 | - $subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName)); |
|
260 | - } |
|
261 | - |
|
262 | - $message = $this->mailer->createMessage(); |
|
263 | - $htmlBody = $this->createMailBody('mail', $filename, $link, $ownerDisplayName, $initiatorDisplayName); |
|
264 | - $textBody = $this->createMailBody('altmail', $filename, $link, $ownerDisplayName, $initiatorDisplayName); |
|
265 | - $message->setTo([$shareWith]); |
|
266 | - $message->setSubject($subject); |
|
267 | - $message->setBody($textBody, 'text/plain'); |
|
268 | - $message->setHtmlBody($htmlBody); |
|
269 | - $this->mailer->send($message); |
|
270 | - |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * create mail body |
|
275 | - * |
|
276 | - * @param $filename |
|
277 | - * @param $link |
|
278 | - * @param $owner |
|
279 | - * @param $initiator |
|
280 | - * @return string plain text mail |
|
281 | - * @throws HintException |
|
282 | - */ |
|
283 | - protected function createMailBody($template, $filename, $link, $owner, $initiator) { |
|
284 | - |
|
285 | - $mailBodyTemplate = new Template('sharebymail', $template, ''); |
|
286 | - $mailBodyTemplate->assign ('filename', \OCP\Util::sanitizeHTML($filename)); |
|
287 | - $mailBodyTemplate->assign ('link', $link); |
|
288 | - $mailBodyTemplate->assign ('owner', \OCP\Util::sanitizeHTML($owner)); |
|
289 | - $mailBodyTemplate->assign ('initiator', \OCP\Util::sanitizeHTML($initiator)); |
|
290 | - $mailBodyTemplate->assign ('onBehalfOf', $initiator !== $owner); |
|
291 | - $mailBody = $mailBodyTemplate->fetchPage(); |
|
292 | - |
|
293 | - if (is_string($mailBody)) { |
|
294 | - return $mailBody; |
|
295 | - } |
|
296 | - |
|
297 | - throw new HintException('Failed to create the E-mail', |
|
298 | - $this->l->t('Failed to create the E-mail')); |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * send password to recipient of a mail share |
|
303 | - * |
|
304 | - * @param string $filename |
|
305 | - * @param string $initiator |
|
306 | - * @param string $shareWith |
|
307 | - */ |
|
308 | - protected function sendPassword($filename, $initiator, $shareWith, $password) { |
|
309 | - |
|
310 | - if ($this->settingsManager->sendPasswordByMail() === false) { |
|
311 | - return; |
|
312 | - } |
|
313 | - |
|
314 | - $initiatorUser = $this->userManager->get($initiator); |
|
315 | - $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
316 | - $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
317 | - |
|
318 | - $message = $this->mailer->createMessage(); |
|
319 | - $htmlBody = $this->createMailBodyToSendPassword('mailpassword', $filename, $initiatorDisplayName, $password); |
|
320 | - $textBody = $this->createMailBodyToSendPassword('altmailpassword', $filename,$initiatorDisplayName, $password); |
|
321 | - $message->setTo([$shareWith]); |
|
322 | - $message->setSubject($subject); |
|
323 | - $message->setBody($textBody, 'text/plain'); |
|
324 | - $message->setHtmlBody($htmlBody); |
|
325 | - $this->mailer->send($message); |
|
326 | - |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * create mail body to send password to recipient |
|
331 | - * |
|
332 | - * @param string $filename |
|
333 | - * @param string $initiator |
|
334 | - * @param string $password |
|
335 | - * @return string plain text mail |
|
336 | - * @throws HintException |
|
337 | - */ |
|
338 | - protected function createMailBodyToSendPassword($template, $filename, $initiator, $password) { |
|
339 | - |
|
340 | - $mailBodyTemplate = new Template('sharebymail', $template, ''); |
|
341 | - $mailBodyTemplate->assign ('filename', \OCP\Util::sanitizeHTML($filename)); |
|
342 | - $mailBodyTemplate->assign ('password', \OCP\Util::sanitizeHTML($password)); |
|
343 | - $mailBodyTemplate->assign ('initiator', \OCP\Util::sanitizeHTML($initiator)); |
|
344 | - $mailBody = $mailBodyTemplate->fetchPage(); |
|
345 | - |
|
346 | - if (is_string($mailBody)) { |
|
347 | - return $mailBody; |
|
348 | - } |
|
349 | - |
|
350 | - throw new HintException('Failed to create the E-mail', |
|
351 | - $this->l->t('Failed to create the E-mail')); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * generate share token |
|
357 | - * |
|
358 | - * @return string |
|
359 | - */ |
|
360 | - protected function generateToken() { |
|
361 | - $token = $this->secureRandom->generate( |
|
362 | - 15, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
363 | - return $token; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Get all children of this share |
|
368 | - * |
|
369 | - * @param IShare $parent |
|
370 | - * @return IShare[] |
|
371 | - */ |
|
372 | - public function getChildren(IShare $parent) { |
|
373 | - $children = []; |
|
374 | - |
|
375 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
376 | - $qb->select('*') |
|
377 | - ->from('share') |
|
378 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
379 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
380 | - ->orderBy('id'); |
|
381 | - |
|
382 | - $cursor = $qb->execute(); |
|
383 | - while($data = $cursor->fetch()) { |
|
384 | - $children[] = $this->createShareObject($data); |
|
385 | - } |
|
386 | - $cursor->closeCursor(); |
|
387 | - |
|
388 | - return $children; |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * add share to the database and return the ID |
|
393 | - * |
|
394 | - * @param int $itemSource |
|
395 | - * @param string $itemType |
|
396 | - * @param string $shareWith |
|
397 | - * @param string $sharedBy |
|
398 | - * @param string $uidOwner |
|
399 | - * @param int $permissions |
|
400 | - * @param string $token |
|
401 | - * @return int |
|
402 | - */ |
|
403 | - protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) { |
|
404 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
405 | - $qb->insert('share') |
|
406 | - ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
407 | - ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
408 | - ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
409 | - ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
410 | - ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
411 | - ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
412 | - ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
413 | - ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
414 | - ->setValue('token', $qb->createNamedParameter($token)) |
|
415 | - ->setValue('stime', $qb->createNamedParameter(time())); |
|
416 | - |
|
417 | - /* |
|
144 | + $alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0); |
|
145 | + if (!empty($alreadyShared)) { |
|
146 | + $message = 'Sharing %s failed, this item is already shared with %s'; |
|
147 | + $message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
148 | + $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
149 | + throw new \Exception($message_t); |
|
150 | + } |
|
151 | + |
|
152 | + $shareId = $this->createMailShare($share); |
|
153 | + $this->createActivity($share); |
|
154 | + $data = $this->getRawShare($shareId); |
|
155 | + return $this->createShareObject($data); |
|
156 | + |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * create activity if a file/folder was shared by mail |
|
161 | + * |
|
162 | + * @param IShare $share |
|
163 | + */ |
|
164 | + protected function createActivity(IShare $share) { |
|
165 | + |
|
166 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
167 | + |
|
168 | + $this->publishActivity( |
|
169 | + Activity::SUBJECT_SHARED_EMAIL_SELF, |
|
170 | + [$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()], |
|
171 | + $share->getSharedBy(), |
|
172 | + $share->getNode()->getId(), |
|
173 | + $userFolder->getRelativePath($share->getNode()->getPath()) |
|
174 | + ); |
|
175 | + |
|
176 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
177 | + $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
178 | + $fileId = $share->getNode()->getId(); |
|
179 | + $nodes = $ownerFolder->getById($fileId); |
|
180 | + $ownerPath = $nodes[0]->getPath(); |
|
181 | + $this->publishActivity( |
|
182 | + Activity::SUBJECT_SHARED_EMAIL_BY, |
|
183 | + [$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()], |
|
184 | + $share->getShareOwner(), |
|
185 | + $fileId, |
|
186 | + $ownerFolder->getRelativePath($ownerPath) |
|
187 | + ); |
|
188 | + } |
|
189 | + |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * publish activity if a file/folder was shared by mail |
|
194 | + * |
|
195 | + * @param $subject |
|
196 | + * @param $parameters |
|
197 | + * @param $affectedUser |
|
198 | + * @param $fileId |
|
199 | + * @param $filePath |
|
200 | + */ |
|
201 | + protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
|
202 | + $event = $this->activityManager->generateEvent(); |
|
203 | + $event->setApp('sharebymail') |
|
204 | + ->setType('shared') |
|
205 | + ->setSubject($subject, $parameters) |
|
206 | + ->setAffectedUser($affectedUser) |
|
207 | + ->setObject('files', $fileId, $filePath); |
|
208 | + $this->activityManager->publish($event); |
|
209 | + |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * @param IShare $share |
|
214 | + * @return int |
|
215 | + * @throws \Exception |
|
216 | + */ |
|
217 | + protected function createMailShare(IShare $share) { |
|
218 | + $share->setToken($this->generateToken()); |
|
219 | + $shareId = $this->addShareToDB( |
|
220 | + $share->getNodeId(), |
|
221 | + $share->getNodeType(), |
|
222 | + $share->getSharedWith(), |
|
223 | + $share->getSharedBy(), |
|
224 | + $share->getShareOwner(), |
|
225 | + $share->getPermissions(), |
|
226 | + $share->getToken() |
|
227 | + ); |
|
228 | + |
|
229 | + try { |
|
230 | + $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', |
|
231 | + ['token' => $share->getToken()]); |
|
232 | + $this->sendMailNotification($share->getNode()->getName(), |
|
233 | + $link, |
|
234 | + $share->getShareOwner(), |
|
235 | + $share->getSharedBy(), $share->getSharedWith()); |
|
236 | + } catch (HintException $hintException) { |
|
237 | + $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); |
|
238 | + $this->removeShareFromTable($shareId); |
|
239 | + throw $hintException; |
|
240 | + } catch (\Exception $e) { |
|
241 | + $this->logger->error('Failed to send share by mail: ' . $e->getMessage()); |
|
242 | + $this->removeShareFromTable($shareId); |
|
243 | + throw new HintException('Failed to send share by mail', |
|
244 | + $this->l->t('Failed to send share by E-mail')); |
|
245 | + } |
|
246 | + |
|
247 | + return $shareId; |
|
248 | + |
|
249 | + } |
|
250 | + |
|
251 | + protected function sendMailNotification($filename, $link, $owner, $initiator, $shareWith) { |
|
252 | + $ownerUser = $this->userManager->get($owner); |
|
253 | + $initiatorUser = $this->userManager->get($initiator); |
|
254 | + $ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner; |
|
255 | + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
256 | + if ($owner === $initiator) { |
|
257 | + $subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); |
|
258 | + } else { |
|
259 | + $subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName)); |
|
260 | + } |
|
261 | + |
|
262 | + $message = $this->mailer->createMessage(); |
|
263 | + $htmlBody = $this->createMailBody('mail', $filename, $link, $ownerDisplayName, $initiatorDisplayName); |
|
264 | + $textBody = $this->createMailBody('altmail', $filename, $link, $ownerDisplayName, $initiatorDisplayName); |
|
265 | + $message->setTo([$shareWith]); |
|
266 | + $message->setSubject($subject); |
|
267 | + $message->setBody($textBody, 'text/plain'); |
|
268 | + $message->setHtmlBody($htmlBody); |
|
269 | + $this->mailer->send($message); |
|
270 | + |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * create mail body |
|
275 | + * |
|
276 | + * @param $filename |
|
277 | + * @param $link |
|
278 | + * @param $owner |
|
279 | + * @param $initiator |
|
280 | + * @return string plain text mail |
|
281 | + * @throws HintException |
|
282 | + */ |
|
283 | + protected function createMailBody($template, $filename, $link, $owner, $initiator) { |
|
284 | + |
|
285 | + $mailBodyTemplate = new Template('sharebymail', $template, ''); |
|
286 | + $mailBodyTemplate->assign ('filename', \OCP\Util::sanitizeHTML($filename)); |
|
287 | + $mailBodyTemplate->assign ('link', $link); |
|
288 | + $mailBodyTemplate->assign ('owner', \OCP\Util::sanitizeHTML($owner)); |
|
289 | + $mailBodyTemplate->assign ('initiator', \OCP\Util::sanitizeHTML($initiator)); |
|
290 | + $mailBodyTemplate->assign ('onBehalfOf', $initiator !== $owner); |
|
291 | + $mailBody = $mailBodyTemplate->fetchPage(); |
|
292 | + |
|
293 | + if (is_string($mailBody)) { |
|
294 | + return $mailBody; |
|
295 | + } |
|
296 | + |
|
297 | + throw new HintException('Failed to create the E-mail', |
|
298 | + $this->l->t('Failed to create the E-mail')); |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * send password to recipient of a mail share |
|
303 | + * |
|
304 | + * @param string $filename |
|
305 | + * @param string $initiator |
|
306 | + * @param string $shareWith |
|
307 | + */ |
|
308 | + protected function sendPassword($filename, $initiator, $shareWith, $password) { |
|
309 | + |
|
310 | + if ($this->settingsManager->sendPasswordByMail() === false) { |
|
311 | + return; |
|
312 | + } |
|
313 | + |
|
314 | + $initiatorUser = $this->userManager->get($initiator); |
|
315 | + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
316 | + $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
317 | + |
|
318 | + $message = $this->mailer->createMessage(); |
|
319 | + $htmlBody = $this->createMailBodyToSendPassword('mailpassword', $filename, $initiatorDisplayName, $password); |
|
320 | + $textBody = $this->createMailBodyToSendPassword('altmailpassword', $filename,$initiatorDisplayName, $password); |
|
321 | + $message->setTo([$shareWith]); |
|
322 | + $message->setSubject($subject); |
|
323 | + $message->setBody($textBody, 'text/plain'); |
|
324 | + $message->setHtmlBody($htmlBody); |
|
325 | + $this->mailer->send($message); |
|
326 | + |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * create mail body to send password to recipient |
|
331 | + * |
|
332 | + * @param string $filename |
|
333 | + * @param string $initiator |
|
334 | + * @param string $password |
|
335 | + * @return string plain text mail |
|
336 | + * @throws HintException |
|
337 | + */ |
|
338 | + protected function createMailBodyToSendPassword($template, $filename, $initiator, $password) { |
|
339 | + |
|
340 | + $mailBodyTemplate = new Template('sharebymail', $template, ''); |
|
341 | + $mailBodyTemplate->assign ('filename', \OCP\Util::sanitizeHTML($filename)); |
|
342 | + $mailBodyTemplate->assign ('password', \OCP\Util::sanitizeHTML($password)); |
|
343 | + $mailBodyTemplate->assign ('initiator', \OCP\Util::sanitizeHTML($initiator)); |
|
344 | + $mailBody = $mailBodyTemplate->fetchPage(); |
|
345 | + |
|
346 | + if (is_string($mailBody)) { |
|
347 | + return $mailBody; |
|
348 | + } |
|
349 | + |
|
350 | + throw new HintException('Failed to create the E-mail', |
|
351 | + $this->l->t('Failed to create the E-mail')); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * generate share token |
|
357 | + * |
|
358 | + * @return string |
|
359 | + */ |
|
360 | + protected function generateToken() { |
|
361 | + $token = $this->secureRandom->generate( |
|
362 | + 15, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
363 | + return $token; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Get all children of this share |
|
368 | + * |
|
369 | + * @param IShare $parent |
|
370 | + * @return IShare[] |
|
371 | + */ |
|
372 | + public function getChildren(IShare $parent) { |
|
373 | + $children = []; |
|
374 | + |
|
375 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
376 | + $qb->select('*') |
|
377 | + ->from('share') |
|
378 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
379 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
380 | + ->orderBy('id'); |
|
381 | + |
|
382 | + $cursor = $qb->execute(); |
|
383 | + while($data = $cursor->fetch()) { |
|
384 | + $children[] = $this->createShareObject($data); |
|
385 | + } |
|
386 | + $cursor->closeCursor(); |
|
387 | + |
|
388 | + return $children; |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * add share to the database and return the ID |
|
393 | + * |
|
394 | + * @param int $itemSource |
|
395 | + * @param string $itemType |
|
396 | + * @param string $shareWith |
|
397 | + * @param string $sharedBy |
|
398 | + * @param string $uidOwner |
|
399 | + * @param int $permissions |
|
400 | + * @param string $token |
|
401 | + * @return int |
|
402 | + */ |
|
403 | + protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) { |
|
404 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
405 | + $qb->insert('share') |
|
406 | + ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
407 | + ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
408 | + ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
409 | + ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
410 | + ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
411 | + ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
412 | + ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
413 | + ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
414 | + ->setValue('token', $qb->createNamedParameter($token)) |
|
415 | + ->setValue('stime', $qb->createNamedParameter(time())); |
|
416 | + |
|
417 | + /* |
|
418 | 418 | * Added to fix https://github.com/owncloud/core/issues/22215 |
419 | 419 | * Can be removed once we get rid of ajax/share.php |
420 | 420 | */ |
421 | - $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
421 | + $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
422 | 422 | |
423 | - $qb->execute(); |
|
424 | - $id = $qb->getLastInsertId(); |
|
423 | + $qb->execute(); |
|
424 | + $id = $qb->getLastInsertId(); |
|
425 | 425 | |
426 | - return (int)$id; |
|
427 | - } |
|
426 | + return (int)$id; |
|
427 | + } |
|
428 | 428 | |
429 | - /** |
|
430 | - * Update a share |
|
431 | - * |
|
432 | - * @param IShare $share |
|
433 | - * @param string|null $plainTextPassword |
|
434 | - * @return IShare The share object |
|
435 | - */ |
|
436 | - public function update(IShare $share, $plainTextPassword = null) { |
|
429 | + /** |
|
430 | + * Update a share |
|
431 | + * |
|
432 | + * @param IShare $share |
|
433 | + * @param string|null $plainTextPassword |
|
434 | + * @return IShare The share object |
|
435 | + */ |
|
436 | + public function update(IShare $share, $plainTextPassword = null) { |
|
437 | 437 | |
438 | - $originalShare = $this->getShareById($share->getId()); |
|
438 | + $originalShare = $this->getShareById($share->getId()); |
|
439 | 439 | |
440 | - // a real password was given |
|
441 | - $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
|
440 | + // a real password was given |
|
441 | + $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
|
442 | 442 | |
443 | - if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
444 | - $this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $plainTextPassword); |
|
445 | - } |
|
446 | - /* |
|
443 | + if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
444 | + $this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $plainTextPassword); |
|
445 | + } |
|
446 | + /* |
|
447 | 447 | * We allow updating the permissions and password of mail shares |
448 | 448 | */ |
449 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
450 | - $qb->update('share') |
|
451 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
452 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
453 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
454 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
455 | - ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
456 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
457 | - ->execute(); |
|
458 | - |
|
459 | - return $share; |
|
460 | - } |
|
461 | - |
|
462 | - /** |
|
463 | - * @inheritdoc |
|
464 | - */ |
|
465 | - public function move(IShare $share, $recipient) { |
|
466 | - /** |
|
467 | - * nothing to do here, mail shares are only outgoing shares |
|
468 | - */ |
|
469 | - return $share; |
|
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * Delete a share (owner unShares the file) |
|
474 | - * |
|
475 | - * @param IShare $share |
|
476 | - */ |
|
477 | - public function delete(IShare $share) { |
|
478 | - $this->removeShareFromTable($share->getId()); |
|
479 | - } |
|
480 | - |
|
481 | - /** |
|
482 | - * @inheritdoc |
|
483 | - */ |
|
484 | - public function deleteFromSelf(IShare $share, $recipient) { |
|
485 | - // nothing to do here, mail shares are only outgoing shares |
|
486 | - return; |
|
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * @inheritdoc |
|
491 | - */ |
|
492 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
493 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
494 | - $qb->select('*') |
|
495 | - ->from('share'); |
|
496 | - |
|
497 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
498 | - |
|
499 | - /** |
|
500 | - * Reshares for this user are shares where they are the owner. |
|
501 | - */ |
|
502 | - if ($reshares === false) { |
|
503 | - //Special case for old shares created via the web UI |
|
504 | - $or1 = $qb->expr()->andX( |
|
505 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
506 | - $qb->expr()->isNull('uid_initiator') |
|
507 | - ); |
|
508 | - |
|
509 | - $qb->andWhere( |
|
510 | - $qb->expr()->orX( |
|
511 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
512 | - $or1 |
|
513 | - ) |
|
514 | - ); |
|
515 | - } else { |
|
516 | - $qb->andWhere( |
|
517 | - $qb->expr()->orX( |
|
518 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
519 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
520 | - ) |
|
521 | - ); |
|
522 | - } |
|
523 | - |
|
524 | - if ($node !== null) { |
|
525 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
526 | - } |
|
527 | - |
|
528 | - if ($limit !== -1) { |
|
529 | - $qb->setMaxResults($limit); |
|
530 | - } |
|
531 | - |
|
532 | - $qb->setFirstResult($offset); |
|
533 | - $qb->orderBy('id'); |
|
534 | - |
|
535 | - $cursor = $qb->execute(); |
|
536 | - $shares = []; |
|
537 | - while($data = $cursor->fetch()) { |
|
538 | - $shares[] = $this->createShareObject($data); |
|
539 | - } |
|
540 | - $cursor->closeCursor(); |
|
541 | - |
|
542 | - return $shares; |
|
543 | - } |
|
544 | - |
|
545 | - /** |
|
546 | - * @inheritdoc |
|
547 | - */ |
|
548 | - public function getShareById($id, $recipientId = null) { |
|
549 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
550 | - |
|
551 | - $qb->select('*') |
|
552 | - ->from('share') |
|
553 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
554 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
555 | - |
|
556 | - $cursor = $qb->execute(); |
|
557 | - $data = $cursor->fetch(); |
|
558 | - $cursor->closeCursor(); |
|
559 | - |
|
560 | - if ($data === false) { |
|
561 | - throw new ShareNotFound(); |
|
562 | - } |
|
563 | - |
|
564 | - try { |
|
565 | - $share = $this->createShareObject($data); |
|
566 | - } catch (InvalidShare $e) { |
|
567 | - throw new ShareNotFound(); |
|
568 | - } |
|
569 | - |
|
570 | - return $share; |
|
571 | - } |
|
572 | - |
|
573 | - /** |
|
574 | - * Get shares for a given path |
|
575 | - * |
|
576 | - * @param \OCP\Files\Node $path |
|
577 | - * @return IShare[] |
|
578 | - */ |
|
579 | - public function getSharesByPath(Node $path) { |
|
580 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
581 | - |
|
582 | - $cursor = $qb->select('*') |
|
583 | - ->from('share') |
|
584 | - ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
585 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
586 | - ->execute(); |
|
587 | - |
|
588 | - $shares = []; |
|
589 | - while($data = $cursor->fetch()) { |
|
590 | - $shares[] = $this->createShareObject($data); |
|
591 | - } |
|
592 | - $cursor->closeCursor(); |
|
593 | - |
|
594 | - return $shares; |
|
595 | - } |
|
596 | - |
|
597 | - /** |
|
598 | - * @inheritdoc |
|
599 | - */ |
|
600 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
601 | - /** @var IShare[] $shares */ |
|
602 | - $shares = []; |
|
603 | - |
|
604 | - //Get shares directly with this user |
|
605 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
606 | - $qb->select('*') |
|
607 | - ->from('share'); |
|
608 | - |
|
609 | - // Order by id |
|
610 | - $qb->orderBy('id'); |
|
611 | - |
|
612 | - // Set limit and offset |
|
613 | - if ($limit !== -1) { |
|
614 | - $qb->setMaxResults($limit); |
|
615 | - } |
|
616 | - $qb->setFirstResult($offset); |
|
617 | - |
|
618 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
619 | - $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
620 | - |
|
621 | - // Filter by node if provided |
|
622 | - if ($node !== null) { |
|
623 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
624 | - } |
|
625 | - |
|
626 | - $cursor = $qb->execute(); |
|
627 | - |
|
628 | - while($data = $cursor->fetch()) { |
|
629 | - $shares[] = $this->createShareObject($data); |
|
630 | - } |
|
631 | - $cursor->closeCursor(); |
|
632 | - |
|
633 | - |
|
634 | - return $shares; |
|
635 | - } |
|
636 | - |
|
637 | - /** |
|
638 | - * Get a share by token |
|
639 | - * |
|
640 | - * @param string $token |
|
641 | - * @return IShare |
|
642 | - * @throws ShareNotFound |
|
643 | - */ |
|
644 | - public function getShareByToken($token) { |
|
645 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
646 | - |
|
647 | - $cursor = $qb->select('*') |
|
648 | - ->from('share') |
|
649 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
650 | - ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
651 | - ->execute(); |
|
652 | - |
|
653 | - $data = $cursor->fetch(); |
|
654 | - |
|
655 | - if ($data === false) { |
|
656 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
657 | - } |
|
658 | - |
|
659 | - try { |
|
660 | - $share = $this->createShareObject($data); |
|
661 | - } catch (InvalidShare $e) { |
|
662 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
663 | - } |
|
664 | - |
|
665 | - return $share; |
|
666 | - } |
|
667 | - |
|
668 | - /** |
|
669 | - * remove share from table |
|
670 | - * |
|
671 | - * @param string $shareId |
|
672 | - */ |
|
673 | - protected function removeShareFromTable($shareId) { |
|
674 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
675 | - $qb->delete('share') |
|
676 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
677 | - $qb->execute(); |
|
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * Create a share object from an database row |
|
682 | - * |
|
683 | - * @param array $data |
|
684 | - * @return IShare |
|
685 | - * @throws InvalidShare |
|
686 | - * @throws ShareNotFound |
|
687 | - */ |
|
688 | - protected function createShareObject($data) { |
|
689 | - |
|
690 | - $share = new Share($this->rootFolder, $this->userManager); |
|
691 | - $share->setId((int)$data['id']) |
|
692 | - ->setShareType((int)$data['share_type']) |
|
693 | - ->setPermissions((int)$data['permissions']) |
|
694 | - ->setTarget($data['file_target']) |
|
695 | - ->setMailSend((bool)$data['mail_send']) |
|
696 | - ->setToken($data['token']); |
|
697 | - |
|
698 | - $shareTime = new \DateTime(); |
|
699 | - $shareTime->setTimestamp((int)$data['stime']); |
|
700 | - $share->setShareTime($shareTime); |
|
701 | - $share->setSharedWith($data['share_with']); |
|
702 | - $share->setPassword($data['password']); |
|
703 | - |
|
704 | - if ($data['uid_initiator'] !== null) { |
|
705 | - $share->setShareOwner($data['uid_owner']); |
|
706 | - $share->setSharedBy($data['uid_initiator']); |
|
707 | - } else { |
|
708 | - //OLD SHARE |
|
709 | - $share->setSharedBy($data['uid_owner']); |
|
710 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
711 | - |
|
712 | - $owner = $path->getOwner(); |
|
713 | - $share->setShareOwner($owner->getUID()); |
|
714 | - } |
|
715 | - |
|
716 | - if ($data['expiration'] !== null) { |
|
717 | - $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
718 | - if ($expiration !== false) { |
|
719 | - $share->setExpirationDate($expiration); |
|
720 | - } |
|
721 | - } |
|
722 | - |
|
723 | - $share->setNodeId((int)$data['file_source']); |
|
724 | - $share->setNodeType($data['item_type']); |
|
725 | - |
|
726 | - $share->setProviderId($this->identifier()); |
|
727 | - |
|
728 | - return $share; |
|
729 | - } |
|
730 | - |
|
731 | - /** |
|
732 | - * Get the node with file $id for $user |
|
733 | - * |
|
734 | - * @param string $userId |
|
735 | - * @param int $id |
|
736 | - * @return \OCP\Files\File|\OCP\Files\Folder |
|
737 | - * @throws InvalidShare |
|
738 | - */ |
|
739 | - private function getNode($userId, $id) { |
|
740 | - try { |
|
741 | - $userFolder = $this->rootFolder->getUserFolder($userId); |
|
742 | - } catch (NotFoundException $e) { |
|
743 | - throw new InvalidShare(); |
|
744 | - } |
|
745 | - |
|
746 | - $nodes = $userFolder->getById($id); |
|
747 | - |
|
748 | - if (empty($nodes)) { |
|
749 | - throw new InvalidShare(); |
|
750 | - } |
|
751 | - |
|
752 | - return $nodes[0]; |
|
753 | - } |
|
754 | - |
|
755 | - /** |
|
756 | - * A user is deleted from the system |
|
757 | - * So clean up the relevant shares. |
|
758 | - * |
|
759 | - * @param string $uid |
|
760 | - * @param int $shareType |
|
761 | - */ |
|
762 | - public function userDeleted($uid, $shareType) { |
|
763 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
764 | - |
|
765 | - $qb->delete('share') |
|
766 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
767 | - ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
768 | - ->execute(); |
|
769 | - } |
|
770 | - |
|
771 | - /** |
|
772 | - * This provider does not support group shares |
|
773 | - * |
|
774 | - * @param string $gid |
|
775 | - */ |
|
776 | - public function groupDeleted($gid) { |
|
777 | - return; |
|
778 | - } |
|
779 | - |
|
780 | - /** |
|
781 | - * This provider does not support group shares |
|
782 | - * |
|
783 | - * @param string $uid |
|
784 | - * @param string $gid |
|
785 | - */ |
|
786 | - public function userDeletedFromGroup($uid, $gid) { |
|
787 | - return; |
|
788 | - } |
|
789 | - |
|
790 | - /** |
|
791 | - * get database row of a give share |
|
792 | - * |
|
793 | - * @param $id |
|
794 | - * @return array |
|
795 | - * @throws ShareNotFound |
|
796 | - */ |
|
797 | - protected function getRawShare($id) { |
|
798 | - |
|
799 | - // Now fetch the inserted share and create a complete share object |
|
800 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
801 | - $qb->select('*') |
|
802 | - ->from('share') |
|
803 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
804 | - |
|
805 | - $cursor = $qb->execute(); |
|
806 | - $data = $cursor->fetch(); |
|
807 | - $cursor->closeCursor(); |
|
808 | - |
|
809 | - if ($data === false) { |
|
810 | - throw new ShareNotFound; |
|
811 | - } |
|
812 | - |
|
813 | - return $data; |
|
814 | - } |
|
815 | - |
|
816 | - public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
817 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
818 | - $qb->select('*') |
|
819 | - ->from('share', 's') |
|
820 | - ->andWhere($qb->expr()->orX( |
|
821 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
822 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
823 | - )) |
|
824 | - ->andWhere( |
|
825 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
826 | - ); |
|
827 | - |
|
828 | - /** |
|
829 | - * Reshares for this user are shares where they are the owner. |
|
830 | - */ |
|
831 | - if ($reshares === false) { |
|
832 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
833 | - } else { |
|
834 | - $qb->andWhere( |
|
835 | - $qb->expr()->orX( |
|
836 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
837 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
838 | - ) |
|
839 | - ); |
|
840 | - } |
|
841 | - |
|
842 | - $qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid'); |
|
843 | - $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
844 | - |
|
845 | - $qb->orderBy('id'); |
|
846 | - |
|
847 | - $cursor = $qb->execute(); |
|
848 | - $shares = []; |
|
849 | - while ($data = $cursor->fetch()) { |
|
850 | - $shares[$data['fileid']][] = $this->createShareObject($data); |
|
851 | - } |
|
852 | - $cursor->closeCursor(); |
|
853 | - |
|
854 | - return $shares; |
|
855 | - } |
|
449 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
450 | + $qb->update('share') |
|
451 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
452 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
453 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
454 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
455 | + ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
456 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
457 | + ->execute(); |
|
458 | + |
|
459 | + return $share; |
|
460 | + } |
|
461 | + |
|
462 | + /** |
|
463 | + * @inheritdoc |
|
464 | + */ |
|
465 | + public function move(IShare $share, $recipient) { |
|
466 | + /** |
|
467 | + * nothing to do here, mail shares are only outgoing shares |
|
468 | + */ |
|
469 | + return $share; |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * Delete a share (owner unShares the file) |
|
474 | + * |
|
475 | + * @param IShare $share |
|
476 | + */ |
|
477 | + public function delete(IShare $share) { |
|
478 | + $this->removeShareFromTable($share->getId()); |
|
479 | + } |
|
480 | + |
|
481 | + /** |
|
482 | + * @inheritdoc |
|
483 | + */ |
|
484 | + public function deleteFromSelf(IShare $share, $recipient) { |
|
485 | + // nothing to do here, mail shares are only outgoing shares |
|
486 | + return; |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * @inheritdoc |
|
491 | + */ |
|
492 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
493 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
494 | + $qb->select('*') |
|
495 | + ->from('share'); |
|
496 | + |
|
497 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
498 | + |
|
499 | + /** |
|
500 | + * Reshares for this user are shares where they are the owner. |
|
501 | + */ |
|
502 | + if ($reshares === false) { |
|
503 | + //Special case for old shares created via the web UI |
|
504 | + $or1 = $qb->expr()->andX( |
|
505 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
506 | + $qb->expr()->isNull('uid_initiator') |
|
507 | + ); |
|
508 | + |
|
509 | + $qb->andWhere( |
|
510 | + $qb->expr()->orX( |
|
511 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
512 | + $or1 |
|
513 | + ) |
|
514 | + ); |
|
515 | + } else { |
|
516 | + $qb->andWhere( |
|
517 | + $qb->expr()->orX( |
|
518 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
519 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
520 | + ) |
|
521 | + ); |
|
522 | + } |
|
523 | + |
|
524 | + if ($node !== null) { |
|
525 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
526 | + } |
|
527 | + |
|
528 | + if ($limit !== -1) { |
|
529 | + $qb->setMaxResults($limit); |
|
530 | + } |
|
531 | + |
|
532 | + $qb->setFirstResult($offset); |
|
533 | + $qb->orderBy('id'); |
|
534 | + |
|
535 | + $cursor = $qb->execute(); |
|
536 | + $shares = []; |
|
537 | + while($data = $cursor->fetch()) { |
|
538 | + $shares[] = $this->createShareObject($data); |
|
539 | + } |
|
540 | + $cursor->closeCursor(); |
|
541 | + |
|
542 | + return $shares; |
|
543 | + } |
|
544 | + |
|
545 | + /** |
|
546 | + * @inheritdoc |
|
547 | + */ |
|
548 | + public function getShareById($id, $recipientId = null) { |
|
549 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
550 | + |
|
551 | + $qb->select('*') |
|
552 | + ->from('share') |
|
553 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
554 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
555 | + |
|
556 | + $cursor = $qb->execute(); |
|
557 | + $data = $cursor->fetch(); |
|
558 | + $cursor->closeCursor(); |
|
559 | + |
|
560 | + if ($data === false) { |
|
561 | + throw new ShareNotFound(); |
|
562 | + } |
|
563 | + |
|
564 | + try { |
|
565 | + $share = $this->createShareObject($data); |
|
566 | + } catch (InvalidShare $e) { |
|
567 | + throw new ShareNotFound(); |
|
568 | + } |
|
569 | + |
|
570 | + return $share; |
|
571 | + } |
|
572 | + |
|
573 | + /** |
|
574 | + * Get shares for a given path |
|
575 | + * |
|
576 | + * @param \OCP\Files\Node $path |
|
577 | + * @return IShare[] |
|
578 | + */ |
|
579 | + public function getSharesByPath(Node $path) { |
|
580 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
581 | + |
|
582 | + $cursor = $qb->select('*') |
|
583 | + ->from('share') |
|
584 | + ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
585 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
586 | + ->execute(); |
|
587 | + |
|
588 | + $shares = []; |
|
589 | + while($data = $cursor->fetch()) { |
|
590 | + $shares[] = $this->createShareObject($data); |
|
591 | + } |
|
592 | + $cursor->closeCursor(); |
|
593 | + |
|
594 | + return $shares; |
|
595 | + } |
|
596 | + |
|
597 | + /** |
|
598 | + * @inheritdoc |
|
599 | + */ |
|
600 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
601 | + /** @var IShare[] $shares */ |
|
602 | + $shares = []; |
|
603 | + |
|
604 | + //Get shares directly with this user |
|
605 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
606 | + $qb->select('*') |
|
607 | + ->from('share'); |
|
608 | + |
|
609 | + // Order by id |
|
610 | + $qb->orderBy('id'); |
|
611 | + |
|
612 | + // Set limit and offset |
|
613 | + if ($limit !== -1) { |
|
614 | + $qb->setMaxResults($limit); |
|
615 | + } |
|
616 | + $qb->setFirstResult($offset); |
|
617 | + |
|
618 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
619 | + $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
620 | + |
|
621 | + // Filter by node if provided |
|
622 | + if ($node !== null) { |
|
623 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
624 | + } |
|
625 | + |
|
626 | + $cursor = $qb->execute(); |
|
627 | + |
|
628 | + while($data = $cursor->fetch()) { |
|
629 | + $shares[] = $this->createShareObject($data); |
|
630 | + } |
|
631 | + $cursor->closeCursor(); |
|
632 | + |
|
633 | + |
|
634 | + return $shares; |
|
635 | + } |
|
636 | + |
|
637 | + /** |
|
638 | + * Get a share by token |
|
639 | + * |
|
640 | + * @param string $token |
|
641 | + * @return IShare |
|
642 | + * @throws ShareNotFound |
|
643 | + */ |
|
644 | + public function getShareByToken($token) { |
|
645 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
646 | + |
|
647 | + $cursor = $qb->select('*') |
|
648 | + ->from('share') |
|
649 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
650 | + ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
651 | + ->execute(); |
|
652 | + |
|
653 | + $data = $cursor->fetch(); |
|
654 | + |
|
655 | + if ($data === false) { |
|
656 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
657 | + } |
|
658 | + |
|
659 | + try { |
|
660 | + $share = $this->createShareObject($data); |
|
661 | + } catch (InvalidShare $e) { |
|
662 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
663 | + } |
|
664 | + |
|
665 | + return $share; |
|
666 | + } |
|
667 | + |
|
668 | + /** |
|
669 | + * remove share from table |
|
670 | + * |
|
671 | + * @param string $shareId |
|
672 | + */ |
|
673 | + protected function removeShareFromTable($shareId) { |
|
674 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
675 | + $qb->delete('share') |
|
676 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
677 | + $qb->execute(); |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * Create a share object from an database row |
|
682 | + * |
|
683 | + * @param array $data |
|
684 | + * @return IShare |
|
685 | + * @throws InvalidShare |
|
686 | + * @throws ShareNotFound |
|
687 | + */ |
|
688 | + protected function createShareObject($data) { |
|
689 | + |
|
690 | + $share = new Share($this->rootFolder, $this->userManager); |
|
691 | + $share->setId((int)$data['id']) |
|
692 | + ->setShareType((int)$data['share_type']) |
|
693 | + ->setPermissions((int)$data['permissions']) |
|
694 | + ->setTarget($data['file_target']) |
|
695 | + ->setMailSend((bool)$data['mail_send']) |
|
696 | + ->setToken($data['token']); |
|
697 | + |
|
698 | + $shareTime = new \DateTime(); |
|
699 | + $shareTime->setTimestamp((int)$data['stime']); |
|
700 | + $share->setShareTime($shareTime); |
|
701 | + $share->setSharedWith($data['share_with']); |
|
702 | + $share->setPassword($data['password']); |
|
703 | + |
|
704 | + if ($data['uid_initiator'] !== null) { |
|
705 | + $share->setShareOwner($data['uid_owner']); |
|
706 | + $share->setSharedBy($data['uid_initiator']); |
|
707 | + } else { |
|
708 | + //OLD SHARE |
|
709 | + $share->setSharedBy($data['uid_owner']); |
|
710 | + $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
711 | + |
|
712 | + $owner = $path->getOwner(); |
|
713 | + $share->setShareOwner($owner->getUID()); |
|
714 | + } |
|
715 | + |
|
716 | + if ($data['expiration'] !== null) { |
|
717 | + $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
718 | + if ($expiration !== false) { |
|
719 | + $share->setExpirationDate($expiration); |
|
720 | + } |
|
721 | + } |
|
722 | + |
|
723 | + $share->setNodeId((int)$data['file_source']); |
|
724 | + $share->setNodeType($data['item_type']); |
|
725 | + |
|
726 | + $share->setProviderId($this->identifier()); |
|
727 | + |
|
728 | + return $share; |
|
729 | + } |
|
730 | + |
|
731 | + /** |
|
732 | + * Get the node with file $id for $user |
|
733 | + * |
|
734 | + * @param string $userId |
|
735 | + * @param int $id |
|
736 | + * @return \OCP\Files\File|\OCP\Files\Folder |
|
737 | + * @throws InvalidShare |
|
738 | + */ |
|
739 | + private function getNode($userId, $id) { |
|
740 | + try { |
|
741 | + $userFolder = $this->rootFolder->getUserFolder($userId); |
|
742 | + } catch (NotFoundException $e) { |
|
743 | + throw new InvalidShare(); |
|
744 | + } |
|
745 | + |
|
746 | + $nodes = $userFolder->getById($id); |
|
747 | + |
|
748 | + if (empty($nodes)) { |
|
749 | + throw new InvalidShare(); |
|
750 | + } |
|
751 | + |
|
752 | + return $nodes[0]; |
|
753 | + } |
|
754 | + |
|
755 | + /** |
|
756 | + * A user is deleted from the system |
|
757 | + * So clean up the relevant shares. |
|
758 | + * |
|
759 | + * @param string $uid |
|
760 | + * @param int $shareType |
|
761 | + */ |
|
762 | + public function userDeleted($uid, $shareType) { |
|
763 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
764 | + |
|
765 | + $qb->delete('share') |
|
766 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
767 | + ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
768 | + ->execute(); |
|
769 | + } |
|
770 | + |
|
771 | + /** |
|
772 | + * This provider does not support group shares |
|
773 | + * |
|
774 | + * @param string $gid |
|
775 | + */ |
|
776 | + public function groupDeleted($gid) { |
|
777 | + return; |
|
778 | + } |
|
779 | + |
|
780 | + /** |
|
781 | + * This provider does not support group shares |
|
782 | + * |
|
783 | + * @param string $uid |
|
784 | + * @param string $gid |
|
785 | + */ |
|
786 | + public function userDeletedFromGroup($uid, $gid) { |
|
787 | + return; |
|
788 | + } |
|
789 | + |
|
790 | + /** |
|
791 | + * get database row of a give share |
|
792 | + * |
|
793 | + * @param $id |
|
794 | + * @return array |
|
795 | + * @throws ShareNotFound |
|
796 | + */ |
|
797 | + protected function getRawShare($id) { |
|
798 | + |
|
799 | + // Now fetch the inserted share and create a complete share object |
|
800 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
801 | + $qb->select('*') |
|
802 | + ->from('share') |
|
803 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
804 | + |
|
805 | + $cursor = $qb->execute(); |
|
806 | + $data = $cursor->fetch(); |
|
807 | + $cursor->closeCursor(); |
|
808 | + |
|
809 | + if ($data === false) { |
|
810 | + throw new ShareNotFound; |
|
811 | + } |
|
812 | + |
|
813 | + return $data; |
|
814 | + } |
|
815 | + |
|
816 | + public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
817 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
818 | + $qb->select('*') |
|
819 | + ->from('share', 's') |
|
820 | + ->andWhere($qb->expr()->orX( |
|
821 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
822 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
823 | + )) |
|
824 | + ->andWhere( |
|
825 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
826 | + ); |
|
827 | + |
|
828 | + /** |
|
829 | + * Reshares for this user are shares where they are the owner. |
|
830 | + */ |
|
831 | + if ($reshares === false) { |
|
832 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
833 | + } else { |
|
834 | + $qb->andWhere( |
|
835 | + $qb->expr()->orX( |
|
836 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
837 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
838 | + ) |
|
839 | + ); |
|
840 | + } |
|
841 | + |
|
842 | + $qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid'); |
|
843 | + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
844 | + |
|
845 | + $qb->orderBy('id'); |
|
846 | + |
|
847 | + $cursor = $qb->execute(); |
|
848 | + $shares = []; |
|
849 | + while ($data = $cursor->fetch()) { |
|
850 | + $shares[$data['fileid']][] = $this->createShareObject($data); |
|
851 | + } |
|
852 | + $cursor->closeCursor(); |
|
853 | + |
|
854 | + return $shares; |
|
855 | + } |
|
856 | 856 | |
857 | 857 | } |
@@ -234,11 +234,11 @@ discard block |
||
234 | 234 | $share->getShareOwner(), |
235 | 235 | $share->getSharedBy(), $share->getSharedWith()); |
236 | 236 | } catch (HintException $hintException) { |
237 | - $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); |
|
237 | + $this->logger->error('Failed to send share by mail: '.$hintException->getMessage()); |
|
238 | 238 | $this->removeShareFromTable($shareId); |
239 | 239 | throw $hintException; |
240 | 240 | } catch (\Exception $e) { |
241 | - $this->logger->error('Failed to send share by mail: ' . $e->getMessage()); |
|
241 | + $this->logger->error('Failed to send share by mail: '.$e->getMessage()); |
|
242 | 242 | $this->removeShareFromTable($shareId); |
243 | 243 | throw new HintException('Failed to send share by mail', |
244 | 244 | $this->l->t('Failed to send share by E-mail')); |
@@ -254,9 +254,9 @@ discard block |
||
254 | 254 | $ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner; |
255 | 255 | $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
256 | 256 | if ($owner === $initiator) { |
257 | - $subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); |
|
257 | + $subject = (string) $this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); |
|
258 | 258 | } else { |
259 | - $subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName)); |
|
259 | + $subject = (string) $this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName)); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | $message = $this->mailer->createMessage(); |
@@ -283,11 +283,11 @@ discard block |
||
283 | 283 | protected function createMailBody($template, $filename, $link, $owner, $initiator) { |
284 | 284 | |
285 | 285 | $mailBodyTemplate = new Template('sharebymail', $template, ''); |
286 | - $mailBodyTemplate->assign ('filename', \OCP\Util::sanitizeHTML($filename)); |
|
287 | - $mailBodyTemplate->assign ('link', $link); |
|
288 | - $mailBodyTemplate->assign ('owner', \OCP\Util::sanitizeHTML($owner)); |
|
289 | - $mailBodyTemplate->assign ('initiator', \OCP\Util::sanitizeHTML($initiator)); |
|
290 | - $mailBodyTemplate->assign ('onBehalfOf', $initiator !== $owner); |
|
286 | + $mailBodyTemplate->assign('filename', \OCP\Util::sanitizeHTML($filename)); |
|
287 | + $mailBodyTemplate->assign('link', $link); |
|
288 | + $mailBodyTemplate->assign('owner', \OCP\Util::sanitizeHTML($owner)); |
|
289 | + $mailBodyTemplate->assign('initiator', \OCP\Util::sanitizeHTML($initiator)); |
|
290 | + $mailBodyTemplate->assign('onBehalfOf', $initiator !== $owner); |
|
291 | 291 | $mailBody = $mailBodyTemplate->fetchPage(); |
292 | 292 | |
293 | 293 | if (is_string($mailBody)) { |
@@ -313,11 +313,11 @@ discard block |
||
313 | 313 | |
314 | 314 | $initiatorUser = $this->userManager->get($initiator); |
315 | 315 | $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
316 | - $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
316 | + $subject = (string) $this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
317 | 317 | |
318 | 318 | $message = $this->mailer->createMessage(); |
319 | 319 | $htmlBody = $this->createMailBodyToSendPassword('mailpassword', $filename, $initiatorDisplayName, $password); |
320 | - $textBody = $this->createMailBodyToSendPassword('altmailpassword', $filename,$initiatorDisplayName, $password); |
|
320 | + $textBody = $this->createMailBodyToSendPassword('altmailpassword', $filename, $initiatorDisplayName, $password); |
|
321 | 321 | $message->setTo([$shareWith]); |
322 | 322 | $message->setSubject($subject); |
323 | 323 | $message->setBody($textBody, 'text/plain'); |
@@ -338,9 +338,9 @@ discard block |
||
338 | 338 | protected function createMailBodyToSendPassword($template, $filename, $initiator, $password) { |
339 | 339 | |
340 | 340 | $mailBodyTemplate = new Template('sharebymail', $template, ''); |
341 | - $mailBodyTemplate->assign ('filename', \OCP\Util::sanitizeHTML($filename)); |
|
342 | - $mailBodyTemplate->assign ('password', \OCP\Util::sanitizeHTML($password)); |
|
343 | - $mailBodyTemplate->assign ('initiator', \OCP\Util::sanitizeHTML($initiator)); |
|
341 | + $mailBodyTemplate->assign('filename', \OCP\Util::sanitizeHTML($filename)); |
|
342 | + $mailBodyTemplate->assign('password', \OCP\Util::sanitizeHTML($password)); |
|
343 | + $mailBodyTemplate->assign('initiator', \OCP\Util::sanitizeHTML($initiator)); |
|
344 | 344 | $mailBody = $mailBodyTemplate->fetchPage(); |
345 | 345 | |
346 | 346 | if (is_string($mailBody)) { |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | */ |
360 | 360 | protected function generateToken() { |
361 | 361 | $token = $this->secureRandom->generate( |
362 | - 15, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
362 | + 15, ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS); |
|
363 | 363 | return $token; |
364 | 364 | } |
365 | 365 | |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | ->orderBy('id'); |
381 | 381 | |
382 | 382 | $cursor = $qb->execute(); |
383 | - while($data = $cursor->fetch()) { |
|
383 | + while ($data = $cursor->fetch()) { |
|
384 | 384 | $children[] = $this->createShareObject($data); |
385 | 385 | } |
386 | 386 | $cursor->closeCursor(); |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | $qb->execute(); |
424 | 424 | $id = $qb->getLastInsertId(); |
425 | 425 | |
426 | - return (int)$id; |
|
426 | + return (int) $id; |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | // a real password was given |
441 | 441 | $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
442 | 442 | |
443 | - if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
443 | + if ($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
444 | 444 | $this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $plainTextPassword); |
445 | 445 | } |
446 | 446 | /* |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | |
535 | 535 | $cursor = $qb->execute(); |
536 | 536 | $shares = []; |
537 | - while($data = $cursor->fetch()) { |
|
537 | + while ($data = $cursor->fetch()) { |
|
538 | 538 | $shares[] = $this->createShareObject($data); |
539 | 539 | } |
540 | 540 | $cursor->closeCursor(); |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | ->execute(); |
587 | 587 | |
588 | 588 | $shares = []; |
589 | - while($data = $cursor->fetch()) { |
|
589 | + while ($data = $cursor->fetch()) { |
|
590 | 590 | $shares[] = $this->createShareObject($data); |
591 | 591 | } |
592 | 592 | $cursor->closeCursor(); |
@@ -625,7 +625,7 @@ discard block |
||
625 | 625 | |
626 | 626 | $cursor = $qb->execute(); |
627 | 627 | |
628 | - while($data = $cursor->fetch()) { |
|
628 | + while ($data = $cursor->fetch()) { |
|
629 | 629 | $shares[] = $this->createShareObject($data); |
630 | 630 | } |
631 | 631 | $cursor->closeCursor(); |
@@ -688,15 +688,15 @@ discard block |
||
688 | 688 | protected function createShareObject($data) { |
689 | 689 | |
690 | 690 | $share = new Share($this->rootFolder, $this->userManager); |
691 | - $share->setId((int)$data['id']) |
|
692 | - ->setShareType((int)$data['share_type']) |
|
693 | - ->setPermissions((int)$data['permissions']) |
|
691 | + $share->setId((int) $data['id']) |
|
692 | + ->setShareType((int) $data['share_type']) |
|
693 | + ->setPermissions((int) $data['permissions']) |
|
694 | 694 | ->setTarget($data['file_target']) |
695 | - ->setMailSend((bool)$data['mail_send']) |
|
695 | + ->setMailSend((bool) $data['mail_send']) |
|
696 | 696 | ->setToken($data['token']); |
697 | 697 | |
698 | 698 | $shareTime = new \DateTime(); |
699 | - $shareTime->setTimestamp((int)$data['stime']); |
|
699 | + $shareTime->setTimestamp((int) $data['stime']); |
|
700 | 700 | $share->setShareTime($shareTime); |
701 | 701 | $share->setSharedWith($data['share_with']); |
702 | 702 | $share->setPassword($data['password']); |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | } else { |
708 | 708 | //OLD SHARE |
709 | 709 | $share->setSharedBy($data['uid_owner']); |
710 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
710 | + $path = $this->getNode($share->getSharedBy(), (int) $data['file_source']); |
|
711 | 711 | |
712 | 712 | $owner = $path->getOwner(); |
713 | 713 | $share->setShareOwner($owner->getUID()); |
@@ -720,7 +720,7 @@ discard block |
||
720 | 720 | } |
721 | 721 | } |
722 | 722 | |
723 | - $share->setNodeId((int)$data['file_source']); |
|
723 | + $share->setNodeId((int) $data['file_source']); |
|
724 | 724 | $share->setNodeType($data['item_type']); |
725 | 725 | |
726 | 726 | $share->setProviderId($this->identifier()); |
@@ -839,7 +839,7 @@ discard block |
||
839 | 839 | ); |
840 | 840 | } |
841 | 841 | |
842 | - $qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid'); |
|
842 | + $qb->innerJoin('s', 'filecache', 'f', 's.file_source = f.fileid'); |
|
843 | 843 | $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
844 | 844 | |
845 | 845 | $qb->orderBy('id'); |
@@ -41,225 +41,225 @@ |
||
41 | 41 | */ |
42 | 42 | class ProviderFactory implements IProviderFactory { |
43 | 43 | |
44 | - /** @var IServerContainer */ |
|
45 | - private $serverContainer; |
|
46 | - /** @var DefaultShareProvider */ |
|
47 | - private $defaultProvider = null; |
|
48 | - /** @var FederatedShareProvider */ |
|
49 | - private $federatedProvider = null; |
|
50 | - /** @var ShareByMailProvider */ |
|
51 | - private $shareByMailProvider; |
|
52 | - /** @var \OCA\Circles\ShareByCircleProvider; |
|
53 | - * ShareByCircleProvider */ |
|
54 | - private $shareByCircleProvider; |
|
55 | - |
|
56 | - /** |
|
57 | - * IProviderFactory constructor. |
|
58 | - * |
|
59 | - * @param IServerContainer $serverContainer |
|
60 | - */ |
|
61 | - public function __construct(IServerContainer $serverContainer) { |
|
62 | - $this->serverContainer = $serverContainer; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Create the default share provider. |
|
67 | - * |
|
68 | - * @return DefaultShareProvider |
|
69 | - */ |
|
70 | - protected function defaultShareProvider() { |
|
71 | - if ($this->defaultProvider === null) { |
|
72 | - $this->defaultProvider = new DefaultShareProvider( |
|
73 | - $this->serverContainer->getDatabaseConnection(), |
|
74 | - $this->serverContainer->getUserManager(), |
|
75 | - $this->serverContainer->getGroupManager(), |
|
76 | - $this->serverContainer->getLazyRootFolder() |
|
77 | - ); |
|
78 | - } |
|
79 | - |
|
80 | - return $this->defaultProvider; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Create the federated share provider |
|
85 | - * |
|
86 | - * @return FederatedShareProvider |
|
87 | - */ |
|
88 | - protected function federatedShareProvider() { |
|
89 | - if ($this->federatedProvider === null) { |
|
90 | - /* |
|
44 | + /** @var IServerContainer */ |
|
45 | + private $serverContainer; |
|
46 | + /** @var DefaultShareProvider */ |
|
47 | + private $defaultProvider = null; |
|
48 | + /** @var FederatedShareProvider */ |
|
49 | + private $federatedProvider = null; |
|
50 | + /** @var ShareByMailProvider */ |
|
51 | + private $shareByMailProvider; |
|
52 | + /** @var \OCA\Circles\ShareByCircleProvider; |
|
53 | + * ShareByCircleProvider */ |
|
54 | + private $shareByCircleProvider; |
|
55 | + |
|
56 | + /** |
|
57 | + * IProviderFactory constructor. |
|
58 | + * |
|
59 | + * @param IServerContainer $serverContainer |
|
60 | + */ |
|
61 | + public function __construct(IServerContainer $serverContainer) { |
|
62 | + $this->serverContainer = $serverContainer; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Create the default share provider. |
|
67 | + * |
|
68 | + * @return DefaultShareProvider |
|
69 | + */ |
|
70 | + protected function defaultShareProvider() { |
|
71 | + if ($this->defaultProvider === null) { |
|
72 | + $this->defaultProvider = new DefaultShareProvider( |
|
73 | + $this->serverContainer->getDatabaseConnection(), |
|
74 | + $this->serverContainer->getUserManager(), |
|
75 | + $this->serverContainer->getGroupManager(), |
|
76 | + $this->serverContainer->getLazyRootFolder() |
|
77 | + ); |
|
78 | + } |
|
79 | + |
|
80 | + return $this->defaultProvider; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Create the federated share provider |
|
85 | + * |
|
86 | + * @return FederatedShareProvider |
|
87 | + */ |
|
88 | + protected function federatedShareProvider() { |
|
89 | + if ($this->federatedProvider === null) { |
|
90 | + /* |
|
91 | 91 | * Check if the app is enabled |
92 | 92 | */ |
93 | - $appManager = $this->serverContainer->getAppManager(); |
|
94 | - if (!$appManager->isEnabledForUser('federatedfilesharing')) { |
|
95 | - return null; |
|
96 | - } |
|
93 | + $appManager = $this->serverContainer->getAppManager(); |
|
94 | + if (!$appManager->isEnabledForUser('federatedfilesharing')) { |
|
95 | + return null; |
|
96 | + } |
|
97 | 97 | |
98 | - /* |
|
98 | + /* |
|
99 | 99 | * TODO: add factory to federated sharing app |
100 | 100 | */ |
101 | - $l = $this->serverContainer->getL10N('federatedfilessharing'); |
|
102 | - $addressHandler = new AddressHandler( |
|
103 | - $this->serverContainer->getURLGenerator(), |
|
104 | - $l, |
|
105 | - $this->serverContainer->getCloudIdManager() |
|
106 | - ); |
|
107 | - $discoveryManager = new DiscoveryManager( |
|
108 | - $this->serverContainer->getMemCacheFactory(), |
|
109 | - $this->serverContainer->getHTTPClientService() |
|
110 | - ); |
|
111 | - $notifications = new Notifications( |
|
112 | - $addressHandler, |
|
113 | - $this->serverContainer->getHTTPClientService(), |
|
114 | - $discoveryManager, |
|
115 | - $this->serverContainer->getJobList() |
|
116 | - ); |
|
117 | - $tokenHandler = new TokenHandler( |
|
118 | - $this->serverContainer->getSecureRandom() |
|
119 | - ); |
|
120 | - |
|
121 | - $this->federatedProvider = new FederatedShareProvider( |
|
122 | - $this->serverContainer->getDatabaseConnection(), |
|
123 | - $addressHandler, |
|
124 | - $notifications, |
|
125 | - $tokenHandler, |
|
126 | - $l, |
|
127 | - $this->serverContainer->getLogger(), |
|
128 | - $this->serverContainer->getLazyRootFolder(), |
|
129 | - $this->serverContainer->getConfig(), |
|
130 | - $this->serverContainer->getUserManager(), |
|
131 | - $this->serverContainer->getCloudIdManager() |
|
132 | - ); |
|
133 | - } |
|
134 | - |
|
135 | - return $this->federatedProvider; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Create the federated share provider |
|
140 | - * |
|
141 | - * @return ShareByMailProvider |
|
142 | - */ |
|
143 | - protected function getShareByMailProvider() { |
|
144 | - if ($this->shareByMailProvider === null) { |
|
145 | - /* |
|
101 | + $l = $this->serverContainer->getL10N('federatedfilessharing'); |
|
102 | + $addressHandler = new AddressHandler( |
|
103 | + $this->serverContainer->getURLGenerator(), |
|
104 | + $l, |
|
105 | + $this->serverContainer->getCloudIdManager() |
|
106 | + ); |
|
107 | + $discoveryManager = new DiscoveryManager( |
|
108 | + $this->serverContainer->getMemCacheFactory(), |
|
109 | + $this->serverContainer->getHTTPClientService() |
|
110 | + ); |
|
111 | + $notifications = new Notifications( |
|
112 | + $addressHandler, |
|
113 | + $this->serverContainer->getHTTPClientService(), |
|
114 | + $discoveryManager, |
|
115 | + $this->serverContainer->getJobList() |
|
116 | + ); |
|
117 | + $tokenHandler = new TokenHandler( |
|
118 | + $this->serverContainer->getSecureRandom() |
|
119 | + ); |
|
120 | + |
|
121 | + $this->federatedProvider = new FederatedShareProvider( |
|
122 | + $this->serverContainer->getDatabaseConnection(), |
|
123 | + $addressHandler, |
|
124 | + $notifications, |
|
125 | + $tokenHandler, |
|
126 | + $l, |
|
127 | + $this->serverContainer->getLogger(), |
|
128 | + $this->serverContainer->getLazyRootFolder(), |
|
129 | + $this->serverContainer->getConfig(), |
|
130 | + $this->serverContainer->getUserManager(), |
|
131 | + $this->serverContainer->getCloudIdManager() |
|
132 | + ); |
|
133 | + } |
|
134 | + |
|
135 | + return $this->federatedProvider; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Create the federated share provider |
|
140 | + * |
|
141 | + * @return ShareByMailProvider |
|
142 | + */ |
|
143 | + protected function getShareByMailProvider() { |
|
144 | + if ($this->shareByMailProvider === null) { |
|
145 | + /* |
|
146 | 146 | * Check if the app is enabled |
147 | 147 | */ |
148 | - $appManager = $this->serverContainer->getAppManager(); |
|
149 | - if (!$appManager->isEnabledForUser('sharebymail')) { |
|
150 | - return null; |
|
151 | - } |
|
152 | - |
|
153 | - $settingsManager = new SettingsManager($this->serverContainer->getConfig()); |
|
154 | - |
|
155 | - $this->shareByMailProvider = new ShareByMailProvider( |
|
156 | - $this->serverContainer->getDatabaseConnection(), |
|
157 | - $this->serverContainer->getSecureRandom(), |
|
158 | - $this->serverContainer->getUserManager(), |
|
159 | - $this->serverContainer->getLazyRootFolder(), |
|
160 | - $this->serverContainer->getL10N('sharebymail'), |
|
161 | - $this->serverContainer->getLogger(), |
|
162 | - $this->serverContainer->getMailer(), |
|
163 | - $this->serverContainer->getURLGenerator(), |
|
164 | - $this->serverContainer->getActivityManager(), |
|
165 | - $settingsManager |
|
166 | - ); |
|
167 | - } |
|
168 | - |
|
169 | - return $this->shareByMailProvider; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * Create the circle share provider |
|
175 | - * |
|
176 | - * @return FederatedShareProvider |
|
177 | - */ |
|
178 | - protected function getShareByCircleProvider() { |
|
179 | - |
|
180 | - $appManager = $this->serverContainer->getAppManager(); |
|
181 | - if (!$appManager->isEnabledForUser('circles')) { |
|
182 | - return null; |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - if ($this->shareByCircleProvider === null) { |
|
187 | - |
|
188 | - $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider( |
|
189 | - $this->serverContainer->getDatabaseConnection(), |
|
190 | - $this->serverContainer->getSecureRandom(), |
|
191 | - $this->serverContainer->getUserManager(), |
|
192 | - $this->serverContainer->getLazyRootFolder(), |
|
193 | - $this->serverContainer->getL10N('circles'), |
|
194 | - $this->serverContainer->getLogger(), |
|
195 | - $this->serverContainer->getURLGenerator() |
|
196 | - ); |
|
197 | - } |
|
198 | - |
|
199 | - return $this->shareByCircleProvider; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @inheritdoc |
|
205 | - */ |
|
206 | - public function getProvider($id) { |
|
207 | - $provider = null; |
|
208 | - if ($id === 'ocinternal') { |
|
209 | - $provider = $this->defaultShareProvider(); |
|
210 | - } else if ($id === 'ocFederatedSharing') { |
|
211 | - $provider = $this->federatedShareProvider(); |
|
212 | - } else if ($id === 'ocMailShare') { |
|
213 | - $provider = $this->getShareByMailProvider(); |
|
214 | - } else if ($id === 'ocCircleShare') { |
|
215 | - $provider = $this->getShareByCircleProvider(); |
|
216 | - } |
|
217 | - |
|
218 | - if ($provider === null) { |
|
219 | - throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
220 | - } |
|
221 | - |
|
222 | - return $provider; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * @inheritdoc |
|
227 | - */ |
|
228 | - public function getProviderForType($shareType) { |
|
229 | - $provider = null; |
|
230 | - |
|
231 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER || |
|
232 | - $shareType === \OCP\Share::SHARE_TYPE_GROUP || |
|
233 | - $shareType === \OCP\Share::SHARE_TYPE_LINK |
|
234 | - ) { |
|
235 | - $provider = $this->defaultShareProvider(); |
|
236 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
237 | - $provider = $this->federatedShareProvider(); |
|
238 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
239 | - $provider = $this->getShareByMailProvider(); |
|
240 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
241 | - $provider = $this->getShareByCircleProvider(); |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - if ($provider === null) { |
|
246 | - throw new ProviderException('No share provider for share type ' . $shareType); |
|
247 | - } |
|
248 | - |
|
249 | - return $provider; |
|
250 | - } |
|
251 | - |
|
252 | - public function getAllProviders() { |
|
253 | - $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()]; |
|
254 | - $shareByMail = $this->getShareByMailProvider(); |
|
255 | - if ($shareByMail !== null) { |
|
256 | - $shares[] = $shareByMail; |
|
257 | - } |
|
258 | - $shareByCircle = $this->getShareByCircleProvider(); |
|
259 | - if ($shareByCircle !== null) { |
|
260 | - $shares[] = $shareByCircle; |
|
261 | - } |
|
262 | - |
|
263 | - return $shares; |
|
264 | - } |
|
148 | + $appManager = $this->serverContainer->getAppManager(); |
|
149 | + if (!$appManager->isEnabledForUser('sharebymail')) { |
|
150 | + return null; |
|
151 | + } |
|
152 | + |
|
153 | + $settingsManager = new SettingsManager($this->serverContainer->getConfig()); |
|
154 | + |
|
155 | + $this->shareByMailProvider = new ShareByMailProvider( |
|
156 | + $this->serverContainer->getDatabaseConnection(), |
|
157 | + $this->serverContainer->getSecureRandom(), |
|
158 | + $this->serverContainer->getUserManager(), |
|
159 | + $this->serverContainer->getLazyRootFolder(), |
|
160 | + $this->serverContainer->getL10N('sharebymail'), |
|
161 | + $this->serverContainer->getLogger(), |
|
162 | + $this->serverContainer->getMailer(), |
|
163 | + $this->serverContainer->getURLGenerator(), |
|
164 | + $this->serverContainer->getActivityManager(), |
|
165 | + $settingsManager |
|
166 | + ); |
|
167 | + } |
|
168 | + |
|
169 | + return $this->shareByMailProvider; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * Create the circle share provider |
|
175 | + * |
|
176 | + * @return FederatedShareProvider |
|
177 | + */ |
|
178 | + protected function getShareByCircleProvider() { |
|
179 | + |
|
180 | + $appManager = $this->serverContainer->getAppManager(); |
|
181 | + if (!$appManager->isEnabledForUser('circles')) { |
|
182 | + return null; |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + if ($this->shareByCircleProvider === null) { |
|
187 | + |
|
188 | + $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider( |
|
189 | + $this->serverContainer->getDatabaseConnection(), |
|
190 | + $this->serverContainer->getSecureRandom(), |
|
191 | + $this->serverContainer->getUserManager(), |
|
192 | + $this->serverContainer->getLazyRootFolder(), |
|
193 | + $this->serverContainer->getL10N('circles'), |
|
194 | + $this->serverContainer->getLogger(), |
|
195 | + $this->serverContainer->getURLGenerator() |
|
196 | + ); |
|
197 | + } |
|
198 | + |
|
199 | + return $this->shareByCircleProvider; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @inheritdoc |
|
205 | + */ |
|
206 | + public function getProvider($id) { |
|
207 | + $provider = null; |
|
208 | + if ($id === 'ocinternal') { |
|
209 | + $provider = $this->defaultShareProvider(); |
|
210 | + } else if ($id === 'ocFederatedSharing') { |
|
211 | + $provider = $this->federatedShareProvider(); |
|
212 | + } else if ($id === 'ocMailShare') { |
|
213 | + $provider = $this->getShareByMailProvider(); |
|
214 | + } else if ($id === 'ocCircleShare') { |
|
215 | + $provider = $this->getShareByCircleProvider(); |
|
216 | + } |
|
217 | + |
|
218 | + if ($provider === null) { |
|
219 | + throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
220 | + } |
|
221 | + |
|
222 | + return $provider; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * @inheritdoc |
|
227 | + */ |
|
228 | + public function getProviderForType($shareType) { |
|
229 | + $provider = null; |
|
230 | + |
|
231 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER || |
|
232 | + $shareType === \OCP\Share::SHARE_TYPE_GROUP || |
|
233 | + $shareType === \OCP\Share::SHARE_TYPE_LINK |
|
234 | + ) { |
|
235 | + $provider = $this->defaultShareProvider(); |
|
236 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
237 | + $provider = $this->federatedShareProvider(); |
|
238 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
239 | + $provider = $this->getShareByMailProvider(); |
|
240 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
241 | + $provider = $this->getShareByCircleProvider(); |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + if ($provider === null) { |
|
246 | + throw new ProviderException('No share provider for share type ' . $shareType); |
|
247 | + } |
|
248 | + |
|
249 | + return $provider; |
|
250 | + } |
|
251 | + |
|
252 | + public function getAllProviders() { |
|
253 | + $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()]; |
|
254 | + $shareByMail = $this->getShareByMailProvider(); |
|
255 | + if ($shareByMail !== null) { |
|
256 | + $shares[] = $shareByMail; |
|
257 | + } |
|
258 | + $shareByCircle = $this->getShareByCircleProvider(); |
|
259 | + if ($shareByCircle !== null) { |
|
260 | + $shares[] = $shareByCircle; |
|
261 | + } |
|
262 | + |
|
263 | + return $shares; |
|
264 | + } |
|
265 | 265 | } |
@@ -27,41 +27,41 @@ |
||
27 | 27 | |
28 | 28 | class Admin implements ISettings { |
29 | 29 | |
30 | - /** @var SettingsManager */ |
|
31 | - private $settingsManager; |
|
30 | + /** @var SettingsManager */ |
|
31 | + private $settingsManager; |
|
32 | 32 | |
33 | - public function __construct(SettingsManager $settingsManager) { |
|
34 | - $this->settingsManager = $settingsManager; |
|
35 | - } |
|
33 | + public function __construct(SettingsManager $settingsManager) { |
|
34 | + $this->settingsManager = $settingsManager; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @return TemplateResponse |
|
39 | - */ |
|
40 | - public function getForm() { |
|
37 | + /** |
|
38 | + * @return TemplateResponse |
|
39 | + */ |
|
40 | + public function getForm() { |
|
41 | 41 | |
42 | - $parameters = [ |
|
43 | - 'sendPasswordMail' => $this->settingsManager->sendPasswordByMail() |
|
44 | - ]; |
|
42 | + $parameters = [ |
|
43 | + 'sendPasswordMail' => $this->settingsManager->sendPasswordByMail() |
|
44 | + ]; |
|
45 | 45 | |
46 | - return new TemplateResponse('sharebymail', 'settings-admin', $parameters, ''); |
|
47 | - } |
|
46 | + return new TemplateResponse('sharebymail', 'settings-admin', $parameters, ''); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return string the section ID, e.g. 'sharing' |
|
51 | - */ |
|
52 | - public function getSection() { |
|
53 | - return 'sharing'; |
|
54 | - } |
|
49 | + /** |
|
50 | + * @return string the section ID, e.g. 'sharing' |
|
51 | + */ |
|
52 | + public function getSection() { |
|
53 | + return 'sharing'; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return int whether the form should be rather on the top or bottom of |
|
58 | - * the admin section. The forms are arranged in ascending order of the |
|
59 | - * priority values. It is required to return a value between 0 and 100. |
|
60 | - * |
|
61 | - * E.g.: 70 |
|
62 | - */ |
|
63 | - public function getPriority() { |
|
64 | - return 40; |
|
65 | - } |
|
56 | + /** |
|
57 | + * @return int whether the form should be rather on the top or bottom of |
|
58 | + * the admin section. The forms are arranged in ascending order of the |
|
59 | + * priority values. It is required to return a value between 0 and 100. |
|
60 | + * |
|
61 | + * E.g.: 70 |
|
62 | + */ |
|
63 | + public function getPriority() { |
|
64 | + return 40; |
|
65 | + } |
|
66 | 66 | |
67 | 67 | } |
@@ -27,23 +27,23 @@ |
||
27 | 27 | |
28 | 28 | class SettingsManager { |
29 | 29 | |
30 | - /** @var IConfig */ |
|
31 | - private $config; |
|
32 | - |
|
33 | - private $defaultSetting = 'yes'; |
|
34 | - |
|
35 | - public function __construct(IConfig $config) { |
|
36 | - $this->config = $config; |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * should the password for a mail share be send to the recipient |
|
41 | - * |
|
42 | - * @return bool |
|
43 | - */ |
|
44 | - public function sendPasswordByMail() { |
|
45 | - $sendPasswordByMail = $this->config->getAppValue('sharebymail', 'sendpasswordmail', $this->defaultSetting); |
|
46 | - return $sendPasswordByMail === 'yes'; |
|
47 | - } |
|
30 | + /** @var IConfig */ |
|
31 | + private $config; |
|
32 | + |
|
33 | + private $defaultSetting = 'yes'; |
|
34 | + |
|
35 | + public function __construct(IConfig $config) { |
|
36 | + $this->config = $config; |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * should the password for a mail share be send to the recipient |
|
41 | + * |
|
42 | + * @return bool |
|
43 | + */ |
|
44 | + public function sendPasswordByMail() { |
|
45 | + $sendPasswordByMail = $this->config->getAppValue('sharebymail', 'sendpasswordmail', $this->defaultSetting); |
|
46 | + return $sendPasswordByMail === 'yes'; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | } |