29 lines
886 B
Python
29 lines
886 B
Python
"""Definition of verify_child_access function."""
|
|
|
|
from fastapi import HTTPException
|
|
from baby_monitor.repositories.interfaces import (
|
|
ChildRepositoryInterface,
|
|
)
|
|
|
|
|
|
def verify_child_access(
|
|
child_repo: ChildRepositoryInterface, child_id: int, user_id: int
|
|
) -> None:
|
|
"""Verify that user has access to the child.
|
|
|
|
Args:
|
|
child_repo: Child repository instance
|
|
child_id: ID of the child to verify access for
|
|
user_id: ID of the user requesting access
|
|
|
|
Raises:
|
|
HTTPException: 404 if child not found, 403 if user is not a parent
|
|
"""
|
|
child = child_repo.get_by_id(child_id)
|
|
if not child:
|
|
raise HTTPException(status_code=404, detail="Child not found")
|
|
|
|
parent_ids = child_repo.get_parent_ids(child_id)
|
|
if user_id not in parent_ids:
|
|
raise HTTPException(status_code=403, detail="Access denied to this child")
|