feat(audit): implement institutional audit logging for logins and system operations v3.4.8
This commit is contained in:
@@ -1441,16 +1441,65 @@ const handleAuditLogs = async (req, res) => {
|
||||
const search = req.query.search || '';
|
||||
const current_module = req.query.module || '';
|
||||
const current_action = req.query.action || '';
|
||||
res.render('admin/audit_logs', {
|
||||
title: 'Bitácora de Auditoría - Edu-Space Admin',
|
||||
logs: [],
|
||||
modules: ['classrooms', 'reservations', 'users', 'auth', 'academic', 'optimizer'],
|
||||
actions: ['CREATE', 'UPDATE', 'DELETE', 'LOGIN', 'LOGOUT'],
|
||||
current_module,
|
||||
current_action,
|
||||
search,
|
||||
pagination: { pages: 1, page: 1, total: 0, has_prev: false, has_next: false }
|
||||
});
|
||||
const page = parseInt(req.query.page, 10) || 1;
|
||||
|
||||
try {
|
||||
const resp = await req.apiClient.get('/admin/audit-logs', {
|
||||
params: {
|
||||
page,
|
||||
per_page: 25,
|
||||
search,
|
||||
module: current_module,
|
||||
action: current_action
|
||||
}
|
||||
});
|
||||
|
||||
const data = resp.data || {};
|
||||
const audit_logs = data.logs || [];
|
||||
const pagination = data.pagination || { pages: 1, page: 1, total: 0, has_prev: false, has_next: false };
|
||||
|
||||
// Generar lista de números de páginas para la plantilla Nunjucks
|
||||
const pages_list = [];
|
||||
const totalPages = pagination.pages || 1;
|
||||
const maxPages = 7;
|
||||
let startPage = Math.max(1, page - Math.floor(maxPages / 2));
|
||||
let endPage = Math.min(totalPages, startPage + maxPages - 1);
|
||||
if (endPage - startPage + 1 < maxPages) {
|
||||
startPage = Math.max(1, endPage - maxPages + 1);
|
||||
}
|
||||
for (let i = startPage; i <= endPage; i++) {
|
||||
pages_list.push(i);
|
||||
}
|
||||
pagination.pages_list = pages_list;
|
||||
|
||||
const modules = (data.modules && data.modules.length > 0) ? data.modules : ['auth', 'reservations', 'classrooms', 'buildings', 'academic', 'optimizer', 'users', 'admin'];
|
||||
const actions = (data.actions && data.actions.length > 0) ? data.actions : ['LOGIN', 'LOGIN_FAILED', 'LOGOUT', 'CREATE', 'UPDATE', 'DELETE', 'CONFIRM', 'CANCEL'];
|
||||
|
||||
res.render('admin/audit_logs', {
|
||||
title: 'Registro de Auditoría Institucional - Edu-Space Admin',
|
||||
audit_logs,
|
||||
logs: audit_logs,
|
||||
modules,
|
||||
actions,
|
||||
current_module,
|
||||
current_action,
|
||||
search,
|
||||
pagination
|
||||
});
|
||||
} catch (err) {
|
||||
console.warn('[Admin] Error fetching audit logs from backend:', err.response?.data || err.message);
|
||||
res.render('admin/audit_logs', {
|
||||
title: 'Registro de Auditoría Institucional - Edu-Space Admin',
|
||||
audit_logs: [],
|
||||
logs: [],
|
||||
modules: ['auth', 'reservations', 'classrooms', 'buildings', 'academic', 'optimizer', 'users', 'admin'],
|
||||
actions: ['LOGIN', 'LOGIN_FAILED', 'LOGOUT', 'CREATE', 'UPDATE', 'DELETE', 'CONFIRM', 'CANCEL'],
|
||||
current_module,
|
||||
current_action,
|
||||
search,
|
||||
pagination: { pages: 1, page: 1, total: 0, has_prev: false, has_next: false, pages_list: [1] }
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
router.get(['/audit_logs', '/audit-logs', '/audit'], handleAuditLogs);
|
||||
|
||||
Reference in New Issue
Block a user