Merge pull request #4689 from owncloud/sharing_mail_notification_master

send mail notification if a file was shared to a user/group
This commit is contained in:
Björn Schießle 2013-10-04 04:06:37 -07:00
commit 31d5565a18
13 changed files with 263 additions and 30 deletions

View File

@ -137,8 +137,10 @@ if ($needUpgrade) {
$tmpl->assign('isPublic', false);
$tmpl->assign('publicUploadEnabled', $publicUploadEnabled);
$tmpl->assign("encryptedFiles", \OCP\Util::encryptedFiles());
$tmpl->assign("mailNotificationEnabled", \OC_Appconfig::getValue('core', 'shareapi_allow_mail_notification', 'yes'));
$tmpl->assign("encryptionInitStatus", $encryptionInitStatus);
$tmpl->assign('disableSharing', false);
$tmpl->assign('ajaxLoad', $ajaxLoad);
$tmpl->printPage();
}

View File

@ -117,3 +117,4 @@
<input type="hidden" name="usedSpacePercent" id="usedSpacePercent" value="<?php p($_['usedSpacePercent']); ?>" />
<input type="hidden" name="encryptedFiles" id="encryptedFiles" value="<?php $_['encryptedFiles'] ? p('1') : p('0'); ?>" />
<input type="hidden" name="encryptedInitStatus" id="encryptionInitStatus" value="<?php p($_['encryptionInitStatus']) ?>" />
<input type="hidden" name="mailNotificationEnabled" id="mailNotificationEnabled" value="<?php p($_['mailNotificationEnabled']) ?>" />

View File

@ -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'])

View File

@ -11,7 +11,7 @@
margin-right:7em;
position:absolute;
right:0;
width:19em;
width:25em;
z-index:500;
padding:1em;
}

View File

@ -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);
}
var mailNotificationEnabled = $('input:hidden[name=mailNotificationEnabled]').val();
if (mailNotificationEnabled === 'yes') {
var 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;">';
@ -699,5 +708,27 @@ $(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');
var action = '';
if (this.checked) {
action = 'informRecipients';
} else {
action = 'informRecipientsDisabled';
}
var shareType = $(li).data('share-type');
var 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'));
}
});
});
});

View File

@ -1,5 +1,9 @@
<?php
print_unescaped($l->t("Hey there,\n\njust letting you know that %s shared %s with you.\nView it: %s\n\nCheers!", array($_['user_displayname'], $_['filename'], $_['link'])));
print_unescaped($l->t("Hey there,\n\njust letting you know that %s shared %s with you.\nView it: %s\n\n", array($_['user_displayname'], $_['filename'], $_['link'])));
if ( isset($_['expiration']) ) {
print_unescaped($l->t("The share will expire on %s.\n\n", array($_['expiration'])));
}
p($l->t("Cheers!"));
?>
--

View File

