ShareController.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Bjoern Schiessle <bjoern@schiessle.org>
  7. * @author Björn Schießle <bjoern@schiessle.org>
  8. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  9. * @author Daniel Calviño Sánchez <danxuliu@gmail.com>
  10. * @author Georg Ehrke <oc.list@georgehrke.com>
  11. * @author j3l11234 <297259024@qq.com>
  12. * @author Joas Schilling <coding@schilljs.com>
  13. * @author John Molakvoæ <skjnldsv@protonmail.com>
  14. * @author Jonas Sulzer <jonas@violoncello.ch>
  15. * @author Julius Härtl <jus@bitgrid.net>
  16. * @author Lukas Reschke <lukas@statuscode.ch>
  17. * @author MartB <mart.b@outlook.de>
  18. * @author Maxence Lange <maxence@pontapreta.net>
  19. * @author Michael Weimann <mail@michael-weimann.eu>
  20. * @author Morris Jobke <hey@morrisjobke.de>
  21. * @author Piotr Filiciak <piotr@filiciak.pl>
  22. * @author Robin Appelman <robin@icewind.nl>
  23. * @author Roeland Jago Douma <roeland@famdouma.nl>
  24. * @author Sascha Sambale <mastixmc@gmail.com>
  25. * @author Thomas Müller <thomas.mueller@tmit.eu>
  26. * @author Vincent Petry <vincent@nextcloud.com>
  27. *
  28. * @license AGPL-3.0
  29. *
  30. * This code is free software: you can redistribute it and/or modify
  31. * it under the terms of the GNU Affero General Public License, version 3,
  32. * as published by the Free Software Foundation.
  33. *
  34. * This program is distributed in the hope that it will be useful,
  35. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  36. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  37. * GNU Affero General Public License for more details.
  38. *
  39. * You should have received a copy of the GNU Affero General Public License, version 3,
  40. * along with this program. If not, see <http://www.gnu.org/licenses/>
  41. *
  42. */
  43. namespace OCA\Files_Sharing\Controller;
  44. use OC\Security\CSP\ContentSecurityPolicy;
  45. use OC_Files;
  46. use OC_Util;
  47. use OCA\FederatedFileSharing\FederatedShareProvider;
  48. use OCA\Files_Sharing\Activity\Providers\Downloads;
  49. use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
  50. use OCA\Files_Sharing\Event\ShareLinkAccessedEvent;
  51. use OCA\Viewer\Event\LoadViewer;
  52. use OCP\Accounts\IAccountManager;
  53. use OCP\AppFramework\AuthPublicShareController;
  54. use OCP\AppFramework\Http\NotFoundResponse;
  55. use OCP\AppFramework\Http\Template\ExternalShareMenuAction;
  56. use OCP\AppFramework\Http\Template\LinkMenuAction;
  57. use OCP\AppFramework\Http\Template\PublicTemplateResponse;
  58. use OCP\AppFramework\Http\Template\SimpleMenuAction;
  59. use OCP\AppFramework\Http\TemplateResponse;
  60. use OCP\Defaults;
  61. use OCP\EventDispatcher\IEventDispatcher;
  62. use OCP\Files\Folder;
  63. use OCP\Files\IRootFolder;
  64. use OCP\Files\NotFoundException;
  65. use OCP\IConfig;
  66. use OCP\IL10N;
  67. use OCP\ILogger;
  68. use OCP\IPreview;
  69. use OCP\IRequest;
  70. use OCP\ISession;
  71. use OCP\IURLGenerator;
  72. use OCP\IUser;
  73. use OCP\IUserManager;
  74. use OCP\Security\ISecureRandom;
  75. use OCP\Share;
  76. use OCP\Share\Exceptions\ShareNotFound;
  77. use OCP\Share\IManager as ShareManager;
  78. use OCP\Share\IShare;
  79. use OCP\Share\IPublicShareTemplateFactory;
  80. use OCP\Template;
  81. /**
  82. * Class ShareController
  83. *
  84. * @package OCA\Files_Sharing\Controllers
  85. */
  86. class ShareController extends AuthPublicShareController {
  87. protected IConfig $config;
  88. protected IUserManager $userManager;
  89. protected ILogger $logger;
  90. protected \OCP\Activity\IManager $activityManager;
  91. protected IPreview $previewManager;
  92. protected IRootFolder $rootFolder;
  93. protected FederatedShareProvider $federatedShareProvider;
  94. protected IAccountManager $accountManager;
  95. protected IEventDispatcher $eventDispatcher;
  96. protected IL10N $l10n;
  97. protected Defaults $defaults;
  98. protected ShareManager $shareManager;
  99. protected ISecureRandom $secureRandom;
  100. protected ?Share\IShare $share = null;
  101. private IPublicShareTemplateFactory $publicShareTemplateFactory;
  102. public function __construct(
  103. string $appName,
  104. IRequest $request,
  105. IConfig $config,
  106. IURLGenerator $urlGenerator,
  107. IUserManager $userManager,
  108. ILogger $logger,
  109. \OCP\Activity\IManager $activityManager,
  110. ShareManager $shareManager,
  111. ISession $session,
  112. IPreview $previewManager,
  113. IRootFolder $rootFolder,
  114. FederatedShareProvider $federatedShareProvider,
  115. IAccountManager $accountManager,
  116. IEventDispatcher $eventDispatcher,
  117. IL10N $l10n,
  118. ISecureRandom $secureRandom,
  119. Defaults $defaults,
  120. IPublicShareTemplateFactory $publicShareTemplateFactory
  121. ) {
  122. parent::__construct($appName, $request, $session, $urlGenerator);
  123. $this->config = $config;
  124. $this->userManager = $userManager;
  125. $this->logger = $logger;
  126. $this->activityManager = $activityManager;
  127. $this->previewManager = $previewManager;
  128. $this->rootFolder = $rootFolder;
  129. $this->federatedShareProvider = $federatedShareProvider;
  130. $this->accountManager = $accountManager;
  131. $this->eventDispatcher = $eventDispatcher;
  132. $this->l10n = $l10n;
  133. $this->secureRandom = $secureRandom;
  134. $this->defaults = $defaults;
  135. $this->shareManager = $shareManager;
  136. $this->publicShareTemplateFactory = $publicShareTemplateFactory;
  137. }
  138. public const SHARE_ACCESS = 'access';
  139. public const SHARE_AUTH = 'auth';
  140. public const SHARE_DOWNLOAD = 'download';
  141. /**
  142. * @PublicPage
  143. * @NoCSRFRequired
  144. *
  145. * Show the authentication page
  146. * The form has to submit to the authenticate method route
  147. */
  148. public function showAuthenticate(): TemplateResponse {
  149. $templateParameters = ['share' => $this->share];
  150. $this->eventDispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($this->share, BeforeTemplateRenderedEvent::SCOPE_PUBLIC_SHARE_AUTH));
  151. $response = new TemplateResponse('core', 'publicshareauth', $templateParameters, 'guest');
  152. if ($this->share->getSendPasswordByTalk()) {
  153. $csp = new ContentSecurityPolicy();
  154. $csp->addAllowedConnectDomain('*');
  155. $csp->addAllowedMediaDomain('blob:');
  156. $response->setContentSecurityPolicy($csp);
  157. }
  158. return $response;
  159. }
  160. /**
  161. * The template to show when authentication failed
  162. */
  163. protected function showAuthFailed(): TemplateResponse {
  164. $templateParameters = ['share' => $this->share, 'wrongpw' => true];
  165. $this->eventDispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($this->share, BeforeTemplateRenderedEvent::SCOPE_PUBLIC_SHARE_AUTH));
  166. $response = new TemplateResponse('core', 'publicshareauth', $templateParameters, 'guest');
  167. if ($this->share->getSendPasswordByTalk()) {
  168. $csp = new ContentSecurityPolicy();
  169. $csp->addAllowedConnectDomain('*');
  170. $csp->addAllowedMediaDomain('blob:');
  171. $response->setContentSecurityPolicy($csp);
  172. }
  173. return $response;
  174. }
  175. /**
  176. * The template to show after user identification
  177. */
  178. protected function showIdentificationResult(bool $success = false): TemplateResponse {
  179. $templateParameters = ['share' => $this->share, 'identityOk' => $success];
  180. $this->eventDispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($this->share, BeforeTemplateRenderedEvent::SCOPE_PUBLIC_SHARE_AUTH));
  181. $response = new TemplateResponse('core', 'publicshareauth', $templateParameters, 'guest');
  182. if ($this->share->getSendPasswordByTalk()) {
  183. $csp = new ContentSecurityPolicy();
  184. $csp->addAllowedConnectDomain('*');
  185. $csp->addAllowedMediaDomain('blob:');
  186. $response->setContentSecurityPolicy($csp);
  187. }
  188. return $response;
  189. }
  190. /**
  191. * Validate the identity token of a public share
  192. *
  193. * @param ?string $identityToken
  194. * @return bool
  195. */
  196. protected function validateIdentity(?string $identityToken = null): bool {
  197. if ($this->share->getShareType() !== IShare::TYPE_EMAIL) {
  198. return false;
  199. }
  200. if ($identityToken === null || $this->share->getSharedWith() === null) {
  201. return false;
  202. }
  203. return $identityToken === $this->share->getSharedWith();
  204. }
  205. /**
  206. * Generates a password for the share, respecting any password policy defined
  207. */
  208. protected function generatePassword(): void {
  209. $event = new \OCP\Security\Events\GenerateSecurePasswordEvent();
  210. $this->eventDispatcher->dispatchTyped($event);
  211. $password = $event->getPassword() ?? $this->secureRandom->generate(20);
  212. $this->share->setPassword($password);
  213. $this->shareManager->updateShare($this->share);
  214. }
  215. protected function verifyPassword(string $password): bool {
  216. return $this->shareManager->checkPassword($this->share, $password);
  217. }
  218. protected function getPasswordHash(): string {
  219. return $this->share->getPassword();
  220. }
  221. public function isValidToken(): bool {
  222. try {
  223. $this->share = $this->shareManager->getShareByToken($this->getToken());
  224. } catch (ShareNotFound $e) {
  225. return false;
  226. }
  227. return true;
  228. }
  229. protected function isPasswordProtected(): bool {
  230. return $this->share->getPassword() !== null;
  231. }
  232. protected function authSucceeded() {
  233. // For share this was always set so it is still used in other apps
  234. $this->session->set('public_link_authenticated', (string)$this->share->getId());
  235. }
  236. protected function authFailed() {
  237. $this->emitAccessShareHook($this->share, 403, 'Wrong password');
  238. $this->emitShareAccessEvent($this->share, self::SHARE_AUTH, 403, 'Wrong password');
  239. }
  240. /**
  241. * throws hooks when a share is attempted to be accessed
  242. *
  243. * @param \OCP\Share\IShare|string $share the Share instance if available,
  244. * otherwise token
  245. * @param int $errorCode
  246. * @param string $errorMessage
  247. *
  248. * @throws \OCP\HintException
  249. * @throws \OC\ServerNotAvailableException
  250. *
  251. * @deprecated use OCP\Files_Sharing\Event\ShareLinkAccessedEvent
  252. */
  253. protected function emitAccessShareHook($share, int $errorCode = 200, string $errorMessage = '') {
  254. $itemType = $itemSource = $uidOwner = '';
  255. $token = $share;
  256. $exception = null;
  257. if ($share instanceof \OCP\Share\IShare) {
  258. try {
  259. $token = $share->getToken();
  260. $uidOwner = $share->getSharedBy();
  261. $itemType = $share->getNodeType();
  262. $itemSource = $share->getNodeId();
  263. } catch (\Exception $e) {
  264. // we log what we know and pass on the exception afterwards
  265. $exception = $e;
  266. }
  267. }
  268. \OC_Hook::emit(Share::class, 'share_link_access', [
  269. 'itemType' => $itemType,
  270. 'itemSource' => $itemSource,
  271. 'uidOwner' => $uidOwner,
  272. 'token' => $token,
  273. 'errorCode' => $errorCode,
  274. 'errorMessage' => $errorMessage
  275. ]);
  276. if (!is_null($exception)) {
  277. throw $exception;
  278. }
  279. }
  280. /**
  281. * Emit a ShareLinkAccessedEvent event when a share is accessed, downloaded, auth...
  282. */
  283. protected function emitShareAccessEvent(IShare $share, string $step = '', int $errorCode = 200, string $errorMessage = ''): void {
  284. if ($step !== self::SHARE_ACCESS &&
  285. $step !== self::SHARE_AUTH &&
  286. $step !== self::SHARE_DOWNLOAD) {
  287. return;
  288. }
  289. $this->eventDispatcher->dispatchTyped(new ShareLinkAccessedEvent($share, $step, $errorCode, $errorMessage));
  290. }
  291. /**
  292. * Validate the permissions of the share
  293. *
  294. * @param Share\IShare $share
  295. * @return bool
  296. */
  297. private function validateShare(\OCP\Share\IShare $share) {
  298. // If the owner is disabled no access to the link is granted
  299. $owner = $this->userManager->get($share->getShareOwner());
  300. if ($owner === null || !$owner->isEnabled()) {
  301. return false;
  302. }
  303. // If the initiator of the share is disabled no access is granted
  304. $initiator = $this->userManager->get($share->getSharedBy());
  305. if ($initiator === null || !$initiator->isEnabled()) {
  306. return false;
  307. }
  308. return $share->getNode()->isReadable() && $share->getNode()->isShareable();
  309. }
  310. /**
  311. * @PublicPage
  312. * @NoCSRFRequired
  313. *
  314. *
  315. * @param string $path
  316. * @return TemplateResponse
  317. * @throws NotFoundException
  318. * @throws \Exception
  319. */
  320. public function showShare($path = ''): TemplateResponse {
  321. \OC_User::setIncognitoMode(true);
  322. // Check whether share exists
  323. try {
  324. $share = $this->shareManager->getShareByToken($this->getToken());
  325. } catch (ShareNotFound $e) {
  326. // The share does not exists, we do not emit an ShareLinkAccessedEvent
  327. $this->emitAccessShareHook($this->getToken(), 404, 'Share not found');
  328. throw new NotFoundException();
  329. }
  330. if (!$this->validateShare($share)) {
  331. throw new NotFoundException();
  332. }
  333. $shareNode = $share->getNode();
  334. try {
  335. $templateProvider = $this->publicShareTemplateFactory->getProvider($share);
  336. $response = $templateProvider->renderPage($share, $this->getToken(), $path);
  337. } catch (NotFoundException $e) {
  338. $this->emitAccessShareHook($share, 404, 'Share not found');
  339. $this->emitShareAccessEvent($share, ShareController::SHARE_ACCESS, 404, 'Share not found');
  340. throw new NotFoundException();
  341. }
  342. // We can't get the path of a file share
  343. try {
  344. if ($shareNode instanceof \OCP\Files\File && $path !== '') {
  345. $this->emitAccessShareHook($share, 404, 'Share not found');
  346. $this->emitShareAccessEvent($share, self::SHARE_ACCESS, 404, 'Share not found');
  347. throw new NotFoundException();
  348. }
  349. } catch (\Exception $e) {
  350. $this->emitAccessShareHook($share, 404, 'Share not found');
  351. $this->emitShareAccessEvent($share, self::SHARE_ACCESS, 404, 'Share not found');
  352. throw $e;
  353. }
  354. $this->emitAccessShareHook($share);
  355. $this->emitShareAccessEvent($share, self::SHARE_ACCESS);
  356. return $response;
  357. }
  358. /**
  359. * @PublicPage
  360. * @NoCSRFRequired
  361. * @NoSameSiteCookieRequired
  362. *
  363. * @param string $token
  364. * @param string $files
  365. * @param string $path
  366. * @param string $downloadStartSecret
  367. * @return void|\OCP\AppFramework\Http\Response
  368. * @throws NotFoundException
  369. */
  370. public function downloadShare($token, $files = null, $path = '', $downloadStartSecret = '') {
  371. \OC_User::setIncognitoMode(true);
  372. $share = $this->shareManager->getShareByToken($token);
  373. if (!($share->getPermissions() & \OCP\Constants::PERMISSION_READ)) {
  374. return new \OCP\AppFramework\Http\DataResponse('Share has no read permission');
  375. }
  376. $files_list = null;
  377. if (!is_null($files)) { // download selected files
  378. $files_list = json_decode($files);
  379. // in case we get only a single file
  380. if ($files_list === null) {
  381. $files_list = [$files];
  382. }
  383. // Just in case $files is a single int like '1234'
  384. if (!is_array($files_list)) {
  385. $files_list = [$files_list];
  386. }
  387. }
  388. if (!$this->validateShare($share)) {
  389. throw new NotFoundException();
  390. }
  391. $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
  392. $originalSharePath = $userFolder->getRelativePath($share->getNode()->getPath());
  393. // Single file share
  394. if ($share->getNode() instanceof \OCP\Files\File) {
  395. // Single file download
  396. $this->singleFileDownloaded($share, $share->getNode());
  397. }
  398. // Directory share
  399. else {
  400. /** @var \OCP\Files\Folder $node */
  401. $node = $share->getNode();
  402. // Try to get the path
  403. if ($path !== '') {
  404. try {
  405. $node = $node->get($path);
  406. } catch (NotFoundException $e) {
  407. $this->emitAccessShareHook($share, 404, 'Share not found');
  408. $this->emitShareAccessEvent($share, self::SHARE_DOWNLOAD, 404, 'Share not found');
  409. return new NotFoundResponse();
  410. }
  411. }
  412. $originalSharePath = $userFolder->getRelativePath($node->getPath());
  413. if ($node instanceof \OCP\Files\File) {
  414. // Single file download
  415. $this->singleFileDownloaded($share, $share->getNode());
  416. } else {
  417. try {
  418. if (!empty($files_list)) {
  419. $this->fileListDownloaded($share, $files_list, $node);
  420. } else {
  421. // The folder is downloaded
  422. $this->singleFileDownloaded($share, $share->getNode());
  423. }
  424. } catch (NotFoundException $e) {
  425. return new NotFoundResponse();
  426. }
  427. }
  428. }
  429. /* FIXME: We should do this all nicely in OCP */
  430. OC_Util::tearDownFS();
  431. OC_Util::setupFS($share->getShareOwner());
  432. /**
  433. * this sets a cookie to be able to recognize the start of the download
  434. * the content must not be longer than 32 characters and must only contain
  435. * alphanumeric characters
  436. */
  437. if (!empty($downloadStartSecret)
  438. && !isset($downloadStartSecret[32])
  439. && preg_match('!^[a-zA-Z0-9]+$!', $downloadStartSecret) === 1) {
  440. // FIXME: set on the response once we use an actual app framework response
  441. setcookie('ocDownloadStarted', $downloadStartSecret, time() + 20, '/');
  442. }
  443. $this->emitAccessShareHook($share);
  444. $this->emitShareAccessEvent($share, self::SHARE_DOWNLOAD);
  445. $server_params = [ 'head' => $this->request->getMethod() === 'HEAD' ];
  446. /**
  447. * Http range requests support
  448. */
  449. if (isset($_SERVER['HTTP_RANGE'])) {
  450. $server_params['range'] = $this->request->getHeader('Range');
  451. }
  452. // download selected files
  453. if (!is_null($files) && $files !== '') {
  454. // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
  455. // after dispatching the request which results in a "Cannot modify header information" notice.
  456. OC_Files::get($originalSharePath, $files_list, $server_params);
  457. exit();
  458. } else {
  459. // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
  460. // after dispatching the request which results in a "Cannot modify header information" notice.
  461. OC_Files::get(dirname($originalSharePath), basename($originalSharePath), $server_params);
  462. exit();
  463. }
  464. }
  465. /**
  466. * create activity for every downloaded file
  467. *
  468. * @param Share\IShare $share
  469. * @param array $files_list
  470. * @param \OCP\Files\Folder $node
  471. * @throws NotFoundException when trying to download a folder or multiple files of a "hide download" share
  472. */
  473. protected function fileListDownloaded(Share\IShare $share, array $files_list, \OCP\Files\Folder $node) {
  474. if ($share->getHideDownload() && count($files_list) > 1) {
  475. throw new NotFoundException('Downloading more than 1 file');
  476. }
  477. foreach ($files_list as $file) {
  478. $subNode = $node->get($file);
  479. $this->singleFileDownloaded($share, $subNode);
  480. }
  481. }
  482. /**
  483. * create activity if a single file was downloaded from a link share
  484. *
  485. * @param Share\IShare $share
  486. * @throws NotFoundException when trying to download a folder of a "hide download" share
  487. */
  488. protected function singleFileDownloaded(Share\IShare $share, \OCP\Files\Node $node) {
  489. if ($share->getHideDownload() && $node instanceof Folder) {
  490. throw new NotFoundException('Downloading a folder');
  491. }
  492. $fileId = $node->getId();
  493. $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
  494. $userNodeList = $userFolder->getById($fileId);
  495. $userNode = $userNodeList[0];
  496. $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
  497. $userPath = $userFolder->getRelativePath($userNode->getPath());
  498. $ownerPath = $ownerFolder->getRelativePath($node->getPath());
  499. $remoteAddress = $this->request->getRemoteAddress();
  500. $dateTime = new \DateTime();
  501. $dateTime = $dateTime->format('Y-m-d H');
  502. $remoteAddressHash = md5($dateTime . '-' . $remoteAddress);
  503. $parameters = [$userPath];
  504. if ($share->getShareType() === IShare::TYPE_EMAIL) {
  505. if ($node instanceof \OCP\Files\File) {
  506. $subject = Downloads::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED;
  507. } else {
  508. $subject = Downloads::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED;
  509. }
  510. $parameters[] = $share->getSharedWith();
  511. } else {
  512. if ($node instanceof \OCP\Files\File) {
  513. $subject = Downloads::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED;
  514. $parameters[] = $remoteAddressHash;
  515. } else {
  516. $subject = Downloads::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED;
  517. $parameters[] = $remoteAddressHash;
  518. }
  519. }
  520. $this->publishActivity($subject, $parameters, $share->getSharedBy(), $fileId, $userPath);
  521. if ($share->getShareOwner() !== $share->getSharedBy()) {
  522. $parameters[0] = $ownerPath;
  523. $this->publishActivity($subject, $parameters, $share->getShareOwner(), $fileId, $ownerPath);
  524. }
  525. }
  526. /**
  527. * publish activity
  528. *
  529. * @param string $subject
  530. * @param array $parameters
  531. * @param string $affectedUser
  532. * @param int $fileId
  533. * @param string $filePath
  534. */
  535. protected function publishActivity($subject,
  536. array $parameters,
  537. $affectedUser,
  538. $fileId,
  539. $filePath) {
  540. $event = $this->activityManager->generateEvent();
  541. $event->setApp('files_sharing')
  542. ->setType('public_links')
  543. ->setSubject($subject, $parameters)
  544. ->setAffectedUser($affectedUser)
  545. ->setObject('files', $fileId, $filePath);
  546. $this->activityManager->publish($event);
  547. }
  548. }