diff --git a/api/funkwhale_api/manage/filters.py b/api/funkwhale_api/manage/filters.py index 984b83133..de12ab1ab 100644 --- a/api/funkwhale_api/manage/filters.py +++ b/api/funkwhale_api/manage/filters.py @@ -235,12 +235,23 @@ class ManageUploadFilterSet(filters.FilterSet): ] +def filter_allowed(queryset, name, value): + """ + If value=false, we want to include object with value=null as well + """ + if value: + return queryset.filter(allowed=True) + else: + return queryset.filter(Q(allowed=False) | Q(allowed__isnull=True)) + + class ManageDomainFilterSet(filters.FilterSet): q = fields.SearchFilter(search_fields=["name"]) + allowed = filters.BooleanFilter(method=filter_allowed) class Meta: model = federation_models.Domain - fields = ["name"] + fields = ["name", "allowed"] class ManageActorFilterSet(filters.FilterSet): diff --git a/api/funkwhale_api/manage/serializers.py b/api/funkwhale_api/manage/serializers.py index 25f8c01db..c72e015bf 100644 --- a/api/funkwhale_api/manage/serializers.py +++ b/api/funkwhale_api/manage/serializers.py @@ -152,7 +152,11 @@ class ManageDomainUpdateSerializer(ManageDomainSerializer): class ManageDomainActionSerializer(common_serializers.ActionSerializer): - actions = [common_serializers.Action("purge", allow_all=False)] + actions = [ + common_serializers.Action("purge", allow_all=False), + common_serializers.Action("allow_list_add", allow_all=True), + common_serializers.Action("allow_list_remove", allow_all=True), + ] filterset_class = filters.ManageDomainFilterSet pk_field = "name" @@ -161,6 +165,14 @@ class ManageDomainActionSerializer(common_serializers.ActionSerializer): ids = objects.values_list("pk", flat=True) common_utils.on_commit(federation_tasks.purge_actors.delay, domains=list(ids)) + @transaction.atomic + def handle_allow_list_add(self, objects): + objects.update(allowed=True) + + @transaction.atomic + def handle_allow_list_remove(self, objects): + objects.update(allowed=False) + class ManageBaseActorSerializer(serializers.ModelSerializer): class Meta: diff --git a/api/funkwhale_api/moderation/dynamic_preferences_registry.py b/api/funkwhale_api/moderation/dynamic_preferences_registry.py index 8d8237cbb..04a732f4d 100644 --- a/api/funkwhale_api/moderation/dynamic_preferences_registry.py +++ b/api/funkwhale_api/moderation/dynamic_preferences_registry.py @@ -19,8 +19,8 @@ class AllowListPublic(types.BooleanPreference): name = "allow_list_public" verbose_name = "Publish your allowed-domains list" help_text = ( - "If enabled, everyone will be able to retrieve the list of domains you allowed. ", + "If enabled, everyone will be able to retrieve the list of domains you allowed. " "This is useful on open setups, to help people decide if they want to join your pod, or to " - "make your moderation policy public.", + "make your moderation policy public." ) default = False diff --git a/api/tests/manage/test_serializers.py b/api/tests/manage/test_serializers.py index cfbb17517..e621bf14c 100644 --- a/api/tests/manage/test_serializers.py +++ b/api/tests/manage/test_serializers.py @@ -176,6 +176,26 @@ def test_manage_domain_action_purge(factories, mocker): ) +def test_manage_domain_action_allow_list_add(factories, mocker): + domains = factories["federation.Domain"].create_batch(size=3, allowed=False) + s = serializers.ManageDomainActionSerializer(queryset=None) + s.handle_allow_list_add(domains[0].__class__.objects.all()) + + for domain in domains: + domain.refresh_from_db() + assert domain.allowed is True + + +def test_manage_domain_action_allow_list_remove(factories, mocker): + domains = factories["federation.Domain"].create_batch(size=3, allowed=True) + s = serializers.ManageDomainActionSerializer(queryset=None) + s.handle_allow_list_remove(domains[0].__class__.objects.all()) + + for domain in domains: + domain.refresh_from_db() + assert domain.allowed is False + + @pytest.mark.parametrize( "param,expected_only", [("block_all", []), ("reject_media", ["media"])] ) diff --git a/front/src/components/manage/moderation/DomainsTable.vue b/front/src/components/manage/moderation/DomainsTable.vue index 544d91156..089b7288e 100644 --- a/front/src/components/manage/moderation/DomainsTable.vue +++ b/front/src/components/manage/moderation/DomainsTable.vue @@ -6,6 +6,14 @@ +