summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/ajax/share.php104
-rw-r--r--core/css/share.css4
-rw-r--r--core/js/share.js36
3 files changed, 135 insertions, 9 deletions
diff --git a/core/ajax/share.php b/core/ajax/share.php
index 648f0a71bd4..8f5432a0fcb 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,100 @@ 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_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
+ 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'], '/');
+ $expiration = null;
+ if (isset($items[0]['expiration'])) {
+ $expiration = $items[0]['expiration'];
+ }
+
+ 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";
+ }
+
+ $url = \OCP\Util::linkToAbsolute('files', 'index.php', array("dir" => $foldername));
+ $text = $defaults->getShareNotificationText(
+ \OCP\User::getDisplayName(),
+ $filename,
+ $itemType,
+ $url,
+ $expiration
+ );
+
+ try {
+ OCP\Util::sendMail(
+ $email,
+ $displayName,
+ $subject,
+ $text,
+ $from,
+ \OCP\User::getDisplayName()
+ );
+ } catch (Exception $exception) {
+ $noMail[] = \OCP\User::getDisplayName($recipient);
+ }
+ } else {
+ $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 +309,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'])
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 5d34faf8a5d..7342747a15a 100644
--- a/core/js/share.js
+++ b/core/js/share.js
@@ -114,6 +114,7 @@ OC.Share={
data = false;
}
}});
+
return data;
},
share:function(itemType, itemSource, shareType, shareWith, permissions, callback) {
@@ -217,9 +218,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.permissions, possiblePermissions, share.mail_send, false);
}
}
if (share.expiration != null) {
@@ -301,7 +302,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] = [];
}
@@ -343,6 +344,14 @@ OC.Share={
}else{
html += escapeHTML(shareWithDisplayName);
}
+ mailNotificationEnabled = $('input:hidden[name=mailNotificationEnabled]').val();
+ if (mailNotificationEnabled === 'yes') {
+ checked = '';
+ if (mailSend === '1') {
+ 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;">';
@@ -688,5 +697,26 @@ $(document).ready(function() {
}
});
+ $(document).on('click', '#dropdown input[name=mailNotification]', function() {
+ 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'));
+ }
+ });
+
+});
+
});