Skip to content

[BE/UI] Business rule enforcement — deletion blocking and task unassignment (Phase 11) #437

@CRamsan

Description

@CRamsan

Phase 11 — Business Rule Enforcement

Implement business rule enforcement for deletion blocking and automatic task unassignment. This is split from #410 which covered the entire MVP Polish epic.

POL-10: Block Deletion of Properties/Units with Active Tasks

UI-level blocking:

  • Delete button for a Unit must be disabled if the unit has any tasks with status Open or InProgress
  • Disabled button shows tooltip: "Cannot delete unit with [N] active tasks. Complete or cancel them first."
  • Delete button for a Property must be disabled if any unit in that property has active tasks

Backend-level enforcement:

  • When a delete request is received for a unit or property with active tasks, return HTTP 409 Conflict:
    { "error": "ACTIVE_TASKS_EXIST", "message": "Cannot delete. [N] active task(s) must be resolved first.", "activeTaskCount": N }
  • App shows dialog: "Cannot delete. Resolve all active tasks first."
  • Applies to both soft and hard deletes

POL-11: Auto-Unassign Open Tasks on Staff Removal

When a Staff member is removed from the org:

  1. Query all tasks: assignee_id = removedUserId AND status IN ('Open', 'InProgress')
  2. Set assignee_id = NULL on all matching tasks
  3. Create admin notification for each unassigned task

Must run within the same database transaction as the membership removal (no partial failure).

Unit test requirements:

  • Remove staff with 3 open tasks: verify all 3 unassigned
  • Remove staff with 0 open tasks: verify no side effects
  • Remove staff with Completed/Cancelled tasks: verify those not modified

Dependencies

What type of task is this?

Development

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions