add activity for share by mail

Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
This commit is contained in:
Bjoern Schiessle 2016-11-03 12:06:22 +01:00
parent 6a156b795c
commit 087dab85b4
No known key found for this signature in database
GPG key ID: 2378A753E2BF04F6
3 changed files with 104 additions and 45 deletions

View file

@ -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:

View file

@ -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);
}
}

View file

@ -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