feat: core-libs AuditEvent contract and audit-event topic names
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
b9912478e0
commit
10f59c5ca8
5 files changed
+85
-1
No files matched your search
@@ -13,7 +13,7 @@ Design: `design.md`. All tasks run serially: each builds on the one before.
|
||||
- Apply them to the local database and emulator. This is local only.
|
||||
- Scope: `local/**`, `openspec/changes/add-admin-audit-log/sql/**`
|
||||
- Verify: `select` shows the table and the module row.
|
||||
- [ ] 1.2 core-libs `AuditEvent` (design decision 1).
|
||||
- [x] 1.2 core-libs `AuditEvent` (design decision 1).
|
||||
- Tests first: JSON round trip through the same `PubSubUtil` used for `ResponseTime`.
|
||||
- Scope: `solvway-core-libs/src/**`
|
||||
- Verify: `mvn -T 1C -B -q -pl solvway-core-libs verify`
|
||||
|
||||
@@ -125,6 +125,11 @@
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.jknack</groupId>
|
||||
<artifactId>handlebars</artifactId>
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.solvway.core.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** One admin audit event: published by mobile-api on audit-event-topic, stored by services-log. */
|
||||
@Setter
|
||||
@Getter
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class AuditEvent {
|
||||
public static final String OUTCOME_SUCCESS = "SUCCESS";
|
||||
public static final String OUTCOME_FAILURE = "FAILURE";
|
||||
|
||||
private Long companyId;
|
||||
private LocalDateTime occurredAt;
|
||||
private String actor;
|
||||
private String module;
|
||||
private String action;
|
||||
private String httpMethod;
|
||||
private String pathTemplate;
|
||||
private String targetId;
|
||||
private String outcome;
|
||||
private Integer httpStatus;
|
||||
private String clientIp;
|
||||
/** JSON: {field: {before, after}} for allow-listed fields, or {fields: [..]} for lead edits. */
|
||||
private String changes;
|
||||
}
|
||||
@@ -47,6 +47,9 @@ pubsub:
|
||||
activate-member:
|
||||
subscription: activate-member-subscription
|
||||
topic: activate-member-topic
|
||||
audit-event:
|
||||
subscription: audit-event-subscription
|
||||
topic: audit-event-topic
|
||||
backoffice-message-source-refresh:
|
||||
subscription: backoffice-message-source-refresh-subscription
|
||||
topic: backoffice-message-source-refresh-topic
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.solvway.core.model;
|
||||
|
||||
import com.solvway.core.utils.PubSubUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class AuditEventTest {
|
||||
|
||||
private final PubSubUtil util = new PubSubUtil();
|
||||
|
||||
@Test
|
||||
void roundTripsEveryFieldThroughPubSubUtil() {
|
||||
AuditEvent e = new AuditEvent();
|
||||
e.setCompanyId(7L);
|
||||
e.setOccurredAt(LocalDateTime.of(2026, 11, 30, 15, 4, 5, 123_000_000));
|
||||
e.setActor("admin");
|
||||
e.setModule("BO_USERS");
|
||||
e.setAction("USER_UPDATE");
|
||||
e.setHttpMethod("PUT");
|
||||
e.setPathTemplate("/api/admin/users/{id}");
|
||||
e.setTargetId("42");
|
||||
e.setOutcome(AuditEvent.OUTCOME_SUCCESS);
|
||||
e.setHttpStatus(200);
|
||||
e.setClientIp("203.0.113.9");
|
||||
e.setChanges("{\"enabled\":{\"before\":true,\"after\":false}}");
|
||||
|
||||
String json = util.convertToString(e);
|
||||
assertThat(json).contains("\"occurredAt\":\"2026-11-30T15:04:05.123\"");
|
||||
|
||||
AuditEvent back = util.convertToOriginalObject(json.getBytes(StandardCharsets.UTF_8), AuditEvent.class);
|
||||
assertThat(back).usingRecursiveComparison().isEqualTo(e);
|
||||
assertThat(AuditEvent.OUTCOME_FAILURE).isEqualTo("FAILURE");
|
||||
}
|
||||
|
||||
@Test
|
||||
void ignoresUnknownFieldsSoTheContractCanGrow() {
|
||||
String json = "{\"actor\":\"admin\",\"action\":\"USER_UPDATE\",\"outcome\":\"SUCCESS\",\"addedLater\":1}";
|
||||
AuditEvent back = util.convertToOriginalObject(json.getBytes(StandardCharsets.UTF_8), AuditEvent.class);
|
||||
assertThat(back).isNotNull();
|
||||
assertThat(back.getActor()).isEqualTo("admin");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user