v2: таблицы v2_→оригинальные + impersonation модуль (IMPERSONATION_TARGET + EXTRA_COMPANIES)
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
// ═══════════════════════════════════════════════════════════════════════════════
|
||||
// V2 — Расширение имперсонации (отдельный модуль)
|
||||
//
|
||||
// ЭТО: middleware — добавляет дополнительные компании имперсонируемому юзеру.
|
||||
// НЕ: жёсткая логика в resolveContext или user/index.js.
|
||||
//
|
||||
// ENV:
|
||||
// IMPERSONATION_TARGET — email юзера, которому добавляем компании
|
||||
// IMPERSONATION_EXTRA_COMPANIES — W-номера через запятую (WZ01112,WZ03709)
|
||||
// ═══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
const TARGET_EMAIL = process.env.IMPERSONATION_TARGET || '';
|
||||
const EXTRA_COMPANIES = (process.env.IMPERSONATION_EXTRA_COMPANIES || '')
|
||||
.split(',').map(s => s.trim()).filter(Boolean);
|
||||
|
||||
function enhanceImpersonation(req, res, next) {
|
||||
if (!TARGET_EMAIL) return next();
|
||||
const u = req.session && req.session.user;
|
||||
if (!u || u.email !== TARGET_EMAIL) return next();
|
||||
|
||||
const current = u.allClientIds || [u.clientId || ''];
|
||||
u.allClientIds = [...new Set([...current, ...EXTRA_COMPANIES])].filter(Boolean);
|
||||
|
||||
if (!u.profiles) u.profiles = [];
|
||||
for (const cid of EXTRA_COMPANIES) {
|
||||
if (!u.profiles.find(p => p.client_id === cid))
|
||||
u.profiles.push({ client_id: cid, company_name: cid, is_active_profile: false });
|
||||
}
|
||||
next();
|
||||
}
|
||||
|
||||
module.exports = { enhanceImpersonation, TARGET_EMAIL, EXTRA_COMPANIES };
|
||||
Reference in New Issue
Block a user