Commit 866055ba authored by Jason Robinson's avatar Jason Robinson

Make it possible to disable relay system subscription

SOCIALHOME_RELAY_SCOPE can be set to "none" now.

Refs: #94
parent 7898c3a3
Pipeline #1302 passed with stage
in 5 minutes and 39 seconds
......@@ -299,6 +299,7 @@ SOCIALHOME_URL = "{protocol}://{domain}".format(
)
# Relay to send public content to
SOCIALHOME_RELAY_ID = env("SOCIALHOME_RELAY_ID", default="relay@relay.iliketoast.net")
SOCIALHOME_RELAY_SCOPE = env("SOCIALHOME_RELAY_SCOPE", default="all")
# Admins
# Boolean whether to show admin contact information to users and in server metadata
# Uses `settings.ADMINS`.
......
......@@ -66,5 +66,6 @@ ENV DJANGO_DEBUG False
ENV DJANGO_ACCOUNT_ALLOW_REGISTRATION=False
ENV DJANGO_ALLOWED_HOSTS socialhome.local
ENV DBHOST=db
ENV SOCIALHOME_RELAY_SCOPE=all
CMD circusd /app/config/circus.ini
......@@ -23,6 +23,8 @@ Added
Content from followed tags is available under a new "Tags" stream.
* It's now possible to disable incoming `relay system <https://git.feneas.org/jaywink/social-relay>`_ integration by setting the environment variable ``SOCIALHOME_RELAY_SCOPE`` to ``none``. (`#94 <https://git.feneas.org/socialhome/socialhome/issues/94>`_)
Changed
.......
......
......@@ -338,11 +338,18 @@ Default: ``https://the-federation.info/socialhome``
URL to make signup link go to in the case that signups are closed.
SOCIALHOME_RELAY_ID
.......................
...................
Default: ``relay@relay.iliketoast.net``
Which relay instance ID to send outgoing content to. Socialhome automatically integrates with the `relay system <https://git.feneas.org/jaywink/social-relay>`_.
Which relay instance ID to send outgoing content to. For more info see `relay system <https://git.feneas.org/jaywink/social-relay>`_.
SOCIALHOME_RELAY_SCOPE
......................
Default: ``all``
Possible values ``all`` or ``none``. Defines at which level the defined relay is subscribed with. Set to ``none`` to disable the relay incoming subscription. For more info see `relay system <https://git.feneas.org/jaywink/social-relay>`_.
SOCIALHOME_ROOT_PROFILE
.......................
......
......@@ -187,3 +187,36 @@ class TestNodeInfoView(SocialhomeTestCase):
author__user__isnull=False, content_type=ContentType.REPLY).count(),
}
)
class TestSocialRelayView(SocialhomeTestCase):
@override_settings(SOCIALHOME_RELAY_SCOPE="all")
def test_view_responds__scope_all(self):
self.get("federate:social-relay")
self.response_200()
self.assertEqual(
json.loads(self.last_response.content),
{
"subscribe": True,
"scope": "all",
"tags": [],
}
)
@override_settings(SOCIALHOME_RELAY_SCOPE="none")
def test_view_responds__scope_none(self):
self.get("federate:social-relay")
self.response_200()
self.assertEqual(
json.loads(self.last_response.content),
{
"subscribe": False,
"scope": "",
"tags": [],
}
)
@override_settings(SOCIALHOME_RELAY_SCOPE="spam")
def test_view_responds__scope_invalid(self):
self.get("federate:social-relay")
self.response_404()
......@@ -5,7 +5,7 @@ from django.conf import settings
from django.contrib.sites.models import Site
from django.core.exceptions import ValidationError
from django.http import HttpResponse, HttpResponseBadRequest
from django.http.response import Http404, JsonResponse, HttpResponseRedirect
from django.http.response import Http404, JsonResponse, HttpResponseRedirect, HttpResponseNotFound
from django.shortcuts import get_object_or_404
from django.utils.timezone import now
from django.views.generic import View
......@@ -112,7 +112,13 @@ def nodeinfo_view(request):
def social_relay_view(request):
"""Generate a .well-known/x-social-relay document."""
relay = SocialRelayWellKnown(subscribe=True)
scope = settings.SOCIALHOME_RELAY_SCOPE
if scope == 'none':
relay = SocialRelayWellKnown(subscribe=False, scope="")
elif scope == 'all':
relay = SocialRelayWellKnown(subscribe=True)
else:
return HttpResponseNotFound()
return JsonResponse(relay.doc)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment