From f007b4e7210288dd14b5ab4c5d057928a9673dfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Mon, 15 Jun 2026 10:23:04 +0400 Subject: [PATCH] =?UTF-8?q?v0.6.6:=20=D1=80=D0=B0=D0=B7=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=E2=80=94=20req.email(=D0=B0=D1=83?= =?UTF-8?q?=D0=B4=D0=B8=D1=82)=20vs=20req.displayEmail(=D1=8D=D0=BA=D1=80?= =?UTF-8?q?=D0=B0=D0=BD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- v2/src/config/index.js | 2 +- v2/src/impersonation/index.js | 3 ++- v2/src/router/index.js | 5 ++++- v2/src/user/index.js | 1 + views/v2/user.ejs | 4 ++-- 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 2f6231c..4348abd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipwhitelist", - "version": "0.6.5", + "version": "0.6.6", "description": "IP WhiteList microservice for cloud provider", "main": "server.js", "scripts": { diff --git a/v2/src/config/index.js b/v2/src/config/index.js index 6c51a09..b4c1221 100644 --- a/v2/src/config/index.js +++ b/v2/src/config/index.js @@ -9,7 +9,7 @@ // ═══════════════════════════════════════════════════════════════════════════════ module.exports = { - version: '0.6.5', + version: '0.6.6', // ── IAM ────────────────────────────────────────────────────────────────── iamUrl: process.env.V2_IAM_URL || 'https://auth-api.ngcloud.ru/api/v1/auth/user', diff --git a/v2/src/impersonation/index.js b/v2/src/impersonation/index.js index 00f0bcf..e2f9758 100644 --- a/v2/src/impersonation/index.js +++ b/v2/src/impersonation/index.js @@ -35,12 +35,13 @@ function enhanceImpersonation(req, res, next) { // Подмена сессии — авто-имперсонация const allCids = [COMPANY, ...EXTRA]; - u.originalUserEmail = ORIGINAL; // кто реально вошёл + u.originalUserEmail = ORIGINAL; // кто реально вошёл (KC) u.email = TARGET; // в кого имперсонируем u.clientId = COMPANY; u.activeClientId = COMPANY; u.allClientIds = allCids; u.isImpersonated = true; + u.impersonatedCompanyId = COMPANY; // для resolveContext u.companyName = COMPANY; u.profiles = allCids.map(cid => ({ client_id: cid, company_name: cid })); diff --git a/v2/src/router/index.js b/v2/src/router/index.js index 888e7a4..31434d6 100644 --- a/v2/src/router/index.js +++ b/v2/src/router/index.js @@ -36,9 +36,12 @@ function resolveContext(req, res, next) { // u.originalUserEmail — реальный админ // u.impersonatedCompanyId — W-номер компании const ADMIN_EMAIL = process.env.ADMIN_EMAIL || ''; - const isImpersonated = !!(u.originalUserEmail && u.impersonatedCompanyId); + const isImpersonated = !!(u.originalUserEmail && u.impersonatedCompanyId) || u.isImpersonated; + // req.email — для АУДИТА (реальный юзер при имперсонации) req.email = isImpersonated ? u.originalUserEmail : (u.email || ''); + // req.displayEmail — для ПОКАЗА на экране (текущий, может быть имперсонированным) + req.displayEmail = u.email || ''; req.clientId = isImpersonated ? u.impersonatedCompanyId : (u.activeClientId || u.clientId || ''); req.companyName = u.companyName || req.clientId; req.isAdmin = !!(u.isAdmin && u.adminMode) || (ADMIN_EMAIL && u.email === ADMIN_EMAIL); diff --git a/v2/src/user/index.js b/v2/src/user/index.js index fbdce60..6b558f3 100644 --- a/v2/src/user/index.js +++ b/v2/src/user/index.js @@ -43,6 +43,7 @@ function createUserRouter() { originalUserEmail: req.impersonatedBy ? req.email : null, email: req.email || (req.user && req.user.email) || (req.session && req.session.user && req.session.user.email) || '', loginEmail: (req.session && req.session.user && (req.session.user.originalUserEmail || req.session.user.email)) || req.email || '', + displayEmail: req.displayEmail || req.email || '', }); } catch (e) { res.status(500).send('

Ошибка

' + e.message + '
Назад'); diff --git a/views/v2/user.ejs b/views/v2/user.ejs index bd990ed..c91a63e 100644 --- a/views/v2/user.ejs +++ b/views/v2/user.ejs @@ -80,7 +80,7 @@ <% if (typeof isImpersonated !== 'undefined' && isImpersonated) { %> <% if (isImpersonated) { %>
- ⚠️ Режим имперсонации — данные сохраняются от имени <%= activeClientId %> + ⚠️ Режим имперсонации — данные сохраняются от имени <%= displayEmail %> (вы: <%= loginEmail %>)
<% } %> @@ -102,7 +102,7 @@
<%= used %>
из <%= limit %>
<%= activeClientId %> - <%= email %> + <%= displayEmail %>