From d058c1ba26c847d87ffa0a6cb789dd1aa780706d Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Thu, 7 Jul 2022 08:36:07 +0200 Subject: [PATCH] Show in reply to admin button --- app/admin.py | 17 +++++++++++++++-- app/boxes.py | 16 +++++++++++++++- app/main.py | 3 +-- app/models.py | 2 +- app/templates/utils.html | 8 ++++++++ 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/app/admin.py b/app/admin.py index 4fc357e..e453706 100644 --- a/app/admin.py +++ b/app/admin.py @@ -76,10 +76,23 @@ async def get_lookup( request: Request, query: str | None = None, db_session: AsyncSession = Depends(get_db_session), -) -> templates.TemplateResponse: +) -> templates.TemplateResponse | RedirectResponse: ap_object = None actors_metadata = {} if query: + requested_object = await boxes.get_anybox_object_by_ap_id(db_session, query) + if requested_object: + if ( + requested_object.ap_type == "Create" + and requested_object.relates_to_anybox_object + ): + query = requested_object.relates_to_anybox_object.ap_id + return RedirectResponse( + request.url_for("admin_object") + f"?ap_id={query}", + status_code=302, + ) + # TODO(ts): redirect to admin_profile if the actor is in DB + ap_object = await lookup(db_session, query) if ap_object.ap_type in ap.ACTOR_TYPES: actors_metadata = await get_actors_metadata( @@ -266,7 +279,7 @@ async def admin_outbox( cursor: str | None = None, ) -> templates.TemplateResponse: where = [ - models.OutboxObject.ap_type.not_in(["Accept", "Delete"]), + models.OutboxObject.ap_type.not_in(["Accept", "Delete", "Update"]), models.OutboxObject.is_deleted.is_(False), ] if filter_by: diff --git a/app/boxes.py b/app/boxes.py index 7d399d0..90e70d7 100644 --- a/app/boxes.py +++ b/app/boxes.py @@ -455,7 +455,21 @@ async def get_outbox_object_by_ap_id( ) -> models.OutboxObject | None: return ( await db_session.execute( - select(models.OutboxObject).where(models.OutboxObject.ap_id == ap_id) + select(models.OutboxObject) + .where(models.OutboxObject.ap_id == ap_id) + .options( + joinedload(models.OutboxObject.outbox_object_attachments).options( + joinedload(models.OutboxObjectAttachment.upload) + ), + joinedload(models.OutboxObject.relates_to_inbox_object).options( + joinedload(models.InboxObject.actor), + ), + joinedload(models.OutboxObject.relates_to_outbox_object).options( + joinedload(models.OutboxObject.outbox_object_attachments).options( + joinedload(models.OutboxObjectAttachment.upload) + ), + ), + ) ) ).scalar_one_or_none() # type: ignore diff --git a/app/main.py b/app/main.py index 5ed7f9c..757f824 100644 --- a/app/main.py +++ b/app/main.py @@ -64,9 +64,8 @@ _RESIZED_CACHE: MutableMapping[tuple[str, int], tuple[bytes, str, Any]] = LFUCac # TODO(ts): # # Next: +# - [ ] show [reply to @truc] next to visiblity # - support update post with history -# - update actor support -# - hash config/profile to detect when to send Update actor # # - [ ] block support # - [ ] prevent SSRF (urlutils from little-boxes) diff --git a/app/models.py b/app/models.py index 3954cee..69700da 100644 --- a/app/models.py +++ b/app/models.py @@ -162,7 +162,7 @@ class OutboxObject(Base, BaseObject): # Never actually delete from the outbox is_deleted = Column(Boolean, nullable=False, default=False) - # Used for Like, Announce and Undo activities + # Used for Create, Like, Announce and Undo activities relates_to_inbox_object_id = Column( Integer, ForeignKey("inbox.id"), diff --git a/app/templates/utils.html b/app/templates/utils.html index ba1b2a2..5edb0d0 100644 --- a/app/templates/utils.html +++ b/app/templates/utils.html @@ -332,6 +332,14 @@