diff --git a/package.json b/package.json index f6f8c12..7640615 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipwhitelist", - "version": "0.1.9", + "version": "0.1.10", "description": "IP WhiteList microservice for cloud provider", "main": "server.js", "scripts": { diff --git a/v2/src/admin/index.js b/v2/src/admin/index.js index 27c6329..9176d5b 100644 --- a/v2/src/admin/index.js +++ b/v2/src/admin/index.js @@ -43,7 +43,8 @@ function createAdminRouter({ generateCsrfToken } = {}) { router.get('/audit', async (req, res) => { try { const companyId = req.query.companyId ? parseInt(req.query.companyId) : null; - const days = Math.min(Math.max(parseInt(req.query.days) || 365, 1), 365); + // days=null → все записи (без фильтра по дате) + const days = req.query.days ? Math.min(Math.max(parseInt(req.query.days), 1), 365) : null; const page = Math.max(parseInt(req.query.page) || 1, 1); const perPage = 100; const result = await q.getAudit({ companyId, days, page, limit: perPage }); diff --git a/v2/src/config/index.js b/v2/src/config/index.js index 62e8183..47b3f14 100644 --- a/v2/src/config/index.js +++ b/v2/src/config/index.js @@ -8,7 +8,7 @@ // ═══════════════════════════════════════════════════════════════════════════════ module.exports = { - version: '0.1.9', + version: '0.1.10', // ── IAM ────────────────────────────────────────────────────────────────── iamUrl: process.env.V2_IAM_URL || 'https://auth-api.ngcloud.ru/api/v1/auth/user', diff --git a/v2/src/db/queries.js b/v2/src/db/queries.js index dabc32c..05c4d1e 100644 --- a/v2/src/db/queries.js +++ b/v2/src/db/queries.js @@ -266,15 +266,15 @@ async function logAudit(userEmail, companyId, action, oldValue, newValue, entryI } /** - * Журнал операций с фильтром по дате и пагинацией. + * Журнал операций с пагинацией и опциональным фильтром по дате. * @param {Object} opts * @param {number|null} opts.companyId — фильтр по компании (null = все) - * @param {number} opts.days — глубина в днях (по умолчанию 365) + * @param {number|null} opts.days — глубина в днях (null = без ограничения) * @param {number} opts.page — страница (с 1) * @param {number} opts.limit — записей на странице * @returns {{ rows: Array, total: number }} */ -async function getAudit({ companyId = null, days = 365, page = 1, limit = 100 } = {}) { +async function getAudit({ companyId = null, days = null, page = 1, limit = 100 } = {}) { const offset = (page - 1) * limit; const params = []; @@ -283,9 +283,11 @@ async function getAudit({ companyId = null, days = 365, page = 1, limit = 100 } where += ' WHERE a.company_id = $' + (params.length + 1); params.push(companyId); } - const dayParam = '$' + (params.length + 1); - where += (where ? ' AND' : ' WHERE') + ' a.created_at > NOW() - (' + dayParam + ' || \' days\')::INTERVAL'; - params.push(String(days)); + if (days) { + const dayParam = '$' + (params.length + 1); + where += (where ? ' AND' : ' WHERE') + ' a.created_at > NOW() - (' + dayParam + ' || \' days\')::INTERVAL'; + params.push(String(days)); + } const limitIdx = params.length + 1; const offsetIdx = params.length + 2; diff --git a/views/v2/admin-audit.ejs b/views/v2/admin-audit.ejs index 5e44e67..0472de0 100644 --- a/views/v2/admin-audit.ejs +++ b/views/v2/admin-audit.ejs @@ -76,9 +76,12 @@