forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccount_deletion_marker.py
More file actions
64 lines (47 loc) · 2.62 KB
/
Copy pathaccount_deletion_marker.py
File metadata and controls
64 lines (47 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Single Firestore plane for the account_deletions/{uid} marker.
Writers (the deletion executor) and readers (the auth fence) must resolve the
same database. The marker is stored on the customer data plane; a compute-plane
default on desktop-backend is a clean miss that reopens a deleting account.
"""
from __future__ import annotations
from typing import Any
from database._client import get_data_plane_firestore_client
from database.account_deletion_policy import normalize_account_deletion_status
from database.firestore_read_metrics import FirestoreReadOutcome, FirestoreReadSite, record_document_read
ACCOUNT_DELETION_COLLECTION = "account_deletions"
def account_deletion_firestore_client(*, firestore_client: Any | None = None) -> Any:
"""The Firestore client that owns account_deletions/{uid}.
Injected clients are for tests. Production always pins the data plane so a
compute-plane fallback cannot silently miss the marker. If the data plane
cannot be resolved, this raises and the auth fence maps that to HTTP 503.
"""
if firestore_client is not None:
return firestore_client
return get_data_plane_firestore_client()
def account_deletion_collection(*, firestore_client: Any | None = None) -> Any:
return account_deletion_firestore_client(firestore_client=firestore_client).collection(ACCOUNT_DELETION_COLLECTION)
def account_deletion_document(uid: str, *, firestore_client: Any | None = None) -> Any:
return account_deletion_collection(firestore_client=firestore_client).document(uid)
def get_user_deletion_wipe_status(uid: str, *, firestore_client: Any | None = None) -> str | None:
"""Return the authoritative deletion lifecycle state for an authenticated UID.
This intentionally bypasses caches: an accepted deletion must become an
access barrier on the very next request, and a cached pre-delete miss would
reopen the exact half-deleted-account window this marker closes.
"""
client = account_deletion_firestore_client(firestore_client=firestore_client)
snapshot = account_deletion_document(uid, firestore_client=client).get()
record_document_read(
FirestoreReadSite.USER_DELETION_WIPE_STATUS,
FirestoreReadOutcome.HIT if snapshot.exists else FirestoreReadOutcome.MISS,
)
if not snapshot.exists:
return None
status = (snapshot.to_dict() or {}).get("wipe_status")
return normalize_account_deletion_status(marker_exists=True, raw_status=status)
__all__ = [
"ACCOUNT_DELETION_COLLECTION",
"account_deletion_collection",
"account_deletion_document",
"account_deletion_firestore_client",
"get_user_deletion_wipe_status",
]