Skip to content

Commit

Permalink
Merge pull request #1273 from nextcloud/add-support-for-sending-the-p…
Browse files Browse the repository at this point in the history
…assword-for-a-link-share-by-nextcloud-talk

Add support for sending the password for a link share by Nextcloud Talk
  • Loading branch information
nickvergessen authored Nov 12, 2018
2 parents b7d9077 + 876165b commit 95cce7d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
18 changes: 8 additions & 10 deletions lib/Controller/PublicShareAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@
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;

class PublicShareAuthController extends OCSController {

/** @var IUserManager */
private $userManager;
/** @var NotificationManager */
private $notificationManager;
/** @var ShareManager */
private $shareManager;
/** @var Manager */
Expand All @@ -51,21 +49,18 @@ class PublicShareAuthController extends OCSController {
* @param string $appName
* @param IRequest $request
* @param IUserManager $userManager
* @param NotificationManager $notificationManager
* @param ShareManager $shareManager
* @param Manager $manager
*/
public function __construct(
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;
}
Expand All @@ -81,9 +76,6 @@ public function __construct(
* 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.
*
Expand All @@ -109,8 +101,14 @@ public function createRoom(string $shareToken): DataResponse {
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,
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ protected function formatRoom(Room $room, Participant $participant = null): arra

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);
Expand Down
41 changes: 30 additions & 11 deletions lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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;

Expand Down Expand Up @@ -463,19 +464,37 @@ protected function parsePasswordRequest(INotification $notification, Room $room,
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;
}
Expand Down

0 comments on commit 95cce7d

Please sign in to comment.