Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable the "switch user" button if it would impersonate the original user #1581

Merged
merged 1 commit into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
"contao/manager-plugin": "<2.0 || >=3.0",
"doctrine/persistence": "1.3.2",
"symfony/config": "<4.4.2",
"symfony/security-bundle": "4.4.* <4.4.5",
"terminal42/contao-ce-access": "<3.0",
"zendframework/zend-code": "<3.3.1"
},
Expand Down
1 change: 1 addition & 0 deletions core-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"contao/core": "*",
"contao/manager-bundle": "4.5.* <4.5.2",
"contao/manager-plugin": "<2.0 || >=3.0",
"symfony/security-bundle": "4.4.* <4.4.5",
"terminal42/contao-ce-access": "<3.0"
},
"require-dev": {
Expand Down
35 changes: 33 additions & 2 deletions core-bundle/src/Resources/contao/dca/tl_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,11 @@
*/
class tl_user extends Contao\Backend
{
/**
* @var int
*/
private static $origUserId;

/**
* Import the back end user object
*/
Expand Down Expand Up @@ -700,14 +705,40 @@ public function deleteUser($row, $href, $label, $title, $icon, $attributes)
*/
public function switchUser($row, $href, $label, $title, $icon)
{
$authorizationChecker = Contao\System::getContainer()->get('security.authorization_checker');
$security = Contao\System::getContainer()->get('security.helper');

if (!$authorizationChecker->isGranted('ROLE_ALLOWED_TO_SWITCH') || $authorizationChecker->isGranted('ROLE_PREVIOUS_ADMIN'))
if (!$security->isGranted('ROLE_ALLOWED_TO_SWITCH'))
{
return '';
}

$disabled = false;

if ($this->User->id == $row['id'])
{
$disabled = true;
}
elseif ($security->isGranted('ROLE_PREVIOUS_ADMIN'))
{
if (self::$origUserId === null)
{
/** @var Symfony\Component\Security\Core\Authentication\Token\TokenInterface $origToken */
$origToken = $security->getToken()->getOriginalToken();
$origUser = $origToken->getUser();

if ($origUser instanceof Contao\BackendUser)
{
self::$origUserId = $origUser->id;
}
}

if (self::$origUserId == $row['id'])
{
$disabled = true;
}
}

if ($disabled)
{
return Contao\Image::getHtml(preg_replace('/\.svg$/i', '_.svg', $icon)) . ' ';
}
Expand Down
3 changes: 2 additions & 1 deletion manager-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"symfony/phpunit-bridge": "4.4.*"
},
"conflict": {
"symfony/config": "<4.4.2"
"symfony/config": "<4.4.2",
"symfony/security-bundle": "4.4.* <4.4.5"
},
"suggest": {
"contao/tcpdf-bundle": "To export articles as PDF files"
Expand Down