Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1469,6 +1469,51 @@ def send_notifications():
|
|
| 1469 |
|
| 1470 |
except Exception as e:
|
| 1471 |
return jsonify({'error': str(e)}), 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1472 |
# ---------- Admin Endpoint to Directly Update Credits ----------
|
| 1473 |
@app.route('/api/admin/users/<string:uid>/credits', methods=['PUT'])
|
| 1474 |
def admin_update_credits(uid):
|
|
|
|
| 1469 |
|
| 1470 |
except Exception as e:
|
| 1471 |
return jsonify({'error': str(e)}), 500
|
| 1472 |
+
|
| 1473 |
+
@app.route('/api/admin/feedback', methods=['GET'])
|
| 1474 |
+
def admin_view_feedback():
|
| 1475 |
+
"""
|
| 1476 |
+
Allows an admin to view all feedback entries (or optionally filter by type/status).
|
| 1477 |
+
"""
|
| 1478 |
+
try:
|
| 1479 |
+
# 1) Verify admin
|
| 1480 |
+
admin_uid = verify_admin(request.headers.get('Authorization', ''))
|
| 1481 |
+
if not admin_uid:
|
| 1482 |
+
return jsonify({'error': 'Unauthorized: Admin access required'}), 401
|
| 1483 |
+
|
| 1484 |
+
# 2) Optional: parse query params for filtering, e.g. ?type=bug or ?status=open
|
| 1485 |
+
feedback_type = request.args.get('type') # e.g. "bug", "feature_request", "general"
|
| 1486 |
+
feedback_status = request.args.get('status') # e.g. "open", "resolved"
|
| 1487 |
+
|
| 1488 |
+
# 3) Fetch all feedback
|
| 1489 |
+
feedback_ref = db.reference('feedback')
|
| 1490 |
+
all_feedback = feedback_ref.get() or {}
|
| 1491 |
+
|
| 1492 |
+
# Convert dict to list
|
| 1493 |
+
feedback_list = []
|
| 1494 |
+
for fb_id, fb_data in all_feedback.items():
|
| 1495 |
+
# If we have a filter for type
|
| 1496 |
+
if feedback_type and fb_data.get('type') != feedback_type:
|
| 1497 |
+
continue
|
| 1498 |
+
# If we have a filter for status
|
| 1499 |
+
if feedback_status and fb_data.get('status') != feedback_status:
|
| 1500 |
+
continue
|
| 1501 |
+
|
| 1502 |
+
feedback_list.append({
|
| 1503 |
+
'feedback_id': fb_id,
|
| 1504 |
+
'user_id': fb_data.get('user_id'),
|
| 1505 |
+
'user_email': fb_data.get('user_email'),
|
| 1506 |
+
'type': fb_data.get('type', 'general'),
|
| 1507 |
+
'message': fb_data.get('message', ''),
|
| 1508 |
+
'created_at': fb_data.get('created_at'),
|
| 1509 |
+
'status': fb_data.get('status', 'open')
|
| 1510 |
+
})
|
| 1511 |
+
|
| 1512 |
+
return jsonify({'feedback': feedback_list}), 200
|
| 1513 |
+
|
| 1514 |
+
except Exception as e:
|
| 1515 |
+
return jsonify({'error': str(e)}), 500
|
| 1516 |
+
|
| 1517 |
# ---------- Admin Endpoint to Directly Update Credits ----------
|
| 1518 |
@app.route('/api/admin/users/<string:uid>/credits', methods=['PUT'])
|
| 1519 |
def admin_update_credits(uid):
|