Validate Hierarchy Integrity Before Structural Changes
Structural edits to the hierarchy carry risk — moving a region could orphan chapters, deactivating a node could break access scopes, or a misconfiguration could create circular parent-child relationships. The hierarchy validator must run pre-commit checks on all structural edits and surface clear, actionable error messages. Validation must cover: circular reference detection, orphan unit detection, RLS policy consistency, and minimum viable structure requirements (e.g., every local chapter must have at least one assigned coordinator or be explicitly marked as unassigned).
User Story
Acceptance Criteria
- Given I attempt to set a unit's parent to one of its own descendants, when I try to save, then validation blocks the save and displays a 'circular reference detected' error specifying the conflicting units
- Given I deactivate a regional node that has active child chapters, when validation runs, then I receive a list of all child chapters that will be without a parent and must be reassigned before the change can be committed
- Given I make a structural change that would invalidate existing RLS policies, when validation runs, then I am warned which user access scopes will be affected and given the option to review before proceeding
- Given all validation checks pass, when I confirm the structural change, then the edit is committed to the database within 3 seconds and the hierarchy tree refreshes automatically
- Given validation has produced warnings (non-blocking), when I review them, then each warning has a 'Fix now' shortcut that navigates directly to the affected unit's management screen
Business Value
Structural hierarchy errors are difficult to detect and correct after the fact — they silently corrupt reporting data, break user access, and may not surface until a Bufdir submission deadline. Pre-commit validation acts as a safety net that allows admins to make structural changes confidently, reducing the risk of accidental data corruption in a system managing the organizational structure of thousands of volunteers.
Components
- Hierarchy Structure Validator infrastructure
- RLS Policy Manager infrastructure
- Hierarchy Service service
- Hierarchy Node Editor Screen ui
- Organization Unit Repository data
- Access Scope Service service