Update main.py
Browse files
main.py
CHANGED
|
@@ -290,6 +290,9 @@ def admin_create_user():
|
|
| 290 |
display_name=display_name if display_name else None
|
| 291 |
)
|
| 292 |
|
|
|
|
|
|
|
|
|
|
| 293 |
# Create user document in Firestore
|
| 294 |
user_data_for_db = {
|
| 295 |
'uid': user_record.uid,
|
|
@@ -297,21 +300,31 @@ def admin_create_user():
|
|
| 297 |
'displayName': display_name,
|
| 298 |
'phone': phone,
|
| 299 |
'isAdmin': is_admin,
|
| 300 |
-
'phoneStatus':
|
| 301 |
'organizationId': None,
|
| 302 |
'createdAt': firestore.SERVER_TIMESTAMP,
|
| 303 |
'updatedAt': firestore.SERVER_TIMESTAMP
|
| 304 |
}
|
| 305 |
|
| 306 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
|
| 308 |
-
logging.info(f"Admin created new user {user_record.uid} with email {email}"
|
|
|
|
| 309 |
|
| 310 |
# Create separate dictionary for JSON response with JSON-friendly timestamps
|
| 311 |
response_data = user_data_for_db.copy()
|
| 312 |
current_time = datetime.utcnow().isoformat() + "Z"
|
| 313 |
response_data['createdAt'] = current_time
|
| 314 |
response_data['updatedAt'] = current_time
|
|
|
|
| 315 |
|
| 316 |
return jsonify({
|
| 317 |
'success': True,
|
|
|
|
| 290 |
display_name=display_name if display_name else None
|
| 291 |
)
|
| 292 |
|
| 293 |
+
# Determine phone status based on whether phone is provided
|
| 294 |
+
phone_status = 'approved' if phone else 'unsubmitted'
|
| 295 |
+
|
| 296 |
# Create user document in Firestore
|
| 297 |
user_data_for_db = {
|
| 298 |
'uid': user_record.uid,
|
|
|
|
| 300 |
'displayName': display_name,
|
| 301 |
'phone': phone,
|
| 302 |
'isAdmin': is_admin,
|
| 303 |
+
'phoneStatus': phone_status,
|
| 304 |
'organizationId': None,
|
| 305 |
'createdAt': firestore.SERVER_TIMESTAMP,
|
| 306 |
'updatedAt': firestore.SERVER_TIMESTAMP
|
| 307 |
}
|
| 308 |
|
| 309 |
+
# Use batch to create user and approve phone if provided
|
| 310 |
+
batch = db.batch()
|
| 311 |
+
batch.set(db.collection('users').document(user_record.uid), user_data_for_db)
|
| 312 |
+
|
| 313 |
+
# If phone number is provided, also create phone approval document
|
| 314 |
+
if phone:
|
| 315 |
+
batch.set(db.collection('users').document(phone), {'status': 'approved'}, merge=True)
|
| 316 |
+
|
| 317 |
+
batch.commit()
|
| 318 |
|
| 319 |
+
logging.info(f"Admin created new user {user_record.uid} with email {email}" +
|
| 320 |
+
(f" and auto-approved phone {phone}" if phone else ""))
|
| 321 |
|
| 322 |
# Create separate dictionary for JSON response with JSON-friendly timestamps
|
| 323 |
response_data = user_data_for_db.copy()
|
| 324 |
current_time = datetime.utcnow().isoformat() + "Z"
|
| 325 |
response_data['createdAt'] = current_time
|
| 326 |
response_data['updatedAt'] = current_time
|
| 327 |
+
response_data['phoneStatus'] = phone_status
|
| 328 |
|
| 329 |
return jsonify({
|
| 330 |
'success': True,
|