Merge pull request #13145 from owncloud/issue/11951-activity-sharing-email

Publish an activity when sending a share link via email
This commit is contained in:
Thomas Müller 2015-09-25 13:48:33 +02:00
commit 2c37d5f7d8
2 changed files with 39 additions and 0 deletions

View File

@ -58,6 +58,7 @@ class Activity implements IExtension {
const SUBJECT_RESHARED_GROUP_BY = 'reshared_group_by';
const SUBJECT_RESHARED_LINK_BY = 'reshared_link_by';
const SUBJECT_RESHARED_USER_BY = 'reshared_user_by';
const SUBJECT_SHARED_EMAIL = 'shared_with_email';
const SUBJECT_SHARED_WITH_BY = 'shared_with_by';
/** @var IFactory */
@ -182,6 +183,8 @@ class Activity implements IExtension {
return (string) $l->t('%2$s shared %1$s with you', $params);
case self::SUBJECT_SHARED_LINK_SELF:
return (string) $l->t('You shared %1$s via link', $params);
case self::SUBJECT_SHARED_EMAIL:
return (string) $l->t('You shared %1$s with %2$s', $params);
}
}
@ -227,6 +230,11 @@ class Activity implements IExtension {
1 => 'username',
2 => '',
];
case self::SUBJECT_SHARED_EMAIL:
return array(
0 => 'file',
1 => '',// 'email' is neither supported nor planned for now
);
case self::SUBJECT_SHARED_USER_SELF:
case self::SUBJECT_SHARED_WITH_BY:

View File

@ -183,6 +183,37 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
$result = $mailNotification->sendLinkShareMail($to_address, $file, $link, $expiration);
if(empty($result)) {
// Get the token from the link
$linkParts = explode('/', $link);
$token = array_pop($linkParts);
// Get the share for the token
$share = \OCP\Share::getShareByToken($token, false);
if ($share !== false) {
$currentUser = \OC::$server->getUserSession()->getUser()->getUID();
$file = '/' . ltrim($file, '/');
// Check whether share belongs to the user and whether the file is the same
if ($share['file_target'] === $file && $share['uid_owner'] === $currentUser) {
// Get the path for the user
$view = new \OC\Files\View('/' . $currentUser . '/files');
$fileId = (int) $share['item_source'];
$path = $view->getPath((int) $share['item_source']);
if ($path !== null) {
$event = \OC::$server->getActivityManager()->generateEvent();
$event->setApp(\OCA\Files_Sharing\Activity::FILES_SHARING_APP)
->setType(\OCA\Files_Sharing\Activity::TYPE_SHARED)
->setAuthor($currentUser)
->setAffectedUser($currentUser)
->setObject('files', $fileId, $path)
->setSubject(\OCA\Files_Sharing\Activity::SUBJECT_SHARED_EMAIL, [$path, $to_address]);
\OC::$server->getActivityManager()->publish($event);
}
}
}
\OCP\JSON::success();
} else {
$l = \OC::$server->getL10N('core');