mirror of
https://github.com/hansjone/netx.git
synced 2026-10-11 12:53:17 +08:00
Protect root maps and auto world map; only sub-regions are deletable.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
8fa4b2e4ea
commit
1b592490a5
6 changed files with 70 additions and 34 deletions
|
|
@ -549,22 +549,25 @@ def update_folder(db: Session, folder_id: str, body: TopologyFolderUpdate) -> To
|
|||
def delete_folder(db: Session, folder_id: str, *, force: bool = False) -> dict[str, Any]:
|
||||
"""Delete a region and cascade-delete nested regions + maps.
|
||||
|
||||
System L2「根图」(manual, no UME external_ref) may be removed only as part of
|
||||
cascading from its parent「根」.
|
||||
Not user-deletable (structure / auto-managed):
|
||||
- kind=root
|
||||
- manual system「根图」(is_system, no UME external_ref)
|
||||
- UME World container and World drill (ume:world / ume:world:drill)
|
||||
|
||||
UME World and UME-synced SBN folders (``external_ref`` set) are user-deletable —
|
||||
they are synced inventory, not structural locks; a later UME apply can recreate them.
|
||||
User-deletable: manual sub-regions and UME-synced SBN folders under World.
|
||||
World map view is never a folder — it is auto created/suppressed by reconcile.
|
||||
"""
|
||||
row = _get_folder_or_404(db, folder_id)
|
||||
if str(row.kind or "") == "root":
|
||||
raise HTTPException(status_code=400, detail="cannot_delete_system_folder")
|
||||
|
||||
from .ume_topology_world import is_ume_world_container
|
||||
from .ume_topology_world import WORLD_DRILL_REF, WORLD_FOLDER_REF, is_ume_world_container
|
||||
|
||||
ext = str(getattr(row, "external_ref", None) or "").strip()
|
||||
ume_synced = bool(ext) # ume:world / ume:world:drill / SBN id
|
||||
# Protect manual system folders (根图); allow UME World + synced children.
|
||||
if bool(row.is_system) and not is_ume_world_container(row) and not ume_synced:
|
||||
if is_ume_world_container(row) or ext in (WORLD_FOLDER_REF, WORLD_DRILL_REF):
|
||||
raise HTTPException(status_code=400, detail="cannot_delete_system_folder")
|
||||
# Manual「根图」and other non-UME system folders stay protected except via parent cascade.
|
||||
if bool(row.is_system) and not ext:
|
||||
raise HTTPException(status_code=400, detail="cannot_delete_system_folder")
|
||||
_ = force
|
||||
from .topology_region_canvas import remove_region_canvas_placements
|
||||
|
|
@ -884,6 +887,10 @@ def update_view(db: Session, view_id: str, body: TopologyViewUpdate) -> Topology
|
|||
|
||||
def delete_view(db: Session, view_id: str, *, force: bool = False) -> dict[str, Any]:
|
||||
row = _get_view_or_404(db, view_id)
|
||||
from .ume_topology_world import is_world_flat_view
|
||||
|
||||
if is_world_flat_view(row):
|
||||
raise HTTPException(status_code=400, detail="cannot_delete_world_map_view")
|
||||
is_physical = normalize_view_kind(row.kind) == VIEW_KIND_PHYSICAL
|
||||
if is_physical and not force:
|
||||
raise HTTPException(status_code=400, detail="cannot_delete_physical_view")
|
||||
|
|
|
|||
|
|
@ -21,16 +21,19 @@ WORLD_FOLDER_REF = "ume:world"
|
|||
WORLD_DRILL_REF = "ume:world:drill"
|
||||
WORLD_VIEW_NAME = "World"
|
||||
WORLD_FLAT_VIEW_NAME = "世界地图"
|
||||
# Pre-rename label kept so existing TopoView rows still match.
|
||||
# Pre-rename / locale labels kept so existing TopoView rows still match.
|
||||
WORLD_FLAT_VIEW_NAME_LEGACY = "完整世界地图"
|
||||
WORLD_FLAT_VIEW_NAME_EN = "World map"
|
||||
WORLD_FLAT_VIEW_NAMES = frozenset(
|
||||
{WORLD_FLAT_VIEW_NAME, WORLD_FLAT_VIEW_NAME_LEGACY, WORLD_FLAT_VIEW_NAME_EN}
|
||||
)
|
||||
# Drill-down root: children of MD (root SBNs + rare direct MEs).
|
||||
WORLD_LEVEL_FILTER = {"ume_level": True, "parent": "md"}
|
||||
WORLD_FLAT_FILTER = {"world_flat": True}
|
||||
|
||||
|
||||
def is_world_flat_view_name(name: str | None) -> bool:
|
||||
n = str(name or "").strip()
|
||||
return n == WORLD_FLAT_VIEW_NAME or n == WORLD_FLAT_VIEW_NAME_LEGACY
|
||||
return str(name or "").strip() in WORLD_FLAT_VIEW_NAMES
|
||||
|
||||
|
||||
def _filt(view: TopoView | None) -> dict[str, Any]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue