Skip to content

Commit 4b137ed

Browse files
authored
Merge pull request #4875 from neos/bugfix/user-impersonation-with-subfolders
BUGFIX: Use a dynamic URL for user impersonation
2 parents 0a234a6 + df81b03 commit 4b137ed

File tree

5 files changed

+47
-17
lines changed

5 files changed

+47
-17
lines changed

Neos.Neos/Resources/Private/Partials/Backend/UserMenu.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{namespace neos=Neos\Neos\ViewHelpers}
2-
<div class="neos-button-group neos-user-menu" data-csrf-Token="{f:security.csrfToken()}">
2+
<div class="neos-button-group neos-user-menu" data-csrf-Token="{f:security.csrfToken()}" data-module-basepath="{neos:uri.module(path: '')}">
33
<button class="neos-dropdown-toggle neos-button" data-neos-toggle="dropdown" href="#" title="{neos:backend.translate(id: 'userSettings.usermenu', source: 'Modules', value: 'User Menu')}" data-neos-tooltip data-placement="left">
44
<i class="fas fa-user"></i> {user.name.fullName} <i class="fas fa-chevron-down"></i>
55
</button>

Neos.Neos/Resources/Public/JavaScript/Components/TopBar/UserMenu.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,35 @@ import { isNil } from '../../Helper'
22
import {ApiService} from '../../Services'
33
import { RestoreButton } from '../../Templates/RestoreButton'
44

5-
const BASE_PATH = '/neos/impersonate/'
65
export default class UserMenu {
76
constructor(_root) {
8-
const csfrTokenField = document.querySelector('.neos-user-menu[data-csrf-token]')
9-
this._csrfToken = !isNil(csfrTokenField)
10-
? csfrTokenField.getAttribute('data-csrf-token')
11-
: ''
7+
const userMenuElement = document.querySelector('.neos-user-menu[data-csrf-token]')
8+
this._csrfToken = isNil(userMenuElement) ? '' : userMenuElement.getAttribute('data-csrf-token')
9+
this._baseModuleUri = this._getBaseModuleUri(userMenuElement)
10+
this._basePath = this._getImpersonationBasePath()
1211
this._root = _root
13-
this._apiService = new ApiService(BASE_PATH, this._csrfToken)
12+
this._apiService = new ApiService(this._basePath, this._csrfToken)
1413

1514
if (!isNil(_root)) {
1615
this._checkImpersonateStatus()
1716
}
1817
}
1918

19+
_getBaseModuleUri(element) {
20+
let url = '/neos'
21+
if (!isNil(element) && element.hasAttribute('data-module-basepath')) {
22+
url = element.getAttribute('data-module-basepath')
23+
}
24+
return url
25+
}
26+
27+
_getImpersonationBasePath() {
28+
let basePath = this._baseModuleUri
29+
if (!basePath.endsWith('/')) {
30+
basePath += '/'
31+
}
32+
return basePath + 'impersonate/'
33+
}
2034
_renderRestoreButton(user) {
2135
const userMenuDropDown = this._root.querySelector('.neos-dropdown-menu')
2236
if (isNil(userMenuDropDown) || isNil(user)) {
@@ -64,7 +78,7 @@ export default class UserMenu {
6478
const response = this._apiService.callRestore()
6579
response
6680
.then((data) => {
67-
const { origin, impersonate, status } = data
81+
const { origin, impersonate } = data
6882
const message = window.NeosCMS.I18n.translate(
6983
'impersonate.success.restoreUser',
7084
'Switched back from {0} to the orginal user {1}.',
@@ -79,7 +93,7 @@ export default class UserMenu {
7993

8094
// load default backend, so we don't need to care for the module permissions.
8195
// because in not every neos version the users have by default the content module or user module
82-
window.location.pathname = '/neos'
96+
window.location.href = this._baseModuleUri
8397
})
8498
.catch(function (error) {
8599
if (window.NeosCMS) {

Neos.Neos/Resources/Public/JavaScript/Main.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Neos.Neos/Resources/Public/JavaScript/Main.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Neos.Neos/Resources/Public/JavaScript/Module/Administration/UserManagement.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import {isNil} from '../../Helper'
22
import {ApiService} from '../../Services'
33
import {ImpersonateButton} from '../../Templates/ImpersonateButton'
44

5-
const BASE_PATH = '/neos/impersonate/'
65
export default class UserManagement {
76
constructor(_root) {
8-
const csfrTokenField = document.querySelector('.neos-user-menu[data-csrf-token]')
7+
const userMenuElement = document.querySelector('.neos-user-menu[data-csrf-token]')
98
this._root = _root
10-
this._csrfToken = !isNil(csfrTokenField) ? csfrTokenField.getAttribute('data-csrf-token') : ''
11-
this._apiService = new ApiService(BASE_PATH, this._csrfToken)
9+
this._csrfToken = isNil(userMenuElement) ? '' : userMenuElement.getAttribute('data-csrf-token')
10+
this._baseModuleUri = this._getBaseModuleUri(userMenuElement)
11+
this._basePath = this._getImpersonationBasePath()
12+
this._apiService = new ApiService(this._basePath, this._csrfToken)
1213

1314
if (!isNil(_root)) {
1415
this._initialize()
@@ -27,6 +28,21 @@ export default class UserManagement {
2728
});
2829
}
2930

31+
_getBaseModuleUri(element) {
32+
let url = '/neos'
33+
if (!isNil(element) && element.hasAttribute('data-module-basepath')) {
34+
url = element.getAttribute('data-module-basepath')
35+
}
36+
return url
37+
}
38+
39+
_getImpersonationBasePath() {
40+
let basePath = this._baseModuleUri
41+
if (!basePath.endsWith('/')) {
42+
basePath += '/'
43+
}
44+
return basePath + 'impersonate/'
45+
}
3046
_renderImpersonateButtons() {
3147
const userTableActionButtons = Array.from(this._root.querySelectorAll('.neos-table .neos-action'))
3248
userTableActionButtons.forEach(_actionContainer => {
@@ -61,14 +77,14 @@ export default class UserManagement {
6177
const response = this._apiService.callUserChange(identifier);
6278
response
6379
.then((data) => {
64-
const {user, status} = data
80+
const {user} = data
6581
const username = isNil(user) ? '' : user.accountIdentifier
6682
const message = window.NeosCMS.I18n.translate('impersonate.success.impersonateUser', 'Switched to the new user {0}.', 'Neos.Neos', 'Main', {0: username})
6783
window.NeosCMS.Notification.ok(message)
6884

6985
// load default backend, so we don't need to care for the module permissions.
7086
// because in not every neos version the users have by default the content module or user module
71-
window.location.pathname = '/neos'
87+
window.location.href = this._baseModuleUri
7288
})
7389
.catch(function (error) {
7490
if (window.NeosCMS) {

0 commit comments

Comments
 (0)