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:

  1. Defines STATE_PRECEDENCE = { ancestor_inherited: 0, archived: 1, deletion_scheduled: 2 }.freeze — the three propagation-relevant states and their ordering.

  2. Implements self.overwritable_states(source_state, target_state) — a class-level method returning the array of descendant states that may be overwritten when propagating target_state from a namespace whose previous state was source_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 at deletion_scheduled)
    • Restore (deletion_scheduled -> ancestor_inherited): overwrites [:deletion_scheduled, :archived]
  • 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.rb

MR 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.

Merge request reports

Loading