v2: userFlow action + ENABLE_TEST_API флаг — отключение без удаления кода
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
// ═══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
module.exports = {
|
||||
version: '0.5.91',
|
||||
version: '0.5.92',
|
||||
iamUrl: process.env.V2_IAM_API_URL || 'https://auth-api.ngcloud.ru',
|
||||
appUrl: process.env.V2_APP_URL || 'https://whitelist.nodejsk8s.services.ngcloud.ru',
|
||||
};
|
||||
|
||||
@@ -84,6 +84,52 @@ function createTestRouter() {
|
||||
return res.json({ ok: true });
|
||||
}
|
||||
|
||||
// ── USERFLOW — полная эмуляция юзера через все слои ──
|
||||
case 'userFlow': {
|
||||
const sub = req.query.sub; // add | edit | delete | list
|
||||
const cidr = req.query.cidr || '';
|
||||
const comment = req.query.comment || '';
|
||||
const entryId = parseInt(req.query.id) || null;
|
||||
|
||||
// Мок сессии + контекст (как после KC+IAM+resolveContext)
|
||||
req.session = req.session || {};
|
||||
req.session.user = {
|
||||
email, clientId, activeClientId: clientId,
|
||||
allClientIds: [clientId], companyName: clientId,
|
||||
isAdmin: user.isAdmin || false,
|
||||
profiles: [{ client_id: clientId, company_name: clientId }],
|
||||
fio: 'Test User'
|
||||
};
|
||||
req.email = email;
|
||||
req.clientId = clientId;
|
||||
req.companyName = clientId;
|
||||
req.isAdmin = user.isAdmin || false;
|
||||
req.profiles = [{ client_id: clientId, company_name: clientId }];
|
||||
req.impersonatedBy = impBy;
|
||||
|
||||
try {
|
||||
if (sub === 'add') {
|
||||
const r = await crud.add(clientId, cidr, comment, email, impBy);
|
||||
return res.json({ ok: true, layer: 'user→crud→db', action: 'add', entry: r.entry, wasNormalized: r.wasNormalized });
|
||||
}
|
||||
if (sub === 'edit' && entryId) {
|
||||
const r = await crud.edit(entryId, clientId, cidr, comment, email, impBy);
|
||||
return res.json({ ok: true, layer: 'user→crud→db', action: 'edit', entry: r.entry, wasNormalized: r.wasNormalized });
|
||||
}
|
||||
if (sub === 'delete' && entryId) {
|
||||
await crud.remove(entryId, clientId, email, impBy);
|
||||
return res.json({ ok: true, layer: 'user→crud→db', action: 'delete' });
|
||||
}
|
||||
if (sub === 'list') {
|
||||
const { entries, used, limit } = await crud.list(clientId);
|
||||
return res.json({ ok: true, layer: 'user→crud→db', action: 'list', entries, count: entries.length, used, limit });
|
||||
}
|
||||
return res.json({ ok: false, error: 'userFlow sub: add|edit|delete|list (id для edit/delete)' });
|
||||
} catch (e) {
|
||||
return res.json({ ok: false, layer: 'user→crud→db', error: e.message });
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
return res.json({ ok: false, error: 'unknown action: ' + action });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user