- Admin account bootstrapped from ADMIN_EMAIL/ADMIN_PASSWORD env vars on startup - Admin panel: list users, view content, reset passwords, disable/delete accounts - is_admin and is_disabled columns on users table - Disabled accounts blocked at login - README updated with admin setup instructions and panel docs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
166 lines
3.7 KiB
Python
166 lines
3.7 KiB
Python
from __future__ import annotations
|
|
from datetime import date, datetime
|
|
from typing import Optional, List
|
|
from pydantic import BaseModel, EmailStr
|
|
from models import Category, SunRequirement, WaterNeeds, BatchStatus
|
|
|
|
|
|
# --- Auth ---
|
|
|
|
class UserCreate(BaseModel):
|
|
email: EmailStr
|
|
password: str
|
|
|
|
|
|
class UserLogin(BaseModel):
|
|
email: str
|
|
password: str
|
|
|
|
|
|
class UserOut(BaseModel):
|
|
id: int
|
|
email: str
|
|
is_admin: bool = False
|
|
is_disabled: bool = False
|
|
created_at: Optional[datetime] = None
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class AdminUserOut(BaseModel):
|
|
id: int
|
|
email: str
|
|
is_admin: bool
|
|
is_disabled: bool
|
|
created_at: Optional[datetime]
|
|
variety_count: int
|
|
batch_count: int
|
|
|
|
|
|
class AdminResetPassword(BaseModel):
|
|
new_password: str
|
|
|
|
|
|
class Token(BaseModel):
|
|
access_token: str
|
|
token_type: str
|
|
|
|
|
|
# --- Variety ---
|
|
|
|
class VarietyBase(BaseModel):
|
|
name: str
|
|
variety_name: Optional[str] = None
|
|
category: Category = Category.vegetable
|
|
weeks_to_start: Optional[int] = None
|
|
weeks_to_greenhouse: Optional[int] = None
|
|
weeks_to_garden: Optional[int] = None
|
|
days_to_germinate: int = 7
|
|
direct_sow_ok: bool = False
|
|
frost_tolerant: bool = False
|
|
sun_requirement: SunRequirement = SunRequirement.full_sun
|
|
water_needs: WaterNeeds = WaterNeeds.medium
|
|
color: str = "#52b788"
|
|
notes: Optional[str] = None
|
|
|
|
|
|
class VarietyCreate(VarietyBase):
|
|
pass
|
|
|
|
|
|
class VarietyUpdate(VarietyBase):
|
|
pass
|
|
|
|
|
|
class VarietyOut(VarietyBase):
|
|
id: int
|
|
created_at: Optional[datetime] = None
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
# --- Batch ---
|
|
|
|
class BatchBase(BaseModel):
|
|
variety_id: int
|
|
label: Optional[str] = None
|
|
quantity: int = 1
|
|
sow_date: Optional[date] = None
|
|
germination_date: Optional[date] = None
|
|
greenhouse_date: Optional[date] = None
|
|
garden_date: Optional[date] = None
|
|
status: BatchStatus = BatchStatus.planned
|
|
notes: Optional[str] = None
|
|
|
|
|
|
class BatchCreate(BatchBase):
|
|
pass
|
|
|
|
|
|
class BatchUpdate(BatchBase):
|
|
pass
|
|
|
|
|
|
class BatchOut(BatchBase):
|
|
id: int
|
|
created_at: Optional[datetime] = None
|
|
variety: Optional[VarietyOut] = None
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
# --- Settings ---
|
|
|
|
class SettingsUpdate(BaseModel):
|
|
last_frost_date: Optional[date] = None
|
|
first_frost_fall_date: Optional[date] = None
|
|
ntfy_topic: Optional[str] = None
|
|
ntfy_server: Optional[str] = "https://ntfy.sh"
|
|
notification_time: Optional[str] = "07:00"
|
|
timezone: Optional[str] = "UTC"
|
|
location_name: Optional[str] = None
|
|
ntfy_username: Optional[str] = None
|
|
ntfy_password: Optional[str] = None
|
|
ntfy_api_key: Optional[str] = None
|
|
|
|
|
|
class SettingsOut(SettingsUpdate):
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
# --- Dashboard ---
|
|
|
|
class Task(BaseModel):
|
|
type: str # "start_seeds", "pot_up", "transplant", "check_batch"
|
|
title: str
|
|
detail: str
|
|
due_date: date
|
|
days_away: int # negative = overdue
|
|
urgency: str # "overdue", "today", "week", "month"
|
|
variety_color: str
|
|
batch_id: Optional[int] = None
|
|
variety_id: Optional[int] = None
|
|
|
|
|
|
class TimelineEntry(BaseModel):
|
|
variety_id: int
|
|
name: str
|
|
full_name: str
|
|
color: str
|
|
start_day: Optional[int] = None # day of year
|
|
greenhouse_day: Optional[int] = None
|
|
garden_day: Optional[int] = None
|
|
end_day: Optional[int] = None # approx harvest / end of season
|
|
|
|
|
|
class DashboardOut(BaseModel):
|
|
tasks_overdue: List[Task]
|
|
tasks_today: List[Task]
|
|
tasks_week: List[Task]
|
|
tasks_month: List[Task]
|
|
active_batches: List[BatchOut]
|
|
timeline: List[TimelineEntry]
|
|
stats: dict
|
|
last_frost_date: Optional[date]
|
|
location_name: Optional[str]
|