See #170: limit the amount of channels allowed per user
This commit is contained in:
parent
11a42e362d
commit
a3505d2099
5 changed files with 52 additions and 2 deletions
|
|
@ -14,3 +14,12 @@ class ChannelsEnabled(types.BooleanPreference):
|
|||
"If disabled, the channels feature will be completely switched off, "
|
||||
"and users won't be able to create channels or subscribe to them."
|
||||
)
|
||||
|
||||
|
||||
@global_preferences_registry.register
|
||||
class MaxChannels(types.IntegerPreference):
|
||||
show_in_api = True
|
||||
section = audio
|
||||
default = 20
|
||||
name = "max_channels"
|
||||
verbose_name = "Max channels allowed per user"
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ from rest_framework import serializers
|
|||
from funkwhale_api.common import serializers as common_serializers
|
||||
from funkwhale_api.common import utils as common_utils
|
||||
from funkwhale_api.common import locales
|
||||
from funkwhale_api.common import preferences
|
||||
from funkwhale_api.federation import serializers as federation_serializers
|
||||
from funkwhale_api.federation import utils as federation_utils
|
||||
from funkwhale_api.music import models as music_models
|
||||
|
|
@ -59,6 +60,11 @@ class ChannelCreateSerializer(serializers.Serializer):
|
|||
metadata = serializers.DictField(required=False)
|
||||
|
||||
def validate(self, validated_data):
|
||||
existing_channels = self.context["actor"].owned_channels.count()
|
||||
if existing_channels >= preferences.get("audio__max_channels"):
|
||||
raise serializers.ValidationError(
|
||||
"You have reached the maximum amount of allowed channels"
|
||||
)
|
||||
validated_data = super().validate(validated_data)
|
||||
metadata = validated_data.pop("metadata", {})
|
||||
if validated_data["content_category"] == "podcast":
|
||||
|
|
|
|||
|
|
@ -138,6 +138,8 @@ class ChannelViewSet(
|
|||
"update",
|
||||
"partial_update",
|
||||
]
|
||||
if self.request.user.is_authenticated:
|
||||
context["actor"] = self.request.user.actor
|
||||
return context
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue