Add is_default flag for system trees

- Add is_default column to trees table
- Default trees have no author and are visible to all users
- Only admins can create default trees
- Update seed script to mark seeded trees as default
- Update seed script to use CLI auth instead of creating seed user

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Michael Chihlas
2026-02-01 01:32:10 -05:00
parent b96cbab087
commit db0b05eba7
5 changed files with 72 additions and 44 deletions

View File

@@ -120,13 +120,17 @@ async def create_tree(
current_user: Annotated[User, Depends(require_engineer_or_admin)]
):
"""Create a new tree (engineers and admins only)."""
# Only admins can create default/system trees
is_default = tree_data.is_default and current_user.role == "admin"
new_tree = Tree(
name=tree_data.name,
description=tree_data.description,
category=tree_data.category,
tree_structure=tree_data.tree_structure,
author_id=current_user.id,
team_id=current_user.team_id
author_id=None if is_default else current_user.id, # Default trees have no author
team_id=None if is_default else current_user.team_id,
is_default=is_default
)
db.add(new_tree)
await db.commit()

View File

@@ -31,6 +31,7 @@ class Tree(Base):
index=True
)
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
is_default: Mapped[bool] = mapped_column(Boolean, default=False, index=True)
version: Mapped[int] = mapped_column(Integer, default=1)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),

View File

@@ -12,6 +12,7 @@ class TreeBase(BaseModel):
class TreeCreate(TreeBase):
tree_structure: dict[str, Any] = Field(..., description="The decision tree structure in JSON format")
is_default: bool = Field(False, description="Mark as a default/system tree (admin only)")
class TreeUpdate(BaseModel):
@@ -28,6 +29,7 @@ class TreeResponse(TreeBase):
author_id: Optional[UUID] = None
team_id: Optional[UUID] = None
is_active: bool
is_default: bool
version: int
created_at: datetime
updated_at: datetime
@@ -43,6 +45,7 @@ class TreeListResponse(BaseModel):
description: Optional[str] = None
category: Optional[str] = None
is_active: bool
is_default: bool
version: int
usage_count: int
created_at: datetime