Merge branch '853-allow-listing-nodeinfo' into 'develop'
See #853: advertise allow-list configuration in nodeinfo See merge request funkwhale/funkwhale!793
This commit is contained in:
commit
d029248f0d
|
@ -2,7 +2,7 @@ import memoize.djangocache
|
||||||
|
|
||||||
import funkwhale_api
|
import funkwhale_api
|
||||||
from funkwhale_api.common import preferences
|
from funkwhale_api.common import preferences
|
||||||
from funkwhale_api.federation import actors
|
from funkwhale_api.federation import actors, models as federation_models
|
||||||
from funkwhale_api.music import utils as music_utils
|
from funkwhale_api.music import utils as music_utils
|
||||||
|
|
||||||
from . import stats
|
from . import stats
|
||||||
|
@ -13,6 +13,16 @@ memo = memoize.Memoizer(store, namespace="instance:stats")
|
||||||
|
|
||||||
def get():
|
def get():
|
||||||
share_stats = preferences.get("instance__nodeinfo_stats_enabled")
|
share_stats = preferences.get("instance__nodeinfo_stats_enabled")
|
||||||
|
allow_list_enabled = preferences.get("moderation__allow_list_enabled")
|
||||||
|
allow_list_public = preferences.get("moderation__allow_list_public")
|
||||||
|
if allow_list_enabled and allow_list_public:
|
||||||
|
allowed_domains = list(
|
||||||
|
federation_models.Domain.objects.filter(allowed=True)
|
||||||
|
.order_by("name")
|
||||||
|
.values_list("name", flat=True)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
allowed_domains = None
|
||||||
data = {
|
data = {
|
||||||
"version": "2.0",
|
"version": "2.0",
|
||||||
"software": {"name": "funkwhale", "version": funkwhale_api.__version__},
|
"software": {"name": "funkwhale", "version": funkwhale_api.__version__},
|
||||||
|
@ -36,6 +46,7 @@ def get():
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
"supportedUploadExtensions": music_utils.SUPPORTED_EXTENSIONS,
|
"supportedUploadExtensions": music_utils.SUPPORTED_EXTENSIONS,
|
||||||
|
"allowList": {"enabled": allow_list_enabled, "domains": allowed_domains},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if share_stats:
|
if share_stats:
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
import funkwhale_api
|
import funkwhale_api
|
||||||
from funkwhale_api.instance import nodeinfo
|
from funkwhale_api.instance import nodeinfo
|
||||||
from funkwhale_api.federation import actors
|
from funkwhale_api.federation import actors
|
||||||
|
@ -48,6 +50,7 @@ def test_nodeinfo_dump(preferences, mocker):
|
||||||
"listenings": {"total": stats["listenings"]},
|
"listenings": {"total": stats["listenings"]},
|
||||||
},
|
},
|
||||||
"supportedUploadExtensions": music_utils.SUPPORTED_EXTENSIONS,
|
"supportedUploadExtensions": music_utils.SUPPORTED_EXTENSIONS,
|
||||||
|
"allowList": {"enabled": False, "domains": None},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert nodeinfo.get() == expected
|
assert nodeinfo.get() == expected
|
||||||
|
@ -79,6 +82,25 @@ def test_nodeinfo_dump_stats_disabled(preferences, mocker):
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
"supportedUploadExtensions": music_utils.SUPPORTED_EXTENSIONS,
|
"supportedUploadExtensions": music_utils.SUPPORTED_EXTENSIONS,
|
||||||
|
"allowList": {"enabled": False, "domains": None},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert nodeinfo.get() == expected
|
assert nodeinfo.get() == expected
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"enabled, public, expected",
|
||||||
|
[
|
||||||
|
(True, True, {"enabled": True, "domains": ["allowed.example"]}),
|
||||||
|
(True, False, {"enabled": True, "domains": None}),
|
||||||
|
(False, False, {"enabled": False, "domains": None}),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_nodeinfo_allow_list_enabled(preferences, factories, enabled, public, expected):
|
||||||
|
preferences["moderation__allow_list_enabled"] = enabled
|
||||||
|
preferences["moderation__allow_list_public"] = public
|
||||||
|
factories["federation.Domain"](name="allowed.example", allowed=True)
|
||||||
|
factories["federation.Domain"](allowed=False)
|
||||||
|
factories["federation.Domain"](allowed=None)
|
||||||
|
|
||||||
|
assert nodeinfo.get()["metadata"]["allowList"] == expected
|
||||||
|
|
Loading…
Reference in New Issue