State machine for statuses#164
Draft
bakhterets wants to merge 48 commits into
Draft
Conversation
hierarcy;
403 resp;
v2 created_by added for events and statuses;
TestValidateStatusesPatches relocated to v2_validation_test.go; 06 migration changed; new errores for maintenance validation; Incident model changed; TestValidateEventCreationTimes added; TestValidateEventCreationImpact added;
implemented SetJWTClaims.
…ame HasGroup to HasAuthorizedGroup
…gration RBAC tests
go version updated
… from unauthenticated users
role operator has been raised to allow to perform all CRUD actions; spec.md revised.
rbac tests redesigned, main tests fixed.
Public key caching removed.
version field assert for incidents (tests) removed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: state machine validation for maintenance event status transitions
Problem
Maintenance events allowed arbitrary status changes — any status could be set to any other, bypassing the expected lifecycle. This made it possible to, for example, jump from
pending_reviewdirectly toin_progress, or re-open acancelledevent.Solution
Introduced a state machine in
internal/event/event.gothat enforces valid status transitions per event type (maintenance, incident, information).Maintenance lifecycle (enforced transitions):
pending_review → reviewed, cancelled
reviewed → planned, cancelled
planned → in_progress, cancelled
in_progress → modified, completed, cancelled
modified → in_progress, completed, cancelled
Special cases:
pending_review → pending_reviewis allowed — creators can update the message without changing statusIncident and information events allow any valid status of their type (existing permissive behaviour preserved).
Changes
internal/event/event.goIsValidTransition()+ per-type transition validatorsinternal/api/v2/v2.goIsValidTransitionon PATCH; return400on invalid transitioninternal/api/errors/incident.goErrInvalidStateTransition,ErrIncidentPatchStatusAlreadySetdocs/auth/permissions.md,rbac.mdtests/HTTP behaviour
400 Bad RequestwithErrInvalidStateTransitionTesting
New test cases added in
v2_events_test.go,v2_test.go, andv2_system_incident_test.gocovering boundary transitions and self-transitions.