feat: company-scoped emails and audit log, company on admin password emails
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
b7d9da8ec0
commit
00ce47bc49
13 files changed
+435
-25
No files matched your search
+3
-2
@@ -32,8 +32,9 @@ public class AdminAuditLogController {
|
||||
@RequestParam(required = false) String from,
|
||||
@RequestParam(required = false) String to,
|
||||
@RequestParam(defaultValue = "0") int page,
|
||||
@RequestParam(defaultValue = "20") int size) {
|
||||
return ResponseEntity.ok(auditLog.search(actor, module, action, outcome, from, to, page, size));
|
||||
@RequestParam(defaultValue = "20") int size,
|
||||
@RequestParam(required = false) Long companyId) {
|
||||
return ResponseEntity.ok(auditLog.search(actor, module, action, outcome, from, to, page, size, companyId));
|
||||
}
|
||||
|
||||
@AppAuth
|
||||
|
||||
+3
-2
@@ -31,8 +31,9 @@ public class AdminEmailController {
|
||||
@RequestParam(required = false) String from,
|
||||
@RequestParam(required = false) String to,
|
||||
@RequestParam(defaultValue = "0") int page,
|
||||
@RequestParam(defaultValue = "20") int size) {
|
||||
return ResponseEntity.ok(adminEmailService.list(recipient, subject, from, to, page, size));
|
||||
@RequestParam(defaultValue = "20") int size,
|
||||
@RequestParam(required = false) Long companyId) {
|
||||
return ResponseEntity.ok(adminEmailService.list(recipient, subject, from, to, page, size, companyId));
|
||||
}
|
||||
|
||||
@Audited(action = "EMAIL_VIEW")
|
||||
|
||||
+23
-3
@@ -3,7 +3,10 @@ package com.solvway.mobile.api.service;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.solvway.mobile.api.constant.api.RestApiLogServiceConstants;
|
||||
import com.solvway.core.model.User;
|
||||
import com.solvway.core.utils.HttpReqRespUtils;
|
||||
import com.solvway.mobile.api.errorhandler.CodedResponseStatusException;
|
||||
import com.solvway.mobile.api.useraccess.AdminCompanyScope;
|
||||
import com.solvway.mobile.api.util.RestTemplateCustomUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
@@ -24,9 +27,13 @@ public class AdminAuditLogService {
|
||||
private static final ObjectMapper JSON = new ObjectMapper();
|
||||
|
||||
private final RestTemplateCustomUtil restTemplateUtil;
|
||||
private final AdminAuthenticationService adminAuthenticationService;
|
||||
private final AdminCompanyScope companyScope;
|
||||
|
||||
public Map<String, Object> search(String actor, String module, String action, String outcome, String from, String to, int page, int size) {
|
||||
public Map<String, Object> search(String actor, String module, String action, String outcome, String from, String to, int page, int size, Long companyId) {
|
||||
Map<String, Object> body = new LinkedHashMap<>();
|
||||
Long scope = companyScope.scope(caller(), companyId);
|
||||
if (scope != null) body.put("companyId", scope);
|
||||
put(body, "actor", actor);
|
||||
put(body, "module", module);
|
||||
put(body, "action", action);
|
||||
@@ -44,12 +51,25 @@ public class AdminAuditLogService {
|
||||
|
||||
public Map<String, Object> get(Long id) {
|
||||
try {
|
||||
return restTemplateUtil.getForEntity(url(RestApiLogServiceConstants.API_REST_LOG_AUDIT_DETAIL), MAP, id).getBody();
|
||||
Map<String, Object> row = restTemplateUtil.getForEntity(url(RestApiLogServiceConstants.API_REST_LOG_AUDIT_DETAIL), MAP, id).getBody();
|
||||
Long scope = companyScope.scope(caller(), null);
|
||||
if (scope != null && row != null && !(row.get("companyId") instanceof Number n && n.longValue() == scope)) throw notFound();
|
||||
return row;
|
||||
} catch (HttpClientErrorException.NotFound e) {
|
||||
throw new CodedResponseStatusException(HttpStatus.NOT_FOUND, "Audit event not found", "NOT_FOUND");
|
||||
throw notFound();
|
||||
}
|
||||
}
|
||||
|
||||
private static CodedResponseStatusException notFound() {
|
||||
return new CodedResponseStatusException(HttpStatus.NOT_FOUND, "Audit event not found", "NOT_FOUND");
|
||||
}
|
||||
|
||||
private User caller() {
|
||||
User caller = adminAuthenticationService.loadUserByToken(HttpReqRespUtils.getJwtToken());
|
||||
if (caller == null) throw new CodedResponseStatusException(HttpStatus.UNAUTHORIZED, "Not signed in", "UNAUTHORIZED");
|
||||
return caller;
|
||||
}
|
||||
|
||||
private static void put(Map<String, Object> body, String key, String value) {
|
||||
if (StringUtils.hasText(value)) body.put(key, value.trim());
|
||||
}
|
||||
|
||||
+11
-1
@@ -5,6 +5,7 @@ import com.solvway.core.utils.HttpReqRespUtils;
|
||||
import com.solvway.mobile.api.constant.api.RestApiEmailServiceConstants;
|
||||
import com.solvway.mobile.api.constant.api.RestApiSystemServiceConstants;
|
||||
import com.solvway.mobile.api.errorhandler.CodedResponseStatusException;
|
||||
import com.solvway.mobile.api.useraccess.AdminCompanyScope;
|
||||
import com.solvway.mobile.api.util.RestTemplateCustomUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -39,9 +40,12 @@ public class AdminEmailService {
|
||||
|
||||
private final RestTemplateCustomUtil restTemplateUtil;
|
||||
private final AdminAuthenticationService adminAuthenticationService;
|
||||
private final AdminCompanyScope companyScope;
|
||||
|
||||
public Map<String, Object> list(String recipient, String subject, String from, String to, int page, int size) {
|
||||
public Map<String, Object> list(String recipient, String subject, String from, String to, int page, int size, Long companyId) {
|
||||
Map<String, Object> property = new LinkedHashMap<>();
|
||||
Long scope = companyScope.scope(caller(), companyId);
|
||||
if (scope != null) property.put("companyId", String.valueOf(scope));
|
||||
if (StringUtils.hasText(recipient)) property.put("recipient", recipient.trim());
|
||||
if (StringUtils.hasText(subject)) property.put("subject", subject.trim());
|
||||
if (StringUtils.hasText(from)) property.put("startDate", upstreamDate(from));
|
||||
@@ -68,6 +72,10 @@ public class AdminEmailService {
|
||||
throw new CodedResponseStatusException(HttpStatus.NOT_FOUND, "Email not found", "EMAIL_NOT_FOUND");
|
||||
}
|
||||
User caller = caller();
|
||||
Long scope = companyScope.scope(caller, null);
|
||||
if (scope != null && !(row.get("companyId") instanceof Number n && n.longValue() == scope)) {
|
||||
throw new CodedResponseStatusException(HttpStatus.NOT_FOUND, "Email not found", "EMAIL_NOT_FOUND");
|
||||
}
|
||||
List<Map<String, Object>> recipients = new ArrayList<>();
|
||||
if (row.get("recipients") instanceof List<?> list) {
|
||||
for (Object item : list) {
|
||||
@@ -84,6 +92,7 @@ public class AdminEmailService {
|
||||
}
|
||||
Map<String, Object> out = new LinkedHashMap<>();
|
||||
out.put("id", row.get("id"));
|
||||
out.put("companyId", row.get("companyId"));
|
||||
out.put("datetime", row.get("datetime"));
|
||||
out.put("sender", row.get("sender"));
|
||||
out.put("subject", row.get("subject"));
|
||||
@@ -101,6 +110,7 @@ public class AdminEmailService {
|
||||
}
|
||||
Map<String, Object> out = new LinkedHashMap<>();
|
||||
out.put("id", row.get("id") instanceof Number n ? n.longValue() : null);
|
||||
out.put("companyId", row.get("companyId"));
|
||||
out.put("datetime", row.get("datetime"));
|
||||
out.put("recipients", to);
|
||||
out.put("subject", row.get("subject"));
|
||||
|
||||
Reference in new issue
Block a user