feat: company on emails and audit search
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
a6996841ac
commit
118c57c0ea
6 files changed
+147
-4
No files matched your search
+12
-4
@@ -24,7 +24,12 @@ import java.util.Map;
|
||||
public class AuditEventController {
|
||||
|
||||
public record SearchRequest(String actor, String module, String action, String outcome,
|
||||
String from, String to, Integer page, Integer size) {
|
||||
String from, String to, Integer page, Integer size, Long companyId) {
|
||||
/** Keeps the pre-company body shape: no companyId means all companies. */
|
||||
public SearchRequest(String actor, String module, String action, String outcome,
|
||||
String from, String to, Integer page, Integer size) {
|
||||
this(actor, module, action, outcome, from, to, page, size, null);
|
||||
}
|
||||
}
|
||||
|
||||
private final AuditEventLogRepository repository;
|
||||
@@ -39,9 +44,12 @@ public class AuditEventController {
|
||||
int s = r.size() == null || r.size() < 1 ? 20 : Math.min(r.size(), 100);
|
||||
LocalDateTime from = day(r.from(), 0);
|
||||
LocalDateTime to = day(r.to(), 1);
|
||||
Page<AuditEventLog> page = repository.search(blankToNull(r.actor()), blankToNull(r.module()),
|
||||
blankToNull(r.action()), blankToNull(r.outcome()), from, to,
|
||||
PageRequest.of(p, s, Sort.by(Sort.Direction.DESC, "occurredAt", "id")));
|
||||
PageRequest paging = PageRequest.of(p, s, Sort.by(Sort.Direction.DESC, "occurredAt", "id"));
|
||||
Page<AuditEventLog> page = r.companyId() == null
|
||||
? repository.search(blankToNull(r.actor()), blankToNull(r.module()),
|
||||
blankToNull(r.action()), blankToNull(r.outcome()), from, to, paging)
|
||||
: repository.searchInCompany(r.companyId(), blankToNull(r.actor()), blankToNull(r.module()),
|
||||
blankToNull(r.action()), blankToNull(r.outcome()), from, to, paging);
|
||||
return Map.of("content", page.getContent(), "totalElements", page.getTotalElements(), "number", p, "size", s);
|
||||
}
|
||||
|
||||
|
||||
+10
@@ -23,6 +23,16 @@ public interface AuditEventLogRepository extends JpaRepository<AuditEventLog, Lo
|
||||
@Param("action") String action, @Param("outcome") String outcome,
|
||||
@Param("from") LocalDateTime from, @Param("to") LocalDateTime to, Pageable pageable);
|
||||
|
||||
/** Same as {@link #search} but only rows of one company; rows with no company never match. */
|
||||
@Query("select e from AuditEventLog e where e.companyId = :companyId and (:actor is null or e.actor = :actor)"
|
||||
+ " and (:module is null or e.module = :module) and (:action is null or e.action = :action)"
|
||||
+ " and (:outcome is null or e.outcome = :outcome)"
|
||||
+ " and (:from is null or e.occurredAt >= :from)"
|
||||
+ " and (:to is null or e.occurredAt < :to)")
|
||||
Page<AuditEventLog> searchInCompany(@Param("companyId") Long companyId, @Param("actor") String actor,
|
||||
@Param("module") String module, @Param("action") String action, @Param("outcome") String outcome,
|
||||
@Param("from") LocalDateTime from, @Param("to") LocalDateTime to, Pageable pageable);
|
||||
|
||||
/** Deletes up to {@code limit} old rows; each call is its own transaction. */
|
||||
@Transactional
|
||||
@Modifying
|
||||
|
||||
Reference in new issue
Block a user