Bugfixes
This commit is contained in:
parent
1062f26970
commit
98287ec8b1
5 changed files with 28 additions and 20 deletions
11
app.py
11
app.py
|
@ -557,10 +557,8 @@ def outbox_detail(item_id):
|
|||
abort(404)
|
||||
|
||||
if doc["meta"].get("deleted", False):
|
||||
obj = ap.parse_activity(doc["activity"])
|
||||
resp = jsonify(**obj.get_tombstone().to_dict())
|
||||
resp.status_code = 410
|
||||
return resp
|
||||
abort(404)
|
||||
|
||||
return jsonify(**activity_from_doc(doc))
|
||||
|
||||
|
||||
|
@ -574,10 +572,7 @@ def outbox_activity(item_id):
|
|||
|
||||
obj = activity_from_doc(data)
|
||||
if data["meta"].get("deleted", False):
|
||||
obj = ap.parse_activity(data["activity"])
|
||||
resp = jsonify(**obj.get_object().get_tombstone().to_dict())
|
||||
resp.status_code = 410
|
||||
return resp
|
||||
abort(404)
|
||||
|
||||
if obj["type"] != ActivityType.CREATE.value:
|
||||
abort(404)
|
||||
|
|
|
@ -68,7 +68,7 @@ def admin_logout() -> _Response:
|
|||
@noindex
|
||||
def admin_login() -> _Response:
|
||||
if session.get("logged_in") is True:
|
||||
return redirect(url_for("admin_notifications"))
|
||||
return redirect(url_for("admin.admin_notifications"))
|
||||
|
||||
devices = [doc["device"] for doc in DB.u2f.find()]
|
||||
u2f_enabled = True if devices else False
|
||||
|
@ -80,7 +80,7 @@ def admin_login() -> _Response:
|
|||
if verify_pass(pwd):
|
||||
session["logged_in"] = True
|
||||
return redirect(
|
||||
request.args.get("redirect") or url_for("admin_notifications")
|
||||
request.args.get("redirect") or url_for("admin.admin_notifications")
|
||||
)
|
||||
else:
|
||||
abort(403)
|
||||
|
@ -98,7 +98,7 @@ def admin_login() -> _Response:
|
|||
|
||||
session["logged_in"] = True
|
||||
return redirect(
|
||||
request.args.get("redirect") or url_for("admin_notifications")
|
||||
request.args.get("redirect") or url_for("admin.admin_notifications")
|
||||
)
|
||||
else:
|
||||
abort(401)
|
||||
|
|
|
@ -118,11 +118,13 @@ class MicroblogPubBackend(Backend):
|
|||
is_public = False
|
||||
if visibility in [ap.Visibility.PUBLIC, ap.Visibility.UNLISTED]:
|
||||
is_public = True
|
||||
|
||||
object_id = None
|
||||
try:
|
||||
object_id = activity.get_object_id()
|
||||
except Exception: # TODO(tsileo): should be ValueError, but replies trigger a KeyError on object
|
||||
pass
|
||||
|
||||
object_visibility = None
|
||||
if activity.has_type(
|
||||
[ap.ActivityType.CREATE, ap.ActivityType.ANNOUNCE, ap.ActivityType.LIKE]
|
||||
|
|
|
@ -7,6 +7,7 @@ from typing import Dict
|
|||
from little_boxes import activitypub as ap
|
||||
|
||||
from core.db import DB
|
||||
from core.db import find_one_activity
|
||||
from core.db import update_many_activities
|
||||
from core.shared import MY_PERSON
|
||||
from core.shared import back
|
||||
|
@ -26,18 +27,26 @@ def process_outbox(activity: ap.BaseActivity, new_meta: _NewMeta) -> None:
|
|||
@process_outbox.register
|
||||
def _delete_process_outbox(delete: ap.Delete, new_meta: _NewMeta) -> None:
|
||||
_logger.info(f"process_outbox activity={delete!r}")
|
||||
obj = delete.get_object()
|
||||
obj_id = delete.get_object_id()
|
||||
|
||||
# Flag everything referencing the deleted object as deleted (except the Delete activity itself)
|
||||
update_many_activities(
|
||||
{"meta.object_id": obj.id}, {"$set": {"meta.deleted": True, "meta.undo": True}}
|
||||
{"meta.object_id": obj_id, "remote_id": {"$ne": delete.id}},
|
||||
{"$set": {"meta.deleted": True, "meta.undo": True}},
|
||||
)
|
||||
|
||||
in_reply_to = obj.get_in_reply_to()
|
||||
if in_reply_to:
|
||||
DB.activities.update_one(
|
||||
{"activity.object.id": in_reply_to},
|
||||
{"$inc": {"meta.count_reply": -1, "meta.count_direct_reply": -1}},
|
||||
)
|
||||
# If the deleted activity was in DB, decrease some threads-related counter
|
||||
data = find_one_activity(
|
||||
{"meta.object_id": obj_id, "type": ap.ActivityType.CREATE.value}
|
||||
)
|
||||
if data:
|
||||
obj = ap.parse_activity(data["activity"])
|
||||
in_reply_to = obj.get_in_reply_to()
|
||||
if in_reply_to:
|
||||
DB.activities.update_one(
|
||||
{"activity.object.id": in_reply_to},
|
||||
{"$inc": {"meta.count_reply": -1, "meta.count_direct_reply": -1}},
|
||||
)
|
||||
|
||||
|
||||
@process_outbox.register
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import binascii
|
||||
import os
|
||||
from datetime import datetime
|
||||
from datetime import timezone
|
||||
|
@ -102,7 +103,7 @@ def post_to_outbox(activity: ap.BaseActivity) -> str:
|
|||
activity = activity.build_create()
|
||||
|
||||
# Assign create a random ID
|
||||
obj_id = back.random_object_id()
|
||||
obj_id = binascii.hexlify(os.urandom(8)).decode("utf-8")
|
||||
uri = activity_url(obj_id)
|
||||
activity._data["id"] = uri
|
||||
if activity.has_type(ap.ActivityType.CREATE):
|
||||
|
@ -112,6 +113,7 @@ def post_to_outbox(activity: ap.BaseActivity) -> str:
|
|||
activity._data["object"]["url"] = urljoin(
|
||||
BASE_URL, url_for("note_by_id", note_id=obj_id)
|
||||
)
|
||||
activity.reset_object_cache()
|
||||
|
||||
back.save(Box.OUTBOX, activity)
|
||||
Tasks.cache_actor(activity.id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue