diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2019-09-25 14:27:06 +0300 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2019-09-26 11:54:28 +0300 |
commit | c1e66878fe4e77937615b5a4260b689d22491845 (patch) | |
tree | 76b9ba53d9792d04415da4176c5edb14b5946dc7 /lib | |
parent | 129a3c13798a469ba9eaba62a48444c1fd727e19 (diff) |
Override the current user when getting the room for a public share page
The public share page uses the incognito mode, so "OC.getCurrentUser()"
never returns a user, even if the user is actually logged in. However,
Talk API requests honour the actual current user, so the Talk UI needs
to honour it as well.
Moreover, when the external signaling server is used, the Talk UI needs
to honour the current user not only to show the right user name and
avatar, but to be able to even connect with the external signaling
server.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/PublicShareController.php | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/Controller/PublicShareController.php b/lib/Controller/PublicShareController.php index ab7f6f395..a555ae86d 100644 --- a/lib/Controller/PublicShareController.php +++ b/lib/Controller/PublicShareController.php @@ -33,6 +33,8 @@ use OCP\AppFramework\OCSController; use OCP\Files\FileInfo; use OCP\Files\NotFoundException; use OCP\IRequest; +use OCP\IUser; +use OCP\IUserManager; use OCP\ISession; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IManager as ShareManager; @@ -40,6 +42,10 @@ use OCP\Share\IShare; class PublicShareController extends OCSController { + /** @var string|null */ + private $userId; + /** @var IUserManager */ + private $userManager; /** @var ShareManager */ private $shareManager; /** @var ISession */ @@ -51,13 +57,17 @@ class PublicShareController extends OCSController { public function __construct( $appName, + ?string $UserId, IRequest $request, + IUserManager $userManager, ShareManager $shareManager, ISession $session, TalkSession $talkSession, Manager $manager ) { parent::__construct($appName, $request); + $this->userId = $UserId; + $this->userManager = $userManager; $this->shareManager = $shareManager; $this->session = $session; $this->talkSession = $talkSession; @@ -87,6 +97,11 @@ class PublicShareController extends OCSController { * be publicly shared (like a link share, for example); an error is returned * otherwise. * + * Besides the token of the room this also returns the current user ID and + * display name, if any; this is needed by the Talk sidebar to know the + * actual current user, as the public share page uses the incognito mode and + * thus logged in users as seen as guests. + * * @param string $shareToken * @return DataResponse the status code is "200 OK" if a room is returned, * or "404 Not found" if the given share token was invalid. @@ -119,8 +134,14 @@ class PublicShareController extends OCSController { $this->talkSession->setFileShareTokenForRoom($room->getToken(), $shareToken); + $currentUser = $this->userManager->get($this->userId); + $currentUserId = $currentUser instanceof IUser ? $currentUser->getUID() : ''; + $currentUserDisplayName = $currentUser instanceof IUser ? $currentUser->getDisplayName() : ''; + return new DataResponse([ - 'token' => $room->getToken() + 'token' => $room->getToken(), + 'userId' => $currentUserId, + 'userDisplayName' => $currentUserDisplayName, ]); } |