Skip to content

Commit

Permalink
relay admin ui
Browse files Browse the repository at this point in the history
  • Loading branch information
alphatownsman committed Sep 1, 2023
1 parent bb2eaa5 commit 9f1dc90
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 0 deletions.
5 changes: 5 additions & 0 deletions takahe/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@
"admin/domains/<domain>/delete/",
admin.DomainDelete.as_view(),
),
path(
"admin/relays/",
admin.RelayRoot.as_view(),
name="admin_relays",
),
path(
"admin/federation/",
admin.FederationRoot.as_view(),
Expand Down
4 changes: 4 additions & 0 deletions templates/admin/_menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ <h3>Administration</h3>
<i class="fa-solid fa-diagram-project"></i>
<span>Federation</span>
</a>
<a href="{% url "admin_relays" %}" {% if section == "relays" %}class="selected"{% endif %} title="Relays">
<i class="fa-solid fa-tower-broadcast"></i>
<span>Relays</span>
</a>
<a href="{% url "admin_users" %}" {% if section == "users" %}class="selected"{% endif %} title="Users">
<i class="fa-solid fa-users"></i>
<span>Users</span>
Expand Down
1 change: 1 addition & 0 deletions templates/admin/identities.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
Remote
<small>{{ identity.followers_count }} local follower{{ identity.followers_count|pluralize }}</small>
{% endif %}
{{ identity.actor_type }}
</td>
<td class="actions">
<a href="{{ identity.urls.admin_edit }}" title="View"><i class="fa-solid fa-eye"></i></a>
Expand Down
69 changes: 69 additions & 0 deletions templates/admin/relays.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{% extends "admin/base_main.html" %}
{% load activity_tags %}

{% block subtitle %}Relay{% endblock %}

{% block settings_content %}
<form action="?subscribe" method="post" class="search">
<input type="url" name="actor_uri" value="" placeholder="relay actor URI, e.g. https://relay.server/actor">
{% csrf_token %}
<button>Subscribe</button>
</form>
<table class="items">
{% for identity in page_obj %}
<tr>
<td class="icon">

</td>
<td class="name">
{{ identity.actor_uri }}
<small>{{ identity.domain.nodeinfo.metadata.nodeName }}</small>
{% if identity.domain.nodeinfo.software %}
<small>{{ identity.domain.nodeinfo.software.name }} / {{ identity.domain.nodeinfo.software.version }}</small>
{% endif %}
</td>
<td>
{% if identity.restriction == 1 %}
<span class="bad">Limited</span>
{% elif identity.restriction == 2 %}
<span class="bad">Blocked</span>
{% endif %}
</td>
<td class="stat">
{% if identity.follow_state == 'accepting' or identity.follow_state == 'accepted' %}
ACTIVE
{% elif identity.follow_state == 'unrequested' or identity.follow_state == 'pending_approval' %}
ACTIVATING
{% else %}
DEACTIVATING
{% endif %}
<small>({{ identity.follow_state }})</small>
</td>
<td class="actions">
<form action="?unsubscribe" method="post">
<input type="hidden" name="actor_uri" value="{{ identity.actor_uri }}">
{% csrf_token %}
<button>Unsubscribe</button>
</form>
</td>
<td class="actions">
<form action="?remove" method="post">
<input type="hidden" name="actor_uri" value="{{ identity.actor_uri }}">
{% csrf_token %}
<button onclick="return confirm('Sure to force remove?')" {%if identity.follow_state == 'accepting' or identity.follow_state == 'accepted'%}disabled{%endif%}>Remove</button>
</form>
</td>
</tr>
{% empty %}
<tr class="empty">
<td>
There are no relay yet.
</td>
</tr>
{% endfor %}
</table>
<div class="view-options">
<small><i class="fa-regular fa-lightbulb"></i>&nbsp; invalid actor uri will not show in this list; (un)subscribing may take a while; use remove only when it's stuck in (DE)ACTIVATING state for a long time.</small>
</div>
{% include "admin/_pagination.html" with nouns="relay,relays" %}
{% endblock %}
11 changes: 11 additions & 0 deletions users/models/relay_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ def unsubscribe(cls, relay_uri):
}
)

@classmethod
def remove(cls, relay_uri):
from .follow import Follow

Follow.objects.filter(
source__actor_uri=cls.actor_uri, target__actor_uri=relay_uri
).delete()
Follow.objects.filter(
target__actor_uri=cls.actor_uri, source__actor_uri=relay_uri
).delete()

@classmethod
def handle_internal_unfollow(cls, payload):
"""
Expand Down
1 change: 1 addition & 0 deletions users/views/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from users.views.admin.hashtags import HashtagEdit, HashtagEnable, Hashtags # noqa
from users.views.admin.identities import IdentitiesRoot, IdentityEdit # noqa
from users.views.admin.invites import InviteCreate, InvitesRoot, InviteView # noqa
from users.views.admin.relays import RelayRoot # noqa
from users.views.admin.reports import ReportsRoot, ReportView # noqa
from users.views.admin.settings import ( # noqa
BasicSettings,
Expand Down
37 changes: 37 additions & 0 deletions users/views/admin/relays.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from django.db import models
from django.shortcuts import redirect
from django.utils.decorators import method_decorator
from django.views.generic import ListView

from users.decorators import admin_required
from users.models import Identity, RelayActor


@method_decorator(admin_required, name="dispatch")
class RelayRoot(ListView):
template_name = "admin/relays.html"
paginate_by = 30

def get(self, request, *args, **kwargs):
self.extra_context = {
"section": "relays",
}
return super().get(request, *args, **kwargs)

def get_queryset(self):
identities = (
Identity.objects.filter(inbound_follows__source=RelayActor.get_identity())
.annotate(follow_state=models.F("inbound_follows__state"))
.order_by("-created")
)
return identities

def post(self, request, *args, **kwargs):
actor_uri = request.POST.get("actor_uri")
if "subscribe" in request.GET:
RelayActor.subscribe(actor_uri)
elif "unsubscribe" in request.GET:
RelayActor.unsubscribe(actor_uri)
elif "remove" in request.GET:
RelayActor.remove(actor_uri)
return redirect(".")

0 comments on commit 9f1dc90

Please sign in to comment.