Verified Commit 22cc2048 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Merge branch 'release/0.9.1'

parents d44b8627 eb275b7e
...@@ -3,6 +3,16 @@ Changelog ...@@ -3,6 +3,16 @@ Changelog
.. towncrier .. towncrier
0.9.1 (2018-04-17)
------------------
Bugfixes:
- Allow null values for musicbrainz_id in Audio ActivityPub representation
- Fixed broken permission check on library scanning and too aggressive page
validation
0.9 (2018-04-17) 0.9 (2018-04-17)
---------------- ----------------
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
__version__ = '0.9' __version__ = '0.9.1'
__version_info__ = tuple([int(num) if num.isdigit() else num for num in __version__.replace('-', '.', 1).split('.')]) __version_info__ = tuple([int(num) if num.isdigit() else num for num in __version__.replace('-', '.', 1).split('.')])
...@@ -16,4 +16,5 @@ class LibraryFollower(BasePermission): ...@@ -16,4 +16,5 @@ class LibraryFollower(BasePermission):
return False return False
library = actors.SYSTEM_ACTORS['library'].get_actor_instance() library = actors.SYSTEM_ACTORS['library'].get_actor_instance()
return library.followers.filter(url=actor.url).exists() return library.received_follows.filter(
approved=True, actor=actor).exists()
...@@ -616,10 +616,12 @@ class CollectionPageSerializer(serializers.Serializer): ...@@ -616,10 +616,12 @@ class CollectionPageSerializer(serializers.Serializer):
if not item_serializer: if not item_serializer:
return v return v
raw_items = [item_serializer(data=i, context=self.context) for i in v] raw_items = [item_serializer(data=i, context=self.context) for i in v]
valid_items = []
for i in raw_items: for i in raw_items:
i.is_valid(raise_exception=True) if i.is_valid():
valid_items.append(i)
return raw_items return valid_items
def to_representation(self, conf): def to_representation(self, conf):
page = conf['page'] page = conf['page']
...@@ -662,17 +664,17 @@ class CollectionPageSerializer(serializers.Serializer): ...@@ -662,17 +664,17 @@ class CollectionPageSerializer(serializers.Serializer):
class ArtistMetadataSerializer(serializers.Serializer): class ArtistMetadataSerializer(serializers.Serializer):
musicbrainz_id = serializers.UUIDField(required=False) musicbrainz_id = serializers.UUIDField(required=False, allow_null=True)
name = serializers.CharField() name = serializers.CharField()
class ReleaseMetadataSerializer(serializers.Serializer): class ReleaseMetadataSerializer(serializers.Serializer):
musicbrainz_id = serializers.UUIDField(required=False) musicbrainz_id = serializers.UUIDField(required=False, allow_null=True)
title = serializers.CharField() title = serializers.CharField()
class RecordingMetadataSerializer(serializers.Serializer): class RecordingMetadataSerializer(serializers.Serializer):
musicbrainz_id = serializers.UUIDField(required=False) musicbrainz_id = serializers.UUIDField(required=False, allow_null=True)
title = serializers.CharField() title = serializers.CharField()
......
...@@ -30,11 +30,26 @@ def test_library_follower_actor_non_follower( ...@@ -30,11 +30,26 @@ def test_library_follower_actor_non_follower(
assert check is False assert check is False
def test_library_follower_actor_follower_not_approved(
factories, api_request, anonymous_user, settings):
settings.FEDERATION_MUSIC_NEEDS_APPROVAL = True
library = actors.SYSTEM_ACTORS['library'].get_actor_instance()
follow = factories['federation.Follow'](target=library, approved=False)
view = APIView.as_view()
permission = permissions.LibraryFollower()
request = api_request.get('/')
setattr(request, 'user', anonymous_user)
setattr(request, 'actor', follow.actor)
check = permission.has_permission(request, view)
assert check is False
def test_library_follower_actor_follower( def test_library_follower_actor_follower(
factories, api_request, anonymous_user, settings): factories, api_request, anonymous_user, settings):
settings.FEDERATION_MUSIC_NEEDS_APPROVAL = True settings.FEDERATION_MUSIC_NEEDS_APPROVAL = True
library = actors.SYSTEM_ACTORS['library'].get_actor_instance() library = actors.SYSTEM_ACTORS['library'].get_actor_instance()
follow = factories['federation.Follow'](target=library) follow = factories['federation.Follow'](target=library, approved=True)
view = APIView.as_view() view = APIView.as_view()
permission = permissions.LibraryFollower() permission = permissions.LibraryFollower()
request = api_request.get('/') request = api_request.get('/')
......
...@@ -431,8 +431,14 @@ def test_collection_page_serializer_validation(): ...@@ -431,8 +431,14 @@ def test_collection_page_serializer_validation():
def test_collection_page_serializer_can_validate_child(): def test_collection_page_serializer_can_validate_child():
base = 'https://test.federation/test'
data = { data = {
'type': 'CollectionPage',
'id': 'https://test.page?page=2',
'actor': 'https://test.actor',
'first': 'https://test.page?page=1',
'last': 'https://test.page?page=3',
'partOf': 'https://test.page',
'totalItems': 1,
'items': [{'in': 'valid'}], 'items': [{'in': 'valid'}],
} }
...@@ -441,8 +447,9 @@ def test_collection_page_serializer_can_validate_child(): ...@@ -441,8 +447,9 @@ def test_collection_page_serializer_can_validate_child():
context={'item_serializer': serializers.AudioSerializer} context={'item_serializer': serializers.AudioSerializer}
) )
assert serializer.is_valid() is False # child are validated but not included in data if not valid
assert 'items' in serializer.errors assert serializer.is_valid(raise_exception=True) is True
assert len(serializer.validated_data['items']) == 0
def test_collection_page_serializer(factories): def test_collection_page_serializer(factories):
......
...@@ -43,7 +43,7 @@ def test_instance_endpoints_405_if_federation_disabled( ...@@ -43,7 +43,7 @@ def test_instance_endpoints_405_if_federation_disabled(
def test_wellknown_webfinger_validates_resource( def test_wellknown_webfinger_validates_resource(
db, api_client, settings, mocker): db, api_client, settings, mocker):
clean = mocker.spy(webfinger, 'clean_resource') clean = mocker.spy(webfinger, 'clean_resource')
url = reverse('federation:well-known-webfinger') url = reverse('federation:well-known-webfinger')
response = api_client.get(url, data={'resource': 'something'}) response = api_client.get(url, data={'resource': 'something'})
......
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