Release v1.6.0 - Audit System Cross-Tenant Viewing
Features: - ✅ Cross-tenant audit log viewing for ADMIN/SUPPORT_MANAGER - ✅ New 'all_tenants' parameter in audit endpoints - ✅ Frontend toggle to view all clients' logs - ✅ Multi-tenant stats support in /audit/stats - ✅ Fixed timezone issue with date filters (UTC consistency) - ✅ Fixed date_to filter overlap causing duplicate records Changes: - backend/app/api/v1/endpoints/audit.py: * Added tenant_id and all_tenants query parameters * Permission checks for cross-tenant viewing * Dynamic tenant filtering based on user role * Fixed date_to filter (removed +1 day overlap) * Updated all stats queries for multi-tenant support - frontend-internal/src/routes/audit/+page.svelte: * Import auth store for role detection * Added 'Ver todos los clientes' toggle for admins * Pass all_tenants parameter to API calls * UI badge indicating multi-tenant mode - Version bump: 1.5.1.2 → 1.6.0 across all packages
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import { onMount } from 'svelte';
|
||||
import { api } from '$lib/utils/api';
|
||||
import { toast } from '$lib/stores/toast';
|
||||
import { auth } from '$lib/stores/auth';
|
||||
import Modal from '$lib/components/Modal.svelte';
|
||||
|
||||
// Estado de carga y datos
|
||||
@@ -24,6 +25,9 @@
|
||||
let filterResourceType = '';
|
||||
let searchText = '';
|
||||
|
||||
// Filtro multi-tenant (solo para ADMIN/SUPPORT_MANAGER)
|
||||
let allTenants = false;
|
||||
|
||||
// Filtro de período
|
||||
let periodFilter: 'today' | 'yesterday' | 'last7days' | 'last30days' | 'custom' = 'today';
|
||||
let customDateFrom = '';
|
||||
@@ -32,6 +36,10 @@
|
||||
// Control de visibilidad de filtros avanzados
|
||||
let showAdvancedFilters = false;
|
||||
|
||||
// Usuario actual
|
||||
$: currentUser = $auth.user;
|
||||
$: canSeeAllTenants = currentUser && (currentUser.role === 'ADMIN' || currentUser.role === 'SUPPORT_MANAGER');
|
||||
|
||||
// Contador de filtros activos (excluyendo el período que es por defecto)
|
||||
$: activeFiltersCount = [filterUserId, filterAction, filterResourceType, searchText].filter(f => f && f.trim()).length;
|
||||
|
||||
@@ -108,7 +116,11 @@
|
||||
*/
|
||||
async function loadStats() {
|
||||
try {
|
||||
stats = await api.get('/audit/stats');
|
||||
const params: any = {};
|
||||
if (allTenants && canSeeAllTenants) {
|
||||
params.all_tenants = true;
|
||||
}
|
||||
stats = await api.get('/audit/stats', params);
|
||||
} catch (e) {
|
||||
console.error('Error cargando estadísticas:', e);
|
||||
}
|
||||
@@ -135,6 +147,11 @@
|
||||
if (filterAction) params.action = filterAction;
|
||||
if (filterResourceType) params.resource_type = filterResourceType;
|
||||
if (searchText) params.search = searchText;
|
||||
|
||||
// Aplicar filtro multi-tenant si el usuario tiene permiso
|
||||
if (allTenants && canSeeAllTenants) {
|
||||
params.all_tenants = true;
|
||||
}
|
||||
|
||||
const response = await api.get('/audit/', params);
|
||||
|
||||
@@ -412,6 +429,41 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Filtro Multi-Tenant (solo para ADMIN/SUPPORT_MANAGER) -->
|
||||
{#if canSeeAllTenants}
|
||||
<div class="bg-white shadow rounded-lg p-4 mb-6">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center">
|
||||
<label for="all-tenants-toggle" class="flex items-center cursor-pointer">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="all-tenants-toggle"
|
||||
bind:checked={allTenants}
|
||||
on:change={() => {
|
||||
currentPage = 1;
|
||||
loadLogs();
|
||||
loadStats();
|
||||
}}
|
||||
class="rounded border-gray-300 text-primary-600 shadow-sm focus:border-primary-500 focus:ring-primary-500 h-4 w-4 mr-3"
|
||||
/>
|
||||
<div>
|
||||
<span class="text-sm font-medium text-gray-900">Ver todos los clientes</span>
|
||||
<p class="text-xs text-gray-500">Mostrar registros de auditoría de todas las organizaciones</p>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
{#if allTenants}
|
||||
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-purple-100 text-purple-800">
|
||||
<svg class="w-3 h-3 mr-1" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path d="M10 2a8 8 0 100 16 8 8 0 000-16zM9 9a1 1 0 012 0v4a1 1 0 11-2 0V9zm1-5a1 1 0 100 2 1 1 0 000-2z" />
|
||||
</svg>
|
||||
Multi-tenant activo
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Estadísticas Rápidas -->
|
||||
{#if stats}
|
||||
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
|
||||
|
||||
Reference in New Issue
Block a user