fix: X-Imp-* headers bridge UI→API impersonation + timezone GMT+4

This commit is contained in:
2026-06-11 20:17:07 +04:00
parent d0a0fdc264
commit 68ea44a81d
5 changed files with 50 additions and 14 deletions
+10 -6
View File
@@ -38,6 +38,7 @@ function createRouter() {
// GET / — список записей
router.get('/', async (req, res) => {
const token = api.token(req);
const imp = api.impHeaders(req);
// ── Переключатель компании через IAM ────────────────────────────────
const switchTo = (req.query.switchTo || '').trim();
@@ -78,7 +79,7 @@ function createRouter() {
let entries = [], limit = 15, selectedCompany = null, companies = [];
if (req.user.adminMode) {
const cr = await api.get('/api/v1/companies', token);
const cr = await api.get('/api/v1/companies', token, imp);
companies = cr.data.companies || [];
const companyId = req.query.company ? parseInt(req.query.company, 10) : null;
@@ -91,7 +92,7 @@ function createRouter() {
if (selectedCompany) {
const includeDeleted = req.query.includeDeleted === 'true' ? '&includeDeleted=true' : '';
const er = await api.get('/api/v1/entries?company=' + selectedCompany.id + includeDeleted, token);
const er = await api.get('/api/v1/entries?company=' + selectedCompany.id + includeDeleted, token, imp);
entries = er.data.entries || [];
limit = er.data.limit || 15;
}
@@ -101,7 +102,7 @@ function createRouter() {
const clientIdParam = req.user.allClientIds && req.user.allClientIds.length > 1
? '?client_id=' + encodeURIComponent(activeClientId)
: '';
const er = await api.get('/api/v1/entries' + clientIdParam, token);
const er = await api.get('/api/v1/entries' + clientIdParam, token, imp);
entries = er.data.entries || [];
limit = er.data.limit || 15;
}
@@ -150,11 +151,12 @@ function createRouter() {
// POST /add — создать запись
router.post('/add', async (req, res) => {
const token = api.token(req);
const imp = api.impHeaders(req);
const { value, comment } = req.body;
const cq = companyQuery(req);
const back = backUrl(req);
try {
const r = await api.post('/api/v1/entries' + cq, token, { value, comment });
const r = await api.post('/api/v1/entries' + cq, token, { value, comment }, imp);
if (r.status === 201) {
const msg = r.data.wasNormalized
? 'Запись добавлена (CIDR нормализован до ' + r.data.entry.value_cidr + ')'
@@ -175,11 +177,12 @@ function createRouter() {
// POST /edit/:id — обновить запись
router.post('/edit/:id', async (req, res) => {
const token = api.token(req);
const imp = api.impHeaders(req);
const { value, comment } = req.body;
const cq = companyQuery(req);
const back = backUrl(req);
try {
const r = await api.patch('/api/v1/entries/' + req.params.id + cq, token, { value, comment });
const r = await api.patch('/api/v1/entries/' + req.params.id + cq, token, { value, comment }, imp);
if (r.status === 200) {
return res.redirect(back + (back.includes('?') ? '&' : '?') + 'success=' + encodeURIComponent('Запись обновлена'));
}
@@ -197,10 +200,11 @@ function createRouter() {
// POST /delete/:id — удалить запись
router.post('/delete/:id', async (req, res) => {
const token = api.token(req);
const imp = api.impHeaders(req);
const cq = companyQuery(req);
const back = backUrl(req);
try {
const r = await api.delete('/api/v1/entries/' + req.params.id + cq, token);
const r = await api.delete('/api/v1/entries/' + req.params.id + cq, token, imp);
if (r.status === 204) {
return res.redirect(back + (back.includes('?') ? '&' : '?') + 'success=' + encodeURIComponent('Запись удалена'));
}