summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2018-11-12 11:16:11 +0100
committerGitHub <noreply@github.com>2018-11-12 11:16:11 +0100
commit95cce7d84c19579ec5fb8f9f8c1fc6ced02055fa (patch)
treee5a2b578cee4ea5847ba05468871024924e090f5
parentb7d907700ddaaece05b948f59a569085e5c75f7f (diff)
parent876165bfde2924f10db94f886250fd616a9501bf (diff)
Merge pull request #1273 from nextcloud/add-support-for-sending-the-password-for-a-link-share-by-nextcloud-talk
Add support for sending the password for a link share by Nextcloud Talk
-rw-r--r--lib/Controller/PublicShareAuthController.php18
-rw-r--r--lib/Controller/RoomController.php2
-rw-r--r--lib/Notification/Notifier.php41
3 files changed, 39 insertions, 22 deletions
diff --git a/lib/Controller/PublicShareAuthController.php b/lib/Controller/PublicShareAuthController.php
index 96fc2ddc0..c0d61394d 100644
--- a/lib/Controller/PublicShareAuthController.php
+++ b/lib/Controller/PublicShareAuthController.php
@@ -32,7 +32,7 @@ use OCP\AppFramework\OCSController;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
-use OCP\Notification\IManager as NotificationManager;
+use OCP\Share;
use OCP\Share\IManager as ShareManager;
use OCP\Share\Exceptions\ShareNotFound;
@@ -40,8 +40,6 @@ class PublicShareAuthController extends OCSController {
/** @var IUserManager */
private $userManager;
- /** @var NotificationManager */
- private $notificationManager;
/** @var ShareManager */
private $shareManager;
/** @var Manager */
@@ -51,7 +49,6 @@ class PublicShareAuthController extends OCSController {
* @param string $appName
* @param IRequest $request
* @param IUserManager $userManager
- * @param NotificationManager $notificationManager
* @param ShareManager $shareManager
* @param Manager $manager
*/
@@ -59,13 +56,11 @@ class PublicShareAuthController extends OCSController {
string $appName,
IRequest $request,
IUserManager $userManager,
- NotificationManager $notificationManager,
ShareManager $shareManager,
Manager $manager
) {
parent::__construct($appName, $request);
$this->userManager = $userManager;
- $this->notificationManager = $notificationManager;
$this->shareManager = $shareManager;
$this->manager = $manager;
}
@@ -81,9 +76,6 @@ class PublicShareAuthController extends OCSController {
* a guest or user on behalf of a registered user, the sharer, who will be
* the owner of the room.
*
- * If there is already a room for requesting the password of the given share
- * no new room is created; the existing room is returned instead.
- *
* The share must have "send password by Talk" enabled; an error is returned
* otherwise.
*
@@ -109,8 +101,14 @@ class PublicShareAuthController extends OCSController {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
+ if ($share->getShareType() === Share::SHARE_TYPE_EMAIL) {
+ $roomName = $share->getSharedWith();
+ } else {
+ $roomName = trim($share->getTarget(), '/');
+ }
+
// Create the room
- $room = $this->manager->createPublicRoom($share->getSharedWith(), 'share:password', $shareToken);
+ $room = $this->manager->createPublicRoom($roomName, 'share:password', $shareToken);
$room->addUsers([
'userId' => $sharerUser->getUID(),
'participantType' => Participant::OWNER,
diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php
index e27ac8069..ad29ca481 100644
--- a/lib/Controller/RoomController.php
+++ b/lib/Controller/RoomController.php
@@ -228,7 +228,7 @@ class RoomController extends OCSController {
if ($room->getObjectType() === 'share:password') {
// FIXME use an event
- $roomData['displayName'] = $this->l10n->t('Password request by %s', [$room->getName()]);
+ $roomData['displayName'] = $this->l10n->t('Password request: %s', [$room->getName()]);
}
$currentUser = $this->userManager->get($this->userId);
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php
index 7bf1d543c..e62c56f82 100644
--- a/lib/Notification/Notifier.php
+++ b/lib/Notification/Notifier.php
@@ -37,6 +37,7 @@ use OCP\L10N\IFactory;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
use OCP\RichObjectStrings\Definitions;
+use OCP\Share;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager as IShareManager;
@@ -463,19 +464,37 @@ class Notifier implements INotifier {
throw new \InvalidArgumentException('Unknown share');
}
- $sharedWith = $share->getSharedWith();
+ try {
+ $file = [
+ 'type' => 'highlight',
+ 'id' => $share->getNodeId(),
+ 'name' => $share->getNode()->getName(),
+ ];
+ } catch (\OCP\Files\NotFoundException $e) {
+ throw new \InvalidArgumentException('Unknown file');
+ }
- $notification
- ->setParsedSubject(str_replace('{email}', $sharedWith, $l->t('{email} requested the password to access a share')))
- ->setRichSubject(
- $l->t('{email} requested the password to access a share'), [
- 'email' => [
- 'type' => 'email',
- 'id' => $sharedWith,
- 'name' => $sharedWith,
+ if ($share->getShareType() === Share::SHARE_TYPE_EMAIL) {
+ $sharedWith = $share->getSharedWith();
+
+ $notification
+ ->setParsedSubject(str_replace(['{email}', '{file}'], [$sharedWith, $file['name']], $l->t('{email} requested the password to access {file}')))
+ ->setRichSubject(
+ $l->t('{email} requested the password to access {file}'),
+ [
+ 'email' => [
+ 'type' => 'email',
+ 'id' => $sharedWith,
+ 'name' => $sharedWith,
+ ],
+ 'file' => $file,
]
- ]
- );
+ );
+ } else {
+ $notification
+ ->setParsedSubject(str_replace('{file}', $file['name'], $l->t('Someone requested the password to access {file}')))
+ ->setRichSubject($l->t('Someone requested the password to access {file}'), ['file' => $file]);
+ }
return $notification;
}