diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2013-08-30 13:53:49 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2013-08-30 13:53:49 +0200 |
commit | 77adaee6457c3e17d0f0b32c74da4cdbfce60164 (patch) | |
tree | fc793d2965d0a9541a183f620a63dae3ea2bfb0b /core | |
parent | 0a23ac18bc1f74cea98eed2c37aa03c99fd957f7 (diff) | |
download | nextcloud-server-77adaee6457c3e17d0f0b32c74da4cdbfce60164.tar.gz nextcloud-server-77adaee6457c3e17d0f0b32c74da4cdbfce60164.zip |
enable user to inform recipients about a shared file by mail
Diffstat (limited to 'core')
-rw-r--r-- | core/ajax/share.php | 106 | ||||
-rw-r--r-- | core/css/share.css | 4 | ||||
-rw-r--r-- | core/js/share.js | 39 |
3 files changed, 139 insertions, 10 deletions
diff --git a/core/ajax/share.php b/core/ajax/share.php index d3c6a8456a6..3f6a9953266 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,102 @@ 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']; + $from = \OCP\Util::getDefaultEmailAddress('sharing-noreply'); + $subject = $defaults->getShareNotificationSubject($itemType); + + $noMail = array(); + $recipientList = array(); + + if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { + $users = \OC_Group::usersInGroup($recipient); + foreach ($users as $user) { + $email = OC_Preferences::getValue($user, 'settings', 'email', ''); + if ($email !== '' || $recipient === \OCP\User::getUser()) { + $recipientList[] = array( + 'email' => $email, + 'displayName' => \OCP\User::getDisplayName($user), + 'uid' => $user, + ); + } else { + $noMail[] = \OCP\User::getDisplayName($user); + } + } + } else { // shared to a single user + $email = OC_Preferences::getValue($recipient, 'settings', 'email', ''); + if ($email !== '') { + $recipientList[] = array( + 'email' => $email, + 'displayName' => \OCP\User::getDisplayName($recipient), + 'uid' => $recipient, + ); + } else { + $noMail[] = \OCP\User::getDisplayName($recipient); + } + } + + // send mail to all recipients with an email address + foreach ($recipientList as $recipient) { + //get correct target folder name + + $users = \OCP\Share::getItemSharedWithUser($itemType, $itemSource, $recipient['uid']); + $targetName = $users[0]['file_target']; + + //$share = $shareManager->getShares($itemType, array('shareWith' => $recipient['uid'], 'isShareWithUser' => true, 'itemSource' => $itemSource)); + //$targetName = $share[0]->getItemTarget(); + if ($itemType === 'folder') { + $foldername = "/Shared/" . $targetName; + $filename = $targetName; + } 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"; + $filename = $targetName; + } + + $url = \OCP\Util::linkToAbsolute('files', 'index.php', array("dir" => $foldername)); + $text = $defaults->getShareNotificationText(\OCP\User::getDisplayName(), $filename, $itemType, $url); + + try { + OCP\Util::sendMail( + $recipient['email'], + $recipient['displayName'], + $subject, + $text, + $from, + \OCP\User::getDisplayName() + ); + } catch (Exception $exception) { + $noMail[] = \OCP\User::getDisplayName($recipient['displayName']); + } + } + + \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']; + $itemType = $_POST['itemType']; + $recipient = $_POST['recipient']; + //$share = $shareManager->getShares($itemType, array('shareWith' => $recipient, 'isShareWithUser' => true, 'itemSource' => $itemSource)); + //$share[0]->setMailSend(false); + //$shareManager->update($share[0]); + //write status to db + OCP\JSON::success(); + break; + case 'email': // read post variables $user = OCP\USER::getUser(); @@ -213,10 +311,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 (stripos($group, $_GET['search']) !== false diff --git a/core/css/share.css b/core/css/share.css index 2d6849b4bb1..b6c5a0c1390 100644 --- a/core/css/share.css +++ b/core/css/share.css @@ -11,7 +11,7 @@ margin-right:7em; position:absolute; right:0; - width:19em; + width:25em; z-index:500; padding:1em; } @@ -24,7 +24,7 @@ #shareWithList li { padding-top:.1em; } - + #shareWithList li:first-child { white-space:normal; } diff --git a/core/js/share.js b/core/js/share.js index 27c16f38b92..c806d83f10c 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -217,9 +217,9 @@ OC.Share={ OC.Share.showLink(share.token, share.share_with, itemSource); } else { if (share.collection) { - OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.collection); + OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.mail_send, share.collection); } else { - OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, false); + OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.mail_send, share.permissions, possiblePermissions, share.mail_send, false); } } if (share.expiration != null) { @@ -299,7 +299,7 @@ OC.Share={ } }); }, - addShareWith:function(shareType, shareWith, shareWithDisplayName, permissions, possiblePermissions, collection) { + addShareWith:function(shareType, shareWith, shareWithDisplayName, permissions, possiblePermissions, mailSend, collection) { if (!OC.Share.itemShares[shareType]) { OC.Share.itemShares[shareType] = []; } @@ -341,6 +341,14 @@ OC.Share={ }else{ html += escapeHTML(shareWithDisplayName); } + mailNotificationEnabled = $('input:hidden[name=mailNotificationEnabled]').val(); + if (mailNotificationEnabled === 'yes') { + checked = ''; + if (mailSend === true) { + checked = 'checked'; + } + html += '<input type="checkbox" name="mailNotification" class="mailNotification" ' + checked + ' />'+t('core', 'notify user by email')+'</label>'; + } if (possiblePermissions & OC.PERMISSION_CREATE || possiblePermissions & OC.PERMISSION_UPDATE || possiblePermissions & OC.PERMISSION_DELETE) { if (editChecked == '') { html += '<label style="display:none;">'; @@ -484,7 +492,7 @@ $(document).ready(function() { $('input:[type=checkbox]', this).hide(); $('label', this).hide(); } - } else { + } else { $('a.unshare', this).hide(); } }); @@ -686,5 +694,28 @@ $(document).ready(function() { } }); + $(document).on('click', '#dropdown input[name=mailNotification]', function(event) { + event.preventDefault(); + event.stopPropagation(); + var li = $(this).parent(); + var itemType = $('#dropdown').data('item-type'); + var itemSource = $('#dropdown').data('item-source'); + if (this.checked) { + action = 'informRecipients'; + } else { + action = 'informRecipientsDisabled'; + } + + shareType = $(li).data('share-type'); + shareWith = $(li).data('share-with'); + + $.post(OC.filePath('core', 'ajax', 'share.php'), {action: action, recipient: shareWith, shareType: shareType, itemSource: itemSource, itemType: itemType}, function(result) { + if (result.status !== 'success') { + OC.dialogs.alert(t('core', result.data.message), t('core', 'Warning')); + } + }); + +}); + }); |