Skip to content

Commit

Permalink
Add support for link shares in "share:password" rooms
Browse files Browse the repository at this point in the history
Until now only the e-mail shares had support for sending the password by
Talk. In Nextcloud 15 that feature was added to link shares too, so the
room name and the notification sent for "share:password" rooms has to be
adjusted accordingly.

The display name of "share:password" rooms is generated from the raw
name of the room (the e-mail for mail shares and the file name for link
shares) each time the room information is sent by the server, so the
display name was generalized to accomodate both types of raw names.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
danxuliu committed Nov 8, 2018
1 parent 86f7c8f commit e13571f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
9 changes: 8 additions & 1 deletion lib/Controller/PublicShareAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Share;
use OCP\Share\IManager as ShareManager;
use OCP\Share\Exceptions\ShareNotFound;

Expand Down Expand Up @@ -100,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 @@ -227,7 +227,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
28 changes: 17 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,24 @@ protected function parsePasswordRequest(INotification $notification, Room $room,
throw new \InvalidArgumentException('Unknown share');
}

$sharedWith = $share->getSharedWith();
if ($share->getShareType() === Share::SHARE_TYPE_EMAIL) {
$sharedWith = $share->getSharedWith();

$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,
$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,
]
]
]
);
);
} else {
$notification
->setParsedSubject($l->t('Someone requested the password to access a share'));
}

return $notification;
}
Expand Down

0 comments on commit e13571f

Please sign in to comment.