eb18994b7d
- Migrate 660+ datetime.utcnow() across 153 files to datetime.now(UTC) - Migrate 30+ datetime.now() without UTC to datetime.now(UTC) - Convert all 170 DateTime columns to DateTime(timezone=True) - Add migrate_datetime_to_timestamptz() in universal_migration with SET LOCAL timezone='UTC' safety - Remove 70+ .replace(tzinfo=None) workarounds - Fix utcfromtimestamp → fromtimestamp(..., tz=UTC) - Fix fromtimestamp() without tz= (system_logs, backup_service, referral_diagnostics) - Fix fromisoformat/isoparse to ensure aware output (platega, yookassa, wata, miniapp, nalogo) - Fix strptime() to add .replace(tzinfo=UTC) (backup_service, referral_diagnostics) - Fix datetime.combine() to include tzinfo=UTC (remnawave_sync, traffic_monitoring) - Fix datetime.max/datetime.min sentinels with .replace(tzinfo=UTC) - Rename panel_datetime_to_naive_utc → panel_datetime_to_utc - Remove DTZ003 from ruff ignore list
74 lines
1.9 KiB
Python
74 lines
1.9 KiB
Python
from datetime import UTC, datetime
|
|
|
|
import structlog
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.database.models import PrivacyPolicy
|
|
|
|
|
|
logger = structlog.get_logger(__name__)
|
|
|
|
|
|
async def get_privacy_policy(db: AsyncSession, language: str) -> PrivacyPolicy | None:
|
|
result = await db.execute(select(PrivacyPolicy).where(PrivacyPolicy.language == language))
|
|
return result.scalar_one_or_none()
|
|
|
|
|
|
async def upsert_privacy_policy(
|
|
db: AsyncSession,
|
|
language: str,
|
|
content: str,
|
|
*,
|
|
enable_if_new: bool = True,
|
|
) -> PrivacyPolicy:
|
|
policy = await get_privacy_policy(db, language)
|
|
|
|
if policy:
|
|
policy.content = content or ''
|
|
policy.updated_at = datetime.now(UTC)
|
|
else:
|
|
policy = PrivacyPolicy(
|
|
language=language,
|
|
content=content or '',
|
|
is_enabled=bool(enable_if_new),
|
|
)
|
|
db.add(policy)
|
|
|
|
await db.commit()
|
|
await db.refresh(policy)
|
|
|
|
logger.info('✅ Политика конфиденциальности для языка обновлена (ID:)', language=language, policy_id=policy.id)
|
|
|
|
return policy
|
|
|
|
|
|
async def set_privacy_policy_enabled(
|
|
db: AsyncSession,
|
|
language: str,
|
|
enabled: bool,
|
|
) -> PrivacyPolicy:
|
|
policy = await get_privacy_policy(db, language)
|
|
|
|
if policy:
|
|
policy.is_enabled = bool(enabled)
|
|
policy.updated_at = datetime.now(UTC)
|
|
else:
|
|
policy = PrivacyPolicy(
|
|
language=language,
|
|
content='',
|
|
is_enabled=bool(enabled),
|
|
)
|
|
db.add(policy)
|
|
|
|
await db.commit()
|
|
await db.refresh(policy)
|
|
|
|
logger.info(
|
|
'✅ Статус политики конфиденциальности для языка %s обновлен: %s',
|
|
language,
|
|
'enabled' if policy.is_enabled else 'disabled',
|
|
)
|
|
|
|
return policy
|