diff --git a/apps/files_sharing/lib/Activity/Providers/Downloads.php b/apps/files_sharing/lib/Activity/Providers/Downloads.php index ac9522ef93b91..567a1528e687a 100644 --- a/apps/files_sharing/lib/Activity/Providers/Downloads.php +++ b/apps/files_sharing/lib/Activity/Providers/Downloads.php @@ -55,11 +55,15 @@ public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) { if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED || $event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED) { - if (!isset($parsedParameters['remote-address-hash']['type'])) { + if (isset($parsedParameters['actor'])) { + $subject = $this->l->t('{file} downloaded via public link by {actor}'); + } else { $subject = $this->l->t('{file} downloaded via public link'); + } + + if (!isset($parsedParameters['remote-address-hash']['type'])) { $this->setSubjects($event, $subject, $parsedParameters); } else { - $subject = $this->l->t('{file} downloaded via public link'); $this->setSubjects($event, $subject, $parsedParameters); $event = $this->eventMerger->mergeEvents('file', $event, $previousEvent); } @@ -92,20 +96,25 @@ protected function getParsedParameters(IEvent $event) { switch ($subject) { case self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED: case self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED: + $parsedParameters = [ + 'file' => $this->getFile($parameters[0], $event), + ]; + if (isset($parameters[1])) { - return [ - 'file' => $this->getFile($parameters[0], $event), - 'remote-address-hash' => [ - 'type' => 'highlight', - 'id' => $parameters[1], - 'name' => $parameters[1], - 'link' => '', - ], + $parsedParameters['remote-address-hash'] = [ + 'type' => 'highlight', + 'id' => $parameters[1], + 'name' => $parameters[1], + 'link' => '', ]; } - return [ - 'file' => $this->getFile($parameters[0], $event), - ]; + + if (isset($parameters[2])) { + $parsedParameters['actor'] = $this->getUser($parameters[2]); + } + + return $parsedParameters; + case self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED: case self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED: return [ diff --git a/apps/files_sharing/lib/Controller/ShareController.php b/apps/files_sharing/lib/Controller/ShareController.php index 8a2e093849be8..9142d9ba092c5 100644 --- a/apps/files_sharing/lib/Controller/ShareController.php +++ b/apps/files_sharing/lib/Controller/ShareController.php @@ -30,7 +30,9 @@ use OCP\IRequest; use OCP\ISession; use OCP\IURLGenerator; +use OCP\IUser; use OCP\IUserManager; +use OCP\IUserSession; use OCP\Security\ISecureRandom; use OCP\Share; use OCP\Share\Exceptions\ShareNotFound; @@ -45,6 +47,7 @@ #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)] class ShareController extends AuthPublicShareController { protected ?Share\IShare $share = null; + private ?IUser $currentUser = null; public const SHARE_ACCESS = 'access'; public const SHARE_AUTH = 'auth'; @@ -68,8 +71,11 @@ public function __construct( protected ISecureRandom $secureRandom, protected Defaults $defaults, private IPublicShareTemplateFactory $publicShareTemplateFactory, + IUserSession $userSession, ) { parent::__construct($appName, $request, $session, $urlGenerator); + + $this->currentUser = $userSession->getUser(); } /** @@ -511,11 +517,11 @@ protected function singleFileDownloaded(Share\IShare $share, \OCP\Files\Node $no } else { if ($node instanceof \OCP\Files\File) { $subject = Downloads::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED; - $parameters[] = $remoteAddressHash; } else { $subject = Downloads::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED; - $parameters[] = $remoteAddressHash; } + $parameters[] = $remoteAddressHash; + $parameters[] = $this->currentUser?->getUID(); } $this->publishActivity($subject, $parameters, $share->getSharedBy(), $fileId, $userPath);