mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-12-22 13:14:28 +00:00
Admin bookmarks support
This commit is contained in:
parent
f365784f93
commit
ff8975acab
5 changed files with 90 additions and 15 deletions
43
app/admin.py
43
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")
|
@router.get("/inbox")
|
||||||
def admin_inbox(
|
def admin_inbox(
|
||||||
request: Request,
|
request: Request,
|
||||||
|
@ -341,6 +368,22 @@ def admin_actions_bookmark(
|
||||||
return RedirectResponse(redirect_url, status_code=302)
|
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")
|
@router.post("/actions/new")
|
||||||
def admin_actions_new(
|
def admin_actions_new(
|
||||||
request: Request,
|
request: Request,
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
In reply to:
|
|
||||||
{% if in_reply_to_object %}
|
{% if in_reply_to_object %}
|
||||||
|
<p>In reply to:</p>
|
||||||
{{ utils.display_object(in_reply_to_object) }}
|
{{ utils.display_object(in_reply_to_object) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
@ -12,8 +12,12 @@ In reply to:
|
||||||
{{ utils.embed_redirect_url() }}
|
{{ utils.embed_redirect_url() }}
|
||||||
<textarea name="content" rows="10" cols="50" autofocus="autofocus" designMode="on" style="font-size:1.2em;width:95%;"></textarea>
|
<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 type="hidden" name="in_reply_to" value="{{ request.query_params.in_reply_to }}">
|
||||||
|
<p>
|
||||||
<input name="files" type="file" multiple>
|
<input name="files" type="file" multiple>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
<input type="submit" value="Publish">
|
<input type="submit" value="Publish">
|
||||||
|
</p>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -25,12 +25,11 @@
|
||||||
<li>{{ admin_link("index", "Public") }}</li>
|
<li>{{ admin_link("index", "Public") }}</li>
|
||||||
<li>{{ admin_link("admin_new", "New") }}</li>
|
<li>{{ admin_link("admin_new", "New") }}</li>
|
||||||
<li>{{ admin_link("stream", "Stream") }}</li>
|
<li>{{ admin_link("stream", "Stream") }}</li>
|
||||||
<li>{{ admin_link("admin_inbox", "Inbox") }}</li>
|
<li>{{ admin_link("admin_inbox", "Inbox") }}/{{ admin_link("admin_outbox", "Outbox") }}</li>
|
||||||
<li>{{ admin_link("admin_outbox", "Outbox") }}</li>
|
|
||||||
<li>{{ admin_link("get_notifications", "Notifications") }} {% if notifications_count %}({{ notifications_count }}){% endif %}</li>
|
<li>{{ admin_link("get_notifications", "Notifications") }} {% if notifications_count %}({{ notifications_count }}){% endif %}</li>
|
||||||
<li>{{ admin_link("get_lookup", "Lookup") }}</li>
|
<li>{{ admin_link("get_lookup", "Lookup") }}</li>
|
||||||
<li><a href="">Bookmarks</a></li>
|
<li>{{ admin_link("admin_bookmarks", "Bookmarks") }}</li>
|
||||||
<li><a href="{{ request.url_for("logout")}}">Logout</a></li>
|
<li><a href="{{ url_for("logout")}}">Logout</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
{%- import "utils.html" as utils with context -%}
|
{%- import "utils.html" as utils with context -%}
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
{% block content %}
|
{% 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">
|
<form action="{{ url_for("get_lookup") }}" method="GET">
|
||||||
<input type="text" name="query" value="{{ query if query else "" }}">
|
<input type="text" name="query" value="{{ query if query else "" }}">
|
||||||
<input type="submit" value="Lookup">
|
<input type="submit" value="Lookup">
|
||||||
</form>
|
</form>
|
||||||
{{ actors_metadata }}
|
|
||||||
{% if ap_object and ap_object.ap_type == "Person" %}
|
{% if ap_object and ap_object.ap_type == "Person" %}
|
||||||
{{ utils.display_actor(ap_object, actors_metadata) }}
|
{{ utils.display_actor(ap_object, actors_metadata) }}
|
||||||
{% elif ap_object %}
|
{% elif ap_object %}
|
||||||
|
|
|
@ -24,12 +24,30 @@
|
||||||
</form>
|
</form>
|
||||||
{% endmacro %}
|
{% 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) %}
|
{% macro admin_announce_button(ap_object_id) %}
|
||||||
<form action="{{ request.url_for("admin_actions_announce") }}" method="POST">
|
<form action="{{ request.url_for("admin_actions_announce") }}" method="POST">
|
||||||
{{ embed_csrf_token() }}
|
{{ embed_csrf_token() }}
|
||||||
{{ embed_redirect_url() }}
|
{{ embed_redirect_url() }}
|
||||||
<input type="hidden" name="ap_object_id" value="{{ ap_object_id }}">
|
<input type="hidden" name="ap_object_id" value="{{ ap_object_id }}">
|
||||||
<input type="submit" value="Announce">
|
<input type="submit" value="Share">
|
||||||
</form>
|
</form>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
@ -193,17 +211,26 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if object.is_from_inbox %}
|
{% if object.is_from_inbox %}
|
||||||
|
<div class="bar-item">
|
||||||
{% if object.liked_via_outbox_object_ap_id %}
|
{% if object.liked_via_outbox_object_ap_id %}
|
||||||
<div class="bar-item">
|
|
||||||
{{ admin_undo_button(object.liked_via_outbox_object_ap_id, "Unlike") }}
|
{{ admin_undo_button(object.liked_via_outbox_object_ap_id, "Unlike") }}
|
||||||
</div>
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="bar-item">
|
|
||||||
{{ admin_like_button(object.ap_id) }}
|
{{ admin_like_button(object.ap_id) }}
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</div>
|
||||||
<div class="bar-item">
|
<div class="bar-item">
|
||||||
|
{% 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) }}
|
{{ admin_announce_button(object.ap_id) }}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="bar-item">
|
<div class="bar-item">
|
||||||
{{ admin_reply_button(object.ap_id) }}
|
{{ admin_reply_button(object.ap_id) }}
|
||||||
|
|
Loading…
Reference in a new issue