From ff8975acab614a5cac3c6b75e7656f4ee0c6d5cf Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 26 Jun 2022 11:09:43 +0200 Subject: [PATCH] Admin bookmarks support --- app/admin.py | 43 ++++++++++++++++++++++++++++++++++++ app/templates/admin_new.html | 10 ++++++--- app/templates/layout.html | 7 +++--- app/templates/lookup.html | 4 +++- app/templates/utils.html | 41 ++++++++++++++++++++++++++++------ 5 files changed, 90 insertions(+), 15 deletions(-) diff --git a/app/admin.py b/app/admin.py index a736d8b..998f0c3 100644 --- a/app/admin.py +++ b/app/admin.py @@ -140,6 +140,33 @@ def stream( ) +@router.get("/bookmarks") +def admin_bookmarks( + request: Request, + db: Session = Depends(get_db), +) -> templates.TemplateResponse: + stream = ( + db.query(models.InboxObject) + .filter( + models.InboxObject.ap_type.in_(["Note", "Article", "Video", "Announce"]), + models.InboxObject.is_hidden_from_stream.is_(False), + models.InboxObject.undone_by_inbox_object_id.is_(None), + models.InboxObject.is_bookmarked.is_(True), + ) + .order_by(models.InboxObject.ap_published_at.desc()) + .limit(20) + .all() + ) + return templates.render_template( + db, + request, + "admin_stream.html", + { + "stream": stream, + }, + ) + + @router.get("/inbox") def admin_inbox( request: Request, @@ -341,6 +368,22 @@ def admin_actions_bookmark( return RedirectResponse(redirect_url, status_code=302) +@router.post("/actions/unbookmark") +def admin_actions_unbookmark( + request: Request, + ap_object_id: str = Form(), + redirect_url: str = Form(), + csrf_check: None = Depends(verify_csrf_token), + db: Session = Depends(get_db), +) -> RedirectResponse: + inbox_object = get_inbox_object_by_ap_id(db, ap_object_id) + if not inbox_object: + raise ValueError("Should never happen") + inbox_object.is_bookmarked = False + db.commit() + return RedirectResponse(redirect_url, status_code=302) + + @router.post("/actions/new") def admin_actions_new( request: Request, diff --git a/app/templates/admin_new.html b/app/templates/admin_new.html index bdf30bf..f11edea 100644 --- a/app/templates/admin_new.html +++ b/app/templates/admin_new.html @@ -2,8 +2,8 @@ {% extends "layout.html" %} {% block content %} -In reply to: {% if in_reply_to_object %} +

In reply to:

{{ utils.display_object(in_reply_to_object) }} {% endif %} @@ -12,8 +12,12 @@ In reply to: {{ utils.embed_redirect_url() }} - - +

+ +

+

+ +

{% endblock %} diff --git a/app/templates/layout.html b/app/templates/layout.html index 6c58ff7..0972101 100644 --- a/app/templates/layout.html +++ b/app/templates/layout.html @@ -25,12 +25,11 @@
  • {{ admin_link("index", "Public") }}
  • {{ admin_link("admin_new", "New") }}
  • {{ admin_link("stream", "Stream") }}
  • -
  • {{ admin_link("admin_inbox", "Inbox") }}
  • -
  • {{ admin_link("admin_outbox", "Outbox") }}
  • +
  • {{ admin_link("admin_inbox", "Inbox") }}/{{ admin_link("admin_outbox", "Outbox") }}
  • {{ admin_link("get_notifications", "Notifications") }} {% if notifications_count %}({{ notifications_count }}){% endif %}
  • {{ admin_link("get_lookup", "Lookup") }}
  • -
  • Bookmarks
  • -
  • Logout
  • +
  • {{ admin_link("admin_bookmarks", "Bookmarks") }}
  • +
  • Logout
  • diff --git a/app/templates/lookup.html b/app/templates/lookup.html index f1d4835..6ae5a16 100644 --- a/app/templates/lookup.html +++ b/app/templates/lookup.html @@ -1,11 +1,13 @@ {%- import "utils.html" as utils with context -%} {% extends "layout.html" %} {% block content %} + +

    Interact with an ActivityPub object via its URL or look for a user using @user@domain.tld

    +
    - {{ actors_metadata }} {% if ap_object and ap_object.ap_type == "Person" %} {{ utils.display_actor(ap_object, actors_metadata) }} {% elif ap_object %} diff --git a/app/templates/utils.html b/app/templates/utils.html index da2b9f5..9a1d770 100644 --- a/app/templates/utils.html +++ b/app/templates/utils.html @@ -24,12 +24,30 @@ {% endmacro %} +{% macro admin_bookmark_button(ap_object_id) %} +
    + {{ embed_csrf_token() }} + {{ embed_redirect_url() }} + + +
    +{% endmacro %} + +{% macro admin_unbookmark_button(ap_object_id) %} +
    + {{ embed_csrf_token() }} + {{ embed_redirect_url() }} + + +
    +{% endmacro %} + {% macro admin_announce_button(ap_object_id) %}
    {{ embed_csrf_token() }} {{ embed_redirect_url() }} - +
    {% endmacro %} @@ -193,17 +211,26 @@ {% endif %} {% if object.is_from_inbox %} - {% if object.liked_via_outbox_object_ap_id %}
    + {% if object.liked_via_outbox_object_ap_id %} {{ admin_undo_button(object.liked_via_outbox_object_ap_id, "Unlike") }} -
    - {% else %} -
    + {% else %} {{ admin_like_button(object.ap_id) }} + {% endif %}
    - {% endif %}
    - {{ admin_announce_button(object.ap_id) }} + {% if object.is_bookmarked %} + {{ admin_unbookmark_button(object.ap_id) }} + {% else %} + {{ admin_bookmark_button(object.ap_id) }} + {% endif %} +
    +
    + {% if object.announced_via_outbox_object_ap_id %} + {{ admin_undo_button(object.liked_via_outbox_object_ap_id, "Unshare") }} + {% else %} + {{ admin_announce_button(object.ap_id) }} + {% endif %}
    {{ admin_reply_button(object.ap_id) }}