Unverified Commit 32e7bc8a authored by Agate's avatar Agate 💬
Browse files

Exclude external podcasts from library home

parent fcd1e1b7
......@@ -4,6 +4,7 @@ import django_filters
from funkwhale_api.common import fields
from funkwhale_api.common import filters as common_filters
from funkwhale_api.federation import actors
from funkwhale_api.moderation import filters as moderation_filters
from . import models
......@@ -28,6 +29,7 @@ class ChannelFilter(moderation_filters.HiddenContentFilterSet):
subscribed = django_filters.BooleanFilter(
field_name="_", method="filter_subscribed"
)
external = django_filters.BooleanFilter(field_name="_", method="filter_external")
ordering = django_filters.OrderingFilter(
# tuple-mapping retains order
fields=(
......@@ -38,7 +40,7 @@ class ChannelFilter(moderation_filters.HiddenContentFilterSet):
class Meta:
model = models.Channel
fields = ["q", "scope", "tag", "subscribed", "ordering"]
fields = ["q", "scope", "tag", "subscribed", "ordering", "external"]
hidden_content_fields_mapping = moderation_filters.USER_FILTER_CONFIG["CHANNEL"]
def filter_subscribed(self, queryset, name, value):
......@@ -56,6 +58,18 @@ class ChannelFilter(moderation_filters.HiddenContentFilterSet):
else:
return queryset.exclude(query)
def filter_external(self, queryset, name, value):
query = Q(
attributed_to=actors.get_service_actor(),
actor__preferred_username__startswith="rssfeed-",
)
if value is True:
queryset = queryset.filter(query)
if value is False:
queryset = queryset.exclude(query)
return queryset
class IncludeChannelsFilterSet(django_filters.FilterSet):
"""
......
import pytest
from funkwhale_api.audio import filters
from funkwhale_api.audio import models
......@@ -30,3 +32,17 @@ def test_channel_filter_subscribed_false(factories, mocker, queryset_equal_list)
)
assert filterset.qs == [other_channel]
@pytest.mark.parametrize("external, expected_index", [("true", 0), ("false", 1)])
def test_channel_filter_external(
external, expected_index, factories, mocker, queryset_equal_list
):
user = factories["users.User"](with_actor=True)
channels = [factories["audio.Channel"](external=True), factories["audio.Channel"]()]
qs = models.Channel.objects.all()
filterset = filters.ChannelFilter(
{"external": external}, request=mocker.Mock(user=user), queryset=qs
)
assert filterset.qs == [channels[expected_index]]
......@@ -30,7 +30,7 @@
<h3 class="ui header" >
<translate translate-context="*/*/*">New channels</translate>
</h3>
<channels-widget :show-modification-date="true" :limit="12" :filters="{ordering: '-creation_date'}"></channels-widget>
<channels-widget :show-modification-date="true" :limit="12" :filters="{ordering: '-creation_date', external: 'false'}"></channels-widget>
</template>
......
Supports Markdown
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