Spaces:
Sleeping
Sleeping
Update resolver.py
Browse files- resolver.py +21 -16
resolver.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
-
|
| 2 |
from firestore_client import get_firestore_client
|
|
|
|
|
|
|
| 3 |
db = get_firestore_client()
|
| 4 |
|
| 5 |
def resolve_user_context(uid: str, company_code: str):
|
|
@@ -10,24 +12,27 @@ def resolve_user_context(uid: str, company_code: str):
|
|
| 10 |
participant_id = None
|
| 11 |
|
| 12 |
# 1) users/{uid} -> email
|
| 13 |
-
|
| 14 |
-
if
|
| 15 |
-
user =
|
| 16 |
email = user.get("email")
|
| 17 |
|
| 18 |
-
# 2)
|
| 19 |
if email:
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
return {"uid": uid, "email": email, "participantId": participant_id}
|
|
|
|
| 1 |
+
# resolver.py
|
| 2 |
from firestore_client import get_firestore_client
|
| 3 |
+
from google.cloud import firestore
|
| 4 |
+
|
| 5 |
db = get_firestore_client()
|
| 6 |
|
| 7 |
def resolve_user_context(uid: str, company_code: str):
|
|
|
|
| 12 |
participant_id = None
|
| 13 |
|
| 14 |
# 1) users/{uid} -> email
|
| 15 |
+
user_snap = db.collection("users").document(uid).get()
|
| 16 |
+
if user_snap.exists:
|
| 17 |
+
user = user_snap.to_dict() or {}
|
| 18 |
email = user.get("email")
|
| 19 |
|
| 20 |
+
# 2) applications where companyCode == ctx AND email == user.email -> participantId
|
| 21 |
if email:
|
| 22 |
+
app_query = (
|
| 23 |
+
db.collection("applications")
|
| 24 |
+
.where(filter=firestore.FieldFilter("companyCode", "==", company_code))
|
| 25 |
+
.where(filter=firestore.FieldFilter("email", "==", email))
|
| 26 |
+
.limit(1)
|
| 27 |
+
)
|
| 28 |
+
app_docs = list(app_query.stream())
|
| 29 |
+
if app_docs:
|
| 30 |
+
participant_id = (app_docs[0].to_dict() or {}).get("participantId")
|
| 31 |
|
| 32 |
+
# 3) Verify the participant doc exists, but do NOT filter by companyCode on participants.
|
| 33 |
+
if participant_id:
|
| 34 |
+
p_snap = db.collection("participants").document(participant_id).get()
|
| 35 |
+
if not p_snap.exists:
|
| 36 |
+
participant_id = None
|
| 37 |
|
| 38 |
return {"uid": uid, "email": email, "participantId": participant_id}
|