Admin bookmarks support

main
Thomas Sileo 2022-06-26 11:09:43 +02:00
parent f365784f93
commit ff8975acab
5 changed files with 90 additions and 15 deletions

View File

@ -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,

View File

@ -2,8 +2,8 @@
{% extends "layout.html" %}
{% block content %}
In reply to:
{% if in_reply_to_object %}
<p>In reply to:</p>
{{ utils.display_object(in_reply_to_object) }}
{% endif %}
@ -12,8 +12,12 @@ In reply to:
{{ utils.embed_redirect_url() }}
<textarea name="content" rows="10" cols="50" autofocus="autofocus" designMode="on" style="font-size:1.2em;width:95%;"></textarea>
<input type="hidden" name="in_reply_to" value="{{ request.query_params.in_reply_to }}">
<input name="files" type="file" multiple>
<input type="submit" value="Publish">
<p>
<input name="files" type="file" multiple>
</p>
<p>
<input type="submit" value="Publish">
</p>
</form>
{% endblock %}

View File

@ -25,12 +25,11 @@
<li>{{ admin_link("index", "Public") }}</li>
<li>{{ admin_link("admin_new", "New") }}</li>
<li>{{ admin_link("stream", "Stream") }}</li>
<li>{{ admin_link("admin_inbox", "Inbox") }}</li>
<li>{{ admin_link("admin_outbox", "Outbox") }}</li>
<li>{{ admin_link("admin_inbox", "Inbox") }}/{{ admin_link("admin_outbox", "Outbox") }}</li>
<li>{{ admin_link("get_notifications", "Notifications") }} {% if notifications_count %}({{ notifications_count }}){% endif %}</li>
<li>{{ admin_link("get_lookup", "Lookup") }}</li>
<li><a href="">Bookmarks</a></li>
<li><a href="{{ request.url_for("logout")}}">Logout</a></li>
<li>{{ admin_link("admin_bookmarks", "Bookmarks") }}</li>
<li><a href="{{ url_for("logout")}}">Logout</a></li>
</ul>
</nav>
</div>

View File

@ -1,11 +1,13 @@
{%- import "utils.html" as utils with context -%}
{% extends "layout.html" %}
{% block content %}
<p>Interact with an ActivityPub object via its URL or look for a user using <i>@user@domain.tld</i></p>
<form action="{{ url_for("get_lookup") }}" method="GET">
<input type="text" name="query" value="{{ query if query else "" }}">
<input type="submit" value="Lookup">
</form>
{{ actors_metadata }}
{% if ap_object and ap_object.ap_type == "Person" %}
{{ utils.display_actor(ap_object, actors_metadata) }}
{% elif ap_object %}

View File

@ -24,12 +24,30 @@
</form>
{% endmacro %}
{% macro admin_bookmark_button(ap_object_id) %}
<form action="{{ request.url_for("admin_actions_bookmark") }}" method="POST">
{{ embed_csrf_token() }}
{{ embed_redirect_url() }}
<input type="hidden" name="ap_object_id" value="{{ ap_object_id }}">
<input type="submit" value="Bookmark">
</form>
{% endmacro %}
{% macro admin_unbookmark_button(ap_object_id) %}
<form action="{{ request.url_for("admin_actions_unbookmark") }}" method="POST">
{{ embed_csrf_token() }}
{{ embed_redirect_url() }}
<input type="hidden" name="ap_object_id" value="{{ ap_object_id }}">
<input type="submit" value="Unbookmark">
</form>
{% endmacro %}
{% macro admin_announce_button(ap_object_id) %}
<form action="{{ request.url_for("admin_actions_announce") }}" method="POST">
{{ embed_csrf_token() }}
{{ embed_redirect_url() }}
<input type="hidden" name="ap_object_id" value="{{ ap_object_id }}">
<input type="submit" value="Announce">
<input type="submit" value="Share">
</form>
{% endmacro %}
@ -193,17 +211,26 @@
{% endif %}
{% if object.is_from_inbox %}
{% if object.liked_via_outbox_object_ap_id %}
<div class="bar-item">
{% if object.liked_via_outbox_object_ap_id %}
{{ admin_undo_button(object.liked_via_outbox_object_ap_id, "Unlike") }}
</div>
{% else %}
<div class="bar-item">
{% else %}
{{ admin_like_button(object.ap_id) }}
{% endif %}
</div>
{% endif %}
<div class="bar-item">
{{ admin_announce_button(object.ap_id) }}
{% if object.is_bookmarked %}
{{ admin_unbookmark_button(object.ap_id) }}
{% else %}
{{ admin_bookmark_button(object.ap_id) }}
{% endif %}
</div>
<div class="bar-item">
{% 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 %}
</div>
<div class="bar-item">
{{ admin_reply_button(object.ap_id) }}