fix: admin without ?company= loads own company (no redirect)
- Убрал редирект на ?company=<id> — админ видит свою компанию по умолчанию - ownCo ищется по clientId из сессии, если не найдена — первая из списка - Больше не пишет ?company= в URL при первом входе
This commit is contained in:
+1
-1
@@ -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": {
|
||||
|
||||
+16
-14
@@ -84,21 +84,23 @@ 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;
|
||||
}
|
||||
} else {
|
||||
selectedCompany = companies.find(c => c.id === companyId) || null;
|
||||
if (selectedCompany) {
|
||||
const includeDeleted = req.query.includeDeleted === 'true' ? '&includeDeleted=true' : '';
|
||||
const er = await api.get('/api/v1/entries?company=' + companyId + includeDeleted, token);
|
||||
entries = er.data.entries || [];
|
||||
limit = er.data.limit || 15;
|
||||
}
|
||||
return res.redirect('/?company=' + (ownCo ? ownCo.id : ''));
|
||||
}
|
||||
|
||||
selectedCompany = companies.find(c => c.id === companyId) || null;
|
||||
if (selectedCompany) {
|
||||
const includeDeleted = req.query.includeDeleted === 'true' ? '&includeDeleted=true' : '';
|
||||
const er = await api.get('/api/v1/entries?company=' + companyId + includeDeleted, token);
|
||||
entries = er.data.entries || [];
|
||||
limit = er.data.limit || 15;
|
||||
}
|
||||
} else {
|
||||
// Обычный пользователь: запрашиваем записи для активной компании
|
||||
|
||||
Reference in New Issue
Block a user