Spaces:
Running
Running
Fix annotation privacy: filter /api/tasks/<id>/ embedded annotations
Browse files- ls_proxy_hf.py +26 -1
ls_proxy_hf.py
CHANGED
|
@@ -1118,6 +1118,28 @@ def projects_ls():
|
|
| 1118 |
return _proxy_stream("/projects/")
|
| 1119 |
|
| 1120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1121 |
@app.route("/api/tasks/<int:task_id>/annotations/", methods=["GET", "POST"])
|
| 1122 |
@app.route("/api/tasks/<int:task_id>/annotations", methods=["GET", "POST"])
|
| 1123 |
def filter_task_annotations(task_id):
|
|
@@ -1178,7 +1200,10 @@ def filter_task_annotations(task_id):
|
|
| 1178 |
return _respond_buffered(resp)
|
| 1179 |
try:
|
| 1180 |
data = resp.json()
|
| 1181 |
-
|
|
|
|
|
|
|
|
|
|
| 1182 |
return Response(json.dumps(own), status=resp.status_code,
|
| 1183 |
content_type="application/json; charset=utf-8")
|
| 1184 |
except Exception:
|
|
|
|
| 1118 |
return _proxy_stream("/projects/")
|
| 1119 |
|
| 1120 |
|
| 1121 |
+
@app.route("/api/tasks/<int:task_id>/", methods=["GET"])
|
| 1122 |
+
@app.route("/api/tasks/<int:task_id>", methods=["GET"])
|
| 1123 |
+
def filter_task_data(task_id):
|
| 1124 |
+
"""Strip other users' embedded annotations from task data so LS shows a blank form."""
|
| 1125 |
+
uid, admin = get_current_user(request)
|
| 1126 |
+
resp = _proxy_buffered(f"/api/tasks/{task_id}/")
|
| 1127 |
+
if admin or uid is None:
|
| 1128 |
+
return _respond_buffered(resp)
|
| 1129 |
+
try:
|
| 1130 |
+
data = resp.json()
|
| 1131 |
+
if "annotations" in data:
|
| 1132 |
+
def _cb_id(ann):
|
| 1133 |
+
cb = ann.get("completed_by")
|
| 1134 |
+
return cb.get("id") if isinstance(cb, dict) else cb
|
| 1135 |
+
data["annotations"] = [a for a in data["annotations"] if _cb_id(a) == uid]
|
| 1136 |
+
data["total_annotations"] = len(data["annotations"])
|
| 1137 |
+
return Response(json.dumps(data), status=resp.status_code,
|
| 1138 |
+
content_type="application/json; charset=utf-8")
|
| 1139 |
+
except Exception:
|
| 1140 |
+
return _respond_buffered(resp)
|
| 1141 |
+
|
| 1142 |
+
|
| 1143 |
@app.route("/api/tasks/<int:task_id>/annotations/", methods=["GET", "POST"])
|
| 1144 |
@app.route("/api/tasks/<int:task_id>/annotations", methods=["GET", "POST"])
|
| 1145 |
def filter_task_annotations(task_id):
|
|
|
|
| 1200 |
return _respond_buffered(resp)
|
| 1201 |
try:
|
| 1202 |
data = resp.json()
|
| 1203 |
+
def _cb_id(ann):
|
| 1204 |
+
cb = ann.get("completed_by")
|
| 1205 |
+
return cb.get("id") if isinstance(cb, dict) else cb
|
| 1206 |
+
own = [ann for ann in data if _cb_id(ann) == uid]
|
| 1207 |
return Response(json.dumps(own), status=resp.status_code,
|
| 1208 |
content_type="application/json; charset=utf-8")
|
| 1209 |
except Exception:
|