aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files/index.php3
-rw-r--r--apps/files/templates/index.php1
-rw-r--r--core/ajax/share.php106
-rw-r--r--core/css/share.css4
-rw-r--r--core/js/share.js39
-rw-r--r--db_structure.xml8
-rw-r--r--lib/defaults.php31
-rw-r--r--lib/public/defaults.php19
-rw-r--r--lib/public/share.php81
-rwxr-xr-xlib/util.php16
-rwxr-xr-xsettings/admin.php5
-rw-r--r--settings/templates/admin.php10
12 files changed, 292 insertions, 31 deletions
diff --git a/apps/files/index.php b/apps/files/index.php
index e4d8e353858..7f5f9ec4741 100644
--- a/apps/files/index.php
+++ b/apps/files/index.php
@@ -131,7 +131,7 @@ if ($needUpgrade) {
if ($trashEnabled) {
$trashEmpty = \OCA\Files_Trashbin\Trashbin::isEmpty($user);
}
-
+
OCP\Util::addscript('files', 'fileactions');
OCP\Util::addscript('files', 'files');
OCP\Util::addscript('files', 'keyboardshortcuts');
@@ -151,5 +151,6 @@ 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->printPage();
}
diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php
index 360874103f8..e3fcecbe47a 100644
--- a/apps/files/templates/index.php
+++ b/apps/files/templates/index.php
@@ -120,3 +120,4 @@
<input type="hidden" name="allowZipDownload" id="allowZipDownload" value="<?php p($_['allowZipDownload']); ?>" />
<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="mailNotificationEnabled" id="mailNotificationEnabled" value="<?php p($_['mailNotificationEnabled']) ?>" />
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'));
+ }
+ });
+
+});
+
});
diff --git a/db_structure.xml b/db_structure.xml
index f926ab44cd4..f782a5e7708 100644
--- a/db_structure.xml
+++ b/db_structure.xml
@@ -846,6 +846,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>
diff --git a/lib/defaults.php b/lib/defaults.php
index 10813a3e8d8..26f417ae2ae 100644
--- a/lib/defaults.php
+++ b/lib/defaults.php
@@ -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")) {
@@ -47,6 +48,32 @@ class OC_Defaults {
return false;
}
+ /**
+ *
+ * @param string $itemType typically "file" or "folder"
+ */
+ public function getShareNotificationSubject($itemType) {
+ if ($this->themeExist('getShareNotificationSubject')) {
+ return $this->theme->getShareNotificationSubject($itemType);
+ } else {
+ return $this->l->t("A %s was shared with you", array($itemType));
+ }
+ }
+
+ /**
+ * @param string $sender owner of the file/folder
+ * @param string $itemName name of the file/folder
+ * @param string $itemType typically "file" or "folder"
+ * @param string $link link directly to the file/folder in your ownCloud
+ */
+ public function getShareNotificationText($sender, $itemName, $itemType, $link) {
+ if ($this->themeExist('getShareNotificationText')) {
+ return $this->theme->getShareNotificationText($sender, $itemName, $itemType, $link);
+ } else {
+ return $this->l->t("%s shared a %s called %s with you. You can find the %s here: %s", array($sender, $itemType, $itemName, $itemType, $link));
+ }
+ }
+
public function getBaseUrl() {
if ($this->themeExist('getBaseUrl')) {
return $this->theme->getBaseUrl();
diff --git a/lib/public/defaults.php b/lib/public/defaults.php
index 147f23e341f..9c8c3c0bdab 100644
--- a/lib/public/defaults.php
+++ b/lib/public/defaults.php
@@ -35,6 +35,25 @@ class Defaults {
}
/**
+ * @brief subject for notification mails if a new file was shared
+ * @param string $itemType typically "file" or "folder"
+ */
+ public function getShareNotificationSubject($itemType = "file") {
+ return $this->defaults->getShareNotificationSubject($itemType);
+ }
+
+ /**
+ * @brief mail body for notification mails if a new file was shared
+ * @param string $sender owner of the file/folder
+ * @param string $itemName name of the file/folder
+ * @param string $itemType typically "file" or "folder"
+ * @param string $link link directly to the file/folder in your ownCloud
+ */
+ public function getShareNotificationText($sender, $itemName, $itemType, $link) {
+ return $this->defaults->getShareNotificationText($sender, $itemName, $itemType, $link);
+ }
+
+ /**
* @breif get base URL for the organisation behind your ownCloud instance
* @return string
*/
diff --git a/lib/public/share.php b/lib/public/share.php
index b38208bc67f..eac6fab2b6a 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -106,22 +106,22 @@ class Share {
}
return false;
}
-
+
/**
* @brief Prepare a path to be passed to DB as file_target
* @return string Prepared path
*/
public static function prepFileTarget( $path ) {
-
+
// Paths in DB are stored with leading slashes, so add one if necessary
if ( substr( $path, 0, 1 ) !== '/' ) {
-
+
$path = '/' . $path;
-
+
}
-
+
return $path;
-
+
}
/**
@@ -251,7 +251,57 @@ class Share {
return self::getItems($itemType, $itemTarget, self::$shareTypeUserAndGroups, \OC_User::getUser(), null, $format,
$parameters, 1, $includeCollections);
}
-
+
+ /**
+ * @brief Get the item of item type shared with a given user by source
+ * @param string Item type
+ * @param string Item source
+ * @param string User user to whom the item was shared
+ * @return 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 = $query->execute(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 = $query->execute(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
@@ -633,6 +683,23 @@ 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` = ?');
+
+ $query->execute(array($status, $itemType, $itemSource, $shareType));
+ }
/**
* @brief Set the permissions of an item for a specific user or group
diff --git a/lib/util.php b/lib/util.php
index e03667b0794..ef77ba8a916 100755
--- a/lib/util.php
+++ b/lib/util.php
@@ -98,7 +98,7 @@ class OC_Util {
public static function getVersion() {
// hint: We only can count up. Reset minor/patchlevel when
// updating major/minor version number.
- return array(5, 80, 05);
+ return array(5, 80, 06);
}
/**
@@ -352,10 +352,10 @@ class OC_Util {
$encryptedFiles = true;
}
}
-
+
return $encryptedFiles;
}
-
+
/**
* Check for correct file permissions of data directory
* @return array arrays with error messages and hints
@@ -581,16 +581,16 @@ class OC_Util {
}
return $value;
}
-
+
/**
* @brief Public function to encode url parameters
*
* This function is used to encode path to file before output.
* Encoding is done according to RFC 3986 with one exception:
- * Character '/' is preserved as is.
+ * Character '/' is preserved as is.
*
* @param string $component part of URI to encode
- * @return string
+ * @return string
*/
public static function encodePath($component) {
$encoded = rawurlencode($component);
@@ -734,7 +734,7 @@ class OC_Util {
}
}
-
+
/**
* Check if the connection to the internet is disabled on purpose
*/
@@ -887,7 +887,7 @@ class OC_Util {
$theme = OC_Config::getValue("theme", '');
if($theme === '') {
-
+
if(is_dir(OC::$SERVERROOT . '/themes/default')) {
$theme = 'default';
}
diff --git a/settings/admin.php b/settings/admin.php
index 869729a9e41..38b77a615dd 100755
--- a/settings/admin.php
+++ b/settings/admin.php
@@ -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) {
diff --git a/settings/templates/admin.php b/settings/templates/admin.php
index e54586b80df..22cf946803e 100644
--- a/settings/templates/admin.php
+++ b/settings/templates/admin.php
@@ -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('style="display:none"');?>>
+ <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);
}?>