Add Namespaces::Stateful::StatePrecedence module
What does this MR do and why?
Implements the overwritable_states precedence logic for namespace state propagation as part of the Namespaces::Stateful system.
Creates a new Namespaces::Stateful::StatePrecedence module (in app/models/concerns/namespaces/stateful/state_precedence.rb) that:
-
Defines
STATE_PRECEDENCE = { ancestor_inherited: 0, archived: 1, deletion_scheduled: 2 }.freeze— the three propagation-relevant states and their ordering. -
Implements
self.overwritable_states(source_state, target_state)— a class-level method returning the array of descendant states that may be overwritten when propagatingtarget_statefrom a namespace whose previous state wassource_state.
The precedence logic:
- Propagating
deletion_scheduled(highest precedence): overwrites[:ancestor_inherited, :archived] - Propagating
archived: overwrites[:ancestor_inherited]only - Propagating
ancestor_inherited(reversal):- Unarchive (
archived -> ancestor_inherited): overwrites[:archived]only (stops atdeletion_scheduled) - Restore (
deletion_scheduled -> ancestor_inherited): overwrites[:deletion_scheduled, :archived]
- Unarchive (
- Equal precedence or unsupported combinations: returns
[]
Comprehensive specs are added covering all source/target combinations, edge cases (equal precedence, states outside the propagation-relevant set), and the full 3x3 matrix of propagation-relevant states.
References
Resolves #599297 (closed)
Screenshots or screen recordings
N/A — backend-only change, no UI.
How to set up and validate locally
bundle exec rspec spec/models/concerns/namespaces/stateful/state_precedence_spec.rbMR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.