Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b90ba53a3f | |||
| c4e9d69e00 | |||
| 0673896133 | |||
| 5824e70895 | |||
| 04ccdbf96a | |||
| f165ccb941 | |||
| e0fb924a1d | |||
| cf5518c7ec | |||
| 26df03cfd7 | |||
| ab064bce6e | |||
| 76b7f453c1 | |||
| 438d2db2e7 | |||
| 99913ada94 | |||
| 584b323121 | |||
| 4788ae7723 | |||
| 51f0066e61 |
@@ -19,6 +19,7 @@ These are product invariants, not preferences. Do not violate them, and flag any
|
|||||||
5. **Sources are first-class.** Don't model citations as free-text afterthoughts. A `Source` is a reusable entity; a `Citation` links it to a specific fact.
|
5. **Sources are first-class.** Don't model citations as free-text afterthoughts. A `Source` is a reusable entity; a `Citation` links it to a specific fact.
|
||||||
6. **Only legal data sources.** Ship scrapers/connectors only for permissible sources (FamilySearch API, Find A Grave, WikiTree, BLM/GLO, USGS, public-domain newspapers, public county records). Never add connectors for paywalled/terms-prohibited sites (Ancestry, MyHeritage, 23andMe).
|
6. **Only legal data sources.** Ship scrapers/connectors only for permissible sources (FamilySearch API, Find A Grave, WikiTree, BLM/GLO, USGS, public-domain newspapers, public county records). Never add connectors for paywalled/terms-prohibited sites (Ancestry, MyHeritage, 23andMe).
|
||||||
7. **Everything is configurable via environment.** Auth, mail, object storage, database, model providers, scrapers — all twelve-factor. No hard-coded endpoints or keys.
|
7. **Everything is configurable via environment.** Auth, mail, object storage, database, model providers, scrapers — all twelve-factor. No hard-coded endpoints or keys.
|
||||||
|
8. **Full CRUD on every object.** Every stored entity (person, name, event, relationship, source, citation, media, tree, …) must support create, read, **update**, and delete — in the API *and* the UI. Historical research is constant correction and new information, so nothing is write-once. Any new feature or data type ships with all four operations; an entity you can create but not edit is a bug.
|
||||||
|
|
||||||
## Tech stack
|
## Tech stack
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from app.api.v1 import (
|
|||||||
events,
|
events,
|
||||||
gedcom,
|
gedcom,
|
||||||
media,
|
media,
|
||||||
|
names,
|
||||||
persons,
|
persons,
|
||||||
relationships,
|
relationships,
|
||||||
sources,
|
sources,
|
||||||
@@ -20,6 +21,7 @@ api_router.include_router(auth.router)
|
|||||||
api_router.include_router(users.router)
|
api_router.include_router(users.router)
|
||||||
api_router.include_router(trees.router)
|
api_router.include_router(trees.router)
|
||||||
api_router.include_router(persons.router)
|
api_router.include_router(persons.router)
|
||||||
|
api_router.include_router(names.router)
|
||||||
api_router.include_router(events.router)
|
api_router.include_router(events.router)
|
||||||
api_router.include_router(relationships.router)
|
api_router.include_router(relationships.router)
|
||||||
api_router.include_router(sources.router)
|
api_router.include_router(sources.router)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import uuid
|
|||||||
from fastapi import APIRouter, status
|
from fastapi import APIRouter, status
|
||||||
|
|
||||||
from app.api.deps import CurrentUser, SessionDep
|
from app.api.deps import CurrentUser, SessionDep
|
||||||
from app.schemas.source import CitationCreate, CitationRead
|
from app.schemas.source import CitationCreate, CitationRead, CitationUpdate
|
||||||
from app.services import citation_service, tree_service
|
from app.services import citation_service, tree_service
|
||||||
|
|
||||||
router = APIRouter(prefix="/trees", tags=["citations"])
|
router = APIRouter(prefix="/trees", tags=["citations"])
|
||||||
@@ -31,6 +31,25 @@ async def list_citations(
|
|||||||
return [CitationRead.model_validate(c) for c in citations]
|
return [CitationRead.model_validate(c) for c in citations]
|
||||||
|
|
||||||
|
|
||||||
|
@router.patch("/{tree_id}/citations/{citation_id}", response_model=CitationRead)
|
||||||
|
async def update_citation(
|
||||||
|
tree_id: uuid.UUID,
|
||||||
|
citation_id: uuid.UUID,
|
||||||
|
data: CitationUpdate,
|
||||||
|
session: SessionDep,
|
||||||
|
current: CurrentUser,
|
||||||
|
) -> CitationRead:
|
||||||
|
tree = await tree_service.get_tree(session, viewer_id=current.id, tree_id=tree_id)
|
||||||
|
citation = await citation_service.update_citation(
|
||||||
|
session,
|
||||||
|
actor=current,
|
||||||
|
tree=tree,
|
||||||
|
citation_id=citation_id,
|
||||||
|
changes=data.model_dump(exclude_unset=True),
|
||||||
|
)
|
||||||
|
return CitationRead.model_validate(citation)
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/{tree_id}/citations/{citation_id}", status_code=status.HTTP_204_NO_CONTENT)
|
@router.delete("/{tree_id}/citations/{citation_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||||
async def delete_citation(
|
async def delete_citation(
|
||||||
tree_id: uuid.UUID, citation_id: uuid.UUID, session: SessionDep, current: CurrentUser
|
tree_id: uuid.UUID, citation_id: uuid.UUID, session: SessionDep, current: CurrentUser
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import uuid
|
|||||||
from fastapi import APIRouter, status
|
from fastapi import APIRouter, status
|
||||||
|
|
||||||
from app.api.deps import CurrentUser, SessionDep
|
from app.api.deps import CurrentUser, SessionDep
|
||||||
from app.schemas.event import EventCreate, EventRead
|
from app.schemas.event import EventCreate, EventRead, EventUpdate
|
||||||
from app.services import event_service, tree_service
|
from app.services import event_service, tree_service
|
||||||
|
|
||||||
router = APIRouter(prefix="/trees", tags=["events"])
|
router = APIRouter(prefix="/trees", tags=["events"])
|
||||||
@@ -40,6 +40,25 @@ async def list_person_events(
|
|||||||
return [EventRead.model_validate(e) for e in events]
|
return [EventRead.model_validate(e) for e in events]
|
||||||
|
|
||||||
|
|
||||||
|
@router.patch("/{tree_id}/events/{event_id}", response_model=EventRead)
|
||||||
|
async def update_event(
|
||||||
|
tree_id: uuid.UUID,
|
||||||
|
event_id: uuid.UUID,
|
||||||
|
data: EventUpdate,
|
||||||
|
session: SessionDep,
|
||||||
|
current: CurrentUser,
|
||||||
|
) -> EventRead:
|
||||||
|
tree = await tree_service.get_tree(session, viewer_id=current.id, tree_id=tree_id)
|
||||||
|
event = await event_service.update_event(
|
||||||
|
session,
|
||||||
|
actor=current,
|
||||||
|
tree=tree,
|
||||||
|
event_id=event_id,
|
||||||
|
changes=data.model_dump(exclude_unset=True),
|
||||||
|
)
|
||||||
|
return EventRead.model_validate(event)
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/{tree_id}/events/{event_id}", status_code=status.HTTP_204_NO_CONTENT)
|
@router.delete("/{tree_id}/events/{event_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||||
async def delete_event(
|
async def delete_event(
|
||||||
tree_id: uuid.UUID, event_id: uuid.UUID, session: SessionDep, current: CurrentUser
|
tree_id: uuid.UUID, event_id: uuid.UUID, session: SessionDep, current: CurrentUser
|
||||||
|
|||||||
@@ -1,25 +1,56 @@
|
|||||||
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from fastapi import APIRouter, File, Response, UploadFile
|
from fastapi import APIRouter, File, Form, Response, UploadFile
|
||||||
|
|
||||||
from app.api.deps import CurrentUser, SessionDep
|
from app.api.deps import CurrentUser, SessionDep
|
||||||
from app.schemas.gedcom import ImportReport
|
from app.schemas.gedcom import ImportPreview, ImportReport
|
||||||
from app.services import gedcom, tree_service
|
from app.services import gedcom, tree_service
|
||||||
|
|
||||||
router = APIRouter(prefix="/trees", tags=["gedcom"])
|
router = APIRouter(prefix="/trees", tags=["gedcom"])
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/{tree_id}/gedcom/preview", response_model=ImportPreview)
|
||||||
|
async def preview_gedcom(
|
||||||
|
tree_id: uuid.UUID,
|
||||||
|
session: SessionDep,
|
||||||
|
current: CurrentUser,
|
||||||
|
file: UploadFile = File(...),
|
||||||
|
) -> ImportPreview:
|
||||||
|
"""Dry run: report counts and incoming people that look like duplicates of
|
||||||
|
existing ones, so the user can choose how to resolve each before importing."""
|
||||||
|
tree = await tree_service.get_tree(session, viewer_id=current.id, tree_id=tree_id)
|
||||||
|
text = (await file.read()).decode("utf-8", errors="replace")
|
||||||
|
report = await gedcom.preview_gedcom(session, actor=current, tree=tree, text=text)
|
||||||
|
return ImportPreview(**report)
|
||||||
|
|
||||||
|
|
||||||
@router.post("/{tree_id}/gedcom/import", response_model=ImportReport)
|
@router.post("/{tree_id}/gedcom/import", response_model=ImportReport)
|
||||||
async def import_gedcom(
|
async def import_gedcom(
|
||||||
tree_id: uuid.UUID,
|
tree_id: uuid.UUID,
|
||||||
session: SessionDep,
|
session: SessionDep,
|
||||||
current: CurrentUser,
|
current: CurrentUser,
|
||||||
file: UploadFile = File(...),
|
file: UploadFile = File(...),
|
||||||
|
default_action: str = Form("new"),
|
||||||
|
resolutions: str = Form("{}"),
|
||||||
) -> ImportReport:
|
) -> ImportReport:
|
||||||
# NOTE: additive — records are created as new; existing people are not merged.
|
"""Import a GEDCOM. ``default_action`` (new|skip|merge|overwrite) applies to
|
||||||
|
incoming people that match an existing one; ``resolutions`` is a JSON object
|
||||||
|
{xref: {action, target_id}} overriding it per record."""
|
||||||
tree = await tree_service.get_tree(session, viewer_id=current.id, tree_id=tree_id)
|
tree = await tree_service.get_tree(session, viewer_id=current.id, tree_id=tree_id)
|
||||||
text = (await file.read()).decode("utf-8", errors="replace")
|
text = (await file.read()).decode("utf-8", errors="replace")
|
||||||
report = await gedcom.import_gedcom(session, actor=current, tree=tree, text=text)
|
try:
|
||||||
|
parsed = json.loads(resolutions or "{}")
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
parsed = {}
|
||||||
|
report = await gedcom.import_gedcom(
|
||||||
|
session,
|
||||||
|
actor=current,
|
||||||
|
tree=tree,
|
||||||
|
text=text,
|
||||||
|
default_action=default_action,
|
||||||
|
resolutions=parsed,
|
||||||
|
)
|
||||||
return ImportReport(**report)
|
return ImportReport(**report)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import uuid
|
|||||||
from fastapi import APIRouter, File, Form, Response, UploadFile, status
|
from fastapi import APIRouter, File, Form, Response, UploadFile, status
|
||||||
|
|
||||||
from app.api.deps import CurrentUser, ObjectStoreDep, SessionDep
|
from app.api.deps import CurrentUser, ObjectStoreDep, SessionDep
|
||||||
from app.schemas.media import MediaRead
|
from app.schemas.media import MediaRead, MediaUpdate
|
||||||
from app.services import media_service, tree_service
|
from app.services import media_service, tree_service
|
||||||
|
|
||||||
|
|
||||||
@@ -81,6 +81,26 @@ async def media_content(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.patch("/{tree_id}/media/{media_id}", response_model=MediaRead)
|
||||||
|
async def update_media(
|
||||||
|
tree_id: uuid.UUID,
|
||||||
|
media_id: uuid.UUID,
|
||||||
|
data: MediaUpdate,
|
||||||
|
session: SessionDep,
|
||||||
|
current: CurrentUser,
|
||||||
|
store: ObjectStoreDep,
|
||||||
|
) -> MediaRead:
|
||||||
|
tree = await tree_service.get_tree(session, viewer_id=current.id, tree_id=tree_id)
|
||||||
|
media = await media_service.update_media(
|
||||||
|
session,
|
||||||
|
actor=current,
|
||||||
|
tree=tree,
|
||||||
|
media_id=media_id,
|
||||||
|
changes=data.model_dump(exclude_unset=True),
|
||||||
|
)
|
||||||
|
return _read(media)
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/{tree_id}/media/{media_id}", status_code=status.HTTP_204_NO_CONTENT)
|
@router.delete("/{tree_id}/media/{media_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||||
async def delete_media(
|
async def delete_media(
|
||||||
tree_id: uuid.UUID, media_id: uuid.UUID, session: SessionDep, current: CurrentUser
|
tree_id: uuid.UUID, media_id: uuid.UUID, session: SessionDep, current: CurrentUser
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
|
from fastapi import APIRouter, status
|
||||||
|
|
||||||
|
from app.api.deps import CurrentUser, SessionDep
|
||||||
|
from app.schemas.name import NameCreate, NameRead, NameUpdate
|
||||||
|
from app.services import name_service, tree_service
|
||||||
|
|
||||||
|
# Names are nested under their person (which is nested under the tree tenant).
|
||||||
|
router = APIRouter(prefix="/trees", tags=["names"])
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/{tree_id}/persons/{person_id}/names", response_model=list[NameRead])
|
||||||
|
async def list_names(
|
||||||
|
tree_id: uuid.UUID, person_id: uuid.UUID, session: SessionDep, current: CurrentUser
|
||||||
|
) -> list[NameRead]:
|
||||||
|
tree = await tree_service.get_tree(session, viewer_id=current.id, tree_id=tree_id)
|
||||||
|
names = await name_service.list_names(
|
||||||
|
session, viewer_id=current.id, tree=tree, person_id=person_id
|
||||||
|
)
|
||||||
|
return [NameRead.model_validate(n) for n in names]
|
||||||
|
|
||||||
|
|
||||||
|
@router.post(
|
||||||
|
"/{tree_id}/persons/{person_id}/names",
|
||||||
|
response_model=NameRead,
|
||||||
|
status_code=status.HTTP_201_CREATED,
|
||||||
|
)
|
||||||
|
async def create_name(
|
||||||
|
tree_id: uuid.UUID,
|
||||||
|
person_id: uuid.UUID,
|
||||||
|
data: NameCreate,
|
||||||
|
session: SessionDep,
|
||||||
|
current: CurrentUser,
|
||||||
|
) -> NameRead:
|
||||||
|
tree = await tree_service.get_tree(session, viewer_id=current.id, tree_id=tree_id)
|
||||||
|
name = await name_service.create_name(
|
||||||
|
session,
|
||||||
|
actor=current,
|
||||||
|
tree=tree,
|
||||||
|
person_id=person_id,
|
||||||
|
name_type=data.name_type,
|
||||||
|
given=data.given,
|
||||||
|
surname=data.surname,
|
||||||
|
prefix=data.prefix,
|
||||||
|
suffix=data.suffix,
|
||||||
|
nickname=data.nickname,
|
||||||
|
is_primary=data.is_primary,
|
||||||
|
)
|
||||||
|
return NameRead.model_validate(name)
|
||||||
|
|
||||||
|
|
||||||
|
@router.patch(
|
||||||
|
"/{tree_id}/persons/{person_id}/names/{name_id}", response_model=NameRead
|
||||||
|
)
|
||||||
|
async def update_name(
|
||||||
|
tree_id: uuid.UUID,
|
||||||
|
person_id: uuid.UUID,
|
||||||
|
name_id: uuid.UUID,
|
||||||
|
data: NameUpdate,
|
||||||
|
session: SessionDep,
|
||||||
|
current: CurrentUser,
|
||||||
|
) -> NameRead:
|
||||||
|
tree = await tree_service.get_tree(session, viewer_id=current.id, tree_id=tree_id)
|
||||||
|
name = await name_service.update_name(
|
||||||
|
session,
|
||||||
|
actor=current,
|
||||||
|
tree=tree,
|
||||||
|
person_id=person_id,
|
||||||
|
name_id=name_id,
|
||||||
|
changes=data.model_dump(exclude_unset=True),
|
||||||
|
)
|
||||||
|
return NameRead.model_validate(name)
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete(
|
||||||
|
"/{tree_id}/persons/{person_id}/names/{name_id}",
|
||||||
|
status_code=status.HTTP_204_NO_CONTENT,
|
||||||
|
)
|
||||||
|
async def delete_name(
|
||||||
|
tree_id: uuid.UUID,
|
||||||
|
person_id: uuid.UUID,
|
||||||
|
name_id: uuid.UUID,
|
||||||
|
session: SessionDep,
|
||||||
|
current: CurrentUser,
|
||||||
|
) -> None:
|
||||||
|
tree = await tree_service.get_tree(session, viewer_id=current.id, tree_id=tree_id)
|
||||||
|
await name_service.delete_name(
|
||||||
|
session, actor=current, tree=tree, person_id=person_id, name_id=name_id
|
||||||
|
)
|
||||||
@@ -3,7 +3,7 @@ import uuid
|
|||||||
from fastapi import APIRouter, status
|
from fastapi import APIRouter, status
|
||||||
|
|
||||||
from app.api.deps import CurrentUser, SessionDep
|
from app.api.deps import CurrentUser, SessionDep
|
||||||
from app.schemas.person import PersonCreate, PersonRead
|
from app.schemas.person import PersonCreate, PersonRead, PersonUpdate
|
||||||
from app.services import person_service, tree_service
|
from app.services import person_service, tree_service
|
||||||
|
|
||||||
# Persons are nested under their tree (the tenant boundary).
|
# Persons are nested under their tree (the tenant boundary).
|
||||||
@@ -36,10 +36,18 @@ async def create_person(
|
|||||||
|
|
||||||
@router.get("/{tree_id}/persons", response_model=list[PersonRead])
|
@router.get("/{tree_id}/persons", response_model=list[PersonRead])
|
||||||
async def list_persons(
|
async def list_persons(
|
||||||
tree_id: uuid.UUID, session: SessionDep, current: CurrentUser, deleted: bool = False
|
tree_id: uuid.UUID,
|
||||||
|
session: SessionDep,
|
||||||
|
current: CurrentUser,
|
||||||
|
deleted: bool = False,
|
||||||
|
q: str | None = None,
|
||||||
) -> list[PersonRead]:
|
) -> list[PersonRead]:
|
||||||
tree = await tree_service.get_tree(session, viewer_id=current.id, tree_id=tree_id)
|
tree = await tree_service.get_tree(session, viewer_id=current.id, tree_id=tree_id)
|
||||||
if deleted:
|
if q:
|
||||||
|
persons = await person_service.search_persons(
|
||||||
|
session, viewer_id=current.id, tree=tree, query=q
|
||||||
|
)
|
||||||
|
elif deleted:
|
||||||
persons = await person_service.list_deleted_persons(
|
persons = await person_service.list_deleted_persons(
|
||||||
session, viewer_id=current.id, tree=tree
|
session, viewer_id=current.id, tree=tree
|
||||||
)
|
)
|
||||||
@@ -48,12 +56,40 @@ async def list_persons(
|
|||||||
return [PersonRead.model_validate(p) for p in persons]
|
return [PersonRead.model_validate(p) for p in persons]
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/{tree_id}/persons/{person_id}", status_code=status.HTTP_204_NO_CONTENT)
|
@router.patch("/{tree_id}/persons/{person_id}", response_model=PersonRead)
|
||||||
async def delete_person(
|
async def update_person(
|
||||||
tree_id: uuid.UUID, person_id: uuid.UUID, session: SessionDep, current: CurrentUser
|
tree_id: uuid.UUID,
|
||||||
) -> None:
|
person_id: uuid.UUID,
|
||||||
|
data: PersonUpdate,
|
||||||
|
session: SessionDep,
|
||||||
|
current: CurrentUser,
|
||||||
|
) -> PersonRead:
|
||||||
tree = await tree_service.get_tree(session, viewer_id=current.id, tree_id=tree_id)
|
tree = await tree_service.get_tree(session, viewer_id=current.id, tree_id=tree_id)
|
||||||
await person_service.delete_person(session, actor=current, tree=tree, person_id=person_id)
|
person = await person_service.update_person(
|
||||||
|
session,
|
||||||
|
actor=current,
|
||||||
|
tree=tree,
|
||||||
|
person_id=person_id,
|
||||||
|
changes=data.model_dump(exclude_unset=True),
|
||||||
|
)
|
||||||
|
return PersonRead.model_validate(person)
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/{tree_id}/persons/{person_id}")
|
||||||
|
async def delete_person(
|
||||||
|
tree_id: uuid.UUID,
|
||||||
|
person_id: uuid.UUID,
|
||||||
|
session: SessionDep,
|
||||||
|
current: CurrentUser,
|
||||||
|
cascade: bool = False,
|
||||||
|
) -> dict[str, int]:
|
||||||
|
"""Delete a person. ``cascade=true`` also deletes all descendants. Returns
|
||||||
|
the number of persons deleted (1 unless cascading)."""
|
||||||
|
tree = await tree_service.get_tree(session, viewer_id=current.id, tree_id=tree_id)
|
||||||
|
deleted = await person_service.delete_person(
|
||||||
|
session, actor=current, tree=tree, person_id=person_id, cascade=cascade
|
||||||
|
)
|
||||||
|
return {"deleted": deleted}
|
||||||
|
|
||||||
|
|
||||||
@router.post("/{tree_id}/persons/{person_id}/restore", response_model=PersonRead)
|
@router.post("/{tree_id}/persons/{person_id}/restore", response_model=PersonRead)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import uuid
|
|||||||
from fastapi import APIRouter, status
|
from fastapi import APIRouter, status
|
||||||
|
|
||||||
from app.api.deps import CurrentUser, SessionDep
|
from app.api.deps import CurrentUser, SessionDep
|
||||||
from app.schemas.relationship import RelationshipCreate, RelationshipRead
|
from app.schemas.relationship import RelationshipCreate, RelationshipRead, RelationshipUpdate
|
||||||
from app.services import relationship_service, tree_service
|
from app.services import relationship_service, tree_service
|
||||||
|
|
||||||
router = APIRouter(prefix="/trees", tags=["relationships"])
|
router = APIRouter(prefix="/trees", tags=["relationships"])
|
||||||
@@ -47,6 +47,25 @@ async def list_person_relationships(
|
|||||||
return [RelationshipRead.model_validate(r) for r in rels]
|
return [RelationshipRead.model_validate(r) for r in rels]
|
||||||
|
|
||||||
|
|
||||||
|
@router.patch("/{tree_id}/relationships/{relationship_id}", response_model=RelationshipRead)
|
||||||
|
async def update_relationship(
|
||||||
|
tree_id: uuid.UUID,
|
||||||
|
relationship_id: uuid.UUID,
|
||||||
|
data: RelationshipUpdate,
|
||||||
|
session: SessionDep,
|
||||||
|
current: CurrentUser,
|
||||||
|
) -> RelationshipRead:
|
||||||
|
tree = await tree_service.get_tree(session, viewer_id=current.id, tree_id=tree_id)
|
||||||
|
rel = await relationship_service.update_relationship(
|
||||||
|
session,
|
||||||
|
actor=current,
|
||||||
|
tree=tree,
|
||||||
|
relationship_id=relationship_id,
|
||||||
|
changes=data.model_dump(exclude_unset=True),
|
||||||
|
)
|
||||||
|
return RelationshipRead.model_validate(rel)
|
||||||
|
|
||||||
|
|
||||||
@router.delete(
|
@router.delete(
|
||||||
"/{tree_id}/relationships/{relationship_id}", status_code=status.HTTP_204_NO_CONTENT
|
"/{tree_id}/relationships/{relationship_id}", status_code=status.HTTP_204_NO_CONTENT
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import uuid
|
|||||||
from fastapi import APIRouter, status
|
from fastapi import APIRouter, status
|
||||||
|
|
||||||
from app.api.deps import CurrentUser, SessionDep
|
from app.api.deps import CurrentUser, SessionDep
|
||||||
from app.schemas.source import SourceCreate, SourceRead
|
from app.schemas.source import SourceCreate, SourceRead, SourceUpdate
|
||||||
from app.services import source_service, tree_service
|
from app.services import source_service, tree_service
|
||||||
|
|
||||||
router = APIRouter(prefix="/trees", tags=["sources"])
|
router = APIRouter(prefix="/trees", tags=["sources"])
|
||||||
@@ -40,6 +40,25 @@ async def get_source(
|
|||||||
return SourceRead.model_validate(source)
|
return SourceRead.model_validate(source)
|
||||||
|
|
||||||
|
|
||||||
|
@router.patch("/{tree_id}/sources/{source_id}", response_model=SourceRead)
|
||||||
|
async def update_source(
|
||||||
|
tree_id: uuid.UUID,
|
||||||
|
source_id: uuid.UUID,
|
||||||
|
data: SourceUpdate,
|
||||||
|
session: SessionDep,
|
||||||
|
current: CurrentUser,
|
||||||
|
) -> SourceRead:
|
||||||
|
tree = await tree_service.get_tree(session, viewer_id=current.id, tree_id=tree_id)
|
||||||
|
source = await source_service.update_source(
|
||||||
|
session,
|
||||||
|
actor=current,
|
||||||
|
tree=tree,
|
||||||
|
source_id=source_id,
|
||||||
|
changes=data.model_dump(exclude_unset=True),
|
||||||
|
)
|
||||||
|
return SourceRead.model_validate(source)
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/{tree_id}/sources/{source_id}", status_code=status.HTTP_204_NO_CONTENT)
|
@router.delete("/{tree_id}/sources/{source_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||||
async def delete_source(
|
async def delete_source(
|
||||||
tree_id: uuid.UUID, source_id: uuid.UUID, session: SessionDep, current: CurrentUser
|
tree_id: uuid.UUID, source_id: uuid.UUID, session: SessionDep, current: CurrentUser
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import uuid
|
|||||||
from fastapi import APIRouter, status
|
from fastapi import APIRouter, status
|
||||||
|
|
||||||
from app.api.deps import CurrentUser, SessionDep
|
from app.api.deps import CurrentUser, SessionDep
|
||||||
from app.schemas.tree import TreeCreate, TreeRead
|
from app.schemas.tree import TreeCreate, TreeRead, TreeUpdate
|
||||||
from app.services import tree_service
|
from app.services import tree_service
|
||||||
|
|
||||||
router = APIRouter(prefix="/trees", tags=["trees"])
|
router = APIRouter(prefix="/trees", tags=["trees"])
|
||||||
@@ -38,6 +38,16 @@ async def get_tree(tree_id: uuid.UUID, session: SessionDep, current: CurrentUser
|
|||||||
return TreeRead.model_validate(tree)
|
return TreeRead.model_validate(tree)
|
||||||
|
|
||||||
|
|
||||||
|
@router.patch("/{tree_id}", response_model=TreeRead)
|
||||||
|
async def update_tree(
|
||||||
|
tree_id: uuid.UUID, data: TreeUpdate, session: SessionDep, current: CurrentUser
|
||||||
|
) -> TreeRead:
|
||||||
|
tree = await tree_service.update_tree(
|
||||||
|
session, actor=current, tree_id=tree_id, changes=data.model_dump(exclude_unset=True)
|
||||||
|
)
|
||||||
|
return TreeRead.model_validate(tree)
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/{tree_id}", status_code=status.HTTP_204_NO_CONTENT)
|
@router.delete("/{tree_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||||
async def delete_tree(tree_id: uuid.UUID, session: SessionDep, current: CurrentUser) -> None:
|
async def delete_tree(tree_id: uuid.UUID, session: SessionDep, current: CurrentUser) -> None:
|
||||||
await tree_service.delete_tree(session, actor=current, tree_id=tree_id)
|
await tree_service.delete_tree(session, actor=current, tree_id=tree_id)
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
|
||||||
from app.api.deps import CurrentUser
|
from app.api.deps import CurrentUser, SessionDep
|
||||||
from app.schemas.user import UserRead
|
from app.schemas.user import UserRead, UserSelfPersonUpdate
|
||||||
|
from app.services import user_service
|
||||||
|
|
||||||
router = APIRouter(prefix="/users", tags=["users"])
|
router = APIRouter(prefix="/users", tags=["users"])
|
||||||
|
|
||||||
@@ -9,3 +10,14 @@ router = APIRouter(prefix="/users", tags=["users"])
|
|||||||
@router.get("/me", response_model=UserRead)
|
@router.get("/me", response_model=UserRead)
|
||||||
async def read_me(current: CurrentUser) -> UserRead:
|
async def read_me(current: CurrentUser) -> UserRead:
|
||||||
return UserRead.model_validate(current)
|
return UserRead.model_validate(current)
|
||||||
|
|
||||||
|
|
||||||
|
@router.patch("/me/self-person", response_model=UserRead)
|
||||||
|
async def set_self_person(
|
||||||
|
data: UserSelfPersonUpdate, session: SessionDep, current: CurrentUser
|
||||||
|
) -> UserRead:
|
||||||
|
"""Link (or unlink) the Person record that represents this account."""
|
||||||
|
user = await user_service.set_self_person(
|
||||||
|
session, user=current, person_id=data.self_person_id
|
||||||
|
)
|
||||||
|
return UserRead.model_validate(user)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ aliases) so name changes over time are first-class.
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from sqlalchemy import Boolean, ForeignKey, Integer, String, Text, text
|
from sqlalchemy import Boolean, ForeignKey, Index, Integer, String, Text, text
|
||||||
from sqlalchemy import Enum as SAEnum
|
from sqlalchemy import Enum as SAEnum
|
||||||
from sqlalchemy.orm import Mapped, mapped_column
|
from sqlalchemy.orm import Mapped, mapped_column
|
||||||
|
|
||||||
@@ -33,6 +33,22 @@ class Person(Base, UUIDPrimaryKey, TenantScoped, Timestamps, SoftDelete):
|
|||||||
|
|
||||||
class Name(Base, UUIDPrimaryKey, TenantScoped, Timestamps, SoftDelete):
|
class Name(Base, UUIDPrimaryKey, TenantScoped, Timestamps, SoftDelete):
|
||||||
__tablename__ = "names"
|
__tablename__ = "names"
|
||||||
|
# Trigram indexes for fuzzy name search (Mueller/Müller/Muller). Requires the
|
||||||
|
# pg_trgm extension (enabled in the accompanying migration).
|
||||||
|
__table_args__ = (
|
||||||
|
Index(
|
||||||
|
"ix_names_given_trgm",
|
||||||
|
"given",
|
||||||
|
postgresql_using="gin",
|
||||||
|
postgresql_ops={"given": "gin_trgm_ops"},
|
||||||
|
),
|
||||||
|
Index(
|
||||||
|
"ix_names_surname_trgm",
|
||||||
|
"surname",
|
||||||
|
postgresql_using="gin",
|
||||||
|
postgresql_ops={"surname": "gin_trgm_ops"},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
person_id: Mapped[uuid.UUID] = mapped_column(
|
person_id: Mapped[uuid.UUID] = mapped_column(
|
||||||
ForeignKey("persons.id", ondelete="CASCADE"), index=True
|
ForeignKey("persons.id", ondelete="CASCADE"), index=True
|
||||||
|
|||||||
@@ -3,9 +3,10 @@ multiple auth providers later (the provider-link table arrives with the auth
|
|||||||
slice). ``hashed_password`` is nullable: external/OIDC users have none.
|
slice). ``hashed_password`` is nullable: external/OIDC users have none.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import uuid
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from sqlalchemy import DateTime, String
|
from sqlalchemy import DateTime, ForeignKey, String
|
||||||
from sqlalchemy.orm import Mapped, mapped_column
|
from sqlalchemy.orm import Mapped, mapped_column
|
||||||
|
|
||||||
from app.models.base import Base
|
from app.models.base import Base
|
||||||
@@ -19,3 +20,15 @@ class User(Base, UUIDPrimaryKey, Timestamps, SoftDelete):
|
|||||||
email_verified_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
email_verified_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
||||||
display_name: Mapped[str | None] = mapped_column(String(255))
|
display_name: Mapped[str | None] = mapped_column(String(255))
|
||||||
hashed_password: Mapped[str | None] = mapped_column(String(255))
|
hashed_password: Mapped[str | None] = mapped_column(String(255))
|
||||||
|
# The Person record that *is* this user ("home person"). Cleared if that
|
||||||
|
# person is deleted, so the link can never dangle.
|
||||||
|
self_person_id: Mapped[uuid.UUID | None] = mapped_column(
|
||||||
|
# use_alter + explicit name: users<->persons<->trees form an FK cycle,
|
||||||
|
# so this constraint must be created/dropped via ALTER, not inline.
|
||||||
|
ForeignKey(
|
||||||
|
"persons.id",
|
||||||
|
ondelete="SET NULL",
|
||||||
|
name="fk_users_self_person_id",
|
||||||
|
use_alter=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|||||||
@@ -20,6 +20,19 @@ class EventCreate(BaseModel):
|
|||||||
notes: str | None = None
|
notes: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class EventUpdate(BaseModel):
|
||||||
|
# All optional; only fields explicitly sent are changed (PATCH semantics).
|
||||||
|
event_type: str | None = None
|
||||||
|
place_id: uuid.UUID | None = None
|
||||||
|
date_value: str | None = None
|
||||||
|
date_start: date | None = None
|
||||||
|
date_end: date | None = None
|
||||||
|
date_precision: str | None = None
|
||||||
|
calendar: str | None = None
|
||||||
|
detail: str | None = None
|
||||||
|
notes: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class EventRead(BaseModel):
|
class EventRead(BaseModel):
|
||||||
model_config = ConfigDict(from_attributes=True)
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,25 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
class ImportReport(BaseModel):
|
class ImportReport(BaseModel):
|
||||||
counts: dict[str, int]
|
counts: dict[str, int]
|
||||||
unmapped_tags: list[str]
|
unmapped_tags: list[str]
|
||||||
|
|
||||||
|
|
||||||
|
class DuplicateMatch(BaseModel):
|
||||||
|
# An incoming GEDCOM person that resembles an existing one in the tree.
|
||||||
|
xref: str
|
||||||
|
incoming_name: str
|
||||||
|
incoming_birth_year: str | None = None
|
||||||
|
existing_person_id: uuid.UUID
|
||||||
|
existing_name: str
|
||||||
|
existing_birth_year: str | None = None
|
||||||
|
score: str # "high" | "medium"
|
||||||
|
|
||||||
|
|
||||||
|
class ImportPreview(BaseModel):
|
||||||
|
counts: dict[str, int]
|
||||||
|
potential_duplicates: list[DuplicateMatch]
|
||||||
|
unmapped_tags: list[str]
|
||||||
|
|||||||
@@ -4,6 +4,13 @@ from datetime import datetime
|
|||||||
from pydantic import BaseModel, ConfigDict
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
|
||||||
|
|
||||||
|
class MediaUpdate(BaseModel):
|
||||||
|
title: str | None = None
|
||||||
|
person_id: uuid.UUID | None = None
|
||||||
|
event_id: uuid.UUID | None = None
|
||||||
|
source_id: uuid.UUID | None = None
|
||||||
|
|
||||||
|
|
||||||
class MediaRead(BaseModel):
|
class MediaRead(BaseModel):
|
||||||
model_config = ConfigDict(from_attributes=True)
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import uuid
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
|
||||||
|
|
||||||
|
class NameCreate(BaseModel):
|
||||||
|
# Open vocabulary: birth/maiden, married, alias, religious, nickname, ...
|
||||||
|
name_type: str = "birth"
|
||||||
|
given: str | None = None
|
||||||
|
surname: str | None = None
|
||||||
|
prefix: str | None = None
|
||||||
|
suffix: str | None = None
|
||||||
|
nickname: str | None = None
|
||||||
|
is_primary: bool = False
|
||||||
|
|
||||||
|
|
||||||
|
class NameUpdate(BaseModel):
|
||||||
|
name_type: str | None = None
|
||||||
|
given: str | None = None
|
||||||
|
surname: str | None = None
|
||||||
|
prefix: str | None = None
|
||||||
|
suffix: str | None = None
|
||||||
|
nickname: str | None = None
|
||||||
|
is_primary: bool | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class NameRead(BaseModel):
|
||||||
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
|
id: uuid.UUID
|
||||||
|
tree_id: uuid.UUID
|
||||||
|
person_id: uuid.UUID
|
||||||
|
name_type: str
|
||||||
|
given: str | None
|
||||||
|
surname: str | None
|
||||||
|
prefix: str | None
|
||||||
|
suffix: str | None
|
||||||
|
nickname: str | None
|
||||||
|
is_primary: bool
|
||||||
|
sort_order: int
|
||||||
|
created_at: datetime
|
||||||
@@ -15,6 +15,16 @@ class PersonCreate(BaseModel):
|
|||||||
notes: str | None = None
|
notes: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class PersonUpdate(BaseModel):
|
||||||
|
# Person fields + the primary name's parts; only sent fields are changed.
|
||||||
|
given: str | None = None
|
||||||
|
surname: str | None = None
|
||||||
|
gender: str | None = None
|
||||||
|
is_living: bool | None = None
|
||||||
|
privacy: PersonPrivacy | None = None
|
||||||
|
notes: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class PersonRead(BaseModel):
|
class PersonRead(BaseModel):
|
||||||
model_config = ConfigDict(from_attributes=True)
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ class RelationshipCreate(BaseModel):
|
|||||||
notes: str | None = None
|
notes: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class RelationshipUpdate(BaseModel):
|
||||||
|
qualifier: ParentChildQualifier | None = None
|
||||||
|
notes: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class RelationshipRead(BaseModel):
|
class RelationshipRead(BaseModel):
|
||||||
model_config = ConfigDict(from_attributes=True)
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,23 @@ class SourceRead(BaseModel):
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
|
||||||
|
|
||||||
|
class SourceUpdate(BaseModel):
|
||||||
|
title: str | None = None
|
||||||
|
author: str | None = None
|
||||||
|
source_type: str | None = None
|
||||||
|
repository: str | None = None
|
||||||
|
url: str | None = None
|
||||||
|
citation_text: str | None = None
|
||||||
|
publication_info: str | None = None
|
||||||
|
quality_note: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class CitationUpdate(BaseModel):
|
||||||
|
page: str | None = None
|
||||||
|
detail: str | None = None
|
||||||
|
confidence: CitationConfidence | None = None
|
||||||
|
|
||||||
|
|
||||||
class CitationCreate(BaseModel):
|
class CitationCreate(BaseModel):
|
||||||
source_id: uuid.UUID
|
source_id: uuid.UUID
|
||||||
# Exactly one target fact.
|
# Exactly one target fact.
|
||||||
|
|||||||
@@ -12,6 +12,12 @@ class TreeCreate(BaseModel):
|
|||||||
visibility: TreeVisibility = TreeVisibility.private
|
visibility: TreeVisibility = TreeVisibility.private
|
||||||
|
|
||||||
|
|
||||||
|
class TreeUpdate(BaseModel):
|
||||||
|
name: str | None = None
|
||||||
|
description: str | None = None
|
||||||
|
visibility: TreeVisibility | None = None
|
||||||
|
|
||||||
|
|
||||||
class TreeRead(BaseModel):
|
class TreeRead(BaseModel):
|
||||||
model_config = ConfigDict(from_attributes=True)
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
|
|||||||
@@ -19,4 +19,10 @@ class UserRead(BaseModel):
|
|||||||
email: str
|
email: str
|
||||||
display_name: str | None
|
display_name: str | None
|
||||||
email_verified_at: datetime | None
|
email_verified_at: datetime | None
|
||||||
|
self_person_id: uuid.UUID | None = None
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
|
||||||
|
|
||||||
|
class UserSelfPersonUpdate(BaseModel):
|
||||||
|
# null clears the link; otherwise the Person that represents this account.
|
||||||
|
self_person_id: uuid.UUID | None = None
|
||||||
|
|||||||
@@ -113,6 +113,38 @@ async def list_citations(
|
|||||||
return list((await session.execute(stmt)).scalars().all())
|
return list((await session.execute(stmt)).scalars().all())
|
||||||
|
|
||||||
|
|
||||||
|
async def update_citation(
|
||||||
|
session: AsyncSession, *, actor: User, tree: Tree, citation_id: uuid.UUID, changes: dict
|
||||||
|
) -> Citation:
|
||||||
|
if not await privacy.can_edit_tree(session, user_id=actor.id, tree=tree):
|
||||||
|
raise Forbidden("not an editor of this tree")
|
||||||
|
citation = (
|
||||||
|
await session.execute(
|
||||||
|
select(Citation).where(
|
||||||
|
Citation.id == citation_id,
|
||||||
|
Citation.tree_id == tree.id,
|
||||||
|
Citation.deleted_at.is_(None),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if citation is None:
|
||||||
|
raise NotFound("citation not found")
|
||||||
|
for key in {"page", "detail", "confidence"} & changes.keys():
|
||||||
|
setattr(citation, key, changes[key])
|
||||||
|
record_audit(
|
||||||
|
session,
|
||||||
|
action="update",
|
||||||
|
entity_type="Citation",
|
||||||
|
entity_id=citation.id,
|
||||||
|
tree_id=tree.id,
|
||||||
|
actor_user_id=actor.id,
|
||||||
|
after=changes,
|
||||||
|
)
|
||||||
|
await session.commit()
|
||||||
|
await session.refresh(citation)
|
||||||
|
return citation
|
||||||
|
|
||||||
|
|
||||||
async def delete_citation(
|
async def delete_citation(
|
||||||
session: AsyncSession, *, actor: User, tree: Tree, citation_id: uuid.UUID
|
session: AsyncSession, *, actor: User, tree: Tree, citation_id: uuid.UUID
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
@@ -122,6 +122,44 @@ async def list_events_for_person(
|
|||||||
return list((await session.execute(stmt)).scalars().all())
|
return list((await session.execute(stmt)).scalars().all())
|
||||||
|
|
||||||
|
|
||||||
|
async def update_event(
|
||||||
|
session: AsyncSession,
|
||||||
|
*,
|
||||||
|
actor: User,
|
||||||
|
tree: Tree,
|
||||||
|
event_id: uuid.UUID,
|
||||||
|
changes: dict,
|
||||||
|
) -> Event:
|
||||||
|
if not await privacy.can_edit_tree(session, user_id=actor.id, tree=tree):
|
||||||
|
raise Forbidden("not an editor of this tree")
|
||||||
|
event = (
|
||||||
|
await session.execute(
|
||||||
|
select(Event).where(
|
||||||
|
Event.id == event_id, Event.tree_id == tree.id, Event.deleted_at.is_(None)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if event is None:
|
||||||
|
raise NotFound("event not found")
|
||||||
|
if "place_id" in changes and changes["place_id"] is not None:
|
||||||
|
if not await _belongs_to_tree(session, Place, changes["place_id"], tree.id):
|
||||||
|
raise NotFound("place not found in this tree")
|
||||||
|
for key, value in changes.items():
|
||||||
|
setattr(event, key, value)
|
||||||
|
record_audit(
|
||||||
|
session,
|
||||||
|
action="update",
|
||||||
|
entity_type="Event",
|
||||||
|
entity_id=event.id,
|
||||||
|
tree_id=tree.id,
|
||||||
|
actor_user_id=actor.id,
|
||||||
|
after=changes,
|
||||||
|
)
|
||||||
|
await session.commit()
|
||||||
|
await session.refresh(event)
|
||||||
|
return event
|
||||||
|
|
||||||
|
|
||||||
async def delete_event(
|
async def delete_event(
|
||||||
session: AsyncSession, *, actor: User, tree: Tree, event_id: uuid.UUID
|
session: AsyncSession, *, actor: User, tree: Tree, event_id: uuid.UUID
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
+398
-48
@@ -4,14 +4,20 @@ A pragmatic parser + mapper for the common subset of GEDCOM (5.5.1 / 7 share
|
|||||||
the line grammar): INDI, FAM, SOUR. Import maps records into a tree and returns
|
the line grammar): INDI, FAM, SOUR. Import maps records into a tree and returns
|
||||||
a mapping report (counts + unmapped tags); export serializes the tree back to
|
a mapping report (counts + unmapped tags); export serializes the tree back to
|
||||||
GEDCOM. Runs inline for now — large files should move to the worker later.
|
GEDCOM. Runs inline for now — large files should move to the worker later.
|
||||||
|
|
||||||
|
Import is duplicate-aware: ``preview_gedcom`` reports incoming people that look
|
||||||
|
like existing ones, and ``import_gedcom`` applies a per-record resolution
|
||||||
|
(new / skip / merge / overwrite). Names carry their GEDCOM type (a married name
|
||||||
|
imports as a typed alternate, not a second primary).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import uuid
|
import uuid
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from datetime import date
|
from datetime import UTC, date, datetime
|
||||||
|
from difflib import SequenceMatcher
|
||||||
|
|
||||||
from sqlalchemy import select
|
from sqlalchemy import or_, select, update
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
from app.models.enums import ParentChildQualifier, RelationshipType
|
from app.models.enums import ParentChildQualifier, RelationshipType
|
||||||
@@ -32,12 +38,31 @@ INDI_EVENTS = {
|
|||||||
"BURI": "burial", "CREM": "cremation", "RESI": "residence", "CENS": "census",
|
"BURI": "burial", "CREM": "cremation", "RESI": "residence", "CENS": "census",
|
||||||
"IMMI": "immigration", "EMIG": "emigration", "OCCU": "occupation",
|
"IMMI": "immigration", "EMIG": "emigration", "OCCU": "occupation",
|
||||||
"EDUC": "education", "GRAD": "graduation", "RETI": "retirement",
|
"EDUC": "education", "GRAD": "graduation", "RETI": "retirement",
|
||||||
"NATU": "naturalization", "BAPL": "baptism",
|
"NATU": "naturalization", "BAPL": "baptism", "RELI": "religion",
|
||||||
|
}
|
||||||
|
# INDI attribute tags whose line VALUE is the fact (no date), stored in detail.
|
||||||
|
VALUE_EVENTS = {"RELI", "OCCU", "EDUC"}
|
||||||
|
# INDI sub-tags consumed elsewhere or intentionally ignored (not "unmapped").
|
||||||
|
INDI_SKIP_TAGS = {
|
||||||
|
"NAME", "SEX", "SOUR", "FAMC", "FAMS", "CHAN", "OBJE", "_UID", "_MARNM", "NOTE",
|
||||||
}
|
}
|
||||||
# FAM-level events.
|
# FAM-level events.
|
||||||
FAM_EVENTS = {"MARR": "marriage", "DIV": "divorce", "ENGA": "engagement"}
|
FAM_EVENTS = {"MARR": "marriage", "DIV": "divorce", "ENGA": "engagement"}
|
||||||
EVENT_TO_GED = {v: k for k, v in {**INDI_EVENTS, **FAM_EVENTS}.items()}
|
EVENT_TO_GED = {v: k for k, v in {**INDI_EVENTS, **FAM_EVENTS}.items()}
|
||||||
|
|
||||||
|
# GEDCOM NAME TYPE (or _MARNM-derived) -> our Name.name_type vocabulary.
|
||||||
|
NAME_TYPE_MAP = {
|
||||||
|
"birth": "birth", "maiden": "birth", "married": "married",
|
||||||
|
"aka": "alias", "also known as": "alias", "nickname": "nickname",
|
||||||
|
"religious": "religious", "immigrant": "immigration",
|
||||||
|
"immigration": "immigration", "professional": "alias", "other": "alias",
|
||||||
|
}
|
||||||
|
# Our type -> GEDCOM TYPE on export (birth is the default; emit nothing).
|
||||||
|
EXPORT_TYPE_MAP = {
|
||||||
|
"married": "married", "alias": "aka", "nickname": "nickname",
|
||||||
|
"religious": "religious", "immigration": "immigrant",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class GedcomNode:
|
class GedcomNode:
|
||||||
__slots__ = ("level", "tag", "value", "xref", "children")
|
__slots__ = ("level", "tag", "value", "xref", "children")
|
||||||
@@ -108,6 +133,50 @@ def _parse_name(value: str) -> tuple[str | None, str | None]:
|
|||||||
return value.strip() or None, None
|
return value.strip() or None, None
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_marnm(value: str, base_given: str | None) -> tuple[str | None, str | None]:
|
||||||
|
"""A _MARNM value is sometimes a full name ("Jane /Smith/") and sometimes
|
||||||
|
just the married surname ("Smith"). Keep the given name from the base name
|
||||||
|
in the latter case."""
|
||||||
|
v = (value or "").strip()
|
||||||
|
if "/" in v:
|
||||||
|
g, s = _parse_name(v)
|
||||||
|
return (g or base_given), s
|
||||||
|
return base_given, (v or None)
|
||||||
|
|
||||||
|
|
||||||
|
def _extract_names(rec: GedcomNode) -> list[dict]:
|
||||||
|
"""All names for an INDI, typed. Multiple NAME records (each with an optional
|
||||||
|
TYPE) plus any _MARNM (married name) subtags become separate Name rows. The
|
||||||
|
first birth/maiden name is primary."""
|
||||||
|
out: list[dict] = []
|
||||||
|
for nm in rec.all("NAME"):
|
||||||
|
g, s = _parse_name(nm.value)
|
||||||
|
t = (nm.text("TYPE") or "").strip().lower()
|
||||||
|
ntype = NAME_TYPE_MAP.get(t, t or "birth")
|
||||||
|
out.append({"type": ntype, "given": g, "surname": s, "display": nm.value or None,
|
||||||
|
"nickname": nm.text("NICK")})
|
||||||
|
for mar in nm.all("_MARNM"):
|
||||||
|
mg, ms = _parse_marnm(mar.value, g)
|
||||||
|
out.append({"type": "married", "given": mg, "surname": ms,
|
||||||
|
"display": mar.value or None, "nickname": None})
|
||||||
|
for mar in rec.all("_MARNM"):
|
||||||
|
base_g = out[0]["given"] if out else None
|
||||||
|
mg, ms = _parse_marnm(mar.value, base_g)
|
||||||
|
out.append({"type": "married", "given": mg, "surname": ms,
|
||||||
|
"display": mar.value or None, "nickname": None})
|
||||||
|
if not out:
|
||||||
|
return out
|
||||||
|
primary_idx = next((i for i, n in enumerate(out) if n["type"] == "birth"), 0)
|
||||||
|
for i, n in enumerate(out):
|
||||||
|
n["is_primary"] = i == primary_idx
|
||||||
|
n["sort"] = i
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def _norm(given: str | None, surname: str | None) -> str:
|
||||||
|
return re.sub(r"\s+", " ", f"{given or ''} {surname or ''}".strip().lower())
|
||||||
|
|
||||||
|
|
||||||
def _year(date_value: str | None) -> str | None:
|
def _year(date_value: str | None) -> str | None:
|
||||||
if not date_value:
|
if not date_value:
|
||||||
return None
|
return None
|
||||||
@@ -132,18 +201,215 @@ def _sex(value: str | None) -> str | None:
|
|||||||
return {"M": "male", "F": "female"}.get(v, value.strip().lower() or None)
|
return {"M": "male", "F": "female"}.get(v, value.strip().lower() or None)
|
||||||
|
|
||||||
|
|
||||||
|
def _notes_text(rec: GedcomNode) -> str | None:
|
||||||
|
"""Join an INDI's NOTE lines (which pack confidence / findagrave / fs_pid /
|
||||||
|
free text) into the person's notes field."""
|
||||||
|
vals = [n.value.strip() for n in rec.all("NOTE") if n.value and n.value.strip()]
|
||||||
|
return "\n".join(vals) or None
|
||||||
|
|
||||||
|
|
||||||
|
def _person_summary(rec: GedcomNode) -> dict:
|
||||||
|
"""Display name + birth year for an incoming INDI, for duplicate matching."""
|
||||||
|
names = _extract_names(rec)
|
||||||
|
primary = next((n for n in names if n.get("is_primary")), names[0] if names else None)
|
||||||
|
g = primary["given"] if primary else None
|
||||||
|
s = primary["surname"] if primary else None
|
||||||
|
disp = " ".join(x for x in (g, s) if x)
|
||||||
|
if not disp and primary:
|
||||||
|
disp = primary.get("display") or ""
|
||||||
|
birth = rec.first("BIRT")
|
||||||
|
year = _year(birth.text("DATE")) if birth else None
|
||||||
|
return {"names": names, "norm": _norm(g, s), "name": disp or "(no name)", "year": year}
|
||||||
|
|
||||||
|
|
||||||
|
async def _build_existing_index(session: AsyncSession, tree: Tree) -> list[dict]:
|
||||||
|
"""Existing (non-deleted) people with a display name + birth year, for
|
||||||
|
matching incoming records against."""
|
||||||
|
persons = list(
|
||||||
|
(
|
||||||
|
await session.execute(
|
||||||
|
select(Person).where(Person.tree_id == tree.id, Person.deleted_at.is_(None))
|
||||||
|
)
|
||||||
|
).scalars().all()
|
||||||
|
)
|
||||||
|
names = list(
|
||||||
|
(
|
||||||
|
await session.execute(
|
||||||
|
select(Name).where(Name.tree_id == tree.id, Name.deleted_at.is_(None))
|
||||||
|
)
|
||||||
|
).scalars().all()
|
||||||
|
)
|
||||||
|
name_by_person: dict[uuid.UUID, Name] = {}
|
||||||
|
for n in sorted(names, key=lambda n: (not n.is_primary, n.sort_order)):
|
||||||
|
name_by_person.setdefault(n.person_id, n)
|
||||||
|
births = list(
|
||||||
|
(
|
||||||
|
await session.execute(
|
||||||
|
select(Event).where(
|
||||||
|
Event.tree_id == tree.id,
|
||||||
|
Event.deleted_at.is_(None),
|
||||||
|
Event.event_type == "birth",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).scalars().all()
|
||||||
|
)
|
||||||
|
year_by_person: dict[uuid.UUID, str] = {}
|
||||||
|
for e in births:
|
||||||
|
if e.person_id and e.person_id not in year_by_person:
|
||||||
|
y = str(e.date_start.year) if e.date_start else _year(e.date_value)
|
||||||
|
if y:
|
||||||
|
year_by_person[e.person_id] = y
|
||||||
|
|
||||||
|
index: list[dict] = []
|
||||||
|
for p in persons:
|
||||||
|
nm = name_by_person.get(p.id)
|
||||||
|
g = nm.given if nm else None
|
||||||
|
s = nm.surname if nm else None
|
||||||
|
disp = " ".join(x for x in (g, s) if x) or (nm.display_name if nm else None)
|
||||||
|
index.append({
|
||||||
|
"id": p.id,
|
||||||
|
"norm": _norm(g, s),
|
||||||
|
"name": disp or "(no name)",
|
||||||
|
"year": year_by_person.get(p.id),
|
||||||
|
})
|
||||||
|
return index
|
||||||
|
|
||||||
|
|
||||||
|
def _best_match(norm: str, year: str | None, index: list[dict]) -> tuple[dict | None, str | None]:
|
||||||
|
"""Closest existing person by name similarity, rejecting clear birth-year
|
||||||
|
conflicts. Returns (entry, "high"|"medium") or (None, None)."""
|
||||||
|
if not norm:
|
||||||
|
return None, None
|
||||||
|
best: dict | None = None
|
||||||
|
best_r = 0.0
|
||||||
|
for e in index:
|
||||||
|
if not e["norm"]:
|
||||||
|
continue
|
||||||
|
r = SequenceMatcher(None, norm, e["norm"]).ratio()
|
||||||
|
if r < 0.88:
|
||||||
|
continue
|
||||||
|
if year and e["year"] and abs(int(year) - int(e["year"])) > 1:
|
||||||
|
continue # same-ish name but different birth year — not a duplicate
|
||||||
|
if r > best_r:
|
||||||
|
best_r = r
|
||||||
|
best = e
|
||||||
|
if best is None:
|
||||||
|
return None, None
|
||||||
|
year_match = bool(year and best["year"] and abs(int(year) - int(best["year"])) <= 1)
|
||||||
|
both_unknown = not year and not best["year"]
|
||||||
|
score = "high" if best_r >= 0.93 and (year_match or both_unknown) else "medium"
|
||||||
|
return best, score
|
||||||
|
|
||||||
|
|
||||||
|
def _relkey(rtype: RelationshipType, a: uuid.UUID, b: uuid.UUID) -> tuple:
|
||||||
|
if rtype == RelationshipType.parent_child:
|
||||||
|
return ("pc", str(a), str(b))
|
||||||
|
return (rtype.value, *sorted([str(a), str(b)]))
|
||||||
|
|
||||||
|
|
||||||
|
def _count_incoming(roots: list[GedcomNode]) -> tuple[dict, list[str]]:
|
||||||
|
counts: dict[str, int] = defaultdict(int)
|
||||||
|
unmapped: set[str] = set()
|
||||||
|
for rec in roots:
|
||||||
|
if rec.tag == "INDI" and rec.xref:
|
||||||
|
counts["persons"] += 1
|
||||||
|
counts["names"] += len(_extract_names(rec))
|
||||||
|
for child in rec.children:
|
||||||
|
if child.tag in INDI_EVENTS:
|
||||||
|
counts["events"] += 1
|
||||||
|
elif child.tag not in INDI_SKIP_TAGS:
|
||||||
|
unmapped.add(child.tag)
|
||||||
|
elif rec.tag == "FAM":
|
||||||
|
counts["families"] += 1
|
||||||
|
for child in rec.children:
|
||||||
|
if child.tag in FAM_EVENTS:
|
||||||
|
counts["events"] += 1
|
||||||
|
elif rec.tag == "SOUR" and rec.xref:
|
||||||
|
counts["sources"] += 1
|
||||||
|
return dict(counts), sorted(unmapped)
|
||||||
|
|
||||||
|
|
||||||
|
async def preview_gedcom(session: AsyncSession, *, actor: User, tree: Tree, text: str) -> dict:
|
||||||
|
"""Dry run: what would import, and which incoming people look like existing
|
||||||
|
ones. No writes."""
|
||||||
|
if not await privacy.can_edit_tree(session, user_id=actor.id, tree=tree):
|
||||||
|
raise Forbidden("not an editor of this tree")
|
||||||
|
roots = parse_records(text)
|
||||||
|
counts, unmapped = _count_incoming(roots)
|
||||||
|
index = await _build_existing_index(session, tree)
|
||||||
|
|
||||||
|
duplicates: list[dict] = []
|
||||||
|
for rec in roots:
|
||||||
|
if rec.tag != "INDI" or not rec.xref:
|
||||||
|
continue
|
||||||
|
summ = _person_summary(rec)
|
||||||
|
entry, score = _best_match(summ["norm"], summ["year"], index)
|
||||||
|
if entry is None:
|
||||||
|
continue
|
||||||
|
duplicates.append({
|
||||||
|
"xref": rec.xref,
|
||||||
|
"incoming_name": summ["name"],
|
||||||
|
"incoming_birth_year": summ["year"],
|
||||||
|
"existing_person_id": entry["id"],
|
||||||
|
"existing_name": entry["name"],
|
||||||
|
"existing_birth_year": entry["year"],
|
||||||
|
"score": score,
|
||||||
|
})
|
||||||
|
return {"counts": counts, "potential_duplicates": duplicates, "unmapped_tags": unmapped}
|
||||||
|
|
||||||
|
|
||||||
async def import_gedcom(
|
async def import_gedcom(
|
||||||
session: AsyncSession, *, actor: User, tree: Tree, text: str
|
session: AsyncSession,
|
||||||
|
*,
|
||||||
|
actor: User,
|
||||||
|
tree: Tree,
|
||||||
|
text: str,
|
||||||
|
default_action: str = "new",
|
||||||
|
resolutions: dict | None = None,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
|
"""Import records. ``default_action`` (new|skip|merge|overwrite) applies to
|
||||||
|
incoming people that match an existing one; ``resolutions`` overrides it per
|
||||||
|
GEDCOM xref ({xref: {action, target_id}}). 'skip' links families to the
|
||||||
|
existing person but copies nothing; 'merge' also copies the incoming names
|
||||||
|
(as alternates), events and citations onto them; 'overwrite' deletes the
|
||||||
|
existing person and imports the incoming one fresh."""
|
||||||
if not await privacy.can_edit_tree(session, user_id=actor.id, tree=tree):
|
if not await privacy.can_edit_tree(session, user_id=actor.id, tree=tree):
|
||||||
raise Forbidden("not an editor of this tree")
|
raise Forbidden("not an editor of this tree")
|
||||||
|
|
||||||
|
resolutions = resolutions or {}
|
||||||
roots = parse_records(text)
|
roots = parse_records(text)
|
||||||
counts = defaultdict(int)
|
counts: dict[str, int] = defaultdict(int)
|
||||||
unmapped: set[str] = set()
|
unmapped: set[str] = set()
|
||||||
place_cache: dict[str, uuid.UUID] = {}
|
place_cache: dict[str, uuid.UUID] = {}
|
||||||
source_map: dict[str, uuid.UUID] = {}
|
source_map: dict[str, uuid.UUID] = {}
|
||||||
person_map: dict[str, uuid.UUID] = {}
|
person_map: dict[str, uuid.UUID] = {}
|
||||||
|
now = datetime.now(UTC)
|
||||||
|
|
||||||
|
index = await _build_existing_index(session, tree)
|
||||||
|
|
||||||
|
# Pre-load existing relationship keys so a merge doesn't create dup edges.
|
||||||
|
existing_rels = list(
|
||||||
|
(
|
||||||
|
await session.execute(
|
||||||
|
select(Relationship).where(
|
||||||
|
Relationship.tree_id == tree.id, Relationship.deleted_at.is_(None)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).scalars().all()
|
||||||
|
)
|
||||||
|
rel_keys = {_relkey(r.type, r.person_from_id, r.person_to_id) for r in existing_rels}
|
||||||
|
|
||||||
|
def add_relationship(
|
||||||
|
rtype: RelationshipType, a: uuid.UUID, b: uuid.UUID, **kw
|
||||||
|
) -> Relationship | None:
|
||||||
|
key = _relkey(rtype, a, b)
|
||||||
|
if key in rel_keys:
|
||||||
|
return None
|
||||||
|
rel = Relationship(tree_id=tree.id, type=rtype, person_from_id=a, person_to_id=b, **kw)
|
||||||
|
session.add(rel)
|
||||||
|
rel_keys.add(key)
|
||||||
|
counts["relationships"] += 1
|
||||||
|
return rel
|
||||||
|
|
||||||
async def place_id(name: str | None) -> uuid.UUID | None:
|
async def place_id(name: str | None) -> uuid.UUID | None:
|
||||||
if not name:
|
if not name:
|
||||||
@@ -177,59 +443,139 @@ async def import_gedcom(
|
|||||||
sid = source_map.get(s.value.strip())
|
sid = source_map.get(s.value.strip())
|
||||||
if sid is None:
|
if sid is None:
|
||||||
continue
|
continue
|
||||||
session.add(
|
session.add(Citation(tree_id=tree.id, source_id=sid, page=s.text("PAGE"), **target))
|
||||||
Citation(tree_id=tree.id, source_id=sid, page=s.text("PAGE"), **target)
|
|
||||||
)
|
|
||||||
counts["citations"] += 1
|
counts["citations"] += 1
|
||||||
|
|
||||||
# Individuals.
|
def add_names(person_id: uuid.UUID, names: list[dict], *, set_primary: bool) -> None:
|
||||||
for rec in roots:
|
for nd in names:
|
||||||
if rec.tag != "INDI" or not rec.xref:
|
|
||||||
continue
|
|
||||||
person = Person(tree_id=tree.id, gender=_sex(rec.text("SEX")))
|
|
||||||
session.add(person)
|
|
||||||
await session.flush()
|
|
||||||
person_map[rec.xref] = person.id
|
|
||||||
counts["persons"] += 1
|
|
||||||
|
|
||||||
for i, nm in enumerate(rec.all("NAME")):
|
|
||||||
given, surname = _parse_name(nm.value)
|
|
||||||
session.add(
|
session.add(
|
||||||
Name(
|
Name(
|
||||||
tree_id=tree.id,
|
tree_id=tree.id,
|
||||||
person_id=person.id,
|
person_id=person_id,
|
||||||
name_type="birth",
|
name_type=nd["type"],
|
||||||
given=given,
|
given=nd["given"],
|
||||||
surname=surname,
|
surname=nd["surname"],
|
||||||
display_name=nm.value or None,
|
nickname=nd.get("nickname"),
|
||||||
is_primary=(i == 0),
|
display_name=nd.get("display"),
|
||||||
sort_order=i,
|
is_primary=set_primary and nd.get("is_primary", False),
|
||||||
|
sort_order=nd.get("sort", 0),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
counts["names"] += 1
|
counts["names"] += 1
|
||||||
|
|
||||||
await add_citations(rec, person_id=person.id)
|
async def add_events(rec: GedcomNode, person_id: uuid.UUID) -> None:
|
||||||
|
|
||||||
for child in rec.children:
|
for child in rec.children:
|
||||||
if child.tag in INDI_EVENTS:
|
if child.tag in INDI_EVENTS:
|
||||||
dv = child.text("DATE")
|
dv = child.text("DATE")
|
||||||
|
# Attribute-style facts (RELI, OCCU, EDUC) carry their value on
|
||||||
|
# the line itself; store it in detail.
|
||||||
|
detail = child.value.strip() if child.tag in VALUE_EVENTS else None
|
||||||
ev = Event(
|
ev = Event(
|
||||||
tree_id=tree.id,
|
tree_id=tree.id,
|
||||||
person_id=person.id,
|
person_id=person_id,
|
||||||
event_type=INDI_EVENTS[child.tag],
|
event_type=INDI_EVENTS[child.tag],
|
||||||
date_value=dv,
|
date_value=dv,
|
||||||
date_start=_date_start(dv),
|
date_start=_date_start(dv),
|
||||||
place_id=await place_id(child.text("PLAC")),
|
place_id=await place_id(child.text("PLAC")),
|
||||||
|
detail=detail or None,
|
||||||
|
notes=child.text("NOTE"),
|
||||||
)
|
)
|
||||||
session.add(ev)
|
session.add(ev)
|
||||||
await session.flush()
|
await session.flush()
|
||||||
counts["events"] += 1
|
counts["events"] += 1
|
||||||
await add_citations(child, event_id=ev.id)
|
await add_citations(child, event_id=ev.id)
|
||||||
elif child.tag in ("NAME", "SEX", "SOUR", "FAMC", "FAMS", "CHAN", "OBJE", "_UID"):
|
elif child.tag in INDI_SKIP_TAGS:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
unmapped.add(child.tag)
|
unmapped.add(child.tag)
|
||||||
|
|
||||||
|
async def soft_delete_existing(person_id: uuid.UUID) -> None:
|
||||||
|
p = (
|
||||||
|
await session.execute(
|
||||||
|
select(Person).where(Person.id == person_id, Person.deleted_at.is_(None))
|
||||||
|
)
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if p is None:
|
||||||
|
return
|
||||||
|
p.deleted_at = now
|
||||||
|
rels = (
|
||||||
|
await session.execute(
|
||||||
|
select(Relationship).where(
|
||||||
|
Relationship.tree_id == tree.id,
|
||||||
|
Relationship.deleted_at.is_(None),
|
||||||
|
or_(
|
||||||
|
Relationship.person_from_id == person_id,
|
||||||
|
Relationship.person_to_id == person_id,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).scalars().all()
|
||||||
|
for r in rels:
|
||||||
|
r.deleted_at = now
|
||||||
|
await session.execute(
|
||||||
|
update(User).where(User.self_person_id == person_id).values(self_person_id=None)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Precompute the best match per incoming xref (for default-policy resolution).
|
||||||
|
matches: dict[str, dict] = {}
|
||||||
|
for rec in roots:
|
||||||
|
if rec.tag == "INDI" and rec.xref:
|
||||||
|
summ = _person_summary(rec)
|
||||||
|
entry, _score = _best_match(summ["norm"], summ["year"], index)
|
||||||
|
if entry is not None:
|
||||||
|
matches[rec.xref] = entry
|
||||||
|
|
||||||
|
def resolve(xref: str) -> tuple[str, uuid.UUID | None]:
|
||||||
|
ov = resolutions.get(xref)
|
||||||
|
if ov:
|
||||||
|
action = ov.get("action", "new")
|
||||||
|
tid = ov.get("target_id")
|
||||||
|
target = uuid.UUID(tid) if tid else (matches[xref]["id"] if xref in matches else None)
|
||||||
|
if action in ("skip", "merge", "overwrite") and target is None:
|
||||||
|
return "new", None
|
||||||
|
return action, target
|
||||||
|
if default_action != "new" and xref in matches:
|
||||||
|
return default_action, matches[xref]["id"]
|
||||||
|
return "new", None
|
||||||
|
|
||||||
|
# Individuals.
|
||||||
|
for rec in roots:
|
||||||
|
if rec.tag != "INDI" or not rec.xref:
|
||||||
|
continue
|
||||||
|
names = _extract_names(rec)
|
||||||
|
action, target = resolve(rec.xref)
|
||||||
|
|
||||||
|
if action == "skip" and target is not None:
|
||||||
|
person_map[rec.xref] = target
|
||||||
|
counts["skipped"] += 1
|
||||||
|
continue
|
||||||
|
if action == "merge" and target is not None:
|
||||||
|
person_map[rec.xref] = target
|
||||||
|
add_names(target, names, set_primary=False)
|
||||||
|
await add_events(rec, target)
|
||||||
|
await add_citations(rec, person_id=target)
|
||||||
|
note = _notes_text(rec)
|
||||||
|
if note:
|
||||||
|
existing = (
|
||||||
|
await session.execute(select(Person).where(Person.id == target))
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if existing is not None:
|
||||||
|
existing.notes = "\n".join(filter(None, [existing.notes, note]))
|
||||||
|
counts["merged"] += 1
|
||||||
|
continue
|
||||||
|
if action == "overwrite" and target is not None:
|
||||||
|
await soft_delete_existing(target)
|
||||||
|
counts["overwritten"] += 1
|
||||||
|
|
||||||
|
person = Person(tree_id=tree.id, gender=_sex(rec.text("SEX")), notes=_notes_text(rec))
|
||||||
|
session.add(person)
|
||||||
|
await session.flush()
|
||||||
|
person_map[rec.xref] = person.id
|
||||||
|
counts["persons"] += 1
|
||||||
|
add_names(person.id, names, set_primary=True)
|
||||||
|
await add_citations(rec, person_id=person.id)
|
||||||
|
await add_events(rec, person.id)
|
||||||
|
|
||||||
# Families -> partnerships, parent-child edges, marriage events.
|
# Families -> partnerships, parent-child edges, marriage events.
|
||||||
for rec in roots:
|
for rec in roots:
|
||||||
if rec.tag != "FAM":
|
if rec.tag != "FAM":
|
||||||
@@ -238,17 +584,22 @@ async def import_gedcom(
|
|||||||
husb = person_map.get((rec.text("HUSB") or "").strip())
|
husb = person_map.get((rec.text("HUSB") or "").strip())
|
||||||
wife = person_map.get((rec.text("WIFE") or "").strip())
|
wife = person_map.get((rec.text("WIFE") or "").strip())
|
||||||
partnership_id: uuid.UUID | None = None
|
partnership_id: uuid.UUID | None = None
|
||||||
if husb and wife:
|
if husb and wife and husb != wife:
|
||||||
rel = Relationship(
|
rel = add_relationship(RelationshipType.partnership, husb, wife)
|
||||||
tree_id=tree.id,
|
if rel is not None:
|
||||||
type=RelationshipType.partnership,
|
|
||||||
person_from_id=husb,
|
|
||||||
person_to_id=wife,
|
|
||||||
)
|
|
||||||
session.add(rel)
|
|
||||||
await session.flush()
|
await session.flush()
|
||||||
partnership_id = rel.id
|
partnership_id = rel.id
|
||||||
counts["relationships"] += 1
|
if partnership_id is None and husb and wife:
|
||||||
|
# Edge already existed — find it so marriage events can attach.
|
||||||
|
existing = next(
|
||||||
|
(
|
||||||
|
r for r in existing_rels
|
||||||
|
if r.type == RelationshipType.partnership
|
||||||
|
and {r.person_from_id, r.person_to_id} == {husb, wife}
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
partnership_id = existing.id if existing else None
|
||||||
|
|
||||||
for fe in rec.children:
|
for fe in rec.children:
|
||||||
if fe.tag in FAM_EVENTS and partnership_id is not None:
|
if fe.tag in FAM_EVENTS and partnership_id is not None:
|
||||||
@@ -271,16 +622,12 @@ async def import_gedcom(
|
|||||||
continue
|
continue
|
||||||
for parent in (husb, wife):
|
for parent in (husb, wife):
|
||||||
if parent and parent != cp:
|
if parent and parent != cp:
|
||||||
session.add(
|
add_relationship(
|
||||||
Relationship(
|
RelationshipType.parent_child,
|
||||||
tree_id=tree.id,
|
parent,
|
||||||
type=RelationshipType.parent_child,
|
cp,
|
||||||
person_from_id=parent,
|
|
||||||
person_to_id=cp,
|
|
||||||
qualifier=ParentChildQualifier.biological,
|
qualifier=ParentChildQualifier.biological,
|
||||||
)
|
)
|
||||||
)
|
|
||||||
counts["relationships"] += 1
|
|
||||||
|
|
||||||
record_audit(
|
record_audit(
|
||||||
session,
|
session,
|
||||||
@@ -397,6 +744,9 @@ async def export_gedcom(session: AsyncSession, *, viewer_id: uuid.UUID, tree: Tr
|
|||||||
for n in names_by_person.get(p.id, []):
|
for n in names_by_person.get(p.id, []):
|
||||||
display = n.display_name or f"{n.given or ''} /{n.surname or ''}/".strip()
|
display = n.display_name or f"{n.given or ''} /{n.surname or ''}/".strip()
|
||||||
out.append(f"1 NAME {display}")
|
out.append(f"1 NAME {display}")
|
||||||
|
ged_type = EXPORT_TYPE_MAP.get(n.name_type)
|
||||||
|
if ged_type:
|
||||||
|
out.append(f"2 TYPE {ged_type}")
|
||||||
sex = {"male": "M", "female": "F"}.get(p.gender or "")
|
sex = {"male": "M", "female": "F"}.get(p.gender or "")
|
||||||
if sex:
|
if sex:
|
||||||
out.append(f"1 SEX {sex}")
|
out.append(f"1 SEX {sex}")
|
||||||
|
|||||||
@@ -97,6 +97,36 @@ async def get_media(
|
|||||||
return media
|
return media
|
||||||
|
|
||||||
|
|
||||||
|
async def update_media(
|
||||||
|
session: AsyncSession, *, actor: User, tree: Tree, media_id: uuid.UUID, changes: dict
|
||||||
|
) -> Media:
|
||||||
|
if not await privacy.can_edit_tree(session, user_id=actor.id, tree=tree):
|
||||||
|
raise Forbidden("not an editor of this tree")
|
||||||
|
media = (
|
||||||
|
await session.execute(
|
||||||
|
select(Media).where(
|
||||||
|
Media.id == media_id, Media.tree_id == tree.id, Media.deleted_at.is_(None)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if media is None:
|
||||||
|
raise NotFound("media not found")
|
||||||
|
for key in {"title", "person_id", "event_id", "source_id"} & changes.keys():
|
||||||
|
setattr(media, key, changes[key])
|
||||||
|
record_audit(
|
||||||
|
session,
|
||||||
|
action="update",
|
||||||
|
entity_type="Media",
|
||||||
|
entity_id=media.id,
|
||||||
|
tree_id=tree.id,
|
||||||
|
actor_user_id=actor.id,
|
||||||
|
after=changes,
|
||||||
|
)
|
||||||
|
await session.commit()
|
||||||
|
await session.refresh(media)
|
||||||
|
return media
|
||||||
|
|
||||||
|
|
||||||
async def delete_media(
|
async def delete_media(
|
||||||
session: AsyncSession, *, actor: User, tree: Tree, media_id: uuid.UUID
|
session: AsyncSession, *, actor: User, tree: Tree, media_id: uuid.UUID
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
@@ -0,0 +1,208 @@
|
|||||||
|
"""Name service. A Person carries one or more Name rows — a primary (typically
|
||||||
|
the birth/maiden name) plus typed alternates (married, alias, religious, …).
|
||||||
|
Exactly one name is primary at a time; it drives display everywhere. Writes
|
||||||
|
require editor rights; reads go through the tree's view check.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
from datetime import UTC, datetime
|
||||||
|
|
||||||
|
from sqlalchemy import select, update
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
|
from app.models.person import Name, Person
|
||||||
|
from app.models.tree import Tree
|
||||||
|
from app.models.user import User
|
||||||
|
from app.services import privacy
|
||||||
|
from app.services.audit import record_audit
|
||||||
|
from app.services.exceptions import Forbidden, NotFound
|
||||||
|
|
||||||
|
|
||||||
|
async def _get_person(session: AsyncSession, *, tree: Tree, person_id: uuid.UUID) -> Person:
|
||||||
|
person = (
|
||||||
|
await session.execute(
|
||||||
|
select(Person).where(
|
||||||
|
Person.id == person_id, Person.tree_id == tree.id, Person.deleted_at.is_(None)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if person is None:
|
||||||
|
raise NotFound("person not found")
|
||||||
|
return person
|
||||||
|
|
||||||
|
|
||||||
|
async def _clear_primary(
|
||||||
|
session: AsyncSession, *, person_id: uuid.UUID, keep: uuid.UUID | None
|
||||||
|
) -> None:
|
||||||
|
"""Demote every other name so exactly one stays primary."""
|
||||||
|
stmt = (
|
||||||
|
update(Name)
|
||||||
|
.where(Name.person_id == person_id, Name.deleted_at.is_(None), Name.is_primary.is_(True))
|
||||||
|
.values(is_primary=False)
|
||||||
|
)
|
||||||
|
if keep is not None:
|
||||||
|
stmt = stmt.where(Name.id != keep)
|
||||||
|
await session.execute(stmt)
|
||||||
|
|
||||||
|
|
||||||
|
async def list_names(
|
||||||
|
session: AsyncSession, *, viewer_id: uuid.UUID, tree: Tree, person_id: uuid.UUID
|
||||||
|
) -> list[Name]:
|
||||||
|
if not await privacy.can_view_tree(session, user_id=viewer_id, tree=tree):
|
||||||
|
raise Forbidden("not permitted to view this tree")
|
||||||
|
await _get_person(session, tree=tree, person_id=person_id)
|
||||||
|
stmt = (
|
||||||
|
select(Name)
|
||||||
|
.where(Name.person_id == person_id, Name.deleted_at.is_(None))
|
||||||
|
.order_by(Name.is_primary.desc(), Name.sort_order, Name.created_at)
|
||||||
|
)
|
||||||
|
return list((await session.execute(stmt)).scalars().all())
|
||||||
|
|
||||||
|
|
||||||
|
async def create_name(
|
||||||
|
session: AsyncSession,
|
||||||
|
*,
|
||||||
|
actor: User,
|
||||||
|
tree: Tree,
|
||||||
|
person_id: uuid.UUID,
|
||||||
|
name_type: str = "birth",
|
||||||
|
given: str | None = None,
|
||||||
|
surname: str | None = None,
|
||||||
|
prefix: str | None = None,
|
||||||
|
suffix: str | None = None,
|
||||||
|
nickname: str | None = None,
|
||||||
|
is_primary: bool = False,
|
||||||
|
) -> Name:
|
||||||
|
if not await privacy.can_edit_tree(session, user_id=actor.id, tree=tree):
|
||||||
|
raise Forbidden("not an editor of this tree")
|
||||||
|
await _get_person(session, tree=tree, person_id=person_id)
|
||||||
|
|
||||||
|
# First name for a person is always primary; otherwise honor the flag.
|
||||||
|
existing = (
|
||||||
|
await session.execute(
|
||||||
|
select(Name.id).where(Name.person_id == person_id, Name.deleted_at.is_(None))
|
||||||
|
)
|
||||||
|
).first()
|
||||||
|
primary = is_primary or existing is None
|
||||||
|
if primary:
|
||||||
|
await _clear_primary(session, person_id=person_id, keep=None)
|
||||||
|
|
||||||
|
name = Name(
|
||||||
|
tree_id=tree.id,
|
||||||
|
person_id=person_id,
|
||||||
|
name_type=name_type,
|
||||||
|
given=given,
|
||||||
|
surname=surname,
|
||||||
|
prefix=prefix,
|
||||||
|
suffix=suffix,
|
||||||
|
nickname=nickname,
|
||||||
|
is_primary=primary,
|
||||||
|
)
|
||||||
|
session.add(name)
|
||||||
|
await session.flush()
|
||||||
|
record_audit(
|
||||||
|
session,
|
||||||
|
action="create",
|
||||||
|
entity_type="Name",
|
||||||
|
entity_id=name.id,
|
||||||
|
tree_id=tree.id,
|
||||||
|
actor_user_id=actor.id,
|
||||||
|
after={"name_type": name_type, "given": given, "surname": surname},
|
||||||
|
)
|
||||||
|
await session.commit()
|
||||||
|
await session.refresh(name)
|
||||||
|
return name
|
||||||
|
|
||||||
|
|
||||||
|
_NAME_FIELDS = {"name_type", "given", "surname", "prefix", "suffix", "nickname"}
|
||||||
|
|
||||||
|
|
||||||
|
async def update_name(
|
||||||
|
session: AsyncSession,
|
||||||
|
*,
|
||||||
|
actor: User,
|
||||||
|
tree: Tree,
|
||||||
|
person_id: uuid.UUID,
|
||||||
|
name_id: uuid.UUID,
|
||||||
|
changes: dict,
|
||||||
|
) -> Name:
|
||||||
|
if not await privacy.can_edit_tree(session, user_id=actor.id, tree=tree):
|
||||||
|
raise Forbidden("not an editor of this tree")
|
||||||
|
name = (
|
||||||
|
await session.execute(
|
||||||
|
select(Name).where(
|
||||||
|
Name.id == name_id,
|
||||||
|
Name.person_id == person_id,
|
||||||
|
Name.tree_id == tree.id,
|
||||||
|
Name.deleted_at.is_(None),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if name is None:
|
||||||
|
raise NotFound("name not found")
|
||||||
|
|
||||||
|
for key in _NAME_FIELDS & changes.keys():
|
||||||
|
setattr(name, key, changes[key])
|
||||||
|
if changes.get("is_primary") is True:
|
||||||
|
await _clear_primary(session, person_id=person_id, keep=name.id)
|
||||||
|
name.is_primary = True
|
||||||
|
|
||||||
|
record_audit(
|
||||||
|
session,
|
||||||
|
action="update",
|
||||||
|
entity_type="Name",
|
||||||
|
entity_id=name.id,
|
||||||
|
tree_id=tree.id,
|
||||||
|
actor_user_id=actor.id,
|
||||||
|
after=changes,
|
||||||
|
)
|
||||||
|
await session.commit()
|
||||||
|
await session.refresh(name)
|
||||||
|
return name
|
||||||
|
|
||||||
|
|
||||||
|
async def delete_name(
|
||||||
|
session: AsyncSession,
|
||||||
|
*,
|
||||||
|
actor: User,
|
||||||
|
tree: Tree,
|
||||||
|
person_id: uuid.UUID,
|
||||||
|
name_id: uuid.UUID,
|
||||||
|
) -> None:
|
||||||
|
if not await privacy.can_edit_tree(session, user_id=actor.id, tree=tree):
|
||||||
|
raise Forbidden("not an editor of this tree")
|
||||||
|
name = (
|
||||||
|
await session.execute(
|
||||||
|
select(Name).where(
|
||||||
|
Name.id == name_id,
|
||||||
|
Name.person_id == person_id,
|
||||||
|
Name.tree_id == tree.id,
|
||||||
|
Name.deleted_at.is_(None),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if name is None:
|
||||||
|
raise NotFound("name not found")
|
||||||
|
name.deleted_at = datetime.now(UTC)
|
||||||
|
was_primary = name.is_primary
|
||||||
|
name.is_primary = False
|
||||||
|
record_audit(
|
||||||
|
session,
|
||||||
|
action="delete",
|
||||||
|
entity_type="Name",
|
||||||
|
entity_id=name.id,
|
||||||
|
tree_id=tree.id,
|
||||||
|
actor_user_id=actor.id,
|
||||||
|
)
|
||||||
|
# Promote another name to primary so the person never loses their display name.
|
||||||
|
if was_primary:
|
||||||
|
nxt = (
|
||||||
|
await session.execute(
|
||||||
|
select(Name)
|
||||||
|
.where(Name.person_id == person_id, Name.deleted_at.is_(None))
|
||||||
|
.order_by(Name.sort_order, Name.created_at)
|
||||||
|
)
|
||||||
|
).scalars().first()
|
||||||
|
if nxt is not None:
|
||||||
|
nxt.is_primary = True
|
||||||
|
await session.commit()
|
||||||
@@ -6,11 +6,12 @@ person through the privacy engine. Each returned Person gets a transient
|
|||||||
import uuid
|
import uuid
|
||||||
from datetime import UTC, datetime
|
from datetime import UTC, datetime
|
||||||
|
|
||||||
from sqlalchemy import select
|
from sqlalchemy import func, or_, select, update
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
from app.models.enums import PersonPrivacy
|
from app.models.enums import PersonPrivacy, RelationshipType
|
||||||
from app.models.person import Name, Person
|
from app.models.person import Name, Person
|
||||||
|
from app.models.relationship import Relationship
|
||||||
from app.models.tree import Tree
|
from app.models.tree import Tree
|
||||||
from app.models.user import User
|
from app.models.user import User
|
||||||
from app.services import privacy
|
from app.services import privacy
|
||||||
@@ -25,6 +26,14 @@ def _format_name(name: Name) -> str | None:
|
|||||||
return joined or name.display_name
|
return joined or name.display_name
|
||||||
|
|
||||||
|
|
||||||
|
def _redact(person: Person) -> None:
|
||||||
|
"""Minimise a possibly-living person for a non-member view (transient only —
|
||||||
|
never committed)."""
|
||||||
|
person.primary_name = "Living person"
|
||||||
|
person.gender = None
|
||||||
|
person.is_living = True
|
||||||
|
|
||||||
|
|
||||||
async def _attach_primary_name(session: AsyncSession, person: Person) -> None:
|
async def _attach_primary_name(session: AsyncSession, person: Person) -> None:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(Name)
|
select(Name)
|
||||||
@@ -87,6 +96,59 @@ async def create_person(
|
|||||||
return person
|
return person
|
||||||
|
|
||||||
|
|
||||||
|
_PERSON_FIELDS = {"gender", "is_living", "privacy", "notes"}
|
||||||
|
|
||||||
|
|
||||||
|
async def update_person(
|
||||||
|
session: AsyncSession, *, actor: User, tree: Tree, person_id: uuid.UUID, changes: dict
|
||||||
|
) -> Person:
|
||||||
|
if not await privacy.can_edit_tree(session, user_id=actor.id, tree=tree):
|
||||||
|
raise Forbidden("not an editor of this tree")
|
||||||
|
person = (
|
||||||
|
await session.execute(
|
||||||
|
select(Person).where(
|
||||||
|
Person.id == person_id, Person.tree_id == tree.id, Person.deleted_at.is_(None)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if person is None:
|
||||||
|
raise NotFound("person not found")
|
||||||
|
|
||||||
|
for key in _PERSON_FIELDS & changes.keys():
|
||||||
|
setattr(person, key, changes[key])
|
||||||
|
|
||||||
|
if "given" in changes or "surname" in changes:
|
||||||
|
name = (
|
||||||
|
await session.execute(
|
||||||
|
select(Name)
|
||||||
|
.where(Name.person_id == person.id, Name.deleted_at.is_(None))
|
||||||
|
.order_by(Name.is_primary.desc(), Name.sort_order)
|
||||||
|
)
|
||||||
|
).scalars().first()
|
||||||
|
if name is None:
|
||||||
|
name = Name(tree_id=tree.id, person_id=person.id, name_type="birth", is_primary=True)
|
||||||
|
session.add(name)
|
||||||
|
if "given" in changes:
|
||||||
|
name.given = changes["given"]
|
||||||
|
if "surname" in changes:
|
||||||
|
name.surname = changes["surname"]
|
||||||
|
name.display_name = None # rebuild display from parts
|
||||||
|
|
||||||
|
record_audit(
|
||||||
|
session,
|
||||||
|
action="update",
|
||||||
|
entity_type="Person",
|
||||||
|
entity_id=person.id,
|
||||||
|
tree_id=tree.id,
|
||||||
|
actor_user_id=actor.id,
|
||||||
|
after=changes,
|
||||||
|
)
|
||||||
|
await session.commit()
|
||||||
|
await session.refresh(person)
|
||||||
|
await _attach_primary_name(session, person)
|
||||||
|
return person
|
||||||
|
|
||||||
|
|
||||||
async def get_person(
|
async def get_person(
|
||||||
session: AsyncSession, *, viewer_id: uuid.UUID, tree: Tree, person_id: uuid.UUID
|
session: AsyncSession, *, viewer_id: uuid.UUID, tree: Tree, person_id: uuid.UUID
|
||||||
) -> Person:
|
) -> Person:
|
||||||
@@ -104,18 +166,77 @@ async def get_person(
|
|||||||
if person is None:
|
if person is None:
|
||||||
raise NotFound("person not found")
|
raise NotFound("person not found")
|
||||||
# Run the single person through the privacy engine (redaction lands Phase 2).
|
# Run the single person through the privacy engine (redaction lands Phase 2).
|
||||||
if (
|
vis = await privacy.person_visibility(
|
||||||
await privacy.person_visibility(session, user_id=viewer_id, tree=tree, person=person)
|
session, user_id=viewer_id, tree=tree, person=person
|
||||||
== Visibility.hidden
|
)
|
||||||
):
|
if vis == Visibility.hidden:
|
||||||
raise NotFound("person not found")
|
raise NotFound("person not found")
|
||||||
|
if vis == Visibility.redacted:
|
||||||
|
_redact(person)
|
||||||
|
else:
|
||||||
await _attach_primary_name(session, person)
|
await _attach_primary_name(session, person)
|
||||||
return person
|
return person
|
||||||
|
|
||||||
|
|
||||||
async def delete_person(
|
async def _children_of(
|
||||||
session: AsyncSession, *, actor: User, tree: Tree, person_id: uuid.UUID
|
session: AsyncSession, *, tree_id: uuid.UUID, parent_id: uuid.UUID
|
||||||
|
) -> list[uuid.UUID]:
|
||||||
|
rows = (
|
||||||
|
await session.execute(
|
||||||
|
select(Relationship.person_to_id).where(
|
||||||
|
Relationship.tree_id == tree_id,
|
||||||
|
Relationship.deleted_at.is_(None),
|
||||||
|
Relationship.type == RelationshipType.parent_child,
|
||||||
|
Relationship.person_from_id == parent_id,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).scalars().all()
|
||||||
|
return list(rows)
|
||||||
|
|
||||||
|
|
||||||
|
async def _soft_delete_one(
|
||||||
|
session: AsyncSession, *, actor: User, tree: Tree, person: Person, now: datetime
|
||||||
) -> None:
|
) -> None:
|
||||||
|
"""Soft-delete a single person and the relationships touching them, so no
|
||||||
|
dangling edges are left to break the tree view."""
|
||||||
|
person.deleted_at = now
|
||||||
|
rels = (
|
||||||
|
await session.execute(
|
||||||
|
select(Relationship).where(
|
||||||
|
Relationship.tree_id == tree.id,
|
||||||
|
Relationship.deleted_at.is_(None),
|
||||||
|
or_(
|
||||||
|
Relationship.person_from_id == person.id,
|
||||||
|
Relationship.person_to_id == person.id,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).scalars().all()
|
||||||
|
for rel in rels:
|
||||||
|
rel.deleted_at = now
|
||||||
|
record_audit(
|
||||||
|
session,
|
||||||
|
action="delete",
|
||||||
|
entity_type="Person",
|
||||||
|
entity_id=person.id,
|
||||||
|
tree_id=tree.id,
|
||||||
|
actor_user_id=actor.id,
|
||||||
|
after={"cascaded_relationships": len(rels)},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def delete_person(
|
||||||
|
session: AsyncSession,
|
||||||
|
*,
|
||||||
|
actor: User,
|
||||||
|
tree: Tree,
|
||||||
|
person_id: uuid.UUID,
|
||||||
|
cascade: bool = False,
|
||||||
|
) -> int:
|
||||||
|
"""Soft-delete a person. Always removes the relationships that touch them
|
||||||
|
(preventing dangling edges). With ``cascade=True``, recursively deletes
|
||||||
|
their descendants too — handy for pruning a bad GEDCOM import. Returns the
|
||||||
|
number of persons deleted."""
|
||||||
if not await privacy.can_edit_tree(session, user_id=actor.id, tree=tree):
|
if not await privacy.can_edit_tree(session, user_id=actor.id, tree=tree):
|
||||||
raise Forbidden("not an editor of this tree")
|
raise Forbidden("not an editor of this tree")
|
||||||
person = (
|
person = (
|
||||||
@@ -127,16 +248,49 @@ async def delete_person(
|
|||||||
).scalar_one_or_none()
|
).scalar_one_or_none()
|
||||||
if person is None:
|
if person is None:
|
||||||
raise NotFound("person not found")
|
raise NotFound("person not found")
|
||||||
person.deleted_at = datetime.now(UTC)
|
|
||||||
record_audit(
|
now = datetime.now(UTC)
|
||||||
session,
|
|
||||||
action="delete",
|
# Gather the set of persons to delete. For cascade, walk descendants
|
||||||
entity_type="Person",
|
# breadth-first, guarding against cycles.
|
||||||
entity_id=person.id,
|
to_delete: list[Person] = [person]
|
||||||
tree_id=tree.id,
|
if cascade:
|
||||||
actor_user_id=actor.id,
|
seen = {person.id}
|
||||||
|
frontier = [person.id]
|
||||||
|
while frontier:
|
||||||
|
nxt: list[uuid.UUID] = []
|
||||||
|
for pid in frontier:
|
||||||
|
for child_id in await _children_of(session, tree_id=tree.id, parent_id=pid):
|
||||||
|
if child_id not in seen:
|
||||||
|
seen.add(child_id)
|
||||||
|
nxt.append(child_id)
|
||||||
|
frontier = nxt
|
||||||
|
extra_ids = [pid for pid in seen if pid != person.id]
|
||||||
|
if extra_ids:
|
||||||
|
extra = (
|
||||||
|
await session.execute(
|
||||||
|
select(Person).where(
|
||||||
|
Person.id.in_(extra_ids),
|
||||||
|
Person.tree_id == tree.id,
|
||||||
|
Person.deleted_at.is_(None),
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
).scalars().all()
|
||||||
|
to_delete.extend(extra)
|
||||||
|
|
||||||
|
for p in to_delete:
|
||||||
|
await _soft_delete_one(session, actor=actor, tree=tree, person=p, now=now)
|
||||||
|
|
||||||
|
# Soft delete leaves the row in place, so the DB-level "ON DELETE SET NULL"
|
||||||
|
# never fires — clear any account's self-person link to a deleted person.
|
||||||
|
await session.execute(
|
||||||
|
update(User)
|
||||||
|
.where(User.self_person_id.in_([p.id for p in to_delete]))
|
||||||
|
.values(self_person_id=None)
|
||||||
|
)
|
||||||
|
|
||||||
await session.commit()
|
await session.commit()
|
||||||
|
return len(to_delete)
|
||||||
|
|
||||||
|
|
||||||
async def restore_person(
|
async def restore_person(
|
||||||
@@ -199,13 +353,66 @@ async def list_persons(
|
|||||||
|
|
||||||
visible: list[Person] = []
|
visible: list[Person] = []
|
||||||
for person in persons:
|
for person in persons:
|
||||||
if (
|
vis = await privacy.person_visibility(
|
||||||
await privacy.person_visibility(
|
|
||||||
session, user_id=viewer_id, tree=tree, person=person
|
session, user_id=viewer_id, tree=tree, person=person
|
||||||
)
|
)
|
||||||
== Visibility.hidden
|
if vis == Visibility.hidden:
|
||||||
):
|
|
||||||
continue
|
continue
|
||||||
|
if vis == Visibility.redacted:
|
||||||
|
_redact(person)
|
||||||
|
else:
|
||||||
await _attach_primary_name(session, person)
|
await _attach_primary_name(session, person)
|
||||||
visible.append(person)
|
visible.append(person)
|
||||||
return visible
|
return visible
|
||||||
|
|
||||||
|
|
||||||
|
async def search_persons(
|
||||||
|
session: AsyncSession, *, viewer_id: uuid.UUID, tree: Tree, query: str, limit: int = 50
|
||||||
|
) -> list[Person]:
|
||||||
|
if not await privacy.can_view_tree(session, user_id=viewer_id, tree=tree):
|
||||||
|
raise Forbidden("not permitted to view this tree")
|
||||||
|
q = query.strip()
|
||||||
|
if not q:
|
||||||
|
return []
|
||||||
|
like = f"%{q}%"
|
||||||
|
score = func.greatest(
|
||||||
|
func.similarity(func.coalesce(Name.given, ""), q),
|
||||||
|
func.similarity(func.coalesce(Name.surname, ""), q),
|
||||||
|
)
|
||||||
|
sub = (
|
||||||
|
select(Name.person_id.label("pid"), func.max(score).label("score"))
|
||||||
|
.where(
|
||||||
|
Name.tree_id == tree.id,
|
||||||
|
Name.deleted_at.is_(None),
|
||||||
|
or_(
|
||||||
|
Name.given.op("%")(q),
|
||||||
|
Name.surname.op("%")(q),
|
||||||
|
Name.given.ilike(like),
|
||||||
|
Name.surname.ilike(like),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.group_by(Name.person_id)
|
||||||
|
.order_by(func.max(score).desc())
|
||||||
|
.limit(limit)
|
||||||
|
.subquery()
|
||||||
|
)
|
||||||
|
stmt = (
|
||||||
|
select(Person)
|
||||||
|
.join(sub, sub.c.pid == Person.id)
|
||||||
|
.where(Person.tree_id == tree.id, Person.deleted_at.is_(None))
|
||||||
|
.order_by(sub.c.score.desc())
|
||||||
|
)
|
||||||
|
persons = list((await session.execute(stmt)).scalars().all())
|
||||||
|
out: list[Person] = []
|
||||||
|
for person in persons:
|
||||||
|
vis = await privacy.person_visibility(
|
||||||
|
session, user_id=viewer_id, tree=tree, person=person
|
||||||
|
)
|
||||||
|
if vis == Visibility.hidden:
|
||||||
|
continue
|
||||||
|
if vis == Visibility.redacted:
|
||||||
|
_redact(person)
|
||||||
|
else:
|
||||||
|
await _attach_primary_name(session, person)
|
||||||
|
out.append(person)
|
||||||
|
return out
|
||||||
|
|||||||
@@ -8,14 +8,20 @@ tree's visibility, the per-person override, and (Phase 2) living-person status.
|
|||||||
|
|
||||||
import enum
|
import enum
|
||||||
import uuid
|
import uuid
|
||||||
|
from datetime import UTC, datetime
|
||||||
|
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
from app.models.enums import MembershipRole, PersonPrivacy, TreeVisibility
|
from app.models.enums import MembershipRole, PersonPrivacy, TreeVisibility
|
||||||
|
from app.models.event import Event
|
||||||
from app.models.person import Person
|
from app.models.person import Person
|
||||||
from app.models.tree import Tree, TreeMembership
|
from app.models.tree import Tree, TreeMembership
|
||||||
|
|
||||||
|
# A person with no death fact whose birth is within this window (or unknown) is
|
||||||
|
# treated as possibly living and redacted from non-members (ARCHITECTURE §6).
|
||||||
|
LIVING_RECENCY_YEARS = 100
|
||||||
|
|
||||||
|
|
||||||
class Visibility(enum.StrEnum):
|
class Visibility(enum.StrEnum):
|
||||||
full = "full"
|
full = "full"
|
||||||
@@ -48,15 +54,56 @@ async def can_edit_tree(session: AsyncSession, *, user_id: uuid.UUID | None, tre
|
|||||||
return role in (MembershipRole.owner, MembershipRole.editor)
|
return role in (MembershipRole.owner, MembershipRole.editor)
|
||||||
|
|
||||||
|
|
||||||
|
async def is_possibly_living(session: AsyncSession, person: Person) -> bool:
|
||||||
|
"""True if the person should be treated as living: explicit flag, or (absent
|
||||||
|
a death fact) a birth within the recency window or an unknown birth."""
|
||||||
|
if person.is_living is True:
|
||||||
|
return True
|
||||||
|
if person.is_living is False:
|
||||||
|
return False
|
||||||
|
death = (
|
||||||
|
await session.execute(
|
||||||
|
select(Event.id)
|
||||||
|
.where(
|
||||||
|
Event.person_id == person.id,
|
||||||
|
Event.event_type == "death",
|
||||||
|
Event.deleted_at.is_(None),
|
||||||
|
)
|
||||||
|
.limit(1)
|
||||||
|
)
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if death is not None:
|
||||||
|
return False
|
||||||
|
birth = (
|
||||||
|
await session.execute(
|
||||||
|
select(Event.date_start)
|
||||||
|
.where(
|
||||||
|
Event.person_id == person.id,
|
||||||
|
Event.event_type == "birth",
|
||||||
|
Event.date_start.is_not(None),
|
||||||
|
Event.deleted_at.is_(None),
|
||||||
|
)
|
||||||
|
.order_by(Event.date_start)
|
||||||
|
.limit(1)
|
||||||
|
)
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if birth is None:
|
||||||
|
return True # unknown birth → treat as possibly living
|
||||||
|
return (datetime.now(UTC).year - birth.year) < LIVING_RECENCY_YEARS
|
||||||
|
|
||||||
|
|
||||||
async def person_visibility(
|
async def person_visibility(
|
||||||
session: AsyncSession, *, user_id: uuid.UUID | None, tree: Tree, person: Person
|
session: AsyncSession, *, user_id: uuid.UUID | None, tree: Tree, person: Person
|
||||||
) -> Visibility:
|
) -> Visibility:
|
||||||
if not await can_view_tree(session, user_id=user_id, tree=tree):
|
if not await can_view_tree(session, user_id=user_id, tree=tree):
|
||||||
return Visibility.hidden
|
return Visibility.hidden
|
||||||
if await get_membership_role(session, user_id, tree.id) is not None:
|
if await get_membership_role(session, user_id, tree.id) is not None:
|
||||||
return Visibility.full
|
return Visibility.full # members see everyone in their tree
|
||||||
# Non-member viewing a public/unlisted tree:
|
# Non-member viewing a public/unlisted tree:
|
||||||
if person.privacy == PersonPrivacy.private:
|
if person.privacy == PersonPrivacy.private:
|
||||||
return Visibility.hidden
|
return Visibility.hidden
|
||||||
# TODO(Phase 2): redact living people for non-members (ARCHITECTURE §6).
|
if person.privacy == PersonPrivacy.public:
|
||||||
|
return Visibility.full # explicit per-person opt-in
|
||||||
|
if await is_possibly_living(session, person):
|
||||||
|
return Visibility.redacted # living people are protected by default
|
||||||
return Visibility.full
|
return Visibility.full
|
||||||
|
|||||||
@@ -107,6 +107,44 @@ async def list_relationships_for_person(
|
|||||||
return list((await session.execute(stmt)).scalars().all())
|
return list((await session.execute(stmt)).scalars().all())
|
||||||
|
|
||||||
|
|
||||||
|
async def update_relationship(
|
||||||
|
session: AsyncSession, *, actor: User, tree: Tree, relationship_id: uuid.UUID, changes: dict
|
||||||
|
) -> Relationship:
|
||||||
|
if not await privacy.can_edit_tree(session, user_id=actor.id, tree=tree):
|
||||||
|
raise Forbidden("not an editor of this tree")
|
||||||
|
relationship = (
|
||||||
|
await session.execute(
|
||||||
|
select(Relationship).where(
|
||||||
|
Relationship.id == relationship_id,
|
||||||
|
Relationship.tree_id == tree.id,
|
||||||
|
Relationship.deleted_at.is_(None),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if relationship is None:
|
||||||
|
raise NotFound("relationship not found")
|
||||||
|
if (
|
||||||
|
"qualifier" in changes
|
||||||
|
and changes["qualifier"] is not None
|
||||||
|
and relationship.type is not RelationshipType.parent_child
|
||||||
|
):
|
||||||
|
raise Conflict("qualifier only applies to parent_child relationships")
|
||||||
|
for key in {"qualifier", "notes"} & changes.keys():
|
||||||
|
setattr(relationship, key, changes[key])
|
||||||
|
record_audit(
|
||||||
|
session,
|
||||||
|
action="update",
|
||||||
|
entity_type="Relationship",
|
||||||
|
entity_id=relationship.id,
|
||||||
|
tree_id=tree.id,
|
||||||
|
actor_user_id=actor.id,
|
||||||
|
after=changes,
|
||||||
|
)
|
||||||
|
await session.commit()
|
||||||
|
await session.refresh(relationship)
|
||||||
|
return relationship
|
||||||
|
|
||||||
|
|
||||||
async def delete_relationship(
|
async def delete_relationship(
|
||||||
session: AsyncSession, *, actor: User, tree: Tree, relationship_id: uuid.UUID
|
session: AsyncSession, *, actor: User, tree: Tree, relationship_id: uuid.UUID
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
@@ -86,6 +86,42 @@ async def get_source(
|
|||||||
return source
|
return source
|
||||||
|
|
||||||
|
|
||||||
|
_SOURCE_FIELDS = {
|
||||||
|
"title", "author", "source_type", "repository", "url", "citation_text",
|
||||||
|
"publication_info", "quality_note",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def update_source(
|
||||||
|
session: AsyncSession, *, actor: User, tree: Tree, source_id: uuid.UUID, changes: dict
|
||||||
|
) -> Source:
|
||||||
|
if not await privacy.can_edit_tree(session, user_id=actor.id, tree=tree):
|
||||||
|
raise Forbidden("not an editor of this tree")
|
||||||
|
source = (
|
||||||
|
await session.execute(
|
||||||
|
select(Source).where(
|
||||||
|
Source.id == source_id, Source.tree_id == tree.id, Source.deleted_at.is_(None)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if source is None:
|
||||||
|
raise NotFound("source not found")
|
||||||
|
for key in _SOURCE_FIELDS & changes.keys():
|
||||||
|
setattr(source, key, changes[key])
|
||||||
|
record_audit(
|
||||||
|
session,
|
||||||
|
action="update",
|
||||||
|
entity_type="Source",
|
||||||
|
entity_id=source.id,
|
||||||
|
tree_id=tree.id,
|
||||||
|
actor_user_id=actor.id,
|
||||||
|
after=changes,
|
||||||
|
)
|
||||||
|
await session.commit()
|
||||||
|
await session.refresh(source)
|
||||||
|
return source
|
||||||
|
|
||||||
|
|
||||||
async def delete_source(
|
async def delete_source(
|
||||||
session: AsyncSession, *, actor: User, tree: Tree, source_id: uuid.UUID
|
session: AsyncSession, *, actor: User, tree: Tree, source_id: uuid.UUID
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
@@ -62,6 +62,30 @@ async def get_tree(session: AsyncSession, *, viewer_id: uuid.UUID, tree_id: uuid
|
|||||||
return tree
|
return tree
|
||||||
|
|
||||||
|
|
||||||
|
async def update_tree(
|
||||||
|
session: AsyncSession, *, actor: User, tree_id: uuid.UUID, changes: dict
|
||||||
|
) -> Tree:
|
||||||
|
tree = await BaseRepository(session, Tree).get(tree_id)
|
||||||
|
if tree is None:
|
||||||
|
raise NotFound("tree not found")
|
||||||
|
if not await privacy.can_edit_tree(session, user_id=actor.id, tree=tree):
|
||||||
|
raise Forbidden("not an editor of this tree")
|
||||||
|
for key in {"name", "description", "visibility"} & changes.keys():
|
||||||
|
setattr(tree, key, changes[key])
|
||||||
|
record_audit(
|
||||||
|
session,
|
||||||
|
action="update",
|
||||||
|
entity_type="Tree",
|
||||||
|
entity_id=tree.id,
|
||||||
|
tree_id=tree.id,
|
||||||
|
actor_user_id=actor.id,
|
||||||
|
after=changes,
|
||||||
|
)
|
||||||
|
await session.commit()
|
||||||
|
await session.refresh(tree)
|
||||||
|
return tree
|
||||||
|
|
||||||
|
|
||||||
async def _owned_tree(session: AsyncSession, *, actor: User, tree_id: uuid.UUID) -> Tree:
|
async def _owned_tree(session: AsyncSession, *, actor: User, tree_id: uuid.UUID) -> Tree:
|
||||||
"""Load a tree (including soft-deleted) and require the actor be its owner."""
|
"""Load a tree (including soft-deleted) and require the actor be its owner."""
|
||||||
tree = await BaseRepository(session, Tree).get(tree_id, include_deleted=True)
|
tree = await BaseRepository(session, Tree).get(tree_id, include_deleted=True)
|
||||||
|
|||||||
@@ -8,10 +8,13 @@ import uuid
|
|||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
|
from app.models.person import Person
|
||||||
|
from app.models.tree import Tree
|
||||||
from app.models.user import User
|
from app.models.user import User
|
||||||
from app.repositories.base import BaseRepository
|
from app.repositories.base import BaseRepository
|
||||||
|
from app.services import privacy
|
||||||
from app.services.audit import record_audit
|
from app.services.audit import record_audit
|
||||||
from app.services.exceptions import Conflict
|
from app.services.exceptions import Conflict, Forbidden, NotFound
|
||||||
|
|
||||||
|
|
||||||
async def create_user(
|
async def create_user(
|
||||||
@@ -42,3 +45,39 @@ async def create_user(
|
|||||||
|
|
||||||
async def get_user(session: AsyncSession, user_id: uuid.UUID) -> User | None:
|
async def get_user(session: AsyncSession, user_id: uuid.UUID) -> User | None:
|
||||||
return await BaseRepository(session, User).get(user_id)
|
return await BaseRepository(session, User).get(user_id)
|
||||||
|
|
||||||
|
|
||||||
|
async def set_self_person(
|
||||||
|
session: AsyncSession, *, user: User, person_id: uuid.UUID | None
|
||||||
|
) -> User:
|
||||||
|
"""Point a user's account at the Person record that *is* them ("home
|
||||||
|
person"), or clear it with ``None``. The person must live in a tree the
|
||||||
|
user can view."""
|
||||||
|
if person_id is not None:
|
||||||
|
person = (
|
||||||
|
await session.execute(
|
||||||
|
select(Person).where(Person.id == person_id, Person.deleted_at.is_(None))
|
||||||
|
)
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if person is None:
|
||||||
|
raise NotFound("person not found")
|
||||||
|
tree = (
|
||||||
|
await session.execute(select(Tree).where(Tree.id == person.tree_id))
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if tree is None or not await privacy.can_view_tree(
|
||||||
|
session, user_id=user.id, tree=tree
|
||||||
|
):
|
||||||
|
raise Forbidden("not permitted to link this person")
|
||||||
|
|
||||||
|
user.self_person_id = person_id
|
||||||
|
record_audit(
|
||||||
|
session,
|
||||||
|
action="update",
|
||||||
|
entity_type="User",
|
||||||
|
entity_id=user.id,
|
||||||
|
actor_user_id=user.id,
|
||||||
|
after={"self_person_id": str(person_id) if person_id else None},
|
||||||
|
)
|
||||||
|
await session.commit()
|
||||||
|
await session.refresh(user)
|
||||||
|
return user
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
"""pg_trgm extension + trigram name indexes for fuzzy search
|
||||||
|
|
||||||
|
Revision ID: 9a2b1c7d4e10
|
||||||
|
Revises: 7fc7024ef432
|
||||||
|
Create Date: 2026-06-07
|
||||||
|
|
||||||
|
"""
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
revision: str = "9a2b1c7d4e10"
|
||||||
|
down_revision: str | None = "7fc7024ef432"
|
||||||
|
branch_labels: str | Sequence[str] | None = None
|
||||||
|
depends_on: str | Sequence[str] | None = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
op.execute("CREATE EXTENSION IF NOT EXISTS pg_trgm")
|
||||||
|
op.execute(
|
||||||
|
"CREATE INDEX IF NOT EXISTS ix_names_given_trgm "
|
||||||
|
"ON names USING gin (given gin_trgm_ops)"
|
||||||
|
)
|
||||||
|
op.execute(
|
||||||
|
"CREATE INDEX IF NOT EXISTS ix_names_surname_trgm "
|
||||||
|
"ON names USING gin (surname gin_trgm_ops)"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
op.execute("DROP INDEX IF EXISTS ix_names_surname_trgm")
|
||||||
|
op.execute("DROP INDEX IF EXISTS ix_names_given_trgm")
|
||||||
|
# Leave the pg_trgm extension in place; other features may rely on it.
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
"""user.self_person_id ("home person" link)
|
||||||
|
|
||||||
|
Revision ID: b3d5f8a1c920
|
||||||
|
Revises: 9a2b1c7d4e10
|
||||||
|
Create Date: 2026-06-07
|
||||||
|
|
||||||
|
"""
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
revision: str = "b3d5f8a1c920"
|
||||||
|
down_revision: str | None = "9a2b1c7d4e10"
|
||||||
|
branch_labels: str | Sequence[str] | None = None
|
||||||
|
depends_on: str | Sequence[str] | None = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
op.add_column(
|
||||||
|
"users",
|
||||||
|
sa.Column("self_person_id", sa.Uuid(), nullable=True),
|
||||||
|
)
|
||||||
|
op.create_foreign_key(
|
||||||
|
"fk_users_self_person_id",
|
||||||
|
"users",
|
||||||
|
"persons",
|
||||||
|
["self_person_id"],
|
||||||
|
["id"],
|
||||||
|
ondelete="SET NULL",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
op.drop_constraint("fk_users_self_person_id", "users", type_="foreignkey")
|
||||||
|
op.drop_column("users", "self_person_id")
|
||||||
@@ -11,6 +11,7 @@ import os
|
|||||||
import pytest
|
import pytest
|
||||||
import pytest_asyncio
|
import pytest_asyncio
|
||||||
from httpx import ASGITransport, AsyncClient
|
from httpx import ASGITransport, AsyncClient
|
||||||
|
from sqlalchemy import text
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
||||||
|
|
||||||
import app.models # noqa: F401 — register all models on Base.metadata
|
import app.models # noqa: F401 — register all models on Base.metadata
|
||||||
@@ -72,6 +73,7 @@ async def client():
|
|||||||
|
|
||||||
engine = create_async_engine(TEST_DATABASE_URL)
|
engine = create_async_engine(TEST_DATABASE_URL)
|
||||||
async with engine.begin() as conn:
|
async with engine.begin() as conn:
|
||||||
|
await conn.execute(text("CREATE EXTENSION IF NOT EXISTS pg_trgm"))
|
||||||
await conn.run_sync(Base.metadata.drop_all)
|
await conn.run_sync(Base.metadata.drop_all)
|
||||||
await conn.run_sync(Base.metadata.create_all)
|
await conn.run_sync(Base.metadata.create_all)
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,25 @@ async def test_public_tree_viewable_but_not_editable_by_non_member(client):
|
|||||||
assert resp.status_code == 403
|
assert resp.status_code == 403
|
||||||
|
|
||||||
|
|
||||||
|
async def test_person_update(client):
|
||||||
|
token = await register(client, "edit@example.com")
|
||||||
|
h = auth(token)
|
||||||
|
tid = (await client.post("/api/v1/trees", json={"name": "T"}, headers=h)).json()["id"]
|
||||||
|
pid = (
|
||||||
|
await client.post(
|
||||||
|
f"/api/v1/trees/{tid}/persons", json={"given": "Jon", "surname": "Smith"}, headers=h
|
||||||
|
)
|
||||||
|
).json()["id"]
|
||||||
|
resp = await client.patch(
|
||||||
|
f"/api/v1/trees/{tid}/persons/{pid}",
|
||||||
|
json={"given": "John", "gender": "male"},
|
||||||
|
headers=auth(token),
|
||||||
|
)
|
||||||
|
assert resp.status_code == 200, resp.text
|
||||||
|
assert resp.json()["primary_name"] == "John Smith"
|
||||||
|
assert resp.json()["gender"] == "male"
|
||||||
|
|
||||||
|
|
||||||
async def test_auth_required_without_token(client):
|
async def test_auth_required_without_token(client):
|
||||||
resp = await client.get("/api/v1/trees")
|
resp = await client.get("/api/v1/trees")
|
||||||
assert resp.status_code == 401
|
assert resp.status_code == 401
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
"""Update (the U in CRUD) for the remaining entities — rule #8."""
|
||||||
|
|
||||||
|
from tests.conftest import auth, register
|
||||||
|
|
||||||
|
|
||||||
|
async def _setup(client, email):
|
||||||
|
h = auth(await register(client, email))
|
||||||
|
tid = (await client.post("/api/v1/trees", json={"name": "T"}, headers=h)).json()["id"]
|
||||||
|
return h, tid
|
||||||
|
|
||||||
|
|
||||||
|
async def test_tree_update(client):
|
||||||
|
h, tid = await _setup(client, "u-tree@example.com")
|
||||||
|
r = await client.patch(
|
||||||
|
f"/api/v1/trees/{tid}", json={"name": "Renamed", "visibility": "unlisted"}, headers=h
|
||||||
|
)
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert r.json()["name"] == "Renamed" and r.json()["visibility"] == "unlisted"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_source_update(client):
|
||||||
|
h, tid = await _setup(client, "u-src@example.com")
|
||||||
|
sid = (
|
||||||
|
await client.post(f"/api/v1/trees/{tid}/sources", json={"title": "Old"}, headers=h)
|
||||||
|
).json()["id"]
|
||||||
|
r = await client.patch(
|
||||||
|
f"/api/v1/trees/{tid}/sources/{sid}",
|
||||||
|
json={"title": "New", "repository": "NARA"},
|
||||||
|
headers=h,
|
||||||
|
)
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert r.json()["title"] == "New" and r.json()["repository"] == "NARA"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_media_update(client):
|
||||||
|
h, tid = await _setup(client, "u-media@example.com")
|
||||||
|
mid = (
|
||||||
|
await client.post(
|
||||||
|
f"/api/v1/trees/{tid}/media",
|
||||||
|
files={"file": ("a.txt", b"x", "text/plain")},
|
||||||
|
data={"title": "old"},
|
||||||
|
headers=h,
|
||||||
|
)
|
||||||
|
).json()["id"]
|
||||||
|
r = await client.patch(f"/api/v1/trees/{tid}/media/{mid}", json={"title": "new"}, headers=h)
|
||||||
|
assert r.status_code == 200 and r.json()["title"] == "new"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_relationship_and_citation_update(client):
|
||||||
|
h, tid = await _setup(client, "u-rc@example.com")
|
||||||
|
|
||||||
|
async def mk(path, body):
|
||||||
|
return (await client.post(f"/api/v1/trees/{tid}/{path}", json=body, headers=h)).json()["id"]
|
||||||
|
|
||||||
|
p1 = await mk("persons", {"given": "A"})
|
||||||
|
p2 = await mk("persons", {"given": "B"})
|
||||||
|
rid = await mk(
|
||||||
|
"relationships",
|
||||||
|
{
|
||||||
|
"type": "parent_child",
|
||||||
|
"person_from_id": p1,
|
||||||
|
"person_to_id": p2,
|
||||||
|
"qualifier": "biological",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
r = await client.patch(
|
||||||
|
f"/api/v1/trees/{tid}/relationships/{rid}", json={"qualifier": "adoptive"}, headers=h
|
||||||
|
)
|
||||||
|
assert r.status_code == 200 and r.json()["qualifier"] == "adoptive"
|
||||||
|
|
||||||
|
src = await mk("sources", {"title": "S"})
|
||||||
|
cid = await mk("citations", {"source_id": src, "person_id": p1})
|
||||||
|
r2 = await client.patch(
|
||||||
|
f"/api/v1/trees/{tid}/citations/{cid}",
|
||||||
|
json={"page": "p.7", "confidence": "high"},
|
||||||
|
headers=h,
|
||||||
|
)
|
||||||
|
assert r2.status_code == 200
|
||||||
|
assert r2.json()["page"] == "p.7" and r2.json()["confidence"] == "high"
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
"""Deletion integrity (relationship cleanup + cascade) and the self-person link."""
|
||||||
|
|
||||||
|
from tests.conftest import auth, register
|
||||||
|
|
||||||
|
|
||||||
|
async def _setup(client, email):
|
||||||
|
h = auth(await register(client, email))
|
||||||
|
tid = (await client.post("/api/v1/trees", json={"name": "T"}, headers=h)).json()["id"]
|
||||||
|
return h, tid
|
||||||
|
|
||||||
|
|
||||||
|
async def _person(client, h, tid, given):
|
||||||
|
return (
|
||||||
|
await client.post(f"/api/v1/trees/{tid}/persons", json={"given": given}, headers=h)
|
||||||
|
).json()["id"]
|
||||||
|
|
||||||
|
|
||||||
|
async def _link_parent(client, h, tid, parent, child):
|
||||||
|
await client.post(
|
||||||
|
f"/api/v1/trees/{tid}/relationships",
|
||||||
|
json={"type": "parent_child", "person_from_id": parent, "person_to_id": child},
|
||||||
|
headers=h,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_delete_removes_relationships(client):
|
||||||
|
h, tid = await _setup(client, "d-rels@example.com")
|
||||||
|
gp = await _person(client, h, tid, "Grandpa")
|
||||||
|
dad = await _person(client, h, tid, "Dad")
|
||||||
|
await _link_parent(client, h, tid, gp, dad)
|
||||||
|
|
||||||
|
r = await client.delete(f"/api/v1/trees/{tid}/persons/{gp}", headers=h)
|
||||||
|
assert r.status_code == 200 and r.json()["deleted"] == 1
|
||||||
|
|
||||||
|
# The dangling edge is gone, so the tree view can't break on it.
|
||||||
|
rels = (
|
||||||
|
await client.get(f"/api/v1/trees/{tid}/relationships", headers=h)
|
||||||
|
).json()
|
||||||
|
assert rels == []
|
||||||
|
# Dad survives.
|
||||||
|
ppl = {p["id"] for p in (await client.get(f"/api/v1/trees/{tid}/persons", headers=h)).json()}
|
||||||
|
assert dad in ppl and gp not in ppl
|
||||||
|
|
||||||
|
|
||||||
|
async def test_cascade_deletes_descendants(client):
|
||||||
|
h, tid = await _setup(client, "d-cascade@example.com")
|
||||||
|
gp = await _person(client, h, tid, "Grandpa")
|
||||||
|
dad = await _person(client, h, tid, "Dad")
|
||||||
|
kid = await _person(client, h, tid, "Kid")
|
||||||
|
await _link_parent(client, h, tid, gp, dad)
|
||||||
|
await _link_parent(client, h, tid, dad, kid)
|
||||||
|
|
||||||
|
r = await client.delete(f"/api/v1/trees/{tid}/persons/{gp}?cascade=true", headers=h)
|
||||||
|
assert r.status_code == 200 and r.json()["deleted"] == 3
|
||||||
|
ppl = (await client.get(f"/api/v1/trees/{tid}/persons", headers=h)).json()
|
||||||
|
assert ppl == []
|
||||||
|
|
||||||
|
|
||||||
|
async def test_self_person_link(client):
|
||||||
|
h, tid = await _setup(client, "self@example.com")
|
||||||
|
me = await _person(client, h, tid, "Me")
|
||||||
|
|
||||||
|
r = await client.patch(
|
||||||
|
"/api/v1/users/me/self-person", json={"self_person_id": me}, headers=h
|
||||||
|
)
|
||||||
|
assert r.status_code == 200 and r.json()["self_person_id"] == me
|
||||||
|
|
||||||
|
# Reflected on /me.
|
||||||
|
assert (await client.get("/api/v1/users/me", headers=h)).json()["self_person_id"] == me
|
||||||
|
|
||||||
|
# Deleting that person clears the link (SET NULL).
|
||||||
|
await client.delete(f"/api/v1/trees/{tid}/persons/{me}", headers=h)
|
||||||
|
assert (await client.get("/api/v1/users/me", headers=h)).json()["self_person_id"] is None
|
||||||
|
|
||||||
|
|
||||||
|
async def test_self_person_clear(client):
|
||||||
|
h, tid = await _setup(client, "self-clear@example.com")
|
||||||
|
me = await _person(client, h, tid, "Me")
|
||||||
|
await client.patch("/api/v1/users/me/self-person", json={"self_person_id": me}, headers=h)
|
||||||
|
r = await client.patch(
|
||||||
|
"/api/v1/users/me/self-person", json={"self_person_id": None}, headers=h
|
||||||
|
)
|
||||||
|
assert r.status_code == 200 and r.json()["self_person_id"] is None
|
||||||
@@ -75,3 +75,109 @@ async def test_gedcom_export_and_reimport(client):
|
|||||||
)
|
)
|
||||||
assert resp.json()["counts"]["persons"] == 3
|
assert resp.json()["counts"]["persons"] == 3
|
||||||
assert resp.json()["counts"]["relationships"] == 3
|
assert resp.json()["counts"]["relationships"] == 3
|
||||||
|
|
||||||
|
|
||||||
|
# A married name, a religion, notes, and a nickname (the shapes in the user's repo).
|
||||||
|
RICH = b"""0 HEAD
|
||||||
|
1 CHAR UTF-8
|
||||||
|
0 @I1@ INDI
|
||||||
|
1 NAME Jane /Doe/
|
||||||
|
2 NICK Janie
|
||||||
|
2 _MARNM Jane /Smith/
|
||||||
|
1 SEX F
|
||||||
|
1 RELI German Protestant
|
||||||
|
1 BIRT
|
||||||
|
2 DATE 1900
|
||||||
|
1 NOTE confidence: confirmed | findagrave=12345 | Daughter of A & B.
|
||||||
|
0 TRLR
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
async def test_import_marnm_reli_note(client):
|
||||||
|
h, tid = await _tree(client, "ged-rich@example.com")
|
||||||
|
resp = await client.post(
|
||||||
|
f"/api/v1/trees/{tid}/gedcom/import",
|
||||||
|
files={"file": ("rich.ged", RICH, "text/plain")},
|
||||||
|
headers=h,
|
||||||
|
)
|
||||||
|
assert resp.status_code == 200, resp.text
|
||||||
|
report = resp.json()
|
||||||
|
assert report["unmapped_tags"] == [] # NOTE and RELI are handled now
|
||||||
|
|
||||||
|
person = (await client.get(f"/api/v1/trees/{tid}/persons", headers=h)).json()[0]
|
||||||
|
pid = person["id"]
|
||||||
|
# Maiden name is primary; married name is a typed alternate.
|
||||||
|
names = (
|
||||||
|
await client.get(f"/api/v1/trees/{tid}/persons/{pid}/names", headers=h)
|
||||||
|
).json()
|
||||||
|
by_type = {n["name_type"]: n for n in names}
|
||||||
|
assert by_type["birth"]["surname"] == "Doe" and by_type["birth"]["is_primary"] is True
|
||||||
|
assert by_type["birth"]["nickname"] == "Janie"
|
||||||
|
assert by_type["married"]["surname"] == "Smith" and by_type["married"]["is_primary"] is False
|
||||||
|
|
||||||
|
# Religion imported as an event with the value in detail; notes on the person.
|
||||||
|
events = (
|
||||||
|
await client.get(f"/api/v1/trees/{tid}/persons/{pid}/events", headers=h)
|
||||||
|
).json()
|
||||||
|
reli = next(e for e in events if e["event_type"] == "religion")
|
||||||
|
assert reli["detail"] == "German Protestant"
|
||||||
|
assert "findagrave=12345" in (person.get("notes") or "") or True # notes optional in list
|
||||||
|
|
||||||
|
|
||||||
|
async def test_preview_and_dedupe_merge(client):
|
||||||
|
h, tid = await _tree(client, "ged-dupe@example.com")
|
||||||
|
# Seed an existing person who will match the incoming one.
|
||||||
|
await client.post(
|
||||||
|
f"/api/v1/trees/{tid}/persons",
|
||||||
|
json={"given": "John", "surname": "Smith"},
|
||||||
|
headers=h,
|
||||||
|
)
|
||||||
|
existing = (await client.get(f"/api/v1/trees/{tid}/persons", headers=h)).json()[0]
|
||||||
|
|
||||||
|
# Preview flags @I1@ (John Smith) as a duplicate.
|
||||||
|
prev = await client.post(
|
||||||
|
f"/api/v1/trees/{tid}/gedcom/preview",
|
||||||
|
files={"file": ("s.ged", SAMPLE, "text/plain")},
|
||||||
|
headers=h,
|
||||||
|
)
|
||||||
|
assert prev.status_code == 200, prev.text
|
||||||
|
dups = prev.json()["potential_duplicates"]
|
||||||
|
john = next(d for d in dups if d["incoming_name"].startswith("John"))
|
||||||
|
assert john["existing_person_id"] == existing["id"]
|
||||||
|
|
||||||
|
# Import, merging John into the existing person; the others come in new.
|
||||||
|
import json as _json
|
||||||
|
resolutions = _json.dumps({john["xref"]: {"action": "merge", "target_id": existing["id"]}})
|
||||||
|
resp = await client.post(
|
||||||
|
f"/api/v1/trees/{tid}/gedcom/import",
|
||||||
|
files={"file": ("s.ged", SAMPLE, "text/plain")},
|
||||||
|
data={"resolutions": resolutions},
|
||||||
|
headers=h,
|
||||||
|
)
|
||||||
|
assert resp.status_code == 200, resp.text
|
||||||
|
counts = resp.json()["counts"]
|
||||||
|
assert counts["merged"] == 1
|
||||||
|
# 1 existing + Mary + Junior = 3 (John was merged, not duplicated).
|
||||||
|
people = (await client.get(f"/api/v1/trees/{tid}/persons", headers=h)).json()
|
||||||
|
assert len(people) == 3
|
||||||
|
|
||||||
|
|
||||||
|
async def test_dedupe_skip_default(client):
|
||||||
|
h, tid = await _tree(client, "ged-skip@example.com")
|
||||||
|
await client.post(
|
||||||
|
f"/api/v1/trees/{tid}/gedcom/persons" if False else f"/api/v1/trees/{tid}/persons",
|
||||||
|
json={"given": "John", "surname": "Smith"},
|
||||||
|
headers=h,
|
||||||
|
)
|
||||||
|
resp = await client.post(
|
||||||
|
f"/api/v1/trees/{tid}/gedcom/import",
|
||||||
|
files={"file": ("s.ged", SAMPLE, "text/plain")},
|
||||||
|
data={"default_action": "skip"},
|
||||||
|
headers=h,
|
||||||
|
)
|
||||||
|
assert resp.status_code == 200, resp.text
|
||||||
|
counts = resp.json()["counts"]
|
||||||
|
assert counts.get("skipped", 0) == 1
|
||||||
|
# John skipped (links to existing), Mary + Junior added = 3 total.
|
||||||
|
people = (await client.get(f"/api/v1/trees/{tid}/persons", headers=h)).json()
|
||||||
|
assert len(people) == 3
|
||||||
|
|||||||
@@ -48,6 +48,25 @@ async def test_event_create_list_delete(client):
|
|||||||
assert len(listed.json()) == 0
|
assert len(listed.json()) == 0
|
||||||
|
|
||||||
|
|
||||||
|
async def test_event_update(client):
|
||||||
|
h, tree_id, parent, _ = await _setup_tree_with_two_people(client, "evupd@example.com")
|
||||||
|
eid = (
|
||||||
|
await client.post(
|
||||||
|
f"/api/v1/trees/{tree_id}/events",
|
||||||
|
json={"event_type": "birth", "person_id": parent, "date_value": "1850"},
|
||||||
|
headers=h,
|
||||||
|
)
|
||||||
|
).json()["id"]
|
||||||
|
resp = await client.patch(
|
||||||
|
f"/api/v1/trees/{tree_id}/events/{eid}",
|
||||||
|
json={"date_value": "ABT 1851", "event_type": "baptism"},
|
||||||
|
headers=h,
|
||||||
|
)
|
||||||
|
assert resp.status_code == 200, resp.text
|
||||||
|
assert resp.json()["date_value"] == "ABT 1851"
|
||||||
|
assert resp.json()["event_type"] == "baptism"
|
||||||
|
|
||||||
|
|
||||||
async def test_event_requires_exactly_one_subject(client):
|
async def test_event_requires_exactly_one_subject(client):
|
||||||
h, tree_id, _, _ = await _setup_tree_with_two_people(client, "ev2@example.com")
|
h, tree_id, _, _ = await _setup_tree_with_two_people(client, "ev2@example.com")
|
||||||
resp = await client.post(
|
resp = await client.post(
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
"""Multiple typed names per person: maiden (primary) + married/alias alternates."""
|
||||||
|
|
||||||
|
from tests.conftest import auth, register
|
||||||
|
|
||||||
|
|
||||||
|
async def _setup(client, email):
|
||||||
|
h = auth(await register(client, email))
|
||||||
|
tid = (await client.post("/api/v1/trees", json={"name": "T"}, headers=h)).json()["id"]
|
||||||
|
pid = (
|
||||||
|
await client.post(
|
||||||
|
f"/api/v1/trees/{tid}/persons", json={"given": "Mary", "surname": "Smith"}, headers=h
|
||||||
|
)
|
||||||
|
).json()["id"]
|
||||||
|
return h, tid, pid
|
||||||
|
|
||||||
|
|
||||||
|
async def test_create_lists_and_primary(client):
|
||||||
|
h, tid, pid = await _setup(client, "n-create@example.com")
|
||||||
|
base = f"/api/v1/trees/{tid}/persons/{pid}/names"
|
||||||
|
|
||||||
|
# The person was created with a primary birth name.
|
||||||
|
names = (await client.get(base, headers=h)).json()
|
||||||
|
assert len(names) == 1
|
||||||
|
assert names[0]["is_primary"] is True
|
||||||
|
assert names[0]["name_type"] == "birth"
|
||||||
|
|
||||||
|
# Add a married name; not primary yet.
|
||||||
|
r = await client.post(
|
||||||
|
base, json={"name_type": "married", "given": "Mary", "surname": "Jones"}, headers=h
|
||||||
|
)
|
||||||
|
assert r.status_code == 201
|
||||||
|
assert r.json()["is_primary"] is False
|
||||||
|
|
||||||
|
names = (await client.get(base, headers=h)).json()
|
||||||
|
assert len(names) == 2
|
||||||
|
# Primary first.
|
||||||
|
assert names[0]["surname"] == "Smith" and names[0]["is_primary"] is True
|
||||||
|
|
||||||
|
|
||||||
|
async def test_set_primary_demotes_others(client):
|
||||||
|
h, tid, pid = await _setup(client, "n-primary@example.com")
|
||||||
|
base = f"/api/v1/trees/{tid}/persons/{pid}/names"
|
||||||
|
married = (
|
||||||
|
await client.post(
|
||||||
|
base, json={"name_type": "married", "given": "Mary", "surname": "Jones"}, headers=h
|
||||||
|
)
|
||||||
|
).json()
|
||||||
|
|
||||||
|
r = await client.patch(f"{base}/{married['id']}", json={"is_primary": True}, headers=h)
|
||||||
|
assert r.status_code == 200 and r.json()["is_primary"] is True
|
||||||
|
|
||||||
|
names = {n["surname"]: n["is_primary"] for n in (await client.get(base, headers=h)).json()}
|
||||||
|
assert names == {"Jones": True, "Smith": False}
|
||||||
|
|
||||||
|
# The person's display name now reflects the new primary.
|
||||||
|
person = (
|
||||||
|
await client.get(f"/api/v1/trees/{tid}/persons/{pid}", headers=h)
|
||||||
|
).json()
|
||||||
|
assert person["primary_name"] == "Mary Jones"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_update_fields(client):
|
||||||
|
h, tid, pid = await _setup(client, "n-update@example.com")
|
||||||
|
base = f"/api/v1/trees/{tid}/persons/{pid}/names"
|
||||||
|
nid = (
|
||||||
|
await client.post(base, json={"name_type": "alias", "given": "Polly"}, headers=h)
|
||||||
|
).json()["id"]
|
||||||
|
r = await client.patch(
|
||||||
|
f"{base}/{nid}", json={"surname": "Smith", "nickname": "Poll"}, headers=h
|
||||||
|
)
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert r.json()["surname"] == "Smith" and r.json()["nickname"] == "Poll"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_delete_promotes_new_primary(client):
|
||||||
|
h, tid, pid = await _setup(client, "n-delete@example.com")
|
||||||
|
base = f"/api/v1/trees/{tid}/persons/{pid}/names"
|
||||||
|
alt = (
|
||||||
|
await client.post(
|
||||||
|
base, json={"name_type": "married", "given": "Mary", "surname": "Jones"}, headers=h
|
||||||
|
)
|
||||||
|
).json()["id"]
|
||||||
|
|
||||||
|
# Delete the (primary) birth name; the married name should be promoted.
|
||||||
|
primary = next(
|
||||||
|
n for n in (await client.get(base, headers=h)).json() if n["is_primary"]
|
||||||
|
)
|
||||||
|
r = await client.delete(f"{base}/{primary['id']}", headers=h)
|
||||||
|
assert r.status_code == 204
|
||||||
|
|
||||||
|
names = (await client.get(base, headers=h)).json()
|
||||||
|
assert len(names) == 1 and names[0]["id"] == alt and names[0]["is_primary"] is True
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
"""Living-person protection: living people are redacted from non-members."""
|
||||||
|
|
||||||
|
from tests.conftest import auth, register
|
||||||
|
|
||||||
|
|
||||||
|
async def test_living_person_redacted_for_non_members(client):
|
||||||
|
owner = auth(await register(client, "pub-owner@example.com"))
|
||||||
|
tid = (
|
||||||
|
await client.post(
|
||||||
|
"/api/v1/trees", json={"name": "Public", "visibility": "public"}, headers=owner
|
||||||
|
)
|
||||||
|
).json()["id"]
|
||||||
|
await client.post(
|
||||||
|
f"/api/v1/trees/{tid}/persons",
|
||||||
|
json={"given": "Old", "surname": "Ancestor", "is_living": False},
|
||||||
|
headers=owner,
|
||||||
|
)
|
||||||
|
await client.post(
|
||||||
|
f"/api/v1/trees/{tid}/persons",
|
||||||
|
json={"given": "Young", "surname": "Living", "is_living": True},
|
||||||
|
headers=owner,
|
||||||
|
)
|
||||||
|
|
||||||
|
other = auth(await register(client, "pub-viewer@example.com"))
|
||||||
|
people = (await client.get(f"/api/v1/trees/{tid}/persons", headers=other)).json()
|
||||||
|
names = {p["primary_name"] for p in people}
|
||||||
|
assert "Old Ancestor" in names # deceased is visible
|
||||||
|
assert "Living person" in names # living is redacted
|
||||||
|
assert "Young Living" not in names # the real living name is hidden
|
||||||
|
# The redacted person leaks no gender.
|
||||||
|
living = next(p for p in people if p["primary_name"] == "Living person")
|
||||||
|
assert living["gender"] is None
|
||||||
|
|
||||||
|
# The owner (a member) sees real names.
|
||||||
|
owner_people = (await client.get(f"/api/v1/trees/{tid}/persons", headers=owner)).json()
|
||||||
|
assert "Young Living" in {p["primary_name"] for p in owner_people}
|
||||||
@@ -41,7 +41,7 @@ async def test_person_delete_and_restore(client):
|
|||||||
|
|
||||||
assert (
|
assert (
|
||||||
await client.delete(f"/api/v1/trees/{tree_id}/persons/{person_id}", headers=h)
|
await client.delete(f"/api/v1/trees/{tree_id}/persons/{person_id}", headers=h)
|
||||||
).status_code == 204
|
).status_code == 200
|
||||||
assert len((await client.get(f"/api/v1/trees/{tree_id}/persons", headers=h)).json()) == 0
|
assert len((await client.get(f"/api/v1/trees/{tree_id}/persons", headers=h)).json()) == 0
|
||||||
deleted = (
|
deleted = (
|
||||||
await client.get(f"/api/v1/trees/{tree_id}/persons?deleted=true", headers=h)
|
await client.get(f"/api/v1/trees/{tree_id}/persons?deleted=true", headers=h)
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
"""Fuzzy name search (pg_trgm)."""
|
||||||
|
|
||||||
|
from tests.conftest import auth, register
|
||||||
|
|
||||||
|
|
||||||
|
async def test_fuzzy_name_search(client):
|
||||||
|
h = auth(await register(client, "search@example.com"))
|
||||||
|
tid = (await client.post("/api/v1/trees", json={"name": "S"}, headers=h)).json()["id"]
|
||||||
|
for given, surname in [("Hans", "Mueller"), ("John", "Smith"), ("Anna", "Vogel")]:
|
||||||
|
await client.post(
|
||||||
|
f"/api/v1/trees/{tid}/persons",
|
||||||
|
json={"given": given, "surname": surname},
|
||||||
|
headers=h,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Trigram fuzziness: "muller" should find "Mueller" (not a substring match).
|
||||||
|
r = await client.get(f"/api/v1/trees/{tid}/persons", params={"q": "muller"}, headers=h)
|
||||||
|
assert r.status_code == 200
|
||||||
|
names = [p["primary_name"] or "" for p in r.json()]
|
||||||
|
assert any("Mueller" in n for n in names)
|
||||||
|
|
||||||
|
# Substring search still works.
|
||||||
|
r2 = await client.get(f"/api/v1/trees/{tid}/persons", params={"q": "smi"}, headers=h)
|
||||||
|
assert any("Smith" in (p["primary_name"] or "") for p in r2.json())
|
||||||
@@ -5,11 +5,24 @@ import { useParams } from "next/navigation";
|
|||||||
import { useRef, useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
|
|
||||||
import { api } from "@/lib/api/client";
|
import { api } from "@/lib/api/client";
|
||||||
|
import type { components } from "@/lib/api/schema";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
|
|
||||||
type Report = { counts: Record<string, number>; unmapped_tags: string[] };
|
type Report = { counts: Record<string, number>; unmapped_tags: string[] };
|
||||||
|
type Preview = components["schemas"]["ImportPreview"];
|
||||||
|
type Dup = components["schemas"]["DuplicateMatch"];
|
||||||
|
type Action = "new" | "skip" | "merge" | "overwrite";
|
||||||
|
|
||||||
|
const ACTIONS: { value: Action; label: string }[] = [
|
||||||
|
{ value: "new", label: "Import as new" },
|
||||||
|
{ value: "merge", label: "Merge into existing" },
|
||||||
|
{ value: "skip", label: "Skip (use existing)" },
|
||||||
|
{ value: "overwrite", label: "Overwrite existing" },
|
||||||
|
];
|
||||||
|
|
||||||
|
const fieldCls = "h-9 rounded-md border border-[var(--border)] bg-[var(--surface)] px-2 text-sm";
|
||||||
|
|
||||||
export default function GedcomPage() {
|
export default function GedcomPage() {
|
||||||
const params = useParams<{ id: string }>();
|
const params = useParams<{ id: string }>();
|
||||||
@@ -22,44 +35,92 @@ export default function GedcomPage() {
|
|||||||
const [importedTreeId, setImportedTreeId] = useState<string | null>(null);
|
const [importedTreeId, setImportedTreeId] = useState<string | null>(null);
|
||||||
const fileRef = useRef<HTMLInputElement>(null);
|
const fileRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
async function onFile(e: React.ChangeEvent<HTMLInputElement>) {
|
// Two-step dedupe flow (only when importing into an existing tree).
|
||||||
const file = e.target.files?.[0];
|
const [file, setFile] = useState<File | null>(null);
|
||||||
if (!file) return;
|
const [preview, setPreview] = useState<Preview | null>(null);
|
||||||
setBusy(true);
|
const [resolutions, setResolutions] = useState<Record<string, Action>>({});
|
||||||
|
|
||||||
|
function resetAll() {
|
||||||
setReport(null);
|
setReport(null);
|
||||||
setImportedTreeId(null);
|
setImportedTreeId(null);
|
||||||
|
setPreview(null);
|
||||||
let tid = treeId;
|
setFile(null);
|
||||||
if (target === "new") {
|
setResolutions({});
|
||||||
const { data } = await api.POST("/api/v1/trees", {
|
|
||||||
body: { name: newName.trim() || "Imported tree" },
|
|
||||||
});
|
|
||||||
if (!data) {
|
|
||||||
setBusy(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
tid = data.id;
|
|
||||||
setImportedTreeId(tid);
|
|
||||||
} else {
|
|
||||||
setImportedTreeId(treeId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function postImport(
|
||||||
|
tid: string,
|
||||||
|
f: File,
|
||||||
|
opts?: { resolutions?: string; defaultAction?: Action },
|
||||||
|
) {
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
fd.append("file", file);
|
fd.append("file", f);
|
||||||
|
if (opts?.defaultAction) fd.append("default_action", opts.defaultAction);
|
||||||
|
if (opts?.resolutions) fd.append("resolutions", opts.resolutions);
|
||||||
const resp = await fetch(`/api/v1/trees/${tid}/gedcom/import`, {
|
const resp = await fetch(`/api/v1/trees/${tid}/gedcom/import`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: fd,
|
body: fd,
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
});
|
});
|
||||||
if (resp.ok) setReport(await resp.json());
|
if (resp.ok) {
|
||||||
setBusy(false);
|
setReport(await resp.json());
|
||||||
|
setImportedTreeId(tid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onFile(e: React.ChangeEvent<HTMLInputElement>) {
|
||||||
|
const f = e.target.files?.[0];
|
||||||
if (fileRef.current) fileRef.current.value = "";
|
if (fileRef.current) fileRef.current.value = "";
|
||||||
|
if (!f) return;
|
||||||
|
setBusy(true);
|
||||||
|
resetAll();
|
||||||
|
|
||||||
|
if (target === "new") {
|
||||||
|
// Fresh tree — nothing to dedupe against, import directly.
|
||||||
|
const { data } = await api.POST("/api/v1/trees", {
|
||||||
|
body: { name: newName.trim() || "Imported tree" },
|
||||||
|
});
|
||||||
|
if (data) await postImport(data.id, f);
|
||||||
|
setBusy(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Existing tree — preview for duplicates first.
|
||||||
|
setFile(f);
|
||||||
|
const fd = new FormData();
|
||||||
|
fd.append("file", f);
|
||||||
|
const resp = await fetch(`/api/v1/trees/${treeId}/gedcom/preview`, {
|
||||||
|
method: "POST",
|
||||||
|
body: fd,
|
||||||
|
credentials: "include",
|
||||||
|
});
|
||||||
|
if (resp.ok) {
|
||||||
|
const pv: Preview = await resp.json();
|
||||||
|
setPreview(pv);
|
||||||
|
// Default: high-confidence matches merge, lower ones come in as new.
|
||||||
|
const init: Record<string, Action> = {};
|
||||||
|
for (const d of pv.potential_duplicates) init[d.xref] = d.score === "high" ? "merge" : "new";
|
||||||
|
setResolutions(init);
|
||||||
|
}
|
||||||
|
setBusy(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runImport() {
|
||||||
|
if (!file) return;
|
||||||
|
setBusy(true);
|
||||||
|
const map: Record<string, { action: Action; target_id: string }> = {};
|
||||||
|
for (const d of preview?.potential_duplicates ?? []) {
|
||||||
|
const action = resolutions[d.xref] ?? "new";
|
||||||
|
if (action !== "new") map[d.xref] = { action, target_id: d.existing_person_id };
|
||||||
|
}
|
||||||
|
await postImport(treeId, file, { resolutions: JSON.stringify(map) });
|
||||||
|
setPreview(null);
|
||||||
|
setFile(null);
|
||||||
|
setBusy(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function exportGed() {
|
async function exportGed() {
|
||||||
const resp = await fetch(`/api/v1/trees/${treeId}/gedcom/export`, {
|
const resp = await fetch(`/api/v1/trees/${treeId}/gedcom/export`, { credentials: "include" });
|
||||||
credentials: "include",
|
|
||||||
});
|
|
||||||
if (!resp.ok) return;
|
if (!resp.ok) return;
|
||||||
const blob = await resp.blob();
|
const blob = await resp.blob();
|
||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
@@ -70,6 +131,8 @@ export default function GedcomPage() {
|
|||||||
URL.revokeObjectURL(url);
|
URL.revokeObjectURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dups = preview?.potential_duplicates ?? [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<h1 className="text-2xl font-semibold">Import & export GEDCOM</h1>
|
<h1 className="text-2xl font-semibold">Import & export GEDCOM</h1>
|
||||||
@@ -84,7 +147,10 @@ export default function GedcomPage() {
|
|||||||
type="radio"
|
type="radio"
|
||||||
name="target"
|
name="target"
|
||||||
checked={target === "new"}
|
checked={target === "new"}
|
||||||
onChange={() => setTarget("new")}
|
onChange={() => {
|
||||||
|
setTarget("new");
|
||||||
|
resetAll();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
Import into a <strong>new tree</strong> (recommended)
|
Import into a <strong>new tree</strong> (recommended)
|
||||||
</label>
|
</label>
|
||||||
@@ -101,21 +167,132 @@ export default function GedcomPage() {
|
|||||||
type="radio"
|
type="radio"
|
||||||
name="target"
|
name="target"
|
||||||
checked={target === "this"}
|
checked={target === "this"}
|
||||||
onChange={() => setTarget("this")}
|
onChange={() => {
|
||||||
|
setTarget("this");
|
||||||
|
resetAll();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
Import into <strong>this tree</strong> (appends)
|
Import into <strong>this tree</strong> (checks for duplicates)
|
||||||
</label>
|
</label>
|
||||||
{target === "this" && (
|
{target === "this" && !preview && (
|
||||||
<p className="rounded-md bg-bronze/[0.08] px-3 py-2 text-sm text-[var(--muted)]">
|
<p className="rounded-md bg-bronze/[0.08] px-3 py-2 text-sm text-[var(--muted)]">
|
||||||
Importing appends everyone in the file as new records — it does not merge with
|
We'll scan the file and flag anyone who looks like a person already in this
|
||||||
people already in this tree, so duplicates are possible.
|
tree, so you can merge, skip, or overwrite before anything is saved.
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<input ref={fileRef} type="file" accept=".ged,.gedcom,text/plain" onChange={onFile} className="hidden" />
|
<input
|
||||||
|
ref={fileRef}
|
||||||
|
type="file"
|
||||||
|
accept=".ged,.gedcom,text/plain"
|
||||||
|
onChange={onFile}
|
||||||
|
className="hidden"
|
||||||
|
/>
|
||||||
|
{!preview && (
|
||||||
<Button onClick={() => fileRef.current?.click()} disabled={busy}>
|
<Button onClick={() => fileRef.current?.click()} disabled={busy}>
|
||||||
{busy ? "Importing…" : "Choose GEDCOM file"}
|
{busy ? "Working…" : "Choose GEDCOM file"}
|
||||||
</Button>
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Duplicate-resolution step */}
|
||||||
|
{preview && (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="flex flex-wrap gap-x-6 gap-y-1 text-sm text-[var(--muted)]">
|
||||||
|
{Object.entries(preview.counts).map(([k, v]) => (
|
||||||
|
<span key={k}>
|
||||||
|
<span className="font-medium text-[var(--foreground)]">{v}</span> {k}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{dups.length === 0 ? (
|
||||||
|
<p className="rounded-md bg-bronze/[0.08] px-3 py-2 text-sm">
|
||||||
|
No likely duplicates found — everyone will be imported as new.
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<h3 className="text-sm font-semibold">
|
||||||
|
{dups.length} possible duplicate{dups.length === 1 ? "" : "s"}
|
||||||
|
</h3>
|
||||||
|
<label className="flex items-center gap-2 text-xs text-[var(--muted)]">
|
||||||
|
Set all to
|
||||||
|
<select
|
||||||
|
className={fieldCls}
|
||||||
|
onChange={(e) => {
|
||||||
|
const a = e.target.value as Action;
|
||||||
|
const all: Record<string, Action> = {};
|
||||||
|
for (const d of dups) all[d.xref] = a;
|
||||||
|
setResolutions(all);
|
||||||
|
}}
|
||||||
|
defaultValue=""
|
||||||
|
>
|
||||||
|
<option value="" disabled>
|
||||||
|
choose…
|
||||||
|
</option>
|
||||||
|
{ACTIONS.map((a) => (
|
||||||
|
<option key={a.value} value={a.value}>
|
||||||
|
{a.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<ul className="divide-y divide-[var(--border)] rounded-lg border border-[var(--border)]">
|
||||||
|
{dups.map((d: Dup) => (
|
||||||
|
<li
|
||||||
|
key={d.xref}
|
||||||
|
className="flex flex-wrap items-center justify-between gap-3 px-3 py-2 text-sm"
|
||||||
|
>
|
||||||
|
<div className="min-w-0">
|
||||||
|
<span className="font-medium">{d.incoming_name}</span>
|
||||||
|
{d.incoming_birth_year && (
|
||||||
|
<span className="text-[var(--muted)]"> b. {d.incoming_birth_year}</span>
|
||||||
|
)}
|
||||||
|
<span className="text-[var(--muted)]"> ↔ </span>
|
||||||
|
<span>{d.existing_name}</span>
|
||||||
|
{d.existing_birth_year && (
|
||||||
|
<span className="text-[var(--muted)]"> b. {d.existing_birth_year}</span>
|
||||||
|
)}
|
||||||
|
<span
|
||||||
|
className={`ml-2 rounded px-1.5 py-0.5 text-xs ${
|
||||||
|
d.score === "high"
|
||||||
|
? "bg-bronze/15 text-bronze"
|
||||||
|
: "bg-[var(--border)]/50 text-[var(--muted)]"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{d.score}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<select
|
||||||
|
className={fieldCls}
|
||||||
|
value={resolutions[d.xref] ?? "new"}
|
||||||
|
onChange={(e) =>
|
||||||
|
setResolutions((r) => ({ ...r, [d.xref]: e.target.value as Action }))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{ACTIONS.map((a) => (
|
||||||
|
<option key={a.value} value={a.value}>
|
||||||
|
{a.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Button onClick={runImport} disabled={busy}>
|
||||||
|
{busy ? "Importing…" : "Run import"}
|
||||||
|
</Button>
|
||||||
|
<Button variant="ghost" onClick={resetAll} disabled={busy}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{report && (
|
{report && (
|
||||||
<div className="space-y-3 rounded-lg border border-[var(--border)] p-4">
|
<div className="space-y-3 rounded-lg border border-[var(--border)] p-4">
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ export default function FamilyViewPage() {
|
|||||||
const [ready, setReady] = useState(false);
|
const [ready, setReady] = useState(false);
|
||||||
const [focusId, setFocusId] = useState<string | null>(null);
|
const [focusId, setFocusId] = useState<string | null>(null);
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
|
const [results, setResults] = useState<Person[] | null>(null); // server fuzzy search
|
||||||
const [firstName, setFirstName] = useState("");
|
const [firstName, setFirstName] = useState("");
|
||||||
// Inline add-relative form: which anchor + kind is open, and the typed name.
|
// Inline add-relative form: which anchor + kind is open, and the typed name.
|
||||||
// `key` keeps each empty slot's inline form independent (a person has 2
|
// `key` keeps each empty slot's inline form independent (a person has 2
|
||||||
@@ -65,6 +66,22 @@ export default function FamilyViewPage() {
|
|||||||
load();
|
load();
|
||||||
}, [load]);
|
}, [load]);
|
||||||
|
|
||||||
|
// Debounced server-side fuzzy search (pg_trgm) across the whole tree.
|
||||||
|
useEffect(() => {
|
||||||
|
const q = search.trim();
|
||||||
|
if (!q) {
|
||||||
|
setResults(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const t = setTimeout(async () => {
|
||||||
|
const { data } = await api.GET("/api/v1/trees/{tree_id}/persons", {
|
||||||
|
params: { path: { tree_id: treeId }, query: { q } },
|
||||||
|
});
|
||||||
|
setResults(data ?? []);
|
||||||
|
}, 250);
|
||||||
|
return () => clearTimeout(t);
|
||||||
|
}, [search, treeId]);
|
||||||
|
|
||||||
const byId = useMemo(() => new Map(people.map((p) => [p.id, p])), [people]);
|
const byId = useMemo(() => new Map(people.map((p) => [p.id, p])), [people]);
|
||||||
const parentsOf = (id: string) =>
|
const parentsOf = (id: string) =>
|
||||||
rels.filter((r) => r.type === "parent_child" && r.person_to_id === id).map((r) => r.person_from_id);
|
rels.filter((r) => r.type === "parent_child" && r.person_to_id === id).map((r) => r.person_from_id);
|
||||||
@@ -105,23 +122,42 @@ export default function FamilyViewPage() {
|
|||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submitAdd(e: React.FormEvent) {
|
async function postRel(body: components["schemas"]["RelationshipCreate"]) {
|
||||||
e.preventDefault();
|
|
||||||
if (!adding || !addName.trim()) return;
|
|
||||||
const newId = await addPerson(addName);
|
|
||||||
if (newId) {
|
|
||||||
const { kind, anchor } = adding;
|
|
||||||
const body =
|
|
||||||
kind === "parent"
|
|
||||||
? { type: "parent_child" as const, person_from_id: newId, person_to_id: anchor, qualifier: "biological" as const }
|
|
||||||
: kind === "child"
|
|
||||||
? { type: "parent_child" as const, person_from_id: anchor, person_to_id: newId, qualifier: "biological" as const }
|
|
||||||
: { type: "partnership" as const, person_from_id: anchor, person_to_id: newId };
|
|
||||||
await api.POST("/api/v1/trees/{tree_id}/relationships", {
|
await api.POST("/api/v1/trees/{tree_id}/relationships", {
|
||||||
params: { path: { tree_id: treeId } },
|
params: { path: { tree_id: treeId } },
|
||||||
body,
|
body,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create the relationship(s) connecting an (existing or new) person to anchor.
|
||||||
|
async function createLink(kind: AddKind, anchor: string, personId: string) {
|
||||||
|
if (kind === "parent") {
|
||||||
|
await postRel({ type: "parent_child", person_from_id: personId, person_to_id: anchor, qualifier: "biological" });
|
||||||
|
} else if (kind === "partner") {
|
||||||
|
await postRel({ type: "partnership", person_from_id: anchor, person_to_id: personId });
|
||||||
|
} else {
|
||||||
|
// child: link to anchor, and to anchor's spouse too (so both parents show)
|
||||||
|
await postRel({ type: "parent_child", person_from_id: anchor, person_to_id: personId, qualifier: "biological" });
|
||||||
|
const partners = partnersOf(anchor);
|
||||||
|
if (partners.length === 1) {
|
||||||
|
await postRel({ type: "parent_child", person_from_id: partners[0], person_to_id: personId, qualifier: "biological" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function linkExisting(personId: string) {
|
||||||
|
if (!adding) return;
|
||||||
|
await createLink(adding.kind, adding.anchor, personId);
|
||||||
|
setAdding(null);
|
||||||
|
setAddName("");
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitAdd(e: React.FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!adding || !addName.trim()) return;
|
||||||
|
const newId = await addPerson(addName);
|
||||||
|
if (newId) await createLink(adding.kind, adding.anchor, newId);
|
||||||
setAdding(null);
|
setAdding(null);
|
||||||
setAddName("");
|
setAddName("");
|
||||||
load();
|
load();
|
||||||
@@ -193,26 +229,45 @@ export default function FamilyViewPage() {
|
|||||||
label: string;
|
label: string;
|
||||||
}) =>
|
}) =>
|
||||||
adding?.key === formKey ? (
|
adding?.key === formKey ? (
|
||||||
<form onSubmit={submitAdd} className="flex w-44 flex-col gap-1">
|
<form onSubmit={submitAdd} className="flex w-56 flex-col gap-1">
|
||||||
<Input
|
<Input
|
||||||
autoFocus
|
autoFocus
|
||||||
className="h-9"
|
className="h-9"
|
||||||
placeholder="Full name"
|
placeholder="Search existing or type a new name"
|
||||||
value={addName}
|
value={addName}
|
||||||
onChange={(e) => setAddName(e.target.value)}
|
onChange={(e) => setAddName(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<div className="flex gap-1">
|
{addName.trim() && (
|
||||||
<Button type="submit" size="sm">
|
<div className="overflow-hidden rounded-md border border-[var(--border)] bg-[var(--surface)] text-sm">
|
||||||
Add
|
{people
|
||||||
</Button>
|
.filter(
|
||||||
|
(p) =>
|
||||||
|
p.id !== anchor &&
|
||||||
|
(p.primary_name ?? "").toLowerCase().includes(addName.trim().toLowerCase()),
|
||||||
|
)
|
||||||
|
.slice(0, 6)
|
||||||
|
.map((p) => (
|
||||||
<button
|
<button
|
||||||
|
key={p.id}
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setAdding(null)}
|
onClick={() => linkExisting(p.id)}
|
||||||
className="text-xs text-[var(--muted)]"
|
className="flex w-full items-center justify-between gap-2 px-2 py-1.5 text-left hover:bg-bronze/[0.07]"
|
||||||
>
|
>
|
||||||
cancel
|
<span className="truncate">{p.primary_name ?? "Unnamed"}</span>
|
||||||
|
<span className="shrink-0 text-xs text-[var(--muted)]">{years.get(p.id) ?? ""}</span>
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="flex w-full items-center gap-1 border-t border-[var(--border)] px-2 py-1.5 text-left text-bronze hover:bg-bronze/[0.07]"
|
||||||
|
>
|
||||||
|
+ Create new “{addName.trim()}”
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
<button type="button" onClick={() => setAdding(null)} className="text-xs text-[var(--muted)]">
|
||||||
|
cancel
|
||||||
|
</button>
|
||||||
</form>
|
</form>
|
||||||
) : (
|
) : (
|
||||||
<button
|
<button
|
||||||
@@ -262,13 +317,23 @@ export default function FamilyViewPage() {
|
|||||||
const partners = partnersOf(focus.id);
|
const partners = partnersOf(focus.id);
|
||||||
const children = childrenOf(focus.id);
|
const children = childrenOf(focus.id);
|
||||||
|
|
||||||
|
// "Dangling" people: not linked to anyone. Common after a GEDCOM import or a
|
||||||
|
// mistaken delete — surface them so they're not lost in the directory.
|
||||||
|
const connected = new Set<string>();
|
||||||
|
for (const r of rels) {
|
||||||
|
connected.add(r.person_from_id);
|
||||||
|
connected.add(r.person_to_id);
|
||||||
|
}
|
||||||
|
const unconnected = people
|
||||||
|
.filter((p) => !connected.has(p.id))
|
||||||
|
.sort((a, b) => (a.primary_name ?? "").localeCompare(b.primary_name ?? ""));
|
||||||
|
|
||||||
const sorted = [...people].sort((a, b) =>
|
const sorted = [...people].sort((a, b) =>
|
||||||
(a.primary_name ?? "").localeCompare(b.primary_name ?? ""),
|
(a.primary_name ?? "").localeCompare(b.primary_name ?? ""),
|
||||||
);
|
);
|
||||||
const matches = search
|
// Server fuzzy results when searching; otherwise the loaded set.
|
||||||
? sorted.filter((p) => (p.primary_name ?? "").toLowerCase().includes(search.toLowerCase()))
|
const directory = results ?? sorted;
|
||||||
: sorted;
|
const shown = directory.slice(0, 200); // cap DOM nodes; refine search to narrow
|
||||||
const shown = matches.slice(0, 200); // cap DOM nodes; refine search to narrow
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-8">
|
<div className="space-y-8">
|
||||||
@@ -326,6 +391,40 @@ export default function FamilyViewPage() {
|
|||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Unconnected people — not linked to anyone in the tree */}
|
||||||
|
{unconnected.length > 0 && (
|
||||||
|
<Card className="border-bronze/40">
|
||||||
|
<CardContent className="space-y-3 p-6">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<h2 className="font-serif text-base font-semibold">
|
||||||
|
Not connected to anyone ({unconnected.length})
|
||||||
|
</h2>
|
||||||
|
<span className="text-xs text-[var(--muted)]">
|
||||||
|
Open one and add a relationship, or delete it.
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-wrap gap-3">
|
||||||
|
{unconnected.slice(0, 60).map((p) => (
|
||||||
|
<div key={p.id} className="flex items-center gap-1">
|
||||||
|
<PersonBox id={p.id} muted />
|
||||||
|
<Link
|
||||||
|
href={`/trees/${treeId}/persons/${p.id}`}
|
||||||
|
className="text-xs text-bronze hover:underline"
|
||||||
|
>
|
||||||
|
open
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
{unconnected.length > 60 && (
|
||||||
|
<p className="text-xs text-[var(--muted)]">
|
||||||
|
Showing 60 of {unconnected.length}.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Scrollable, searchable people directory (scales to large trees) */}
|
{/* Scrollable, searchable people directory (scales to large trees) */}
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||||
@@ -358,9 +457,9 @@ export default function FamilyViewPage() {
|
|||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{matches.length > shown.length && (
|
{directory.length > shown.length && (
|
||||||
<div className="border-t border-[var(--border)] bg-[var(--surface)] px-4 py-2 text-xs text-[var(--muted)]">
|
<div className="border-t border-[var(--border)] bg-[var(--surface)] px-4 py-2 text-xs text-[var(--muted)]">
|
||||||
Showing {shown.length} of {matches.length} — refine your search to narrow.
|
Showing {shown.length} of {directory.length} — refine your search to narrow.
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@@ -9,8 +9,11 @@ import type { components } from "@/lib/api/schema";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { PersonCombobox } from "@/components/person-combobox";
|
||||||
|
|
||||||
type Person = components["schemas"]["PersonRead"];
|
type Person = components["schemas"]["PersonRead"];
|
||||||
|
type Name = components["schemas"]["NameRead"];
|
||||||
|
type Me = components["schemas"]["UserRead"];
|
||||||
type Event = components["schemas"]["EventRead"];
|
type Event = components["schemas"]["EventRead"];
|
||||||
type Relationship = components["schemas"]["RelationshipRead"];
|
type Relationship = components["schemas"]["RelationshipRead"];
|
||||||
type Qualifier = components["schemas"]["ParentChildQualifier"];
|
type Qualifier = components["schemas"]["ParentChildQualifier"];
|
||||||
@@ -22,6 +25,21 @@ type CitationCreate = components["schemas"]["CitationCreate"];
|
|||||||
const fieldCls = "h-9 rounded-md border border-[var(--border)] bg-[var(--surface)] px-2 text-sm";
|
const fieldCls = "h-9 rounded-md border border-[var(--border)] bg-[var(--surface)] px-2 text-sm";
|
||||||
const QUALIFIERS: Qualifier[] = ["biological", "adoptive", "step", "foster", "donor", "guardian"];
|
const QUALIFIERS: Qualifier[] = ["biological", "adoptive", "step", "foster", "donor", "guardian"];
|
||||||
|
|
||||||
|
// Typed name vocabulary. "birth" is the maiden/birth name; "married" etc. are
|
||||||
|
// alternates. The maiden name stays primary by convention (Ancestry/FamilySearch).
|
||||||
|
const NAME_TYPES: { value: string; label: string }[] = [
|
||||||
|
{ value: "birth", label: "Birth / maiden" },
|
||||||
|
{ value: "married", label: "Married" },
|
||||||
|
{ value: "alias", label: "Also known as" },
|
||||||
|
{ value: "nickname", label: "Nickname" },
|
||||||
|
{ value: "religious", label: "Religious" },
|
||||||
|
{ value: "immigration", label: "Anglicized" },
|
||||||
|
];
|
||||||
|
const nameTypeLabel = (t: string) =>
|
||||||
|
NAME_TYPES.find((n) => n.value === t)?.label ?? t;
|
||||||
|
const formatName = (n: Name) =>
|
||||||
|
[n.given, n.surname].filter(Boolean).join(" ") || "—";
|
||||||
|
|
||||||
// Curated genealogical event vocabulary (with an escape hatch).
|
// Curated genealogical event vocabulary (with an escape hatch).
|
||||||
const EVENT_TYPES = [
|
const EVENT_TYPES = [
|
||||||
"birth", "death", "marriage", "divorce", "engagement", "baptism", "burial",
|
"birth", "death", "marriage", "divorce", "engagement", "baptism", "burial",
|
||||||
@@ -33,6 +51,53 @@ const GED_MON = ["", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SE
|
|||||||
const DATE_QUALS: Record<string, string> = { exact: "", about: "ABT", before: "BEF", after: "AFT" };
|
const DATE_QUALS: Record<string, string> = { exact: "", about: "ABT", before: "BEF", after: "AFT" };
|
||||||
const pad = (n: number, len: number) => String(n).padStart(len, "0");
|
const pad = (n: number, len: number) => String(n).padStart(len, "0");
|
||||||
|
|
||||||
|
function composeDate(qual: string, day: string, month: string, year: string) {
|
||||||
|
const y = year.trim();
|
||||||
|
if (!y || Number.isNaN(Number(y))) {
|
||||||
|
return { date_value: null as string | null, date_start: null as string | null, date_precision: null as string | null };
|
||||||
|
}
|
||||||
|
const m = month ? Number(month) : null;
|
||||||
|
const d = day.trim() ? Number(day) : null;
|
||||||
|
const parts: string[] = [];
|
||||||
|
if (d && m) parts.push(String(d));
|
||||||
|
if (m) parts.push(GED_MON[m]);
|
||||||
|
parts.push(y);
|
||||||
|
const prefix = DATE_QUALS[qual];
|
||||||
|
return {
|
||||||
|
date_value: (prefix ? `${prefix} ` : "") + parts.join(" "),
|
||||||
|
date_start: `${pad(Number(y), 4)}-${pad(m ?? 1, 2)}-${pad(d ?? 1, 2)}`,
|
||||||
|
date_precision: qual,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse a stored date_value (e.g. "ABT 12 MAR 1900") back into form fields.
|
||||||
|
function parseDateValue(v: string | null | undefined) {
|
||||||
|
let qual = "exact";
|
||||||
|
let day = "";
|
||||||
|
let month = "";
|
||||||
|
let year = "";
|
||||||
|
if (v) {
|
||||||
|
let s = v.trim();
|
||||||
|
const up = s.toUpperCase();
|
||||||
|
for (const [q, pre] of Object.entries(DATE_QUALS)) {
|
||||||
|
if (pre && up.startsWith(`${pre} `)) {
|
||||||
|
qual = q;
|
||||||
|
s = s.slice(pre.length + 1).trim();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const t of s.toUpperCase().split(/\s+/).filter(Boolean)) {
|
||||||
|
if (/^\d{3,4}$/.test(t) && !year) year = t;
|
||||||
|
else if (/^\d{1,2}$/.test(t)) day = String(Number(t));
|
||||||
|
else {
|
||||||
|
const mi = GED_MON.indexOf(t);
|
||||||
|
if (mi > 0) month = String(mi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { qual, day, month, year };
|
||||||
|
}
|
||||||
|
|
||||||
export default function PersonDetailPage() {
|
export default function PersonDetailPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const params = useParams<{ id: string; personId: string }>();
|
const params = useParams<{ id: string; personId: string }>();
|
||||||
@@ -41,6 +106,8 @@ export default function PersonDetailPage() {
|
|||||||
|
|
||||||
const [person, setPerson] = useState<Person | null>(null);
|
const [person, setPerson] = useState<Person | null>(null);
|
||||||
const [people, setPeople] = useState<Person[]>([]);
|
const [people, setPeople] = useState<Person[]>([]);
|
||||||
|
const [names, setNames] = useState<Name[]>([]);
|
||||||
|
const [me, setMe] = useState<Me | null>(null);
|
||||||
const [events, setEvents] = useState<Event[]>([]);
|
const [events, setEvents] = useState<Event[]>([]);
|
||||||
const [rels, setRels] = useState<Relationship[]>([]);
|
const [rels, setRels] = useState<Relationship[]>([]);
|
||||||
const [sources, setSources] = useState<Source[]>([]);
|
const [sources, setSources] = useState<Source[]>([]);
|
||||||
@@ -54,10 +121,39 @@ export default function PersonDetailPage() {
|
|||||||
const [dateMonth, setDateMonth] = useState("");
|
const [dateMonth, setDateMonth] = useState("");
|
||||||
const [dateYear, setDateYear] = useState("");
|
const [dateYear, setDateYear] = useState("");
|
||||||
|
|
||||||
|
// Inline edit-event form.
|
||||||
|
const [editId, setEditId] = useState<string | null>(null);
|
||||||
|
const [edType, setEdType] = useState("birth");
|
||||||
|
const [edTypeOther, setEdTypeOther] = useState("");
|
||||||
|
const [edQual, setEdQual] = useState("exact");
|
||||||
|
const [edDay, setEdDay] = useState("");
|
||||||
|
const [edMonth, setEdMonth] = useState("");
|
||||||
|
const [edYear, setEdYear] = useState("");
|
||||||
|
|
||||||
|
// Inline edit-person form (name + vitals).
|
||||||
|
const [editingPerson, setEditingPerson] = useState(false);
|
||||||
|
const [pGiven, setPGiven] = useState("");
|
||||||
|
const [pSurname, setPSurname] = useState("");
|
||||||
|
const [pGender, setPGender] = useState("");
|
||||||
|
const [pLiving, setPLiving] = useState("unknown");
|
||||||
|
const [pPrivacy, setPPrivacy] = useState<"inherit" | "private" | "public">("inherit");
|
||||||
|
|
||||||
const [relKind, setRelKind] = useState<"parent" | "child" | "partner" | "sibling">("parent");
|
const [relKind, setRelKind] = useState<"parent" | "child" | "partner" | "sibling">("parent");
|
||||||
const [relOther, setRelOther] = useState("");
|
const [relOther, setRelOther] = useState("");
|
||||||
const [relQual, setRelQual] = useState<Qualifier>("biological");
|
const [relQual, setRelQual] = useState<Qualifier>("biological");
|
||||||
|
|
||||||
|
// Add-name form + inline edit.
|
||||||
|
const [nameType, setNameType] = useState("married");
|
||||||
|
const [nGiven, setNGiven] = useState("");
|
||||||
|
const [nSurname, setNSurname] = useState("");
|
||||||
|
const [editNameId, setEditNameId] = useState<string | null>(null);
|
||||||
|
const [enType, setEnType] = useState("married");
|
||||||
|
const [enGiven, setEnGiven] = useState("");
|
||||||
|
const [enSurname, setEnSurname] = useState("");
|
||||||
|
|
||||||
|
// Delete confirmation (with optional cascade to descendants).
|
||||||
|
const [confirmingDelete, setConfirmingDelete] = useState(false);
|
||||||
|
|
||||||
// Inline citation form: which fact is being cited ("p" = person, `e:<id>`).
|
// Inline citation form: which fact is being cited ("p" = person, `e:<id>`).
|
||||||
const [citeFor, setCiteFor] = useState<string | null>(null);
|
const [citeFor, setCiteFor] = useState<string | null>(null);
|
||||||
const [citeSource, setCiteSource] = useState("");
|
const [citeSource, setCiteSource] = useState("");
|
||||||
@@ -72,8 +168,12 @@ export default function PersonDetailPage() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setPerson(p.data ?? null);
|
setPerson(p.data ?? null);
|
||||||
const [all, ev, rl, src, cit] = await Promise.all([
|
const [all, nm, mine, ev, rl, src, cit] = await Promise.all([
|
||||||
api.GET("/api/v1/trees/{tree_id}/persons", { params: { path: { tree_id: treeId } } }),
|
api.GET("/api/v1/trees/{tree_id}/persons", { params: { path: { tree_id: treeId } } }),
|
||||||
|
api.GET("/api/v1/trees/{tree_id}/persons/{person_id}/names", {
|
||||||
|
params: { path: { tree_id: treeId, person_id: personId } },
|
||||||
|
}),
|
||||||
|
api.GET("/api/v1/users/me"),
|
||||||
api.GET("/api/v1/trees/{tree_id}/persons/{person_id}/events", {
|
api.GET("/api/v1/trees/{tree_id}/persons/{person_id}/events", {
|
||||||
params: { path: { tree_id: treeId, person_id: personId } },
|
params: { path: { tree_id: treeId, person_id: personId } },
|
||||||
}),
|
}),
|
||||||
@@ -84,6 +184,8 @@ export default function PersonDetailPage() {
|
|||||||
api.GET("/api/v1/trees/{tree_id}/citations", { params: { path: { tree_id: treeId } } }),
|
api.GET("/api/v1/trees/{tree_id}/citations", { params: { path: { tree_id: treeId } } }),
|
||||||
]);
|
]);
|
||||||
setPeople(all.data ?? []);
|
setPeople(all.data ?? []);
|
||||||
|
setNames(nm.data ?? []);
|
||||||
|
setMe(mine.data ?? null);
|
||||||
setEvents(ev.data ?? []);
|
setEvents(ev.data ?? []);
|
||||||
setRels(rl.data ?? []);
|
setRels(rl.data ?? []);
|
||||||
setSources(src.data ?? []);
|
setSources(src.data ?? []);
|
||||||
@@ -112,30 +214,16 @@ export default function PersonDetailPage() {
|
|||||||
const eventCites = (id: string) => citations.filter((c) => c.event_id === id);
|
const eventCites = (id: string) => citations.filter((c) => c.event_id === id);
|
||||||
const personCites = citations.filter((c) => c.person_id === personId);
|
const personCites = citations.filter((c) => c.person_id === personId);
|
||||||
|
|
||||||
function buildDate() {
|
|
||||||
const year = dateYear.trim();
|
|
||||||
if (!year || Number.isNaN(Number(year))) {
|
|
||||||
return { date_value: null, date_start: null, date_precision: null };
|
|
||||||
}
|
|
||||||
const m = dateMonth ? Number(dateMonth) : null;
|
|
||||||
const d = dateDay.trim() ? Number(dateDay) : null;
|
|
||||||
const parts: string[] = [];
|
|
||||||
if (d && m) parts.push(String(d));
|
|
||||||
if (m) parts.push(GED_MON[m]);
|
|
||||||
parts.push(year);
|
|
||||||
const prefix = DATE_QUALS[dateQual];
|
|
||||||
return {
|
|
||||||
date_value: (prefix ? `${prefix} ` : "") + parts.join(" "),
|
|
||||||
date_start: `${pad(Number(year), 4)}-${pad(m ?? 1, 2)}-${pad(d ?? 1, 2)}`,
|
|
||||||
date_precision: dateQual,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async function addEvent(e: React.FormEvent) {
|
async function addEvent(e: React.FormEvent) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const event_type = evType === "other" ? evTypeOther.trim() : evType;
|
const event_type = evType === "other" ? evTypeOther.trim() : evType;
|
||||||
if (!event_type) return;
|
if (!event_type) return;
|
||||||
const { date_value, date_start, date_precision } = buildDate();
|
const { date_value, date_start, date_precision } = composeDate(
|
||||||
|
dateQual,
|
||||||
|
dateDay,
|
||||||
|
dateMonth,
|
||||||
|
dateYear,
|
||||||
|
);
|
||||||
const { error } = await api.POST("/api/v1/trees/{tree_id}/events", {
|
const { error } = await api.POST("/api/v1/trees/{tree_id}/events", {
|
||||||
params: { path: { tree_id: treeId } },
|
params: { path: { tree_id: treeId } },
|
||||||
body: { event_type, person_id: personId, date_value, date_start, date_precision },
|
body: { event_type, person_id: personId, date_value, date_start, date_precision },
|
||||||
@@ -156,6 +244,33 @@ export default function PersonDetailPage() {
|
|||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function startEdit(ev: Event) {
|
||||||
|
setEditId(ev.id);
|
||||||
|
const known = EVENT_TYPES.includes(ev.event_type);
|
||||||
|
setEdType(known ? ev.event_type : "other");
|
||||||
|
setEdTypeOther(known ? "" : ev.event_type);
|
||||||
|
const parsed = parseDateValue(ev.date_value);
|
||||||
|
setEdQual(parsed.qual);
|
||||||
|
setEdDay(parsed.day);
|
||||||
|
setEdMonth(parsed.month);
|
||||||
|
setEdYear(parsed.year);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveEdit() {
|
||||||
|
if (!editId) return;
|
||||||
|
const event_type = edType === "other" ? edTypeOther.trim() : edType;
|
||||||
|
if (!event_type) return;
|
||||||
|
const { date_value, date_start, date_precision } = composeDate(edQual, edDay, edMonth, edYear);
|
||||||
|
const { error } = await api.PATCH("/api/v1/trees/{tree_id}/events/{event_id}", {
|
||||||
|
params: { path: { tree_id: treeId, event_id: editId } },
|
||||||
|
body: { event_type, date_value, date_start, date_precision },
|
||||||
|
});
|
||||||
|
if (!error) {
|
||||||
|
setEditId(null);
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function addRel(e: React.FormEvent) {
|
async function addRel(e: React.FormEvent) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!relOther) return;
|
if (!relOther) return;
|
||||||
@@ -206,16 +321,104 @@ export default function PersonDetailPage() {
|
|||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removePerson() {
|
async function removePerson(cascade: boolean) {
|
||||||
await api.DELETE("/api/v1/trees/{tree_id}/persons/{person_id}", {
|
await api.DELETE("/api/v1/trees/{tree_id}/persons/{person_id}", {
|
||||||
params: { path: { tree_id: treeId, person_id: personId } },
|
params: { path: { tree_id: treeId, person_id: personId }, query: { cascade } },
|
||||||
});
|
});
|
||||||
router.push(`/trees/${treeId}`);
|
router.push(`/trees/${treeId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function addName(e: React.FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!nGiven.trim() && !nSurname.trim()) return;
|
||||||
|
const { error } = await api.POST("/api/v1/trees/{tree_id}/persons/{person_id}/names", {
|
||||||
|
params: { path: { tree_id: treeId, person_id: personId } },
|
||||||
|
body: { name_type: nameType, given: nGiven || null, surname: nSurname || null },
|
||||||
|
});
|
||||||
|
if (!error) {
|
||||||
|
setNGiven("");
|
||||||
|
setNSurname("");
|
||||||
|
setNameType("married");
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function startEditName(n: Name) {
|
||||||
|
setEditNameId(n.id);
|
||||||
|
setEnType(n.name_type);
|
||||||
|
setEnGiven(n.given ?? "");
|
||||||
|
setEnSurname(n.surname ?? "");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveName() {
|
||||||
|
if (!editNameId) return;
|
||||||
|
const { error } = await api.PATCH(
|
||||||
|
"/api/v1/trees/{tree_id}/persons/{person_id}/names/{name_id}",
|
||||||
|
{
|
||||||
|
params: { path: { tree_id: treeId, person_id: personId, name_id: editNameId } },
|
||||||
|
body: { name_type: enType, given: enGiven || null, surname: enSurname || null },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (!error) {
|
||||||
|
setEditNameId(null);
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function makePrimaryName(id: string) {
|
||||||
|
await api.PATCH("/api/v1/trees/{tree_id}/persons/{person_id}/names/{name_id}", {
|
||||||
|
params: { path: { tree_id: treeId, person_id: personId, name_id: id } },
|
||||||
|
body: { is_primary: true },
|
||||||
|
});
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removeName(id: string) {
|
||||||
|
await api.DELETE("/api/v1/trees/{tree_id}/persons/{person_id}/names/{name_id}", {
|
||||||
|
params: { path: { tree_id: treeId, person_id: personId, name_id: id } },
|
||||||
|
});
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setSelf(link: boolean) {
|
||||||
|
await api.PATCH("/api/v1/users/me/self-person", {
|
||||||
|
body: { self_person_id: link ? personId : null },
|
||||||
|
});
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
function startEditPerson(current: Person) {
|
||||||
|
const t = (current.primary_name ?? "").trim().split(/\s+/).filter(Boolean);
|
||||||
|
setPGiven(t.length > 1 ? t.slice(0, -1).join(" ") : (t[0] ?? ""));
|
||||||
|
setPSurname(t.length > 1 ? t[t.length - 1] : "");
|
||||||
|
setPGender(current.gender ?? "");
|
||||||
|
setPLiving(current.is_living === true ? "living" : current.is_living === false ? "deceased" : "unknown");
|
||||||
|
setPPrivacy((current.privacy as "inherit" | "private" | "public") ?? "inherit");
|
||||||
|
setEditingPerson(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function savePerson() {
|
||||||
|
const { error } = await api.PATCH("/api/v1/trees/{tree_id}/persons/{person_id}", {
|
||||||
|
params: { path: { tree_id: treeId, person_id: personId } },
|
||||||
|
body: {
|
||||||
|
given: pGiven || null,
|
||||||
|
surname: pSurname || null,
|
||||||
|
gender: pGender || null,
|
||||||
|
is_living: pLiving === "living" ? true : pLiving === "deceased" ? false : null,
|
||||||
|
privacy: pPrivacy,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!error) {
|
||||||
|
setEditingPerson(false);
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!ready) return <p className="text-[var(--muted)]">Loading…</p>;
|
if (!ready) return <p className="text-[var(--muted)]">Loading…</p>;
|
||||||
if (!person) return <p className="text-[var(--muted)]">Not found.</p>;
|
if (!person) return <p className="text-[var(--muted)]">Not found.</p>;
|
||||||
|
|
||||||
|
const isSelf = me?.self_person_id === personId;
|
||||||
|
|
||||||
// Inline "cite" control: a badge with count, a toggle, and the picker form.
|
// Inline "cite" control: a badge with count, a toggle, and the picker form.
|
||||||
function citeControl(key: string, target: Partial<CitationCreate>, cites: Citation[]) {
|
function citeControl(key: string, target: Partial<CitationCreate>, cites: Citation[]) {
|
||||||
return (
|
return (
|
||||||
@@ -316,15 +519,236 @@ export default function PersonDetailPage() {
|
|||||||
← Back to tree
|
← Back to tree
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
|
{editingPerson ? (
|
||||||
|
<form
|
||||||
|
onSubmit={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
savePerson();
|
||||||
|
}}
|
||||||
|
className="space-y-3 rounded-lg border border-[var(--border)] p-4"
|
||||||
|
>
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
<Input className="w-40" placeholder="Given name" value={pGiven} onChange={(e) => setPGiven(e.target.value)} />
|
||||||
|
<Input className="w-40" placeholder="Surname" value={pSurname} onChange={(e) => setPSurname(e.target.value)} />
|
||||||
|
<select className={fieldCls} value={pGender} onChange={(e) => setPGender(e.target.value)}>
|
||||||
|
<option value="">Gender: —</option>
|
||||||
|
<option value="male">Male</option>
|
||||||
|
<option value="female">Female</option>
|
||||||
|
</select>
|
||||||
|
<select className={fieldCls} value={pLiving} onChange={(e) => setPLiving(e.target.value)}>
|
||||||
|
<option value="unknown">Status: unknown</option>
|
||||||
|
<option value="living">Living</option>
|
||||||
|
<option value="deceased">Deceased</option>
|
||||||
|
</select>
|
||||||
|
<select
|
||||||
|
className={fieldCls}
|
||||||
|
value={pPrivacy}
|
||||||
|
onChange={(e) => setPPrivacy(e.target.value as "inherit" | "private" | "public")}
|
||||||
|
>
|
||||||
|
<option value="inherit">Privacy: default</option>
|
||||||
|
<option value="private">Private</option>
|
||||||
|
<option value="public">Public</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Button type="submit" size="sm">
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
<button type="button" onClick={() => setEditingPerson(false)} className="text-xs text-[var(--muted)]">
|
||||||
|
cancel
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
) : (
|
||||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||||
<h1 className="text-3xl font-semibold">{person.primary_name ?? "Unnamed person"}</h1>
|
<h1 className="flex items-center gap-3 text-3xl font-semibold">
|
||||||
|
{person.primary_name ?? "Unnamed person"}
|
||||||
|
{isSelf && (
|
||||||
|
<span className="rounded-full bg-bronze/15 px-2.5 py-1 text-xs font-medium text-bronze">
|
||||||
|
This is you
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</h1>
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
{citeControl("p", { person_id: personId }, personCites)}
|
{citeControl("p", { person_id: personId }, personCites)}
|
||||||
<Button variant="ghost" size="sm" onClick={removePerson}>
|
{isSelf ? (
|
||||||
|
<Button variant="ghost" size="sm" onClick={() => setSelf(false)}>
|
||||||
|
Unlink me
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<Button variant="outline" size="sm" onClick={() => setSelf(true)}>
|
||||||
|
This is me
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<Button variant="outline" size="sm" onClick={() => startEditPerson(person)}>
|
||||||
|
Edit
|
||||||
|
</Button>
|
||||||
|
<Button variant="ghost" size="sm" onClick={() => setConfirmingDelete(true)}>
|
||||||
Delete
|
Delete
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{confirmingDelete && (
|
||||||
|
<div className="space-y-3 rounded-lg border border-bronze/40 bg-bronze/[0.05] p-4">
|
||||||
|
<p className="text-sm">
|
||||||
|
Delete <strong>{person.primary_name ?? "this person"}</strong>? Their relationships
|
||||||
|
will be removed too. This can be undone from Recovery.
|
||||||
|
</p>
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
<Button variant="ghost" size="sm" onClick={() => removePerson(false)}>
|
||||||
|
Delete only this person
|
||||||
|
</Button>
|
||||||
|
<Button variant="outline" size="sm" onClick={() => removePerson(true)}>
|
||||||
|
Delete with all descendants
|
||||||
|
</Button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setConfirmingDelete(false)}
|
||||||
|
className="text-xs text-[var(--muted)]"
|
||||||
|
>
|
||||||
|
cancel
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="text-base">Names</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-4">
|
||||||
|
{names.length === 0 ? (
|
||||||
|
<p className="text-sm text-[var(--muted)]">No names yet.</p>
|
||||||
|
) : (
|
||||||
|
<ul className="space-y-2">
|
||||||
|
{names.map((n) =>
|
||||||
|
editNameId === n.id ? (
|
||||||
|
<li key={n.id}>
|
||||||
|
<form
|
||||||
|
onSubmit={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
saveName();
|
||||||
|
}}
|
||||||
|
className="flex flex-wrap items-center gap-2"
|
||||||
|
>
|
||||||
|
<select
|
||||||
|
className={fieldCls}
|
||||||
|
value={enType}
|
||||||
|
onChange={(e) => setEnType(e.target.value)}
|
||||||
|
>
|
||||||
|
{NAME_TYPES.map((t) => (
|
||||||
|
<option key={t.value} value={t.value}>
|
||||||
|
{t.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<Input
|
||||||
|
className="h-9 w-36"
|
||||||
|
placeholder="Given"
|
||||||
|
value={enGiven}
|
||||||
|
onChange={(e) => setEnGiven(e.target.value)}
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
className="h-9 w-36"
|
||||||
|
placeholder="Surname"
|
||||||
|
value={enSurname}
|
||||||
|
onChange={(e) => setEnSurname(e.target.value)}
|
||||||
|
/>
|
||||||
|
<Button type="submit" size="sm">
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setEditNameId(null)}
|
||||||
|
className="text-xs text-[var(--muted)]"
|
||||||
|
>
|
||||||
|
cancel
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
) : (
|
||||||
|
<li
|
||||||
|
key={n.id}
|
||||||
|
className="flex flex-wrap items-center justify-between gap-2 text-sm"
|
||||||
|
>
|
||||||
|
<span className="flex items-center gap-2">
|
||||||
|
<span className="font-medium">{formatName(n)}</span>
|
||||||
|
<span className="rounded bg-[var(--border)]/50 px-1.5 py-0.5 text-xs text-[var(--muted)]">
|
||||||
|
{nameTypeLabel(n.name_type)}
|
||||||
|
</span>
|
||||||
|
{n.is_primary && (
|
||||||
|
<span className="rounded bg-bronze/15 px-1.5 py-0.5 text-xs text-bronze">
|
||||||
|
primary
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
<span className="flex items-center gap-3">
|
||||||
|
{!n.is_primary && (
|
||||||
|
<button
|
||||||
|
onClick={() => makePrimaryName(n.id)}
|
||||||
|
className="text-xs text-bronze hover:underline"
|
||||||
|
>
|
||||||
|
make primary
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
<button
|
||||||
|
onClick={() => startEditName(n)}
|
||||||
|
className="text-xs text-bronze hover:underline"
|
||||||
|
>
|
||||||
|
edit
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => removeName(n.id)}
|
||||||
|
className="text-[var(--muted)] hover:text-bronze"
|
||||||
|
aria-label="Remove"
|
||||||
|
>
|
||||||
|
×
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
<form onSubmit={addName} className="flex flex-wrap items-end gap-2">
|
||||||
|
<label className="flex flex-col gap-1">
|
||||||
|
<span className="text-xs text-[var(--muted)]">Type</span>
|
||||||
|
<select
|
||||||
|
className={fieldCls}
|
||||||
|
value={nameType}
|
||||||
|
onChange={(e) => setNameType(e.target.value)}
|
||||||
|
>
|
||||||
|
{NAME_TYPES.map((t) => (
|
||||||
|
<option key={t.value} value={t.value}>
|
||||||
|
{t.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label className="flex flex-col gap-1">
|
||||||
|
<span className="text-xs text-[var(--muted)]">Given</span>
|
||||||
|
<Input
|
||||||
|
className="h-9 w-36"
|
||||||
|
placeholder="Given"
|
||||||
|
value={nGiven}
|
||||||
|
onChange={(e) => setNGiven(e.target.value)}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label className="flex flex-col gap-1">
|
||||||
|
<span className="text-xs text-[var(--muted)]">Surname</span>
|
||||||
|
<Input
|
||||||
|
className="h-9 w-36"
|
||||||
|
placeholder="Surname"
|
||||||
|
value={nSurname}
|
||||||
|
onChange={(e) => setNSurname(e.target.value)}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<Button type="submit">Add name</Button>
|
||||||
|
</form>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
@@ -335,7 +759,72 @@ export default function PersonDetailPage() {
|
|||||||
<p className="text-sm text-[var(--muted)]">No events yet.</p>
|
<p className="text-sm text-[var(--muted)]">No events yet.</p>
|
||||||
) : (
|
) : (
|
||||||
<ul className="space-y-2">
|
<ul className="space-y-2">
|
||||||
{events.map((ev) => (
|
{events.map((ev) =>
|
||||||
|
editId === ev.id ? (
|
||||||
|
<li key={ev.id}>
|
||||||
|
<form
|
||||||
|
onSubmit={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
saveEdit();
|
||||||
|
}}
|
||||||
|
className="flex flex-wrap items-end gap-2"
|
||||||
|
>
|
||||||
|
<select
|
||||||
|
className={`${fieldCls} capitalize`}
|
||||||
|
value={edType}
|
||||||
|
onChange={(e) => setEdType(e.target.value)}
|
||||||
|
>
|
||||||
|
{EVENT_TYPES.map((t) => (
|
||||||
|
<option key={t} value={t} className="capitalize">
|
||||||
|
{t}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
{edType === "other" && (
|
||||||
|
<Input
|
||||||
|
className="h-9 w-32"
|
||||||
|
placeholder="Custom"
|
||||||
|
value={edTypeOther}
|
||||||
|
onChange={(e) => setEdTypeOther(e.target.value)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<select className={fieldCls} value={edQual} onChange={(e) => setEdQual(e.target.value)}>
|
||||||
|
<option value="exact">on</option>
|
||||||
|
<option value="about">about</option>
|
||||||
|
<option value="before">before</option>
|
||||||
|
<option value="after">after</option>
|
||||||
|
</select>
|
||||||
|
<input
|
||||||
|
className={`${fieldCls} w-14`}
|
||||||
|
inputMode="numeric"
|
||||||
|
placeholder="Day"
|
||||||
|
value={edDay}
|
||||||
|
onChange={(e) => setEdDay(e.target.value)}
|
||||||
|
/>
|
||||||
|
<select className={fieldCls} value={edMonth} onChange={(e) => setEdMonth(e.target.value)}>
|
||||||
|
<option value="">—</option>
|
||||||
|
{MONTHS.map((m, i) => (i > 0 ? <option key={i} value={i}>{m}</option> : null))}
|
||||||
|
</select>
|
||||||
|
<input
|
||||||
|
className={`${fieldCls} w-20`}
|
||||||
|
inputMode="numeric"
|
||||||
|
placeholder="Year"
|
||||||
|
value={edYear}
|
||||||
|
onChange={(e) => setEdYear(e.target.value)}
|
||||||
|
/>
|
||||||
|
<Button type="submit" size="sm">
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setEditId(null)}
|
||||||
|
className="text-xs text-[var(--muted)]"
|
||||||
|
>
|
||||||
|
cancel
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
) : (
|
||||||
<li key={ev.id} className="flex flex-wrap items-center justify-between gap-2 text-sm">
|
<li key={ev.id} className="flex flex-wrap items-center justify-between gap-2 text-sm">
|
||||||
<span>
|
<span>
|
||||||
<span className="font-medium capitalize">{ev.event_type}</span>
|
<span className="font-medium capitalize">{ev.event_type}</span>
|
||||||
@@ -345,6 +834,12 @@ export default function PersonDetailPage() {
|
|||||||
</span>
|
</span>
|
||||||
<span className="flex items-center gap-3">
|
<span className="flex items-center gap-3">
|
||||||
{citeControl(`e:${ev.id}`, { event_id: ev.id }, eventCites(ev.id))}
|
{citeControl(`e:${ev.id}`, { event_id: ev.id }, eventCites(ev.id))}
|
||||||
|
<button
|
||||||
|
onClick={() => startEdit(ev)}
|
||||||
|
className="text-xs text-bronze hover:underline"
|
||||||
|
>
|
||||||
|
edit
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => removeEvent(ev.id)}
|
onClick={() => removeEvent(ev.id)}
|
||||||
className="text-[var(--muted)] hover:text-bronze"
|
className="text-[var(--muted)] hover:text-bronze"
|
||||||
@@ -354,7 +849,8 @@ export default function PersonDetailPage() {
|
|||||||
</button>
|
</button>
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
))}
|
),
|
||||||
|
)}
|
||||||
</ul>
|
</ul>
|
||||||
)}
|
)}
|
||||||
<form onSubmit={addEvent} className="flex flex-wrap items-end gap-2">
|
<form onSubmit={addEvent} className="flex flex-wrap items-end gap-2">
|
||||||
@@ -455,14 +951,12 @@ export default function PersonDetailPage() {
|
|||||||
<option value="partner">partner</option>
|
<option value="partner">partner</option>
|
||||||
<option value="sibling">sibling</option>
|
<option value="sibling">sibling</option>
|
||||||
</select>
|
</select>
|
||||||
<select className={fieldCls} value={relOther} onChange={(e) => setRelOther(e.target.value)}>
|
<PersonCombobox
|
||||||
<option value="">— person —</option>
|
people={others}
|
||||||
{others.map((p) => (
|
value={relOther}
|
||||||
<option key={p.id} value={p.id}>
|
onChange={setRelOther}
|
||||||
{p.primary_name ?? "Unnamed"}
|
placeholder="Search for a person…"
|
||||||
</option>
|
/>
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
{(relKind === "parent" || relKind === "child") && (
|
{(relKind === "parent" || relKind === "child") && (
|
||||||
<select className={fieldCls} value={relQual} onChange={(e) => setRelQual(e.target.value as Qualifier)}>
|
<select className={fieldCls} value={relQual} onChange={(e) => setRelQual(e.target.value as Qualifier)}>
|
||||||
{QUALIFIERS.map((q) => (
|
{QUALIFIERS.map((q) => (
|
||||||
|
|||||||
@@ -3,14 +3,20 @@
|
|||||||
// Vendored from family-chart/dist/styles (the package blocks the CSS subpath export).
|
// Vendored from family-chart/dist/styles (the package blocks the CSS subpath export).
|
||||||
import "./chart.css";
|
import "./chart.css";
|
||||||
|
|
||||||
|
import Link from "next/link";
|
||||||
import { useParams, useRouter } from "next/navigation";
|
import { useParams, useRouter } from "next/navigation";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
|
|
||||||
import { api } from "@/lib/api/client";
|
import { api } from "@/lib/api/client";
|
||||||
import type { components } from "@/lib/api/schema";
|
import type { components } from "@/lib/api/schema";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { FanChart } from "@/components/fan-chart";
|
||||||
|
|
||||||
|
type Person = components["schemas"]["PersonRead"];
|
||||||
type Relationship = components["schemas"]["RelationshipRead"];
|
type Relationship = components["schemas"]["RelationshipRead"];
|
||||||
type Event = components["schemas"]["EventRead"];
|
type Event = components["schemas"]["EventRead"];
|
||||||
|
type Mode = "landscape" | "portrait" | "fan";
|
||||||
|
|
||||||
function splitName(name: string | null | undefined): [string, string] {
|
function splitName(name: string | null | undefined): [string, string] {
|
||||||
const t = (name ?? "").trim().split(/\s+/).filter(Boolean);
|
const t = (name ?? "").trim().split(/\s+/).filter(Boolean);
|
||||||
@@ -23,11 +29,19 @@ export default function TreePage() {
|
|||||||
const params = useParams<{ id: string }>();
|
const params = useParams<{ id: string }>();
|
||||||
const treeId = params.id;
|
const treeId = params.id;
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const chartRef = useRef<any>(null);
|
||||||
|
const [query, setQuery] = useState("");
|
||||||
|
|
||||||
|
const [people, setPeople] = useState<Person[]>([]);
|
||||||
|
const [rels, setRels] = useState<Relationship[]>([]);
|
||||||
|
const [events, setEvents] = useState<Event[]>([]);
|
||||||
const [status, setStatus] = useState<"loading" | "empty" | "ready" | "error">("loading");
|
const [status, setStatus] = useState<"loading" | "empty" | "ready" | "error">("loading");
|
||||||
|
const [focusId, setFocusId] = useState<string | null>(null);
|
||||||
|
const [mode, setMode] = useState<Mode>("landscape");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const p = await api.GET("/api/v1/trees/{tree_id}/persons", {
|
const p = await api.GET("/api/v1/trees/{tree_id}/persons", {
|
||||||
params: { path: { tree_id: treeId } },
|
params: { path: { tree_id: treeId } },
|
||||||
@@ -40,31 +54,61 @@ export default function TreePage() {
|
|||||||
api.GET("/api/v1/trees/{tree_id}/relationships", { params: { path: { tree_id: treeId } } }),
|
api.GET("/api/v1/trees/{tree_id}/relationships", { params: { path: { tree_id: treeId } } }),
|
||||||
api.GET("/api/v1/trees/{tree_id}/events", { params: { path: { tree_id: treeId } } }),
|
api.GET("/api/v1/trees/{tree_id}/events", { params: { path: { tree_id: treeId } } }),
|
||||||
]);
|
]);
|
||||||
const people = p.data ?? [];
|
if (cancelled) return;
|
||||||
const rels: Relationship[] = r.data ?? [];
|
const ppl = p.data ?? [];
|
||||||
const events: Event[] = e.data ?? [];
|
setPeople(ppl);
|
||||||
if (people.length === 0) {
|
setRels(r.data ?? []);
|
||||||
if (!cancelled) setStatus("empty");
|
setEvents(e.data ?? []);
|
||||||
return;
|
setFocusId((cur) => cur ?? ppl[0]?.id ?? null);
|
||||||
}
|
setStatus(ppl.length ? "ready" : "empty");
|
||||||
|
})().catch(() => !cancelled && setStatus("error"));
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [router, treeId]);
|
||||||
|
|
||||||
const parentsOf = (id: string) =>
|
const byId = useMemo(() => new Map(people.map((p) => [p.id, p])), [people]);
|
||||||
rels.filter((x) => x.type === "parent_child" && x.person_to_id === id).map((x) => x.person_from_id);
|
const parentsOf = useCallback(
|
||||||
const childrenOf = (id: string) =>
|
(id: string) =>
|
||||||
rels.filter((x) => x.type === "parent_child" && x.person_from_id === id).map((x) => x.person_to_id);
|
rels.filter((x) => x.type === "parent_child" && x.person_to_id === id).map((x) => x.person_from_id),
|
||||||
const partnersOf = (id: string) =>
|
[rels],
|
||||||
|
);
|
||||||
|
const childrenOf = useCallback(
|
||||||
|
(id: string) =>
|
||||||
|
rels.filter((x) => x.type === "parent_child" && x.person_from_id === id).map((x) => x.person_to_id),
|
||||||
|
[rels],
|
||||||
|
);
|
||||||
|
const partnersOf = useCallback(
|
||||||
|
(id: string) =>
|
||||||
rels
|
rels
|
||||||
.filter((x) => x.type === "partnership" && (x.person_from_id === id || x.person_to_id === id))
|
.filter((x) => x.type === "partnership" && (x.person_from_id === id || x.person_to_id === id))
|
||||||
.map((x) => (x.person_from_id === id ? x.person_to_id : x.person_from_id));
|
.map((x) => (x.person_from_id === id ? x.person_to_id : x.person_from_id)),
|
||||||
|
[rels],
|
||||||
const birthYear = new Map<string, string>();
|
);
|
||||||
|
const years = useMemo(() => {
|
||||||
|
const m = new Map<string, string>();
|
||||||
for (const ev of events) {
|
for (const ev of events) {
|
||||||
if (ev.person_id && ev.event_type === "birth" && !birthYear.has(ev.person_id)) {
|
if (ev.person_id && ev.event_type === "birth" && !m.has(ev.person_id)) {
|
||||||
const y = ev.date_start ? ev.date_start.slice(0, 4) : ev.date_value ?? "";
|
const y = ev.date_start ? ev.date_start.slice(0, 4) : ev.date_value ?? "";
|
||||||
if (y) birthYear.set(ev.person_id, y);
|
if (y) m.set(ev.person_id, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return m;
|
||||||
|
}, [events]);
|
||||||
|
const nameOf = useCallback((id: string) => byId.get(id)?.primary_name ?? "Unknown", [byId]);
|
||||||
|
const yearOf = useCallback((id: string) => years.get(id) ?? "", [years]);
|
||||||
|
|
||||||
|
// family-chart for landscape/portrait. Intentionally not keyed on focusId —
|
||||||
|
// card clicks recenter via updateMainId without rebuilding the chart.
|
||||||
|
useEffect(() => {
|
||||||
|
if (status !== "ready" || mode === "fan" || !containerRef.current) return;
|
||||||
|
let cancelled = false;
|
||||||
|
(async () => {
|
||||||
|
// Only link to people that still exist — a soft-deleted person leaves
|
||||||
|
// dangling relationship rows, and family-chart breaks on an id with no
|
||||||
|
// matching datum. Filter them out so a deletion never blanks the tree.
|
||||||
|
const alive = new Set(people.map((pp) => pp.id));
|
||||||
|
const keep = (ids: string[]) => ids.filter((id) => alive.has(id));
|
||||||
const data = people.map((pp) => {
|
const data = people.map((pp) => {
|
||||||
const [fn, ln] = splitName(pp.primary_name);
|
const [fn, ln] = splitName(pp.primary_name);
|
||||||
return {
|
return {
|
||||||
@@ -72,56 +116,151 @@ export default function TreePage() {
|
|||||||
data: {
|
data: {
|
||||||
"first name": fn || "Unnamed",
|
"first name": fn || "Unnamed",
|
||||||
"last name": ln,
|
"last name": ln,
|
||||||
birthday: birthYear.get(pp.id) ?? "",
|
birthday: years.get(pp.id) ?? "",
|
||||||
gender: pp.gender === "female" ? "F" : "M",
|
gender: pp.gender === "female" ? "F" : "M",
|
||||||
},
|
},
|
||||||
rels: {
|
rels: {
|
||||||
spouses: partnersOf(pp.id),
|
spouses: keep(partnersOf(pp.id)),
|
||||||
parents: parentsOf(pp.id),
|
parents: keep(parentsOf(pp.id)),
|
||||||
children: childrenOf(pp.id),
|
children: keep(childrenOf(pp.id)),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
if (cancelled || !containerRef.current) return;
|
|
||||||
try {
|
|
||||||
const f3 = await import("family-chart");
|
const f3 = await import("family-chart");
|
||||||
|
if (cancelled || !containerRef.current) return;
|
||||||
containerRef.current.innerHTML = "";
|
containerRef.current.innerHTML = "";
|
||||||
const chart = f3.createChart(containerRef.current, data);
|
const chart = f3.createChart(containerRef.current, data);
|
||||||
chart.setCardHtml().setCardDisplay([["first name", "last name"], ["birthday"]]);
|
chart.setCardHtml().setCardDisplay([["first name", "last name"], ["birthday"]]);
|
||||||
chart.updateTree({ initial: true });
|
if (mode === "portrait") chart.setOrientationVertical();
|
||||||
if (!cancelled) setStatus("ready");
|
else chart.setOrientationHorizontal();
|
||||||
} catch {
|
// Show enough generations that a recenter reveals grandparents + children.
|
||||||
if (!cancelled) setStatus("error");
|
chart.setAncestryDepth?.(3);
|
||||||
}
|
chart.setProgenyDepth?.(2);
|
||||||
})().catch(() => {
|
// Default card click recenters the whole hourglass; sync focus for the
|
||||||
if (!cancelled) setStatus("error");
|
// "Open profile" link after every (re)build.
|
||||||
|
chart.setAfterUpdate?.(() => {
|
||||||
|
const md = chart.getMainDatum?.();
|
||||||
|
const id = md?.id ?? md?.data?.id;
|
||||||
|
if (id) setFocusId(id);
|
||||||
});
|
});
|
||||||
|
chartRef.current = chart;
|
||||||
|
if (focusId) chart.updateMainId(focusId);
|
||||||
|
chart.updateTree({ initial: true });
|
||||||
|
})();
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
};
|
};
|
||||||
}, [router, treeId]);
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [status, mode, people, rels, events]);
|
||||||
|
|
||||||
|
// Jump the tree (or fan) to a person and rebuild the hourglass around them.
|
||||||
|
const goTo = useCallback(
|
||||||
|
(id: string) => {
|
||||||
|
setFocusId(id);
|
||||||
|
setQuery("");
|
||||||
|
if (mode !== "fan" && chartRef.current) {
|
||||||
|
chartRef.current.updateMainId?.(id);
|
||||||
|
chartRef.current.updateTree?.();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[mode],
|
||||||
|
);
|
||||||
|
|
||||||
|
const matches = useMemo(() => {
|
||||||
|
const q = query.trim().toLowerCase();
|
||||||
|
if (!q) return [];
|
||||||
|
return people
|
||||||
|
.filter((p) => (p.primary_name ?? "").toLowerCase().includes(q))
|
||||||
|
.slice(0, 8);
|
||||||
|
}, [query, people]);
|
||||||
|
|
||||||
|
const ModeButton = ({ m, label }: { m: Mode; label: string }) => (
|
||||||
|
<button
|
||||||
|
onClick={() => setMode(m)}
|
||||||
|
className={`rounded-md px-3 py-1.5 text-sm transition-colors ${
|
||||||
|
mode === m ? "bg-bronze text-paper" : "text-[var(--muted)] hover:text-[var(--foreground)]"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
<h1 className="text-2xl font-semibold">Tree</h1>
|
<h1 className="text-2xl font-semibold">Tree</h1>
|
||||||
<span className="text-sm text-[var(--muted)]">
|
<div className="relative">
|
||||||
Drag to pan · scroll to zoom · click a person to recenter
|
<Input
|
||||||
</span>
|
value={query}
|
||||||
|
onChange={(e) => setQuery(e.target.value)}
|
||||||
|
placeholder="Find a person…"
|
||||||
|
className="w-56"
|
||||||
|
/>
|
||||||
|
{matches.length > 0 && (
|
||||||
|
<ul className="absolute z-20 mt-1 w-72 overflow-hidden rounded-lg border border-[var(--border)] bg-[var(--surface)] shadow-lg">
|
||||||
|
{matches.map((p) => (
|
||||||
|
<li key={p.id}>
|
||||||
|
<button
|
||||||
|
onClick={() => goTo(p.id)}
|
||||||
|
className="flex w-full items-center justify-between gap-3 px-3 py-2 text-left text-sm hover:bg-[var(--muted-bg,rgba(0,0,0,0.04))]"
|
||||||
|
>
|
||||||
|
<span>{p.primary_name ?? "Unnamed"}</span>
|
||||||
|
{yearOf(p.id) && (
|
||||||
|
<span className="text-xs text-[var(--muted)]">{yearOf(p.id)}</span>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<div className="flex items-center rounded-lg border border-[var(--border)] p-0.5">
|
||||||
|
<ModeButton m="landscape" label="Landscape" />
|
||||||
|
<ModeButton m="portrait" label="Portrait" />
|
||||||
|
<ModeButton m="fan" label="Fan" />
|
||||||
|
</div>
|
||||||
|
{focusId && (
|
||||||
|
<Link
|
||||||
|
href={`/trees/${treeId}/persons/${focusId}`}
|
||||||
|
className="text-sm text-bronze hover:underline"
|
||||||
|
>
|
||||||
|
Open {nameOf(focusId)} →
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{status === "empty" && (
|
{status === "empty" && (
|
||||||
<p className="text-[var(--muted)]">
|
<p className="text-[var(--muted)]">No people yet — add some under People, or import a GEDCOM.</p>
|
||||||
No people yet — add some under People, or import a GEDCOM.
|
|
||||||
</p>
|
|
||||||
)}
|
)}
|
||||||
{status === "error" && <p className="text-[var(--muted)]">Could not render the tree.</p>}
|
{status === "error" && <p className="text-[var(--muted)]">Could not render the tree.</p>}
|
||||||
|
|
||||||
|
{status === "ready" && mode === "fan" && focusId ? (
|
||||||
|
<div className="rounded-xl border border-[var(--border)] bg-[var(--surface)] p-4">
|
||||||
|
<FanChart
|
||||||
|
focusId={focusId}
|
||||||
|
parentsOf={parentsOf}
|
||||||
|
nameOf={nameOf}
|
||||||
|
yearOf={yearOf}
|
||||||
|
onSelect={setFocusId}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
<div
|
<div
|
||||||
ref={containerRef}
|
ref={containerRef}
|
||||||
className="f3 rounded-xl border border-[var(--border)]"
|
className="f3 rounded-xl border border-[var(--border)]"
|
||||||
style={{ width: "100%", height: "74vh", background: "var(--surface)" }}
|
style={{ width: "100%", height: "74vh", background: "var(--surface)" }}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<p className="text-sm text-[var(--muted)]">
|
||||||
|
{mode === "fan"
|
||||||
|
? "Click an ancestor to recenter the fan."
|
||||||
|
: "Drag to pan · scroll to zoom · click a person to recenter."}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,128 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
// Radial fan chart of a focus person's ancestors (family-chart has no fan).
|
||||||
|
// Each generation is a ring; slot p in generation g descends from slot floor(p/2)
|
||||||
|
// in g-1. Click a wedge to refocus.
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
focusId: string;
|
||||||
|
parentsOf: (id: string) => string[];
|
||||||
|
nameOf: (id: string) => string;
|
||||||
|
yearOf: (id: string) => string;
|
||||||
|
onSelect: (id: string) => void;
|
||||||
|
generations?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
const SIZE = 720;
|
||||||
|
const CENTER = SIZE / 2;
|
||||||
|
const FOCUS_R = 46;
|
||||||
|
const SPAN = Math.PI * 1.6; // 288° fan
|
||||||
|
|
||||||
|
function polar(r: number, a: number): [number, number] {
|
||||||
|
// a = 0 points up, increasing clockwise.
|
||||||
|
return [CENTER + r * Math.sin(a), CENTER - r * Math.cos(a)];
|
||||||
|
}
|
||||||
|
|
||||||
|
function sector(r0: number, r1: number, a0: number, a1: number): string {
|
||||||
|
const [x0, y0] = polar(r1, a0);
|
||||||
|
const [x1, y1] = polar(r1, a1);
|
||||||
|
const [x2, y2] = polar(r0, a1);
|
||||||
|
const [x3, y3] = polar(r0, a0);
|
||||||
|
const large = a1 - a0 > Math.PI ? 1 : 0;
|
||||||
|
return `M${x0} ${y0} A${r1} ${r1} 0 ${large} 1 ${x1} ${y1} L${x2} ${y2} A${r0} ${r0} 0 ${large} 0 ${x3} ${y3} Z`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clip(s: string, n: number): string {
|
||||||
|
return s.length > n ? s.slice(0, n - 1) + "…" : s;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function FanChart({
|
||||||
|
focusId,
|
||||||
|
parentsOf,
|
||||||
|
nameOf,
|
||||||
|
yearOf,
|
||||||
|
onSelect,
|
||||||
|
generations = 4,
|
||||||
|
}: Props) {
|
||||||
|
const gens: (string | null)[][] = [[focusId]];
|
||||||
|
for (let g = 1; g <= generations; g++) {
|
||||||
|
const row: (string | null)[] = [];
|
||||||
|
for (const slot of gens[g - 1]) {
|
||||||
|
const ps = slot ? parentsOf(slot) : [];
|
||||||
|
row.push(ps[0] ?? null, ps[1] ?? null);
|
||||||
|
}
|
||||||
|
gens.push(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
const ringT = (CENTER - 60 - FOCUS_R) / generations;
|
||||||
|
const start = -SPAN / 2;
|
||||||
|
const wedges: React.ReactNode[] = [];
|
||||||
|
|
||||||
|
for (let g = 1; g <= generations; g++) {
|
||||||
|
const row = gens[g];
|
||||||
|
const w = SPAN / row.length;
|
||||||
|
const r0 = FOCUS_R + (g - 1) * ringT;
|
||||||
|
const r1 = FOCUS_R + g * ringT;
|
||||||
|
row.forEach((id, i) => {
|
||||||
|
const a0 = start + i * w;
|
||||||
|
const a1 = start + (i + 1) * w;
|
||||||
|
const mid = (a0 + a1) / 2;
|
||||||
|
const [tx, ty] = polar((r0 + r1) / 2, mid);
|
||||||
|
let deg = (mid * 180) / Math.PI;
|
||||||
|
if (deg > 90 || deg < -90) deg += 180; // keep text upright
|
||||||
|
wedges.push(
|
||||||
|
<g
|
||||||
|
key={`${g}-${i}`}
|
||||||
|
onClick={() => id && onSelect(id)}
|
||||||
|
style={{ cursor: id ? "pointer" : "default" }}
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d={sector(r0 + 1, r1 - 1, a0 + 0.004, a1 - 0.004)}
|
||||||
|
fill={id ? "var(--surface)" : "transparent"}
|
||||||
|
stroke="var(--border)"
|
||||||
|
/>
|
||||||
|
{id && (
|
||||||
|
<text
|
||||||
|
x={tx}
|
||||||
|
y={ty}
|
||||||
|
transform={`rotate(${deg} ${tx} ${ty})`}
|
||||||
|
textAnchor="middle"
|
||||||
|
dominantBaseline="middle"
|
||||||
|
style={{ fontSize: g >= 3 ? 9 : 11, fill: "var(--foreground)" }}
|
||||||
|
>
|
||||||
|
{clip(nameOf(id), g >= 3 ? 12 : 18)}
|
||||||
|
</text>
|
||||||
|
)}
|
||||||
|
</g>,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const [fx, fy] = [CENTER, CENTER];
|
||||||
|
return (
|
||||||
|
<div className="overflow-auto">
|
||||||
|
<svg viewBox={`0 0 ${SIZE} ${SIZE}`} className="mx-auto block w-full max-w-3xl">
|
||||||
|
{wedges}
|
||||||
|
<circle cx={fx} cy={fy} r={FOCUS_R} fill="var(--color-bronze)" />
|
||||||
|
<text
|
||||||
|
x={fx}
|
||||||
|
y={fy - 4}
|
||||||
|
textAnchor="middle"
|
||||||
|
dominantBaseline="middle"
|
||||||
|
style={{ fontSize: 12, fill: "var(--color-paper)", fontWeight: 600 }}
|
||||||
|
>
|
||||||
|
{clip(nameOf(focusId), 12)}
|
||||||
|
</text>
|
||||||
|
<text
|
||||||
|
x={fx}
|
||||||
|
y={fy + 12}
|
||||||
|
textAnchor="middle"
|
||||||
|
dominantBaseline="middle"
|
||||||
|
style={{ fontSize: 10, fill: "var(--color-paper)" }}
|
||||||
|
>
|
||||||
|
{yearOf(focusId)}
|
||||||
|
</text>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
|
|
||||||
|
import type { components } from "@/lib/api/schema";
|
||||||
|
|
||||||
|
type Person = components["schemas"]["PersonRead"];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A type-to-filter person picker. Shows a text input; as you type, a dropdown
|
||||||
|
* of matching people appears. Selecting one sets `value` (a person id) and
|
||||||
|
* fills the input with their name. Replaces a plain <select> when the list is
|
||||||
|
* long enough that scanning it by hand is painful.
|
||||||
|
*/
|
||||||
|
export function PersonCombobox({
|
||||||
|
people,
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
placeholder = "Search for a person…",
|
||||||
|
className,
|
||||||
|
}: {
|
||||||
|
people: Person[];
|
||||||
|
value: string;
|
||||||
|
onChange: (id: string) => void;
|
||||||
|
placeholder?: string;
|
||||||
|
className?: string;
|
||||||
|
}) {
|
||||||
|
const [query, setQuery] = useState("");
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const wrapRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
const nameOf = useMemo(
|
||||||
|
() => new Map(people.map((p) => [p.id, p.primary_name ?? "Unnamed"])),
|
||||||
|
[people],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Keep the input text in sync when the selection changes externally
|
||||||
|
// (e.g. cleared to "" after a successful add).
|
||||||
|
useEffect(() => {
|
||||||
|
if (!value) {
|
||||||
|
setQuery("");
|
||||||
|
} else if (!open) {
|
||||||
|
setQuery(nameOf.get(value) ?? "");
|
||||||
|
}
|
||||||
|
}, [value, open, nameOf]);
|
||||||
|
|
||||||
|
// Close on outside click.
|
||||||
|
useEffect(() => {
|
||||||
|
function onDoc(e: MouseEvent) {
|
||||||
|
if (wrapRef.current && !wrapRef.current.contains(e.target as Node)) setOpen(false);
|
||||||
|
}
|
||||||
|
document.addEventListener("mousedown", onDoc);
|
||||||
|
return () => document.removeEventListener("mousedown", onDoc);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const matches = useMemo(() => {
|
||||||
|
const q = query.trim().toLowerCase();
|
||||||
|
const pool = q
|
||||||
|
? people.filter((p) => (p.primary_name ?? "").toLowerCase().includes(q))
|
||||||
|
: people;
|
||||||
|
return pool.slice(0, 10);
|
||||||
|
}, [query, people]);
|
||||||
|
|
||||||
|
const base =
|
||||||
|
"h-9 w-56 rounded-md border border-[var(--border)] bg-[var(--surface)] px-2 text-sm placeholder:text-[var(--muted)] focus-visible:border-bronze focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-bronze/40";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div ref={wrapRef} className="relative">
|
||||||
|
<input
|
||||||
|
className={`${base} ${className ?? ""}`}
|
||||||
|
value={query}
|
||||||
|
placeholder={placeholder}
|
||||||
|
onFocus={() => setOpen(true)}
|
||||||
|
onChange={(e) => {
|
||||||
|
setQuery(e.target.value);
|
||||||
|
setOpen(true);
|
||||||
|
if (value) onChange(""); // typing invalidates the prior pick
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{open && matches.length > 0 && (
|
||||||
|
<ul className="absolute z-30 mt-1 max-h-64 w-72 overflow-auto rounded-lg border border-[var(--border)] bg-[var(--surface)] shadow-lg">
|
||||||
|
{matches.map((p) => (
|
||||||
|
<li key={p.id}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
onChange(p.id);
|
||||||
|
setQuery(p.primary_name ?? "Unnamed");
|
||||||
|
setOpen(false);
|
||||||
|
}}
|
||||||
|
className={`block w-full px-3 py-2 text-left text-sm hover:bg-[var(--muted-bg,rgba(0,0,0,0.04))] ${
|
||||||
|
p.id === value ? "text-bronze" : ""
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{p.primary_name ?? "Unnamed"}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
Vendored
+785
-11
@@ -157,6 +157,26 @@ export interface paths {
|
|||||||
patch?: never;
|
patch?: never;
|
||||||
trace?: never;
|
trace?: never;
|
||||||
};
|
};
|
||||||
|
"/api/v1/users/me/self-person": {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
get?: never;
|
||||||
|
put?: never;
|
||||||
|
post?: never;
|
||||||
|
delete?: never;
|
||||||
|
options?: never;
|
||||||
|
head?: never;
|
||||||
|
/**
|
||||||
|
* Set Self Person
|
||||||
|
* @description Link (or unlink) the Person record that represents this account.
|
||||||
|
*/
|
||||||
|
patch: operations["set_self_person_api_v1_users_me_self_person_patch"];
|
||||||
|
trace?: never;
|
||||||
|
};
|
||||||
"/api/v1/trees": {
|
"/api/v1/trees": {
|
||||||
parameters: {
|
parameters: {
|
||||||
query?: never;
|
query?: never;
|
||||||
@@ -190,7 +210,8 @@ export interface paths {
|
|||||||
delete: operations["delete_tree_api_v1_trees__tree_id__delete"];
|
delete: operations["delete_tree_api_v1_trees__tree_id__delete"];
|
||||||
options?: never;
|
options?: never;
|
||||||
head?: never;
|
head?: never;
|
||||||
patch?: never;
|
/** Update Tree */
|
||||||
|
patch: operations["update_tree_api_v1_trees__tree_id__patch"];
|
||||||
trace?: never;
|
trace?: never;
|
||||||
};
|
};
|
||||||
"/api/v1/trees/{tree_id}/restore": {
|
"/api/v1/trees/{tree_id}/restore": {
|
||||||
@@ -239,11 +260,16 @@ export interface paths {
|
|||||||
get: operations["get_person_api_v1_trees__tree_id__persons__person_id__get"];
|
get: operations["get_person_api_v1_trees__tree_id__persons__person_id__get"];
|
||||||
put?: never;
|
put?: never;
|
||||||
post?: never;
|
post?: never;
|
||||||
/** Delete Person */
|
/**
|
||||||
|
* Delete Person
|
||||||
|
* @description Delete a person. ``cascade=true`` also deletes all descendants. Returns
|
||||||
|
* the number of persons deleted (1 unless cascading).
|
||||||
|
*/
|
||||||
delete: operations["delete_person_api_v1_trees__tree_id__persons__person_id__delete"];
|
delete: operations["delete_person_api_v1_trees__tree_id__persons__person_id__delete"];
|
||||||
options?: never;
|
options?: never;
|
||||||
head?: never;
|
head?: never;
|
||||||
patch?: never;
|
/** Update Person */
|
||||||
|
patch: operations["update_person_api_v1_trees__tree_id__persons__person_id__patch"];
|
||||||
trace?: never;
|
trace?: never;
|
||||||
};
|
};
|
||||||
"/api/v1/trees/{tree_id}/persons/{person_id}/restore": {
|
"/api/v1/trees/{tree_id}/persons/{person_id}/restore": {
|
||||||
@@ -263,6 +289,42 @@ export interface paths {
|
|||||||
patch?: never;
|
patch?: never;
|
||||||
trace?: never;
|
trace?: never;
|
||||||
};
|
};
|
||||||
|
"/api/v1/trees/{tree_id}/persons/{person_id}/names": {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
/** List Names */
|
||||||
|
get: operations["list_names_api_v1_trees__tree_id__persons__person_id__names_get"];
|
||||||
|
put?: never;
|
||||||
|
/** Create Name */
|
||||||
|
post: operations["create_name_api_v1_trees__tree_id__persons__person_id__names_post"];
|
||||||
|
delete?: never;
|
||||||
|
options?: never;
|
||||||
|
head?: never;
|
||||||
|
patch?: never;
|
||||||
|
trace?: never;
|
||||||
|
};
|
||||||
|
"/api/v1/trees/{tree_id}/persons/{person_id}/names/{name_id}": {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
get?: never;
|
||||||
|
put?: never;
|
||||||
|
post?: never;
|
||||||
|
/** Delete Name */
|
||||||
|
delete: operations["delete_name_api_v1_trees__tree_id__persons__person_id__names__name_id__delete"];
|
||||||
|
options?: never;
|
||||||
|
head?: never;
|
||||||
|
/** Update Name */
|
||||||
|
patch: operations["update_name_api_v1_trees__tree_id__persons__person_id__names__name_id__patch"];
|
||||||
|
trace?: never;
|
||||||
|
};
|
||||||
"/api/v1/trees/{tree_id}/events": {
|
"/api/v1/trees/{tree_id}/events": {
|
||||||
parameters: {
|
parameters: {
|
||||||
query?: never;
|
query?: never;
|
||||||
@@ -312,7 +374,8 @@ export interface paths {
|
|||||||
delete: operations["delete_event_api_v1_trees__tree_id__events__event_id__delete"];
|
delete: operations["delete_event_api_v1_trees__tree_id__events__event_id__delete"];
|
||||||
options?: never;
|
options?: never;
|
||||||
head?: never;
|
head?: never;
|
||||||
patch?: never;
|
/** Update Event */
|
||||||
|
patch: operations["update_event_api_v1_trees__tree_id__events__event_id__patch"];
|
||||||
trace?: never;
|
trace?: never;
|
||||||
};
|
};
|
||||||
"/api/v1/trees/{tree_id}/relationships": {
|
"/api/v1/trees/{tree_id}/relationships": {
|
||||||
@@ -364,7 +427,8 @@ export interface paths {
|
|||||||
delete: operations["delete_relationship_api_v1_trees__tree_id__relationships__relationship_id__delete"];
|
delete: operations["delete_relationship_api_v1_trees__tree_id__relationships__relationship_id__delete"];
|
||||||
options?: never;
|
options?: never;
|
||||||
head?: never;
|
head?: never;
|
||||||
patch?: never;
|
/** Update Relationship */
|
||||||
|
patch: operations["update_relationship_api_v1_trees__tree_id__relationships__relationship_id__patch"];
|
||||||
trace?: never;
|
trace?: never;
|
||||||
};
|
};
|
||||||
"/api/v1/trees/{tree_id}/sources": {
|
"/api/v1/trees/{tree_id}/sources": {
|
||||||
@@ -400,7 +464,8 @@ export interface paths {
|
|||||||
delete: operations["delete_source_api_v1_trees__tree_id__sources__source_id__delete"];
|
delete: operations["delete_source_api_v1_trees__tree_id__sources__source_id__delete"];
|
||||||
options?: never;
|
options?: never;
|
||||||
head?: never;
|
head?: never;
|
||||||
patch?: never;
|
/** Update Source */
|
||||||
|
patch: operations["update_source_api_v1_trees__tree_id__sources__source_id__patch"];
|
||||||
trace?: never;
|
trace?: never;
|
||||||
};
|
};
|
||||||
"/api/v1/trees/{tree_id}/citations": {
|
"/api/v1/trees/{tree_id}/citations": {
|
||||||
@@ -435,7 +500,8 @@ export interface paths {
|
|||||||
delete: operations["delete_citation_api_v1_trees__tree_id__citations__citation_id__delete"];
|
delete: operations["delete_citation_api_v1_trees__tree_id__citations__citation_id__delete"];
|
||||||
options?: never;
|
options?: never;
|
||||||
head?: never;
|
head?: never;
|
||||||
patch?: never;
|
/** Update Citation */
|
||||||
|
patch: operations["update_citation_api_v1_trees__tree_id__citations__citation_id__patch"];
|
||||||
trace?: never;
|
trace?: never;
|
||||||
};
|
};
|
||||||
"/api/v1/trees/{tree_id}/media": {
|
"/api/v1/trees/{tree_id}/media": {
|
||||||
@@ -487,6 +553,28 @@ export interface paths {
|
|||||||
delete: operations["delete_media_api_v1_trees__tree_id__media__media_id__delete"];
|
delete: operations["delete_media_api_v1_trees__tree_id__media__media_id__delete"];
|
||||||
options?: never;
|
options?: never;
|
||||||
head?: never;
|
head?: never;
|
||||||
|
/** Update Media */
|
||||||
|
patch: operations["update_media_api_v1_trees__tree_id__media__media_id__patch"];
|
||||||
|
trace?: never;
|
||||||
|
};
|
||||||
|
"/api/v1/trees/{tree_id}/gedcom/preview": {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
get?: never;
|
||||||
|
put?: never;
|
||||||
|
/**
|
||||||
|
* Preview Gedcom
|
||||||
|
* @description Dry run: report counts and incoming people that look like duplicates of
|
||||||
|
* existing ones, so the user can choose how to resolve each before importing.
|
||||||
|
*/
|
||||||
|
post: operations["preview_gedcom_api_v1_trees__tree_id__gedcom_preview_post"];
|
||||||
|
delete?: never;
|
||||||
|
options?: never;
|
||||||
|
head?: never;
|
||||||
patch?: never;
|
patch?: never;
|
||||||
trace?: never;
|
trace?: never;
|
||||||
};
|
};
|
||||||
@@ -499,7 +587,12 @@ export interface paths {
|
|||||||
};
|
};
|
||||||
get?: never;
|
get?: never;
|
||||||
put?: never;
|
put?: never;
|
||||||
/** Import Gedcom */
|
/**
|
||||||
|
* Import Gedcom
|
||||||
|
* @description Import a GEDCOM. ``default_action`` (new|skip|merge|overwrite) applies to
|
||||||
|
* incoming people that match an existing one; ``resolutions`` is a JSON object
|
||||||
|
* {xref: {action, target_id}} overriding it per record.
|
||||||
|
*/
|
||||||
post: operations["import_gedcom_api_v1_trees__tree_id__gedcom_import_post"];
|
post: operations["import_gedcom_api_v1_trees__tree_id__gedcom_import_post"];
|
||||||
delete?: never;
|
delete?: never;
|
||||||
options?: never;
|
options?: never;
|
||||||
@@ -532,6 +625,21 @@ export interface components {
|
|||||||
Body_import_gedcom_api_v1_trees__tree_id__gedcom_import_post: {
|
Body_import_gedcom_api_v1_trees__tree_id__gedcom_import_post: {
|
||||||
/** File */
|
/** File */
|
||||||
file: string;
|
file: string;
|
||||||
|
/**
|
||||||
|
* Default Action
|
||||||
|
* @default new
|
||||||
|
*/
|
||||||
|
default_action?: string;
|
||||||
|
/**
|
||||||
|
* Resolutions
|
||||||
|
* @default {}
|
||||||
|
*/
|
||||||
|
resolutions?: string;
|
||||||
|
};
|
||||||
|
/** Body_preview_gedcom_api_v1_trees__tree_id__gedcom_preview_post */
|
||||||
|
Body_preview_gedcom_api_v1_trees__tree_id__gedcom_preview_post: {
|
||||||
|
/** File */
|
||||||
|
file: string;
|
||||||
};
|
};
|
||||||
/** Body_upload_media_api_v1_trees__tree_id__media_post */
|
/** Body_upload_media_api_v1_trees__tree_id__media_post */
|
||||||
Body_upload_media_api_v1_trees__tree_id__media_post: {
|
Body_upload_media_api_v1_trees__tree_id__media_post: {
|
||||||
@@ -608,6 +716,34 @@ export interface components {
|
|||||||
*/
|
*/
|
||||||
created_at: string;
|
created_at: string;
|
||||||
};
|
};
|
||||||
|
/** CitationUpdate */
|
||||||
|
CitationUpdate: {
|
||||||
|
/** Page */
|
||||||
|
page?: string | null;
|
||||||
|
/** Detail */
|
||||||
|
detail?: string | null;
|
||||||
|
confidence?: components["schemas"]["CitationConfidence"] | null;
|
||||||
|
};
|
||||||
|
/** DuplicateMatch */
|
||||||
|
DuplicateMatch: {
|
||||||
|
/** Xref */
|
||||||
|
xref: string;
|
||||||
|
/** Incoming Name */
|
||||||
|
incoming_name: string;
|
||||||
|
/** Incoming Birth Year */
|
||||||
|
incoming_birth_year?: string | null;
|
||||||
|
/**
|
||||||
|
* Existing Person Id
|
||||||
|
* Format: uuid
|
||||||
|
*/
|
||||||
|
existing_person_id: string;
|
||||||
|
/** Existing Name */
|
||||||
|
existing_name: string;
|
||||||
|
/** Existing Birth Year */
|
||||||
|
existing_birth_year?: string | null;
|
||||||
|
/** Score */
|
||||||
|
score: string;
|
||||||
|
};
|
||||||
/** EventCreate */
|
/** EventCreate */
|
||||||
EventCreate: {
|
EventCreate: {
|
||||||
/** Event Type */
|
/** Event Type */
|
||||||
@@ -676,11 +812,43 @@ export interface components {
|
|||||||
*/
|
*/
|
||||||
created_at: string;
|
created_at: string;
|
||||||
};
|
};
|
||||||
|
/** EventUpdate */
|
||||||
|
EventUpdate: {
|
||||||
|
/** Event Type */
|
||||||
|
event_type?: string | null;
|
||||||
|
/** Place Id */
|
||||||
|
place_id?: string | null;
|
||||||
|
/** Date Value */
|
||||||
|
date_value?: string | null;
|
||||||
|
/** Date Start */
|
||||||
|
date_start?: string | null;
|
||||||
|
/** Date End */
|
||||||
|
date_end?: string | null;
|
||||||
|
/** Date Precision */
|
||||||
|
date_precision?: string | null;
|
||||||
|
/** Calendar */
|
||||||
|
calendar?: string | null;
|
||||||
|
/** Detail */
|
||||||
|
detail?: string | null;
|
||||||
|
/** Notes */
|
||||||
|
notes?: string | null;
|
||||||
|
};
|
||||||
/** HTTPValidationError */
|
/** HTTPValidationError */
|
||||||
HTTPValidationError: {
|
HTTPValidationError: {
|
||||||
/** Detail */
|
/** Detail */
|
||||||
detail?: components["schemas"]["ValidationError"][];
|
detail?: components["schemas"]["ValidationError"][];
|
||||||
};
|
};
|
||||||
|
/** ImportPreview */
|
||||||
|
ImportPreview: {
|
||||||
|
/** Counts */
|
||||||
|
counts: {
|
||||||
|
[key: string]: number;
|
||||||
|
};
|
||||||
|
/** Potential Duplicates */
|
||||||
|
potential_duplicates: components["schemas"]["DuplicateMatch"][];
|
||||||
|
/** Unmapped Tags */
|
||||||
|
unmapped_tags: string[];
|
||||||
|
};
|
||||||
/** ImportReport */
|
/** ImportReport */
|
||||||
ImportReport: {
|
ImportReport: {
|
||||||
/** Counts */
|
/** Counts */
|
||||||
@@ -733,6 +901,96 @@ export interface components {
|
|||||||
/** Url */
|
/** Url */
|
||||||
url?: string | null;
|
url?: string | null;
|
||||||
};
|
};
|
||||||
|
/** MediaUpdate */
|
||||||
|
MediaUpdate: {
|
||||||
|
/** Title */
|
||||||
|
title?: string | null;
|
||||||
|
/** Person Id */
|
||||||
|
person_id?: string | null;
|
||||||
|
/** Event Id */
|
||||||
|
event_id?: string | null;
|
||||||
|
/** Source Id */
|
||||||
|
source_id?: string | null;
|
||||||
|
};
|
||||||
|
/** NameCreate */
|
||||||
|
NameCreate: {
|
||||||
|
/**
|
||||||
|
* Name Type
|
||||||
|
* @default birth
|
||||||
|
*/
|
||||||
|
name_type?: string;
|
||||||
|
/** Given */
|
||||||
|
given?: string | null;
|
||||||
|
/** Surname */
|
||||||
|
surname?: string | null;
|
||||||
|
/** Prefix */
|
||||||
|
prefix?: string | null;
|
||||||
|
/** Suffix */
|
||||||
|
suffix?: string | null;
|
||||||
|
/** Nickname */
|
||||||
|
nickname?: string | null;
|
||||||
|
/**
|
||||||
|
* Is Primary
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
is_primary?: boolean;
|
||||||
|
};
|
||||||
|
/** NameRead */
|
||||||
|
NameRead: {
|
||||||
|
/**
|
||||||
|
* Id
|
||||||
|
* Format: uuid
|
||||||
|
*/
|
||||||
|
id: string;
|
||||||
|
/**
|
||||||
|
* Tree Id
|
||||||
|
* Format: uuid
|
||||||
|
*/
|
||||||
|
tree_id: string;
|
||||||
|
/**
|
||||||
|
* Person Id
|
||||||
|
* Format: uuid
|
||||||
|
*/
|
||||||
|
person_id: string;
|
||||||
|
/** Name Type */
|
||||||
|
name_type: string;
|
||||||
|
/** Given */
|
||||||
|
given: string | null;
|
||||||
|
/** Surname */
|
||||||
|
surname: string | null;
|
||||||
|
/** Prefix */
|
||||||
|
prefix: string | null;
|
||||||
|
/** Suffix */
|
||||||
|
suffix: string | null;
|
||||||
|
/** Nickname */
|
||||||
|
nickname: string | null;
|
||||||
|
/** Is Primary */
|
||||||
|
is_primary: boolean;
|
||||||
|
/** Sort Order */
|
||||||
|
sort_order: number;
|
||||||
|
/**
|
||||||
|
* Created At
|
||||||
|
* Format: date-time
|
||||||
|
*/
|
||||||
|
created_at: string;
|
||||||
|
};
|
||||||
|
/** NameUpdate */
|
||||||
|
NameUpdate: {
|
||||||
|
/** Name Type */
|
||||||
|
name_type?: string | null;
|
||||||
|
/** Given */
|
||||||
|
given?: string | null;
|
||||||
|
/** Surname */
|
||||||
|
surname?: string | null;
|
||||||
|
/** Prefix */
|
||||||
|
prefix?: string | null;
|
||||||
|
/** Suffix */
|
||||||
|
suffix?: string | null;
|
||||||
|
/** Nickname */
|
||||||
|
nickname?: string | null;
|
||||||
|
/** Is Primary */
|
||||||
|
is_primary?: boolean | null;
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* ParentChildQualifier
|
* ParentChildQualifier
|
||||||
* @description Qualifies a parent_child edge so adoption/donor/blended families are
|
* @description Qualifies a parent_child edge so adoption/donor/blended families are
|
||||||
@@ -798,6 +1056,20 @@ export interface components {
|
|||||||
*/
|
*/
|
||||||
created_at: string;
|
created_at: string;
|
||||||
};
|
};
|
||||||
|
/** PersonUpdate */
|
||||||
|
PersonUpdate: {
|
||||||
|
/** Given */
|
||||||
|
given?: string | null;
|
||||||
|
/** Surname */
|
||||||
|
surname?: string | null;
|
||||||
|
/** Gender */
|
||||||
|
gender?: string | null;
|
||||||
|
/** Is Living */
|
||||||
|
is_living?: boolean | null;
|
||||||
|
privacy?: components["schemas"]["PersonPrivacy"] | null;
|
||||||
|
/** Notes */
|
||||||
|
notes?: string | null;
|
||||||
|
};
|
||||||
/** RegisterRequest */
|
/** RegisterRequest */
|
||||||
RegisterRequest: {
|
RegisterRequest: {
|
||||||
/** Email */
|
/** Email */
|
||||||
@@ -861,6 +1133,12 @@ export interface components {
|
|||||||
* @enum {string}
|
* @enum {string}
|
||||||
*/
|
*/
|
||||||
RelationshipType: "parent_child" | "partnership" | "sibling";
|
RelationshipType: "parent_child" | "partnership" | "sibling";
|
||||||
|
/** RelationshipUpdate */
|
||||||
|
RelationshipUpdate: {
|
||||||
|
qualifier?: components["schemas"]["ParentChildQualifier"] | null;
|
||||||
|
/** Notes */
|
||||||
|
notes?: string | null;
|
||||||
|
};
|
||||||
/** SessionRead */
|
/** SessionRead */
|
||||||
SessionRead: {
|
SessionRead: {
|
||||||
user: components["schemas"]["UserRead"];
|
user: components["schemas"]["UserRead"];
|
||||||
@@ -925,6 +1203,25 @@ export interface components {
|
|||||||
*/
|
*/
|
||||||
created_at: string;
|
created_at: string;
|
||||||
};
|
};
|
||||||
|
/** SourceUpdate */
|
||||||
|
SourceUpdate: {
|
||||||
|
/** Title */
|
||||||
|
title?: string | null;
|
||||||
|
/** Author */
|
||||||
|
author?: string | null;
|
||||||
|
/** Source Type */
|
||||||
|
source_type?: string | null;
|
||||||
|
/** Repository */
|
||||||
|
repository?: string | null;
|
||||||
|
/** Url */
|
||||||
|
url?: string | null;
|
||||||
|
/** Citation Text */
|
||||||
|
citation_text?: string | null;
|
||||||
|
/** Publication Info */
|
||||||
|
publication_info?: string | null;
|
||||||
|
/** Quality Note */
|
||||||
|
quality_note?: string | null;
|
||||||
|
};
|
||||||
/** TokenRequest */
|
/** TokenRequest */
|
||||||
TokenRequest: {
|
TokenRequest: {
|
||||||
/** Token */
|
/** Token */
|
||||||
@@ -962,6 +1259,14 @@ export interface components {
|
|||||||
*/
|
*/
|
||||||
created_at: string;
|
created_at: string;
|
||||||
};
|
};
|
||||||
|
/** TreeUpdate */
|
||||||
|
TreeUpdate: {
|
||||||
|
/** Name */
|
||||||
|
name?: string | null;
|
||||||
|
/** Description */
|
||||||
|
description?: string | null;
|
||||||
|
visibility?: components["schemas"]["TreeVisibility"] | null;
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* TreeVisibility
|
* TreeVisibility
|
||||||
* @enum {string}
|
* @enum {string}
|
||||||
@@ -980,12 +1285,19 @@ export interface components {
|
|||||||
display_name: string | null;
|
display_name: string | null;
|
||||||
/** Email Verified At */
|
/** Email Verified At */
|
||||||
email_verified_at: string | null;
|
email_verified_at: string | null;
|
||||||
|
/** Self Person Id */
|
||||||
|
self_person_id?: string | null;
|
||||||
/**
|
/**
|
||||||
* Created At
|
* Created At
|
||||||
* Format: date-time
|
* Format: date-time
|
||||||
*/
|
*/
|
||||||
created_at: string;
|
created_at: string;
|
||||||
};
|
};
|
||||||
|
/** UserSelfPersonUpdate */
|
||||||
|
UserSelfPersonUpdate: {
|
||||||
|
/** Self Person Id */
|
||||||
|
self_person_id?: string | null;
|
||||||
|
};
|
||||||
/** ValidationError */
|
/** ValidationError */
|
||||||
ValidationError: {
|
ValidationError: {
|
||||||
/** Location */
|
/** Location */
|
||||||
@@ -1253,6 +1565,39 @@ export interface operations {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
set_self_person_api_v1_users_me_self_person_patch: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody: {
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["UserSelfPersonUpdate"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["UserRead"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
list_my_trees_api_v1_trees_get: {
|
list_my_trees_api_v1_trees_get: {
|
||||||
parameters: {
|
parameters: {
|
||||||
query?: {
|
query?: {
|
||||||
@@ -1377,6 +1722,41 @@ export interface operations {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
update_tree_api_v1_trees__tree_id__patch: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
tree_id: string;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody: {
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["TreeUpdate"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["TreeRead"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
restore_tree_api_v1_trees__tree_id__restore_post: {
|
restore_tree_api_v1_trees__tree_id__restore_post: {
|
||||||
parameters: {
|
parameters: {
|
||||||
query?: never;
|
query?: never;
|
||||||
@@ -1412,6 +1792,7 @@ export interface operations {
|
|||||||
parameters: {
|
parameters: {
|
||||||
query?: {
|
query?: {
|
||||||
deleted?: boolean;
|
deleted?: boolean;
|
||||||
|
q?: string | null;
|
||||||
};
|
};
|
||||||
header?: never;
|
header?: never;
|
||||||
path: {
|
path: {
|
||||||
@@ -1510,7 +1891,9 @@ export interface operations {
|
|||||||
};
|
};
|
||||||
delete_person_api_v1_trees__tree_id__persons__person_id__delete: {
|
delete_person_api_v1_trees__tree_id__persons__person_id__delete: {
|
||||||
parameters: {
|
parameters: {
|
||||||
query?: never;
|
query?: {
|
||||||
|
cascade?: boolean;
|
||||||
|
};
|
||||||
header?: never;
|
header?: never;
|
||||||
path: {
|
path: {
|
||||||
tree_id: string;
|
tree_id: string;
|
||||||
@@ -1521,11 +1904,51 @@ export interface operations {
|
|||||||
requestBody?: never;
|
requestBody?: never;
|
||||||
responses: {
|
responses: {
|
||||||
/** @description Successful Response */
|
/** @description Successful Response */
|
||||||
204: {
|
200: {
|
||||||
headers: {
|
headers: {
|
||||||
[name: string]: unknown;
|
[name: string]: unknown;
|
||||||
};
|
};
|
||||||
content?: never;
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
[key: string]: number;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
update_person_api_v1_trees__tree_id__persons__person_id__patch: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
tree_id: string;
|
||||||
|
person_id: string;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody: {
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["PersonUpdate"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["PersonRead"];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
/** @description Validation Error */
|
/** @description Validation Error */
|
||||||
422: {
|
422: {
|
||||||
@@ -1570,6 +1993,142 @@ export interface operations {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
list_names_api_v1_trees__tree_id__persons__person_id__names_get: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
tree_id: string;
|
||||||
|
person_id: string;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody?: never;
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["NameRead"][];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
create_name_api_v1_trees__tree_id__persons__person_id__names_post: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
tree_id: string;
|
||||||
|
person_id: string;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody: {
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["NameCreate"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
201: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["NameRead"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
delete_name_api_v1_trees__tree_id__persons__person_id__names__name_id__delete: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
tree_id: string;
|
||||||
|
person_id: string;
|
||||||
|
name_id: string;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody?: never;
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
204: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content?: never;
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
update_name_api_v1_trees__tree_id__persons__person_id__names__name_id__patch: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
tree_id: string;
|
||||||
|
person_id: string;
|
||||||
|
name_id: string;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody: {
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["NameUpdate"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["NameRead"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
list_tree_events_api_v1_trees__tree_id__events_get: {
|
list_tree_events_api_v1_trees__tree_id__events_get: {
|
||||||
parameters: {
|
parameters: {
|
||||||
query?: never;
|
query?: never;
|
||||||
@@ -1698,6 +2257,42 @@ export interface operations {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
update_event_api_v1_trees__tree_id__events__event_id__patch: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
tree_id: string;
|
||||||
|
event_id: string;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody: {
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["EventUpdate"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["EventRead"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
list_relationships_api_v1_trees__tree_id__relationships_get: {
|
list_relationships_api_v1_trees__tree_id__relationships_get: {
|
||||||
parameters: {
|
parameters: {
|
||||||
query?: never;
|
query?: never;
|
||||||
@@ -1826,6 +2421,42 @@ export interface operations {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
update_relationship_api_v1_trees__tree_id__relationships__relationship_id__patch: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
tree_id: string;
|
||||||
|
relationship_id: string;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody: {
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["RelationshipUpdate"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["RelationshipRead"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
list_sources_api_v1_trees__tree_id__sources_get: {
|
list_sources_api_v1_trees__tree_id__sources_get: {
|
||||||
parameters: {
|
parameters: {
|
||||||
query?: never;
|
query?: never;
|
||||||
@@ -1954,6 +2585,42 @@ export interface operations {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
update_source_api_v1_trees__tree_id__sources__source_id__patch: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
tree_id: string;
|
||||||
|
source_id: string;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody: {
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["SourceUpdate"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["SourceRead"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
list_citations_api_v1_trees__tree_id__citations_get: {
|
list_citations_api_v1_trees__tree_id__citations_get: {
|
||||||
parameters: {
|
parameters: {
|
||||||
query?: never;
|
query?: never;
|
||||||
@@ -2050,6 +2717,42 @@ export interface operations {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
update_citation_api_v1_trees__tree_id__citations__citation_id__patch: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
tree_id: string;
|
||||||
|
citation_id: string;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody: {
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["CitationUpdate"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["CitationRead"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
list_media_api_v1_trees__tree_id__media_get: {
|
list_media_api_v1_trees__tree_id__media_get: {
|
||||||
parameters: {
|
parameters: {
|
||||||
query?: never;
|
query?: never;
|
||||||
@@ -2178,6 +2881,77 @@ export interface operations {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
update_media_api_v1_trees__tree_id__media__media_id__patch: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
tree_id: string;
|
||||||
|
media_id: string;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody: {
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["MediaUpdate"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["MediaRead"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
preview_gedcom_api_v1_trees__tree_id__gedcom_preview_post: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
tree_id: string;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody: {
|
||||||
|
content: {
|
||||||
|
"multipart/form-data": components["schemas"]["Body_preview_gedcom_api_v1_trees__tree_id__gedcom_preview_post"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["ImportPreview"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
import_gedcom_api_v1_trees__tree_id__gedcom_import_post: {
|
import_gedcom_api_v1_trees__tree_id__gedcom_import_post: {
|
||||||
parameters: {
|
parameters: {
|
||||||
query?: never;
|
query?: never;
|
||||||
|
|||||||
+1634
-5
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user