fix: admin without ?company= loads own company (no redirect)

- Убрал редирект на ?company=<id> — админ видит свою компанию по умолчанию
- ownCo ищется по clientId из сессии, если не найдена — первая из списка
- Больше не пишет ?company= в URL при первом входе
This commit is contained in:
2026-06-11 11:16:37 +04:00
parent 4f1f64dd6c
commit 2acad33fd4
2 changed files with 17 additions and 15 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "ipwhitelist",
"version": "0.5.38",
"version": "0.5.39",
"description": "IP WhiteList microservice for cloud provider",
"main": "server.js",
"scripts": {
+10 -8
View File
@@ -84,15 +84,16 @@ function createRouter() {
const companyId = req.query.company ? parseInt(req.query.company, 10) : null;
if (!companyId) {
let ownCo = companies.find(c => c.client_id === req.user.clientId) || null;
if (!ownCo) {
await api.get('/api/v1/entries', token);
const cr2 = await api.get('/api/v1/companies', token);
ownCo = (cr2.data.companies || []).find(c => c.client_id === req.user.clientId) || null;
// Админ без ?company= — показываем свою компанию
const ownCo = companies.find(c => c.client_id === req.user.clientId) || companies[0];
if (ownCo) {
const includeDeleted = req.query.includeDeleted === 'true' ? '&includeDeleted=true' : '';
const er = await api.get('/api/v1/entries?company=' + ownCo.id + includeDeleted, token);
entries = er.data.entries || [];
limit = er.data.limit || 15;
selectedCompany = ownCo;
}
return res.redirect('/?company=' + (ownCo ? ownCo.id : ''));
}
} else {
selectedCompany = companies.find(c => c.id === companyId) || null;
if (selectedCompany) {
const includeDeleted = req.query.includeDeleted === 'true' ? '&includeDeleted=true' : '';
@@ -100,6 +101,7 @@ function createRouter() {
entries = er.data.entries || [];
limit = er.data.limit || 15;
}
}
} else {
// Обычный пользователь: запрашиваем записи для активной компании
const activeClientId = req.user.activeClientId || req.user.clientId;