@ -12,7 +12,11 @@
<td bgcolor="#f8f8f8" width="20px">&nbsp;</td>
<td bgcolor="#f8f8f8" style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">
<?php
print_unescaped($l->t('Hey there,<br><br>just letting you know that %s shared »%s« with you.<br><a href="%s">View it!</a><br><br>Cheers!', array($_['user_displayname'], $_['filename'], $_['link'])));
print_unescaped($l->t('Hey there,<br><br>just letting you know that %s shared »%s« with you.<br><a href="%s">View it!</a><br><br>', array($_['user_displayname'], $_['filename'], $_['link'])));
if ( isset($_['expiration']) ) {
print_unescaped($l->t("The share will expire on %s.<br><br>", array($_['expiration'])));
}
p($l->t('Cheers!'));
?>
</td>
</tr>
@ -22,7 +26,8 @@ print_unescaped($l->t('Hey there,<br><br>just letting you know that %s shared »
<td bgcolor="#f8f8f8" style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">--<br>
<?php p($theme->getName()); ?> -
<?php p($theme->getSlogan()); ?>
<br><a href="<?php print_unescaped($theme->getBaseUrl()); ?>"><?php print_unescaped($theme->getBaseUrl());?></a></td>
<br><a href="<?php print_unescaped($theme->getBaseUrl()); ?>"><?php print_unescaped($theme->getBaseUrl());?></a>
</td>
</tr>
<tr>
<td bgcolor="#f8f8f8" colspan="2">&nbsp;</td>

View File

@ -844,6 +844,14 @@
<length>32</length>
</field>
<field>
<name>mail_send</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
<length>1</length>
</field>
<index>
<name>token_index</name>
<field>

View File

@ -13,6 +13,7 @@ if (file_exists(OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.
class OC_Defaults {
private $theme;
private $l;
private $defaultEntity;
private $defaultName;
@ -24,7 +25,7 @@ class OC_Defaults {
private $defaultLogoClaim;
function __construct() {
$l = OC_L10N::get('core');
$this->l = OC_L10N::get('core');
$this->defaultEntity = "ownCloud"; /* e.g. company name, used for footers and copyright notices */
$this->defaultName = "ownCloud"; /* short name, used when referring to the software */
@ -32,7 +33,7 @@ class OC_Defaults {
$this->defaultBaseUrl = "http://owncloud.org";
$this->defaultSyncClientUrl = " http://owncloud.org/sync-clients/";
$this->defaultDocBaseUrl = "http://doc.owncloud.org";
$this->defaultSlogan = $l->t("web services under your control");
$this->defaultSlogan = $this->l->t("web services under your control");
$this->defaultLogoClaim = "";
if (class_exists("OC_Theme")) {

View File

@ -168,7 +168,7 @@ class OC_Util {
OC_Util::loadVersion();
return \OC::$server->getSession()->get('OC_Channel');
}
/**
* @description get the build number of the current installed of ownCloud.
* @return string

View File

@ -246,9 +246,9 @@ class Share {
/**
* @brief Get the item of item type shared with the current user
* @param string Item type
* @param string Item target
* @param int Format (optional) Format type must be defined by the backend
* @param string $itemType
* @param string $ItemTarget
* @param int $format (optional) Format type must be defined by the backend
* @return Return depends on format
*/
public static function getItemSharedWith($itemType, $itemTarget, $format = self::FORMAT_NONE,
@ -257,6 +257,55 @@ class Share {
$parameters, 1, $includeCollections);
}
/**
* @brief Get the item of item type shared with a given user by source
* @param string $ItemType
* @param string $ItemSource
* @param string $user User user to whom the item was shared
* @return array Return list of items with file_target, permissions and expiration
*/
public static function getItemSharedWithUser($itemType, $itemSource, $user) {
$shares = array();
// first check if there is a db entry for the specific user
$query = \OC_DB::prepare(
'SELECT `file_target`, `permissions`, `expiration`
FROM
`*PREFIX*share`
WHERE
`item_source` = ? AND `item_type` = ? AND `share_with` = ?'
);
$result = \OC_DB::executeAudited($query, array($itemSource, $itemType, $user));
while ($row = $result->fetchRow()) {
$shares[] = $row;
}
//if didn't found a result than let's look for a group share.
if(empty($shares)) {
$groups = \OC_Group::getUserGroups($user);
$query = \OC_DB::prepare(
'SELECT `file_target`, `permissions`, `expiration`
FROM
`*PREFIX*share`
WHERE
`item_source` = ? AND `item_type` = ? AND `share_with` in (?)'
);
$result = \OC_DB::executeAudited($query, array($itemSource, $itemType, implode(',', $groups)));
while ($row = $result->fetchRow()) {
$shares[] = $row;
}
}
return $shares;
}
/**
* @brief Get the item of item type shared with the current user by source
* @param string Item type
@ -653,6 +702,29 @@ class Share {
}
return false;
}
/**
* @brief sent status if users got informed by mail about share
* @param string $itemType
* @param string $itemSource
* @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
* @param bool $status
*/
public static function setSendMailStatus($itemType, $itemSource, $shareType, $status) {
$status = $status ? 1 : 0;
$query = \OC_DB::prepare(
'UPDATE `*PREFIX*share`
SET `mail_send` = ?
WHERE `item_type` = ? AND `item_source` = ? AND `share_type` = ?');
$result = $query->execute(array($status, $itemType, $itemSource, $shareType));
if($result === false) {
\OC_Log::write('OCP\Share', 'Couldn\'t set send mail status', \OC_Log::ERROR);
}
}
/**
* @brief Set the permissions of an item for a specific user or group
@ -983,19 +1055,19 @@ class Share {
if ($format == self::FORMAT_STATUSES) {
if ($itemType == 'file' || $itemType == 'folder') {
$select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`,'
.' `share_type`, `file_source`, `path`, `expiration`, `storage`';
.' `share_type`, `file_source`, `path`, `expiration`, `storage`, `mail_send`';
} else {
$select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `expiration`';
$select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `expiration`, `mail_send`';
}
} else {
if (isset($uidOwner)) {
if ($itemType == 'file' || $itemType == 'folder') {
$select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`,'
.' `share_type`, `share_with`, `file_source`, `path`, `permissions`, `stime`,'
.' `expiration`, `token`, `storage`';
.' `expiration`, `token`, `storage`, `mail_send`';
} else {
$select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `permissions`,'
.' `stime`, `file_source`, `expiration`, `token`';
.' `stime`, `file_source`, `expiration`, `token`, `mail_send`';
}
} else {
if ($fileDependent) {
@ -1006,11 +1078,11 @@ class Share {
$select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `uid_owner`, '
.'`share_type`, `share_with`, `file_source`, `path`, `file_target`, '
.'`permissions`, `expiration`, `storage`, `*PREFIX*filecache`.`parent` as `file_parent`, '
.'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`';
.'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`, `mail_send`';
} else {
$select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`,
`*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`,
`file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`';
`file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`, `mail_send`';
}
} else {
$select = '*';

View File

@ -33,16 +33,17 @@ $tmpl->assign('shareAPIEnabled', OC_Appconfig::getValue('core', 'shareapi_enable
// Check if connected using HTTPS
if (OC_Request::serverProtocol() === 'https') {
$connectedHTTPS = true;
$connectedHTTPS = true;
} else {
$connectedHTTPS = false;
}
}
$tmpl->assign('isConnectedViaHTTPS', $connectedHTTPS);
$tmpl->assign('enforceHTTPSEnabled', OC_Config::getValue( "forcessl", false));
$tmpl->assign('allowLinks', OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes'));
$tmpl->assign('allowPublicUpload', OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes'));
$tmpl->assign('allowResharing', OC_Appconfig::getValue('core', 'shareapi_allow_resharing', 'yes'));
$tmpl->assign('allowMailNotification', OC_Appconfig::getValue('core', 'shareapi_allow_mail_notification', 'yes'));
$tmpl->assign('sharePolicy', OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global'));
$tmpl->assign('forms', array());
foreach($forms as $form) {

View File

@ -128,7 +128,7 @@ if (!$_['internetconnectionworking']) {
</td>
</tr>
<tr>
<td <?php if ($_['shareAPIEnabled'] === 'no') print_unescaped('style="display:none"');?>>
<td <?php if ($_['shareAPIEnabled'] === 'no') print_unescaped('class="hidden"');?>>
<input type="checkbox" name="shareapi_allow_links" id="allowLinks"
value="1" <?php if ($_['allowLinks'] === 'yes') print_unescaped('checked="checked"'); ?> />
<label for="allowLinks"><?php p($l->t('Allow links'));?></label><br/>
@ -137,7 +137,7 @@ if (!$_['internetconnectionworking']) {
</tr>
<?php if (!\OCP\App::isEnabled('files_encryption')) { ?>
<tr>
<td <?php if ($_['shareAPIEnabled'] == 'no') print_unescaped('style="display:none"');?>>
<td <?php if ($_['shareAPIEnabled'] == 'no') print_unescaped('class="hidden"');?>>
<input type="checkbox" name="shareapi_allow_public_upload" id="allowPublicUpload"
value="1" <?php if ($_['allowPublicUpload'] == 'yes') print_unescaped('checked="checked"'); ?> />
<label for="allowPublicUpload"><?php p($l->t('Allow public uploads'));?></label><br/>
@ -146,7 +146,7 @@ if (!$_['internetconnectionworking']) {
</tr>
<?php } ?>
<tr>
<td <?php if ($_['shareAPIEnabled'] === 'no') print_unescaped('style="display:none"');?>>
<td <?php if ($_['shareAPIEnabled'] === 'no') print_unescaped('class="hidden"');?>>
<input type="checkbox" name="shareapi_allow_resharing" id="allowResharing"
value="1" <?php if ($_['allowResharing'] === 'yes') print_unescaped('checked="checked"'); ?> />
<label for="allowResharing"><?php p($l->t('Allow resharing'));?></label><br/>
@ -154,7 +154,7 @@ if (!$_['internetconnectionworking']) {
</td>
</tr>
<tr>
<td <?php if ($_['shareAPIEnabled'] === 'no') print_unescaped('style="display:none"');?>>
<td <?php if ($_['shareAPIEnabled'] === 'no') print_unescaped('class="hidden"');?>>
<input type="radio" name="shareapi_share_policy" id="sharePolicyGlobal"
value="global" <?php if ($_['sharePolicy'] === 'global') print_unescaped('checked="checked"'); ?> />
<label for="sharePolicyGlobal"><?php p($l->t('Allow users to share with anyone')); ?></label><br/>
@ -163,6 +163,14 @@ if (!$_['internetconnectionworking']) {
<label for="sharePolicyGroupsOnly"><?php p($l->t('Allow users to only share with users in their groups'));?></label><br/>
</td>
</tr>
<tr>
<td <?php if ($_['shareAPIEnabled'] === 'no') print_unescaped('class="hidden"');?>>
<input type="checkbox" name="shareapi_allow_mail_notification" id="allowMailNotification"
value="1" <?php if ($_['allowMailNotification'] === 'yes') print_unescaped('checked="checked"'); ?> />
<label for="allowMailNotification"><?php p($l->t('Allow mail notification'));?></label><br/>
<em><?php p($l->t('Allow user to send mail notification for shared files')); ?></em>
</td>
</tr>
</table>
</fieldset>
@ -223,7 +231,7 @@ endfor;?>
</td>
<td>
<?php if(is_int($entry->time)){
p(OC_Util::formatDate($entry->time));
p(OC_Util::formatDate($entry->time));
} else {
p($entry->time);
}?>