diff options
author | Björn Schießle <bjoern@schiessle.org> | 2013-10-04 04:06:37 -0700 |
---|---|---|
committer | Björn Schießle <bjoern@schiessle.org> | 2013-10-04 04:06:37 -0700 |
commit | 31d5565a18d151ef1518789a5e80520efa4719cd (patch) | |
tree | 7d2da02957552a8ac49eb6f2f3bd6b08e1049406 /core/ajax | |
parent | 514d7a884a5211fe246487421ea8103202d004d7 (diff) | |
parent | 51295e9a6b9cd8e351132e988858b5d4bd223968 (diff) | |
download | nextcloud-server-31d5565a18d151ef1518789a5e80520efa4719cd.tar.gz nextcloud-server-31d5565a18d151ef1518789a5e80520efa4719cd.zip |
Merge pull request #4689 from owncloud/sharing_mail_notification_master
send mail notification if a file was shared to a user/group
Diffstat (limited to 'core/ajax')
-rw-r--r-- | core/ajax/share.php | 108 |
1 files changed, 104 insertions, 4 deletions
diff --git a/core/ajax/share.php b/core/ajax/share.php index 648f0a71bd4..ed9cbfd109a 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -23,6 +23,8 @@ OC_JSON::checkLoggedIn(); OCP\JSON::callCheck(); OC_App::loadApps(); +$defaults = new \OCP\Defaults(); + if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSource'])) { switch ($_POST['action']) { case 'share': @@ -33,7 +35,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo if ($shareType === OCP\Share::SHARE_TYPE_LINK && $shareWith == '') { $shareWith = null; } - + $token = OCP\Share::shareItem( $_POST['itemType'], $_POST['itemSource'], @@ -41,7 +43,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo $shareWith, $_POST['permissions'] ); - + if (is_string($token)) { OC_JSON::success(array('data' => array('token' => $token))); } else { @@ -81,6 +83,104 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo ($return) ? OC_JSON::success() : OC_JSON::error(); } break; + case 'informRecipients': + + $l = OC_L10N::get('core'); + + $shareType = (int) $_POST['shareType']; + $itemType = $_POST['itemType']; + $itemSource = $_POST['itemSource']; + $recipient = $_POST['recipient']; + $ownerDisplayName = \OCP\User::getDisplayName(); + $from = \OCP\Util::getDefaultEmailAddress('sharing-noreply'); + + $noMail = array(); + $recipientList = array(); + + if($shareType === \OCP\Share::SHARE_TYPE_USER) { + $recipientList[] = $recipient; + } elseif ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { + $recipientList = \OC_Group::usersInGroup($recipient); + } + + // don't send a mail to the user who shared the file + $recipientList = array_diff($recipientList, [\OCP\User::getUser()]); + + // send mail to all recipients with an email address + foreach ($recipientList as $recipient) { + //get correct target folder name + $email = OC_Preferences::getValue($recipient, 'settings', 'email', ''); + + if ($email !== '') { + $displayName = \OCP\User::getDisplayName($recipient); + $items = \OCP\Share::getItemSharedWithUser($itemType, $itemSource, $recipient); + $filename = trim($items[0]['file_target'], '/'); + $subject = (string)$l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); + $expiration = null; + if (isset($items[0]['expiration'])) { + $date = new DateTime($items[0]['expiration']); + $expiration = $date->format('Y-m-d'); + } + + if ($itemType === 'folder') { + $foldername = "/Shared/" . $filename; + } else { + // if it is a file we can just link to the Shared folder, + // that's the place where the user will find the file + $foldername = "/Shared"; + } + + $link = \OCP\Util::linkToAbsolute('files', 'index.php', array("dir" => $foldername)); + + $content = new OC_Template("core", "mail", ""); + $content->assign('link', $link); + $content->assign('user_displayname', $ownerDisplayName); + $content->assign('filename', $filename); + $content->assign('expiration', $expiration); + $text = $content->fetchPage(); + + $content = new OC_Template("core", "altmail", ""); + $content->assign('link', $link); + $content->assign('user_displayname', $ownerDisplayName); + $content->assign('filename', $filename); + $content->assign('expiration', $expiration); + $alttext = $content->fetchPage(); + + $default_from = OCP\Util::getDefaultEmailAddress('sharing-noreply'); + $from = OCP\Config::getUserValue(\OCP\User::getUser(), 'settings', 'email', $default_from); + + // send it out now + try { + OCP\Util::sendMail($email, $displayName, $subject, $text, $from, $ownerDisplayName, 1, $alttext); + } catch (Exception $exception) { + $noMail[] = \OCP\User::getDisplayName($recipient); + } + } + } + + \OCP\Share::setSendMailStatus($itemType, $itemSource, $shareType, true); + + if (empty($noMail)) { + OCP\JSON::success(); + } else { + OCP\JSON::error(array( + 'data' => array( + 'message' => $l->t("Couldn't send mail to following users: %s ", + implode(', ', $noMail) + ) + ) + )); + } + break; + case 'informRecipientsDisabled': + $itemSource = $_POST['itemSource']; + $shareType = $_POST['shareType']; + $itemType = $_POST['itemType']; + $recipient = $_POST['recipient']; + \OCP\Share::setSendMailStatus($itemType, $itemSource, $shareType, false); + OCP\JSON::success(); + break; + case 'email': // read post variables $user = OCP\USER::getUser(); @@ -213,10 +313,10 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo } } $count = 0; - + // enable l10n support $l = OC_L10N::get('core'); - + foreach ($groups as $group) { if ($count < 15) { if (!isset($_GET['itemShares']) |