v0.5.125: switchTo без редиректа, дебаг на странице
This commit is contained in:
+6
-19
@@ -50,29 +50,15 @@ function createUserRouter() {
|
||||
}
|
||||
|
||||
// ── Переключение компании (до crud.list — не грузить зря) ────
|
||||
let switchDebug = null;
|
||||
if (req.query.switchTo) {
|
||||
const targetId = req.query.switchTo;
|
||||
const allowed = isAdmin || (req.profiles || []).find(p => p.client_id === targetId);
|
||||
if (allowed) {
|
||||
console.log('[v2:switchTo] before save', {
|
||||
sessionID: req.sessionID,
|
||||
oldActiveClientId: req.session && req.session.user ? req.session.user.activeClientId : null,
|
||||
oldClientId: req.session && req.session.user ? req.session.user.clientId : null,
|
||||
targetId,
|
||||
email: req.email,
|
||||
});
|
||||
const oldId = req.session.user.activeClientId;
|
||||
req.session.user.activeClientId = targetId;
|
||||
return req.session.save(err => {
|
||||
if (err) {
|
||||
console.error('[v2:switchTo] save error:', err.message);
|
||||
} else {
|
||||
console.log('[v2:switchTo] after save', {
|
||||
sessionID: req.sessionID,
|
||||
savedActiveClientId: req.session && req.session.user ? req.session.user.activeClientId : null,
|
||||
});
|
||||
}
|
||||
res.redirect('/v2/app');
|
||||
});
|
||||
// clId теперь новый — рендерим сразу, без редиректа
|
||||
switchDebug = { from: oldId, to: targetId, sessionID: req.sessionID };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,11 +82,12 @@ function createUserRouter() {
|
||||
res.render('v2/user', {
|
||||
entries, limit, used,
|
||||
companies,
|
||||
activeClientId: clId,
|
||||
activeClientId: switchDebug ? switchDebug.to : clId,
|
||||
debugClientId: clId,
|
||||
sessionId: req.sessionID || '',
|
||||
sessionActiveClientId: req.session && req.session.user ? (req.session.user.activeClientId || '') : '',
|
||||
sessionClientId: req.session && req.session.user ? (req.session.user.clientId || '') : '',
|
||||
switchDebug,
|
||||
user: templateUser,
|
||||
includeDeleted,
|
||||
version: config.version,
|
||||
|
||||
@@ -139,6 +139,14 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% if (typeof switchDebug !== 'undefined' && switchDebug) { %>
|
||||
<div style="background:#fff3cd;border:2px solid #d97706;color:#92400e;padding:.5rem 1rem;border-radius:8px;margin-bottom:.5rem;font-size:.85rem;">
|
||||
<strong>DEBUG SWITCH:</strong> <%= switchDebug.from %> → <%= switchDebug.to %>
|
||||
| sessionID: <%= switchDebug.sessionID %>
|
||||
| activeClientId: <%= activeClientId %>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
<% if (user.isImpersonated) { %>
|
||||
<div class="alert alert-warn">
|
||||
⚠️ Режим имперсонации — данные сохраняются от имени <strong><%= activeClientId %></strong>
|
||||
|
||||
Reference in New Issue
Block a user