| | | 1 | | using OzonDomains.Models.Authorization; |
| | | 2 | | using OzonOrdersWeb.WebServices.Grid; |
| | | 3 | | |
| | | 4 | | namespace OzonOrdersWeb.WebServices.Admin; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Серверный грид журнала аудита /Admin/AuditLog (AG Grid Infinite Row Model поверх <see cref="ServerGridQuery"/>): |
| | | 8 | | /// whitelist колонок (colId → выражение EF), поиск и порядок «новые сверху». Журнал растёт без ограничения, |
| | | 9 | | /// поэтому фильтры, сортировка и фасеты считаются на сервере по всему набору. |
| | | 10 | | /// </summary> |
| | | 11 | | public static class AdminAuditGridDefinition |
| | | 12 | | { |
| | 1 | 13 | | public static readonly ServerGridDefinition<AuditLogEntry> Entries = |
| | 1 | 14 | | new ServerGridDefinition<AuditLogEntry> |
| | 1 | 15 | | { |
| | 0 | 16 | | DefaultOrder = q => q.OrderByDescending(e => e.Timestamp).ThenByDescending(e => e.Id), |
| | 1 | 17 | | TieBreaker = e => e.Id |
| | 1 | 18 | | } |
| | 1 | 19 | | .Col("id", e => e.Id) |
| | 1 | 20 | | .Col("timestamp", e => e.Timestamp) |
| | 1 | 21 | | .Col("actorUserName", e => e.ActorUserName) |
| | 1 | 22 | | .Col("action", e => e.Action) |
| | 1 | 23 | | .Col("entityType", e => e.EntityType) |
| | 1 | 24 | | .Col("entityId", e => e.EntityId) |
| | 1 | 25 | | .Col("ipAddress", e => e.IpAddress) |
| | 1 | 26 | | .Col("comment", e => e.Comment) |
| | 1 | 27 | | .Search(e => e.ActorUserName, e => e.Action, e => e.EntityType, e => e.EntityId, e => e.Comment); |
| | | 28 | | |
| | | 29 | | /// <summary>Параметры прежних ссылок журнала (?action=&entity=&user=) — ограничение набора до фильтров грид |
| | | 30 | | public static IQueryable<AuditLogEntry> ApplyParams(IQueryable<AuditLogEntry> query, IReadOnlyDictionary<string, str |
| | | 31 | | { |
| | 3 | 32 | | if (parameters.TryGetValue("action", out var action) && !string.IsNullOrWhiteSpace(action)) |
| | 1 | 33 | | query = query.Where(e => e.Action == action); |
| | 3 | 34 | | if (parameters.TryGetValue("entity", out var entity) && !string.IsNullOrWhiteSpace(entity)) |
| | 1 | 35 | | query = query.Where(e => e.EntityType == entity); |
| | 3 | 36 | | if (parameters.TryGetValue("user", out var user) && !string.IsNullOrWhiteSpace(user)) |
| | 1 | 37 | | query = query.Where(e => (e.ActorUserName != null && e.ActorUserName.Contains(user)) || e.ActorUserId == use |
| | 3 | 38 | | return query; |
| | | 39 | | } |
| | | 40 | | } |