Skip to content

Commit

Permalink
add direct link to the file for user/group shares
Browse files Browse the repository at this point in the history
  • Loading branch information
schiessle committed Jul 12, 2018
1 parent 106beb6 commit 278fe41
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
22 changes: 18 additions & 4 deletions lib/private/Share20/DefaultShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCP\Defaults;
use OCP\Files\Folder;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Mail\IMailer;
use OCP\Share\IShare;
Expand Down Expand Up @@ -81,6 +82,9 @@ class DefaultShareProvider implements IShareProvider {
/** @var IL10N */
private $l;

/** @var IURLGenerator */
private $urlGenerator;

/**
* DefaultShareProvider constructor.
*
Expand All @@ -91,6 +95,7 @@ class DefaultShareProvider implements IShareProvider {
* @param IMailer $mailer ;
* @param Defaults $defaults
* @param IL10N $l
* @param IURLGenerator $urlGenerator
*/
public function __construct(
IDBConnection $connection,
Expand All @@ -99,14 +104,16 @@ public function __construct(
IRootFolder $rootFolder,
IMailer $mailer,
Defaults $defaults,
IL10N $l) {
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;
}

/**
Expand Down Expand Up @@ -1309,18 +1316,25 @@ private function sendNote(array $recipients, IShare $share) {
$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 want to add:', [$initiatorDisplayName, $filename]);
$htmlHeading = $this->l->t('%1$s shared »%2$s« with you and want to add:', [$initiatorDisplayName, $filename]);

$link = $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $share->getNode()->getId()]);
if($share->getNode()->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
$plainLink = $this->l->t('Direct link to the file: %s', [$link]);
$htmlLink = $this->l->t('<a href="%s">Direct link to the file.</a>', [$link]);
} else {
$plainLink = $this->l->t('Direct link to the folder: %s', [$link]);
$htmlLink = $this->l->t('<a href="%s">Direct link to the folder.</a>', [$link]);
}
$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(htmlspecialchars($htmlHeading), $plainHeading);
$emailTemplate->addHeading($htmlHeading, $plainHeading);
$emailTemplate->addBodyText(htmlspecialchars($note), $note);
$emailTemplate->addBodyText($htmlLink, $plainLink);

// The "From" contains the sharers name
$instanceName = $this->defaults->getName();
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Share20/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ protected function defaultShareProvider() {
$this->serverContainer->getLazyRootFolder(),
$this->serverContainer->getMailer(),
$this->serverContainer->query(Defaults::class),
$this->serverContainer->getL10N('sharing')
$this->serverContainer->getL10N('sharing'),
$this->serverContainer->getURLGenerator()
);
}

Expand Down

0 comments on commit 278fe41

Please sign in to comment.