Skip to content

Commit

Permalink
fix logout as impersonated user
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Feb 27, 2023
1 parent 92b78be commit 2bb059c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
8 changes: 3 additions & 5 deletions js/impersonate_logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ document.addEventListener('DOMContentLoaded', function() {
}
);

function logoutHandler(userId) {
function logoutHandler() {
var promisObj = $.post(
OC.generateUrl('apps/impersonate/logout'),
{userId: userId}
OC.generateUrl('apps/impersonate/logout')
).promise()

promisObj.done(function () {
Expand All @@ -27,7 +26,6 @@ document.addEventListener('DOMContentLoaded', function() {

$('#settings ul li:last').on('click', function (event) {
event.preventDefault()
var userId = $("#expandDisplayName").text()
logoutHandler(userId)
logoutHandler()
})
})
14 changes: 6 additions & 8 deletions lib/Controller/LogoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,28 @@ public function __construct($appName,
* @UseSession
* @NoAdminRequired
*/
public function logout(string $userId): JSONResponse {
public function logout(): JSONResponse {
/** @var ?string $impersonatorUid */
$impersonatorUid = $this->session->get('oldUserId');
$impersonator = $this->userManager->get($impersonatorUid);

if ($impersonator === null) {
return new JSONResponse(
sprintf(
'No user found for %s',
$userId
),
'No impersonating user found.',
Http::STATUS_NOT_FOUND
);
}

$impersonatedUser = $this->userManager->get($userId);
$impersonatedUser = $this->userSession->getUser();

$this->eventDispatcher->dispatchTyped(new EndImpersonateEvent($impersonator, $impersonatedUser));

$this->userSession->setUser($impersonator);

$this->logger->info(
sprintf(
'Switching back to previous user %s',
$userId
'Switching back to previous user %s from user %s',
$impersonatorUid, $impersonatedUser->getUID()
),
[
'app' => 'impersonate',
Expand Down

0 comments on commit 2bb059c

Please sign in to comment.