fix(tenants): Setting the current status again is a no-op
POST /v1/tenants/{id}/status with the status the tenant already has wrote
an update, a tenant.status_changed audit entry ("trial" → "trial") and a
Keycloak sync. Staff picking "Apply" instead of "Extend" on a trial then saw
an audit entry but no change. Now the call answers 200 with the unchanged
tenant and does nothing else, so repeating it stays harmless.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
This commit is contained in:
1 parent
358c4abcb7
commit
34783ec3e0
2 files changed
+19
No files matched your search
@@ -97,6 +97,19 @@ func TestSetStatus_rejectsBogus(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestSetStatus_unchangedIsNoOp(t *testing.T) {
|
||||
eachStore(t, func(t *testing.T, h *testHarness) {
|
||||
before := auditCount(t, h, "action=tenant.status_changed&tenant_id="+h.tenant.ID)
|
||||
resp, raw := h.do("POST", "/v1/tenants/"+h.tenant.ID+"/status", map[string]any{"status": h.tenant.Status, "source": "test"})
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("same status: %d %s", resp.StatusCode, raw)
|
||||
}
|
||||
if n := auditCount(t, h, "action=tenant.status_changed&tenant_id="+h.tenant.ID); n != before {
|
||||
t.Fatalf("audit entries: %d, want %d", n, before)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestListTenants_pagination(t *testing.T) {
|
||||
eachStore(t, func(t *testing.T, h *testHarness) {
|
||||
for _, s := range []string{"p-one", "p-two", "p-three"} {
|
||||
|
||||
@@ -390,6 +390,12 @@ func (s *Server) setTenantStatus(w http.ResponseWriter, r *http.Request) {
|
||||
writeError(w, http.StatusInternalServerError, "internal", err.Error())
|
||||
return
|
||||
}
|
||||
// Setting the status a tenant already has changes nothing: no write, no
|
||||
// audit entry, no Keycloak sync. Repeating a call stays harmless.
|
||||
if before.Status == in.Status {
|
||||
writeJSON(w, http.StatusOK, before)
|
||||
return
|
||||
}
|
||||
t, err := s.Store.UpdateTenant(ctx, before.ID, store.TenantUpdate{Status: ptrStr(in.Status)})
|
||||
if err != nil {
|
||||
if mapStoreError(w, err) {
|
||||
|
||||
Reference in new issue
Block a user