summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2018-07-24 09:12:03 +0200
committerGitHub <noreply@github.com>2018-07-24 09:12:03 +0200
commitb41d0d32e2183b8b241d3764f06a3b0f7d6b86c1 (patch)
tree915e14ceafed060f95255e8d2d7d4ad3ab3df7b5 /lib
parent241e5705cb85d24a9c3479c133fcc4d9c069d8c7 (diff)
parentfee62fd20b01b08ffbc7120720ba3bad0a89be73 (diff)
downloadnextcloud-server-b41d0d32e2183b8b241d3764f06a3b0f7d6b86c1.tar.gz
nextcloud-server-b41d0d32e2183b8b241d3764f06a3b0f7d6b86c1.zip
Merge pull request #10218 from nextcloud/share-comments
allow to add a personal note to a share
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/Share/Share.php1
-rw-r--r--lib/private/Share20/DefaultShareProvider.php137
-rw-r--r--lib/private/Share20/ProviderFactory.php6
-rw-r--r--lib/private/Share20/Share.php20
-rw-r--r--lib/private/TemplateLayout.php4
-rw-r--r--lib/private/legacy/util.php10
-rw-r--r--lib/public/Share/IShare.php18
-rw-r--r--lib/public/Util.php10
10 files changed, 205 insertions, 3 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 234aa418f56..a060131979d 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -611,6 +611,7 @@ return array(
'OC\\Core\\Migrations\\Version14000Date20180518120534' => $baseDir . '/core/Migrations/Version14000Date20180518120534.php',
'OC\\Core\\Migrations\\Version14000Date20180522074438' => $baseDir . '/core/Migrations/Version14000Date20180522074438.php',
'OC\\Core\\Migrations\\Version14000Date20180626223656' => $baseDir . '/core/Migrations/Version14000Date20180626223656.php',
+ 'OC\\Core\\Migrations\\Version14000Date20180712153140' => $baseDir . '/core/Migrations/Version14000Date20180712153140.php',
'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php',
'OC\\DB\\AdapterMySQL' => $baseDir . '/lib/private/DB/AdapterMySQL.php',
'OC\\DB\\AdapterOCI8' => $baseDir . '/lib/private/DB/AdapterOCI8.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index c54120586f9..4c6c55a59ad 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -641,6 +641,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Core\\Migrations\\Version14000Date20180518120534' => __DIR__ . '/../../..' . '/core/Migrations/Version14000Date20180518120534.php',
'OC\\Core\\Migrations\\Version14000Date20180522074438' => __DIR__ . '/../../..' . '/core/Migrations/Version14000Date20180522074438.php',
'OC\\Core\\Migrations\\Version14000Date20180626223656' => __DIR__ . '/../../..' . '/core/Migrations/Version14000Date20180626223656.php',
+ 'OC\\Core\\Migrations\\Version14000Date20180712153140' => __DIR__ . '/../../..' . '/core/Migrations/Version14000Date20180712153140.php',
'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php',
'OC\\DB\\AdapterMySQL' => __DIR__ . '/../../..' . '/lib/private/DB/AdapterMySQL.php',
'OC\\DB\\AdapterOCI8' => __DIR__ . '/../../..' . '/lib/private/DB/AdapterOCI8.php',
diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php
index 52e0628987b..0a9371d35b8 100644
--- a/lib/private/Share/Share.php
+++ b/lib/private/Share/Share.php
@@ -86,7 +86,6 @@ class Share extends Constants {
);
if(count(self::$backendTypes) === 1) {
Util::addScript('core', 'merged-share-backend');
- \OC_Util::addStyle('core', 'share');
}
return true;
}
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php
index 5e52156d1d0..9c5d78a5958 100644
--- a/lib/private/Share20/DefaultShareProvider.php
+++ b/lib/private/Share20/DefaultShareProvider.php
@@ -30,8 +30,14 @@
namespace OC\Share20;
use OC\Files\Cache\Cache;
+use OCP\Defaults;
use OCP\Files\Folder;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\Mail\IMailer;
use OCP\Share\IShare;
+use OCP\Share\IShareHelper;
use OCP\Share\IShareProvider;
use OC\Share20\Exception\InvalidShare;
use OC\Share20\Exception\ProviderException;
@@ -67,6 +73,18 @@ class DefaultShareProvider implements IShareProvider {
/** @var IRootFolder */
private $rootFolder;
+ /** @var IMailer */
+ private $mailer;
+
+ /** @var Defaults */
+ private $defaults;
+
+ /** @var IL10N */
+ private $l;
+
+ /** @var IURLGenerator */
+ private $urlGenerator;
+
/**
* DefaultShareProvider constructor.
*
@@ -74,16 +92,28 @@ class DefaultShareProvider implements IShareProvider {
* @param IUserManager $userManager
* @param IGroupManager $groupManager
* @param IRootFolder $rootFolder
+ * @param IMailer $mailer ;
+ * @param Defaults $defaults
+ * @param IL10N $l
+ * @param IURLGenerator $urlGenerator
*/
public function __construct(
IDBConnection $connection,
IUserManager $userManager,
IGroupManager $groupManager,
- IRootFolder $rootFolder) {
+ IRootFolder $rootFolder,
+ IMailer $mailer,
+ Defaults $defaults,
+ IL10N $l,
+ IURLGenerator $urlGenerator) {
$this->dbConn = $connection;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->rootFolder = $rootFolder;
+ $this->mailer = $mailer;
+ $this->defaults = $defaults;
+ $this->l = $l;
+ $this->urlGenerator = $urlGenerator;
}
/**
@@ -197,6 +227,9 @@ class DefaultShareProvider implements IShareProvider {
* @return \OCP\Share\IShare The share object
*/
public function update(\OCP\Share\IShare $share) {
+
+ $originalShare = $this->getShareById($share->getId());
+
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
/*
* We allow updating the recipient on user shares.
@@ -211,6 +244,7 @@ class DefaultShareProvider implements IShareProvider {
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
+ ->set('note', $qb->createNamedParameter($share->getNote()))
->execute();
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
$qb = $this->dbConn->getQueryBuilder();
@@ -222,6 +256,7 @@ class DefaultShareProvider implements IShareProvider {
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
+ ->set('note', $qb->createNamedParameter($share->getNote()))
->execute();
/*
@@ -235,6 +270,7 @@ class DefaultShareProvider implements IShareProvider {
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
+ ->set('note', $qb->createNamedParameter($share->getNote()))
->execute();
/*
@@ -259,9 +295,15 @@ class DefaultShareProvider implements IShareProvider {
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('token', $qb->createNamedParameter($share->getToken()))
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
+ ->set('note', $qb->createNamedParameter($share->getNote()))
->execute();
}
+ if ($originalShare->getNote() !== $share->getNote() && $share->getNote() !== '') {
+ $this->propagateNote($share);
+ }
+
+
return $share;
}
@@ -875,6 +917,7 @@ class DefaultShareProvider implements IShareProvider {
->setShareType((int)$data['share_type'])
->setPermissions((int)$data['permissions'])
->setTarget($data['file_target'])
+ ->setNote($data['note'])
->setMailSend((bool)$data['mail_send']);
$shareTime = new \DateTime();
@@ -1227,4 +1270,96 @@ class DefaultShareProvider implements IShareProvider {
return $best;
}
+
+ /**
+ * propagate notes to the recipients
+ *
+ * @param IShare $share
+ * @throws \OCP\Files\NotFoundException
+ */
+ private function propagateNote(IShare $share) {
+ if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
+ $user = $this->userManager->get($share->getSharedWith());
+ $this->sendNote([$user], $share);
+ } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
+ $group = $this->groupManager->get($share->getSharedWith());
+ $groupMembers = $group->getUsers();
+ $this->sendNote($groupMembers, $share);
+ }
+ }
+
+ /**
+ * send note by mail
+ *
+ * @param array $recipients
+ * @param IShare $share
+ * @throws \OCP\Files\NotFoundException
+ */
+ private function sendNote(array $recipients, IShare $share) {
+
+ $toList = [];
+
+ foreach ($recipients as $recipient) {
+ /** @var IUser $recipient */
+ $email = $recipient->getEMailAddress();
+ if ($email) {
+ $toList[$email] = $recipient->getDisplayName();
+ }
+ }
+
+ if (!empty($toList)) {
+
+ $filename = $share->getNode()->getName();
+ $initiator = $share->getSharedBy();
+ $note = $share->getNote();
+
+ $initiatorUser = $this->userManager->get($initiator);
+ $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
+ $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
+ $plainHeading = $this->l->t('%1$s shared »%2$s« with you and wants to add:', [$initiatorDisplayName, $filename]);
+ $htmlHeading = $this->l->t('%1$s shared »%2$s« with you and wants to add', [$initiatorDisplayName, $filename]);
+ $message = $this->mailer->createMessage();
+
+ $emailTemplate = $this->mailer->createEMailTemplate('defaultShareProvider.sendNote');
+
+ $emailTemplate->setSubject($this->l->t('»%s« added a note to a file shared with you', [$initiatorDisplayName]));
+ $emailTemplate->addHeader();
+ $emailTemplate->addHeading($htmlHeading, $plainHeading);
+ $emailTemplate->addBodyText(htmlspecialchars($note), $note);
+
+ $link = $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $share->getNode()->getId()]);
+ $emailTemplate->addBodyButton(
+ $this->l->t('Open »%s«', [$filename]),
+ $link
+ );
+
+
+ // The "From" contains the sharers name
+ $instanceName = $this->defaults->getName();
+ $senderName = $this->l->t(
+ '%1$s via %2$s',
+ [
+ $initiatorDisplayName,
+ $instanceName
+ ]
+ );
+ $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
+ if ($initiatorEmailAddress !== null) {
+ $message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]);
+ $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
+ } else {
+ $emailTemplate->addFooter();
+ }
+
+ if (count($toList) === 1) {
+ $message->setTo($toList);
+ } else {
+ $message->setTo([]);
+ $message->setBcc($toList);
+ }
+ $message->useTemplate($emailTemplate);
+ $this->mailer->send($message);
+ }
+
+ }
}
diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php
index e4d34146911..0aacca409d1 100644
--- a/lib/private/Share20/ProviderFactory.php
+++ b/lib/private/Share20/ProviderFactory.php
@@ -81,7 +81,11 @@ class ProviderFactory implements IProviderFactory {
$this->serverContainer->getDatabaseConnection(),
$this->serverContainer->getUserManager(),
$this->serverContainer->getGroupManager(),
- $this->serverContainer->getLazyRootFolder()
+ $this->serverContainer->getLazyRootFolder(),
+ $this->serverContainer->getMailer(),
+ $this->serverContainer->query(Defaults::class),
+ $this->serverContainer->getL10N('sharing'),
+ $this->serverContainer->getURLGenerator()
);
}
diff --git a/lib/private/Share20/Share.php b/lib/private/Share20/Share.php
index d7810165dac..e54497c9b55 100644
--- a/lib/private/Share20/Share.php
+++ b/lib/private/Share20/Share.php
@@ -57,6 +57,8 @@ class Share implements \OCP\Share\IShare {
private $shareOwner;
/** @var int */
private $permissions;
+ /** @var string */
+ private $note = '';
/** @var \DateTime */
private $expireDate;
/** @var string */
@@ -311,6 +313,24 @@ class Share implements \OCP\Share\IShare {
/**
* @inheritdoc
*/
+ public function setNote($note) {
+ $this->note = $note;
+ return $this;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function getNote() {
+ if (is_string($this->note)) {
+ return $this->note;
+ }
+ return '';
+ }
+
+ /**
+ * @inheritdoc
+ */
public function setExpirationDate($expireDate) {
//TODO checks
diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php
index 1efdf8b441c..fc2e5798e1c 100644
--- a/lib/private/TemplateLayout.php
+++ b/lib/private/TemplateLayout.php
@@ -42,6 +42,7 @@ use OC\Template\JSCombiner;
use OC\Template\JSConfigHelper;
use OC\Template\SCSSCacher;
use OCP\Defaults;
+use OC\AppFramework\Http\Request;
class TemplateLayout extends \OC_Template {
@@ -61,6 +62,9 @@ class TemplateLayout extends \OC_Template {
// yes - should be injected ....
$this->config = \OC::$server->getConfig();
+ if(\OCP\Util::isIE()) {
+ \OC_Util::addStyle('ie');
+ }
// Decide which page we show
if($renderAs == 'user') {
diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php
index b285eb382e7..a581397212a 100644
--- a/lib/private/legacy/util.php
+++ b/lib/private/legacy/util.php
@@ -64,6 +64,7 @@ use OCP\IConfig;
use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IUser;
+use OC\AppFramework\Http\Request;
class OC_Util {
public static $scripts = array();
@@ -1528,4 +1529,13 @@ class OC_Util {
}
}
+ /**
+ * is this Internet explorer ?
+ *
+ * @return boolean
+ */
+ public static function isIe() {
+ return preg_match(Request::USER_AGENT_IE, $_SERVER['HTTP_USER_AGENT']) === 1;
+ }
+
}
diff --git a/lib/public/Share/IShare.php b/lib/public/Share/IShare.php
index 870794d6536..5303cde45a6 100644
--- a/lib/public/Share/IShare.php
+++ b/lib/public/Share/IShare.php
@@ -223,6 +223,24 @@ interface IShare {
public function getPermissions();
/**
+ * Attach a note to a share
+ *
+ * @param string $note
+ * @return \OCP\Share\IShare The modified object
+ * @since 14.0.0
+ */
+ public function setNote($note);
+
+ /**
+ * Get note attached to a share
+ *
+ * @return string
+ * @since 14.0.0
+ */
+ public function getNote();
+
+
+ /**
* Set the expiration date
*
* @param null|\DateTime $expireDate
diff --git a/lib/public/Util.php b/lib/public/Util.php
index 27b703ea2d8..9892f4a1ecb 100644
--- a/lib/public/Util.php
+++ b/lib/public/Util.php
@@ -558,4 +558,14 @@ class Util {
}
return self::$needUpgradeCache;
}
+
+ /**
+ * is this Internet explorer ?
+ *
+ * @return boolean
+ * @since 14.0.0
+ */
+ public static function isIe() {
+ return \OC_Util::isIe();
+ }
}