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",
|
"name": "ipwhitelist",
|
||||||
"version": "0.5.38",
|
"version": "0.5.39",
|
||||||
"description": "IP WhiteList microservice for cloud provider",
|
"description": "IP WhiteList microservice for cloud provider",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
+16
-14
@@ -84,21 +84,23 @@ function createRouter() {
|
|||||||
const companyId = req.query.company ? parseInt(req.query.company, 10) : null;
|
const companyId = req.query.company ? parseInt(req.query.company, 10) : null;
|
||||||
|
|
||||||
if (!companyId) {
|
if (!companyId) {
|
||||||
let ownCo = companies.find(c => c.client_id === req.user.clientId) || null;
|
// Админ без ?company= — показываем свою компанию
|
||||||
if (!ownCo) {
|
const ownCo = companies.find(c => c.client_id === req.user.clientId) || companies[0];
|
||||||
await api.get('/api/v1/entries', token);
|
if (ownCo) {
|
||||||
const cr2 = await api.get('/api/v1/companies', token);
|
const includeDeleted = req.query.includeDeleted === 'true' ? '&includeDeleted=true' : '';
|
||||||
ownCo = (cr2.data.companies || []).find(c => c.client_id === req.user.clientId) || null;
|
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 {
|
} else {
|
||||||
// Обычный пользователь: запрашиваем записи для активной компании
|
// Обычный пользователь: запрашиваем записи для активной компании
|
||||||
|
|||||||
Reference in New Issue
Block a user