fix: ownCo not found → getOrCreateCompany instead of companies[0]
- Убрал fallback на companies[0] — небезопасно - Если компания админа не найдена — создаём через getOrCreateCompany
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ipwhitelist",
|
"name": "ipwhitelist",
|
||||||
"version": "0.5.39",
|
"version": "0.5.40",
|
||||||
"description": "IP WhiteList microservice for cloud provider",
|
"description": "IP WhiteList microservice for cloud provider",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -85,7 +85,12 @@ function createRouter() {
|
|||||||
|
|
||||||
if (!companyId) {
|
if (!companyId) {
|
||||||
// Админ без ?company= — показываем свою компанию
|
// Админ без ?company= — показываем свою компанию
|
||||||
const ownCo = companies.find(c => c.client_id === req.user.clientId) || companies[0];
|
let ownCo = companies.find(c => c.client_id === req.user.clientId) || null;
|
||||||
|
if (!ownCo) {
|
||||||
|
await api.get('/api/v1/entries', token); // создаст компанию через getOrCreateCompany
|
||||||
|
const cr2 = await api.get('/api/v1/companies', token);
|
||||||
|
ownCo = (cr2.data.companies || []).find(c => c.client_id === req.user.clientId) || null;
|
||||||
|
}
|
||||||
if (ownCo) {
|
if (ownCo) {
|
||||||
const includeDeleted = req.query.includeDeleted === 'true' ? '&includeDeleted=true' : '';
|
const includeDeleted = req.query.includeDeleted === 'true' ? '&includeDeleted=true' : '';
|
||||||
const er = await api.get('/api/v1/entries?company=' + ownCo.id + includeDeleted, token);
|
const er = await api.get('/api/v1/entries?company=' + ownCo.id + includeDeleted, token);
|
||||||
|
|||||||
Reference in New Issue
Block a user