Added FUNKWHALE_HOSTNAME and FEDERATION_HOSTNAME settings
This commit is contained in:
parent
588da6ff33
commit
90c1d02919
|
@ -10,6 +10,7 @@ https://docs.djangoproject.com/en/dev/ref/settings/
|
||||||
"""
|
"""
|
||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
from urllib.parse import urlsplit
|
||||||
import os
|
import os
|
||||||
import environ
|
import environ
|
||||||
from funkwhale_api import __version__
|
from funkwhale_api import __version__
|
||||||
|
@ -24,8 +25,13 @@ try:
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS')
|
|
||||||
FUNKWHALE_URL = env('FUNKWHALE_URL')
|
FUNKWHALE_URL = env('FUNKWHALE_URL')
|
||||||
|
FUNKWHALE_HOSTNAME = urlsplit(FUNKWHALE_URL).netloc
|
||||||
|
|
||||||
|
FEDERATION_ENABLED = env.bool('FEDERATION_ENABLED', default=True)
|
||||||
|
FEDERATION_HOSTNAME = env('FEDERATION_HOSTNAME', default=FUNKWHALE_HOSTNAME)
|
||||||
|
|
||||||
|
ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS')
|
||||||
|
|
||||||
# APP CONFIGURATION
|
# APP CONFIGURATION
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -395,4 +401,5 @@ ACCOUNT_USERNAME_BLACKLIST = [
|
||||||
'owner',
|
'owner',
|
||||||
'superuser',
|
'superuser',
|
||||||
'staff',
|
'staff',
|
||||||
|
'service',
|
||||||
] + env.list('ACCOUNT_USERNAME_BLACKLIST', default=[])
|
] + env.list('ACCOUNT_USERNAME_BLACKLIST', default=[])
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
|
def full_url(path):
|
||||||
|
"""
|
||||||
|
Given a relative path, return a full url usable for federation purpose
|
||||||
|
"""
|
||||||
|
root = settings.FUNKWHALE_URL
|
||||||
|
if path.startswith('/') and root.endswith('/'):
|
||||||
|
return root + path[1:]
|
||||||
|
elif not path.startswith('/') and not root.endswith('/'):
|
||||||
|
return root + '/' + path
|
||||||
|
else:
|
||||||
|
return root + path
|
|
@ -0,0 +1,14 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from funkwhale_api.federation import utils
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('url,path,expected', [
|
||||||
|
('http://test.com', '/hello', 'http://test.com/hello'),
|
||||||
|
('http://test.com/', 'hello', 'http://test.com/hello'),
|
||||||
|
('http://test.com/', '/hello', 'http://test.com/hello'),
|
||||||
|
('http://test.com', 'hello', 'http://test.com/hello'),
|
||||||
|
])
|
||||||
|
def test_full_url(settings, url, path, expected):
|
||||||
|
settings.FUNKWHALE_URL = url
|
||||||
|
assert utils.full_url(path) == expected
|
Loading…
Reference in New Issue