Tweak the admin UI

This commit is contained in:
Thomas Sileo 2018-07-14 12:14:08 +02:00
parent feb611f4ce
commit d8f7967e6a
6 changed files with 46 additions and 21 deletions

View file

@ -14,6 +14,10 @@ reload-fed:
WEB_PORT=5006 CONFIG_DIR=./tests/fixtures/instance1/config docker-compose -p instance1 -f docker-compose-tests.yml up -d --force-recreate --build WEB_PORT=5006 CONFIG_DIR=./tests/fixtures/instance1/config docker-compose -p instance1 -f docker-compose-tests.yml up -d --force-recreate --build
WEB_PORT=5007 CONFIG_DIR=./tests/fixtures/instance2/config docker-compose -p instance2 -f docker-compose-tests.yml up -d --force-recreate --build WEB_PORT=5007 CONFIG_DIR=./tests/fixtures/instance2/config docker-compose -p instance2 -f docker-compose-tests.yml up -d --force-recreate --build
reload-dev:
docker build . -t microblogpub:latest
docker-compose -f docker-compose-dev.yml up -d --force-recreate
update: update:
git pull git pull
docker build . -t microblogpub:latest docker build . -t microblogpub:latest

View file

@ -103,19 +103,15 @@ class MicroblogPubBackend(Backend):
def outbox_new(self, as_actor: ap.Person, activity: ap.BaseActivity) -> None: def outbox_new(self, as_actor: ap.Person, activity: ap.BaseActivity) -> None:
self.save(Box.OUTBOX, activity) self.save(Box.OUTBOX, activity)
def parse_collection( def followers(self) -> List[str]:
self, payload: Optional[Dict[str, Any]] = None, url: Optional[str] = None
) -> List[str]:
"""Resolve/fetch a `Collection`/`OrderedCollection`."""
# Resolve internal collections via MongoDB directly
if url == ID + "/followers":
q = { q = {
"box": Box.INBOX.value, "box": Box.INBOX.value,
"type": ap.ActivityType.FOLLOW.value, "type": ap.ActivityType.FOLLOW.value,
"meta.undo": False, "meta.undo": False,
} }
return [doc["activity"]["actor"] for doc in DB.activities.find(q)] return [doc["activity"]["actor"] for doc in DB.activities.find(q)]
elif url == ID + "/following":
def following(self) -> List[str]:
q = { q = {
"box": Box.OUTBOX.value, "box": Box.OUTBOX.value,
"type": ap.ActivityType.FOLLOW.value, "type": ap.ActivityType.FOLLOW.value,
@ -123,6 +119,16 @@ class MicroblogPubBackend(Backend):
} }
return [doc["activity"]["object"] for doc in DB.activities.find(q)] return [doc["activity"]["object"] for doc in DB.activities.find(q)]
def parse_collection(
self, payload: Optional[Dict[str, Any]] = None, url: Optional[str] = None
) -> List[str]:
"""Resolve/fetch a `Collection`/`OrderedCollection`."""
# Resolve internal collections via MongoDB directly
if url == ID + "/followers":
return self.followers()
elif url == ID + "/following":
return self.following()
return super().parse_collection(payload, url) return super().parse_collection(payload, url)
@ensure_it_is_me @ensure_it_is_me

2
app.py
View file

@ -1585,7 +1585,7 @@ def following():
following, older_than, newer_than = paginated_query(DB.activities, q) following, older_than, newer_than = paginated_query(DB.activities, q)
following = [ following = [
get_backend().fetch_iri(doc["activity"]["object"]) for doc in following (doc["remote_id"], get_backend().fetch_iri(doc["activity"]["object"])) for doc in following
] ]
return render_template( return render_template(
"following.html", "following.html",

View file

@ -37,6 +37,9 @@ def process_new_activity(self, iri: str) -> None:
activity = ap.fetch_remote_activity(iri) activity = ap.fetch_remote_activity(iri)
log.info(f"activity={activity!r}") log.info(f"activity={activity!r}")
# Is the activity expected?
# following = ap.get_backend().following()
tag_stream = False tag_stream = False
if activity.has_type(ap.ActivityType.ANNOUNCE): if activity.has_type(ap.ActivityType.ANNOUNCE):
tag_stream = True tag_stream = True

View file

@ -8,7 +8,18 @@
{% include "header.html" %} {% include "header.html" %}
<div id="following"> <div id="following">
{% for followed in following_data %} {% for (follow_id, followed) in following_data %}
{% if session.logged_in %}
<div style="margin-left:90px;padding-bottom:5px;margin-bottom:15px;">
<form action="/api/undo" class="action-form" method="POST">
<input type="hidden" name="redirect" value="{{ request.path }}"/>
<input type="hidden" name="id" value="{{ follow_id }}"/>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
<button type="submit" class="bar-item">unfollow</button>
</form>
</div>
{% endif %}
<div style="height: 100px;"> <div style="height: 100px;">
{{ utils.display_actor_inline(followed, size=80) }} {{ utils.display_actor_inline(followed, size=80) }}
</div> </div>

View file

@ -65,18 +65,19 @@
<a class ="bar-item" href="{{ obj.url }}">permalink</a> <a class ="bar-item" href="{{ obj.url }}">permalink</a>
{% if meta.count_reply %}<a class ="bar-item" href="{{ obj.url }}"><strong>{{ meta.count_reply }}</strong> replies</a>{% endif %} {% if meta.count_reply %}<a class ="bar-item" href="{{ obj.url }}"><strong>{{ meta.count_reply }}</strong> replies</a>{% endif %}
{% if meta.count_boost %}<a class ="bar-item" href="{{ obj.url }}"><strong>{{ meta.count_boost }}</strong> boosts</a>{% endif %} {% if meta.count_boost and obj.id | is_from_outbox %}<a class ="bar-item" href="{{ obj.url }}"><strong>{{ meta.count_boost }}</strong> boosts</a>{% endif %}
{% if meta.count_like %}<a class ="bar-item" href="{{ obj.url }}"><strong>{{ meta.count_like }}</strong> likes</a>{% endif %} {% if meta.count_like and obj.id | is_from_outbox %}<a class ="bar-item" href="{{ obj.url }}"><strong>{{ meta.count_like }}</strong> likes</a>{% endif %}
{% endif %}
{% if session.logged_in %}
{% set perma_id = obj.id | permalink_id %}
{% set redir = request.path + "#activity-" + perma_id %}
{% set aid = obj.id | quote_plus %}
{% endif %} {% endif %}
{% if ui and session.logged_in %} {% if ui and session.logged_in %}
{% set aid = obj.id | quote_plus %}
<a class="bar-item" href="/admin/new?reply={{ aid }}">reply</a> <a class="bar-item" href="/admin/new?reply={{ aid }}">reply</a>
{% set perma_id = obj.id | permalink_id %}
{% set redir = request.path + "#activity-" + perma_id %}
{% if meta.boosted %} {% if meta.boosted %}
<form action="/api/undo" class="action-form" method="POST"> <form action="/api/undo" class="action-form" method="POST">
<input type="hidden" name="redirect" value="{{ redir }}"> <input type="hidden" name="redirect" value="{{ redir }}">