Decoupling audit cleanup: fix protocol gaps, remove dead APIs
- Add search_posts, entry_ids_for_content, visible_entries_for_period to protocols and stubs - Delete internal_api.py and factory cleanup hook (zero callers) - Convert utils.py to utils/ package with calendar_helpers module - Remove deleted_at check from calendar_view template (service filters) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ calendar-domain tables on behalf of other domains.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from sqlalchemy import select, update, func
|
||||
@@ -168,6 +169,75 @@ class SqlCalendarService:
|
||||
)
|
||||
return set(result.scalars().all())
|
||||
|
||||
async def visible_entries_for_period(
|
||||
self, session: AsyncSession, calendar_id: int,
|
||||
period_start: datetime, period_end: datetime,
|
||||
*, user_id: int | None, is_admin: bool, session_id: str | None,
|
||||
) -> list[CalendarEntryDTO]:
|
||||
"""Return visible entries for a calendar in a date range.
|
||||
|
||||
Visibility rules:
|
||||
- Everyone sees confirmed entries.
|
||||
- Current user/session sees their own entries (any state).
|
||||
- Admins also see ordered + provisional entries for all users.
|
||||
"""
|
||||
# User/session entries (any state)
|
||||
user_entries: list[CalendarEntry] = []
|
||||
if user_id or session_id:
|
||||
conditions = [
|
||||
CalendarEntry.calendar_id == calendar_id,
|
||||
CalendarEntry.deleted_at.is_(None),
|
||||
CalendarEntry.start_at >= period_start,
|
||||
CalendarEntry.start_at < period_end,
|
||||
]
|
||||
if user_id:
|
||||
conditions.append(CalendarEntry.user_id == user_id)
|
||||
elif session_id:
|
||||
conditions.append(CalendarEntry.session_id == session_id)
|
||||
result = await session.execute(
|
||||
select(CalendarEntry).where(*conditions)
|
||||
.options(selectinload(CalendarEntry.calendar))
|
||||
)
|
||||
user_entries = list(result.scalars().all())
|
||||
|
||||
# Confirmed entries for everyone
|
||||
result = await session.execute(
|
||||
select(CalendarEntry).where(
|
||||
CalendarEntry.calendar_id == calendar_id,
|
||||
CalendarEntry.state == "confirmed",
|
||||
CalendarEntry.deleted_at.is_(None),
|
||||
CalendarEntry.start_at >= period_start,
|
||||
CalendarEntry.start_at < period_end,
|
||||
).options(selectinload(CalendarEntry.calendar))
|
||||
)
|
||||
confirmed_entries = list(result.scalars().all())
|
||||
|
||||
# Admin: ordered + provisional for everyone
|
||||
admin_entries: list[CalendarEntry] = []
|
||||
if is_admin:
|
||||
result = await session.execute(
|
||||
select(CalendarEntry).where(
|
||||
CalendarEntry.calendar_id == calendar_id,
|
||||
CalendarEntry.state.in_(("ordered", "provisional")),
|
||||
CalendarEntry.deleted_at.is_(None),
|
||||
CalendarEntry.start_at >= period_start,
|
||||
CalendarEntry.start_at < period_end,
|
||||
).options(selectinload(CalendarEntry.calendar))
|
||||
)
|
||||
admin_entries = list(result.scalars().all())
|
||||
|
||||
# Merge, deduplicate, sort
|
||||
entries_by_id: dict[int, CalendarEntry] = {}
|
||||
for e in confirmed_entries:
|
||||
entries_by_id[e.id] = e
|
||||
for e in admin_entries:
|
||||
entries_by_id[e.id] = e
|
||||
for e in user_entries:
|
||||
entries_by_id[e.id] = e
|
||||
|
||||
merged = sorted(entries_by_id.values(), key=lambda e: e.start_at or period_start)
|
||||
return [_entry_to_dto(e) for e in merged]
|
||||
|
||||
async def associated_entries(
|
||||
self, session: AsyncSession, content_type: str, content_id: int, page: int,
|
||||
) -> tuple[list[CalendarEntryDTO], bool]:
|
||||
|
||||
Reference in New Issue
Block a user