diff options
-rw-r--r-- | apps/files_sharing/lib/Activity.php | 20 | ||||
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareController.php | 128 | ||||
-rw-r--r-- | lib/public/Activity/IExtension.php | 1 |
3 files changed, 104 insertions, 45 deletions
diff --git a/apps/files_sharing/lib/Activity.php b/apps/files_sharing/lib/Activity.php index f0d4ca39047..a5aabab9acd 100644 --- a/apps/files_sharing/lib/Activity.php +++ b/apps/files_sharing/lib/Activity.php @@ -73,6 +73,9 @@ class Activity implements IExtension { const SUBJECT_LINK_BY_EXPIRED = 'link_by_expired'; const SUBJECT_SHARED_EMAIL = 'shared_with_email'; + const SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED = 'file_shared_with_email_downloaded'; + const SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED = 'folder_shared_with_email_downloaded'; + const SUBJECT_SHARED_WITH_BY = 'shared_with_by'; const SUBJECT_UNSHARED_BY = 'unshared_by'; @@ -113,7 +116,7 @@ class Activity implements IExtension { return array( self::TYPE_SHARED => (string) $l->t('A file or folder has been <strong>shared</strong>'), self::TYPE_REMOTE_SHARE => (string) $l->t('A file or folder was shared from <strong>another server</strong>'), - self::TYPE_PUBLIC_LINKS => (string) $l->t('A public shared file or folder was <strong>downloaded</strong>'), + self::TYPE_PUBLIC_LINKS => (string) $l->t('A file or folder shared by mail or by public link was <strong>downloaded</strong>'), ); } @@ -246,8 +249,13 @@ class Activity implements IExtension { return (string) $l->t('%2$s shared %1$s with you', $params); case self::SUBJECT_UNSHARED_BY: return (string) $l->t('%2$s removed the share for %1$s', $params); + case self::SUBJECT_SHARED_EMAIL: return (string) $l->t('You shared %1$s with %2$s', $params); + case self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED: + return (string) $l->t('File %1$s shared by email with %2$s was downloaded', $params); + case self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED: + return (string) $l->t('Folder %1$s shared by email with %2$s was downloaded', $params); } return false; @@ -298,8 +306,12 @@ class Activity implements IExtension { case self::SUBJECT_SHARED_WITH_BY: return (string) $l->t('Shared by %2$s', $params); + case self::SUBJECT_SHARED_EMAIL: return (string) $l->t('Shared with %2$s', $params); + case self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED: + case self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED: + return (string) $l->t('Downloaded by %2$s', $params); default: return false; @@ -312,6 +324,7 @@ class Activity implements IExtension { * Currently known types are: * * file => will strip away the path of the file and add a tooltip with it * * username => will add the avatar of the user + * * email => will add a mailto link * * @param string $app * @param string $text @@ -347,10 +360,11 @@ class Activity implements IExtension { 1 => 'username', 2 => '', ]; - case self::SUBJECT_SHARED_EMAIL: + case self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED: + case self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED: return array( 0 => 'file', - 1 => '',// 'email' is neither supported nor planned for now + 1 => 'email', ); case self::SUBJECT_SHARED_USER_SELF: diff --git a/apps/files_sharing/lib/Controller/ShareController.php b/apps/files_sharing/lib/Controller/ShareController.php index 5ad7d3a99f1..910cbbdf397 100644 --- a/apps/files_sharing/lib/Controller/ShareController.php +++ b/apps/files_sharing/lib/Controller/ShareController.php @@ -32,6 +32,7 @@ namespace OCA\Files_Sharing\Controller; +use OC\Files\Node\Folder; use OC_Files; use OC_Util; use OCA\FederatedFileSharing\FederatedShareProvider; @@ -50,7 +51,6 @@ use OCP\ILogger; use OCP\IUserManager; use OCP\ISession; use OCP\IPreview; -use OCP\Util; use OCA\Files_Sharing\Activity; use \OCP\Files\NotFoundException; use OCP\Files\IRootFolder; @@ -464,13 +464,7 @@ class ShareController extends Controller { // Single file share if ($share->getNode() instanceof \OCP\Files\File) { // Single file download - $event = $this->activityManager->generateEvent(); - $event->setApp('files_sharing') - ->setType(Activity::TYPE_PUBLIC_LINKS) - ->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$userFolder->getRelativePath($share->getNode()->getPath())]) - ->setAffectedUser($share->getShareOwner()) - ->setObject('files', $share->getNode()->getId(), $userFolder->getRelativePath($share->getNode()->getPath())); - $this->activityManager->publish($event); + $this->singleFileDownloaded($share, $share->getNode()); } // Directory share else { @@ -491,43 +485,12 @@ class ShareController extends Controller { if ($node instanceof \OCP\Files\File) { // Single file download - $event = $this->activityManager->generateEvent(); - $event->setApp('files_sharing') - ->setType(Activity::TYPE_PUBLIC_LINKS) - ->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$userFolder->getRelativePath($node->getPath())]) - ->setAffectedUser($share->getShareOwner()) - ->setObject('files', $node->getId(), $userFolder->getRelativePath($node->getPath())); - $this->activityManager->publish($event); + $this->singleFileDownloaded($share, $share->getNode()); } else if (!empty($files_list)) { - /** @var \OCP\Files\Folder $node */ - - // Subset of files is downloaded - foreach ($files_list as $file) { - $subNode = $node->get($file); - - $event = $this->activityManager->generateEvent(); - $event->setApp('files_sharing') - ->setType(Activity::TYPE_PUBLIC_LINKS) - ->setAffectedUser($share->getShareOwner()) - ->setObject('files', $subNode->getId(), $userFolder->getRelativePath($subNode->getPath())); - - if ($subNode instanceof \OCP\Files\File) { - $event->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$userFolder->getRelativePath($subNode->getPath())]); - } else { - $event->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED, [$userFolder->getRelativePath($subNode->getPath())]); - } - - $this->activityManager->publish($event); - } + $this->fileListDownloaded($share, $files_list); } else { // The folder is downloaded - $event = $this->activityManager->generateEvent(); - $event->setApp('files_sharing') - ->setType(Activity::TYPE_PUBLIC_LINKS) - ->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED, [$userFolder->getRelativePath($node->getPath())]) - ->setAffectedUser($share->getShareOwner()) - ->setObject('files', $node->getId(), $userFolder->getRelativePath($node->getPath())); - $this->activityManager->publish($event); + $this->singleFileDownloaded($share, $share->getNode()); } } @@ -572,4 +535,85 @@ class ShareController extends Controller { exit(); } } + + /** + * create activity for every downloaded file + * + * @param Share\IShare $share + * @param array $files_list + */ + protected function fileListDownloaded(Share\IShare $share, array $files_list) { + foreach ($files_list as $file) { + $subNode = $share->getNode()->get($file); + $this->singleFileDownloaded($share, $subNode); + } + + } + + /** + * create activity if a single file was downloaded from a link share + * + * @param Share\IShare $share + */ + protected function singleFileDownloaded(Share\IShare $share, \OCP\Files\Node $node) { + + $fileId = $node->getId(); + + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); + $userNodeList = $userFolder->getById($fileId); + $userNode = $userNodeList[0]; + $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); + $userPath = $userFolder->getRelativePath($userNode->getPath()); + $ownerPath = $ownerFolder->getRelativePath($node->getPath()); + + $parameters = [$userPath]; + + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { + if ($node instanceof \OCP\Files\File) { + $subject = Activity::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED; + } else { + $subject = Activity::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED; + } + $parameters[] = $share->getSharedWith(); + } else { + if ($node instanceof \OCP\Files\File) { + $subject = Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED; + } else { + $subject = Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED; + } + } + + $this->publishActivity($subject, $parameters, $share->getSharedBy(), $fileId, $userPath); + + if ($share->getShareOwner() !== $share->getSharedBy()) { + $parameters[0] = $ownerPath; + $this->publishActivity($subject, $parameters, $share->getShareOwner(), $fileId, $ownerPath); + } + } + + /** + * publish activity + * + * @param string $subject + * @param array $parameters + * @param string $affectedUser + * @param int $fileId + * @param string $filePath + */ + protected function publishActivity($subject, + array $parameters, + $affectedUser, + $fileId, + $filePath) { + + $event = $this->activityManager->generateEvent(); + $event->setApp('files_sharing') + ->setType(Activity::TYPE_PUBLIC_LINKS) + ->setSubject($subject, $parameters) + ->setAffectedUser($affectedUser) + ->setObject('files', $fileId, $filePath); + $this->activityManager->publish($event); + } + + } diff --git a/lib/public/Activity/IExtension.php b/lib/public/Activity/IExtension.php index a86837892ba..aaa4c869561 100644 --- a/lib/public/Activity/IExtension.php +++ b/lib/public/Activity/IExtension.php @@ -103,6 +103,7 @@ interface IExtension { * Currently known types are: * * file => will strip away the path of the file and add a tooltip with it * * username => will add the avatar of the user + * * email => will add a mailto link * * @param string $app * @param string $text |