expose approval_notes (+ source) in addon response for developers+unlisted (#19601)

This commit is contained in:
Andrew Williamson 2022-08-24 13:23:08 +01:00 коммит произвёл GitHub
Родитель 3584c25c1e
Коммит 9c4a7ba58e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 51 добавлений и 18 удалений

Просмотреть файл

@ -651,6 +651,29 @@ class DeveloperListVersionSerializer(DeveloperVersionSerializer):
license = CompactLicenseSerializer()
class SimpleDeveloperVersionSerializer(DeveloperVersionSerializer):
# Used with DeveloperAddonSerializer - essentially SimpleVersionSerializer +
# developer-only fields like source, approval_notes, etc.
license = CompactLicenseSerializer(read_only=True)
class Meta:
model = Version
fields = (
'id',
'approval_notes',
'compatibility',
'edit_url',
'file',
'is_strict_compatibility_enabled',
'license',
'release_notes',
'reviewed',
'version',
'source',
)
read_only_fields = fields
class CurrentVersionSerializer(SimpleVersionSerializer):
def to_representation(self, obj):
# If the add-on is a langpack, and `appversion` is passed, try to
@ -728,7 +751,7 @@ class AddonEulaPolicySerializer(serializers.ModelSerializer):
)
class AddonDeveloperSerializer(BaseUserSerializer):
class UserSerializerWithPictureUrl(BaseUserSerializer):
picture_url = serializers.SerializerMethodField()
class Meta(BaseUserSerializer.Meta):
@ -845,7 +868,7 @@ class PromotedAddonSerializer(serializers.ModelSerializer):
class AddonSerializer(serializers.ModelSerializer):
authors = AddonDeveloperSerializer(
authors = UserSerializerWithPictureUrl(
many=True, source='listed_authors', read_only=True
)
categories = CategoriesSerializerField(source='all_categories', required=False)
@ -1210,8 +1233,9 @@ class AddonSerializer(serializers.ModelSerializer):
return instance
class AddonSerializerWithUnlistedData(AddonSerializer):
latest_unlisted_version = SimpleVersionSerializer(read_only=True)
class DeveloperAddonSerializer(AddonSerializer):
current_version = SimpleDeveloperVersionSerializer(read_only=True)
latest_unlisted_version = SimpleDeveloperVersionSerializer(read_only=True)
class Meta(AddonSerializer.Meta):
fields = AddonSerializer.Meta.fields + ('latest_unlisted_version',)

Просмотреть файл

@ -17,9 +17,9 @@ from olympia.addons.models import (
)
from olympia.addons.serializers import (
AddonAuthorSerializer,
AddonDeveloperSerializer,
UserSerializerWithPictureUrl,
AddonSerializer,
AddonSerializerWithUnlistedData,
DeveloperAddonSerializer,
DeveloperVersionSerializer,
DeveloperListVersionSerializer,
ESAddonAutoCompleteSerializer,
@ -979,7 +979,7 @@ class TestAddonSerializerOutput(AddonSerializerOutputTestMixin, TestCase):
assert result['current_version']['is_strict_compatibility_enabled']
def test_latest_unlisted_version_with_right_serializer(self):
self.serializer_class = AddonSerializerWithUnlistedData
self.serializer_class = DeveloperAddonSerializer
self.addon = addon_factory()
version_factory(
@ -1580,8 +1580,8 @@ class TestESAddonAutoCompleteSerializer(ESTestCase):
assert result['name'] == translated_name['fr']
class TestAddonDeveloperSerializer(TestCase, BaseTestUserMixin):
serializer_class = AddonDeveloperSerializer
class TestUserSerializerWithPictureUrl(TestCase, BaseTestUserMixin):
serializer_class = UserSerializerWithPictureUrl
def setUp(self):
self.request = APIRequestFactory().get('/')

Просмотреть файл

@ -86,7 +86,7 @@ from ..models import (
from ..serializers import (
AddonAuthorSerializer,
AddonPendingAuthorSerializer,
AddonSerializerWithUnlistedData,
DeveloperAddonSerializer,
CompactLicenseSerializer,
DeveloperVersionSerializer,
LicenseSerializer,
@ -871,7 +871,7 @@ class TestAddonViewSetCreate(UploadMixin, AddonViewSetCreateUpdateMixin, TestCas
request = APIRequestFactory().get('/')
request.version = 'v5'
request.user = self.user
assert data == AddonSerializerWithUnlistedData(
assert data == DeveloperAddonSerializer(
context={'request': request}
).to_representation(addon)
assert addon.find_latest_version(channel=None).channel == amo.CHANNEL_UNLISTED
@ -902,7 +902,7 @@ class TestAddonViewSetCreate(UploadMixin, AddonViewSetCreateUpdateMixin, TestCas
request = APIRequestFactory().get('/')
request.version = 'v5'
request.user = self.user
assert data == AddonSerializerWithUnlistedData(
assert data == DeveloperAddonSerializer(
context={'request': request}
).to_representation(addon)
assert addon.current_version.channel == amo.CHANNEL_LISTED
@ -1122,7 +1122,11 @@ class TestAddonViewSetCreate(UploadMixin, AddonViewSetCreateUpdateMixin, TestCas
'summary': {'en-US': 'new summary', 'fr': 'lé summary'},
'support_email': {'en-US': 'email@me.me'},
'support_url': {'en-US': 'https://my.home.page/support/'},
'version': {'upload': self.upload.uuid, 'license': self.license.slug},
'version': {
'upload': self.upload.uuid,
'license': self.license.slug,
'approval_notes': 'approve me!',
},
}
response = self.request(**data)
@ -1155,6 +1159,11 @@ class TestAddonViewSetCreate(UploadMixin, AddonViewSetCreateUpdateMixin, TestCas
assert addon.support_email == 'email@me.me'
assert data['support_url']['url'] == {'en-US': 'https://my.home.page/support/'}
assert addon.support_url == 'https://my.home.page/support/'
assert (
data['current_version']['approval_notes']
== addon.current_version.approval_notes
== 'approve me!'
)
self.statsd_incr_mock.assert_any_call('addons.submission.addon.listed')
def test_override_manifest_localization(self):
@ -1587,7 +1596,7 @@ class TestAddonViewSetUpdate(AddonViewSetCreateUpdateMixin, TestCase):
request = APIRequestFactory().get('/')
request.version = 'v5'
request.user = self.user
assert data == AddonSerializerWithUnlistedData(
assert data == DeveloperAddonSerializer(
context={'request': request}
).to_representation(self.addon)
assert self.addon.summary == 'summary update!'

Просмотреть файл

@ -83,7 +83,7 @@ from .serializers import (
AddonEulaPolicySerializer,
AddonAuthorSerializer,
AddonSerializer,
AddonSerializerWithUnlistedData,
DeveloperAddonSerializer,
DeveloperVersionSerializer,
DeveloperListVersionSerializer,
ESAddonAutoCompleteSerializer,
@ -240,7 +240,7 @@ class AddonViewSet(
RegionalRestriction | GroupPermission(amo.permissions.ADDONS_EDIT)
]
serializer_class = AddonSerializer
serializer_class_with_unlisted_data = AddonSerializerWithUnlistedData
serializer_class_for_developers = DeveloperAddonSerializer
lookup_value_regex = '[^/]+' # Allow '.' for email-like guids.
throttle_classes = addon_submission_throttles
@ -268,7 +268,7 @@ class AddonViewSet(
return qs
def get_serializer_class(self):
# Override serializer to use serializer_class_with_unlisted_data if
# Override serializer to use serializer_class_for_developers if the author or
# we are allowed to access unlisted data.
obj = getattr(self, 'instance', None)
request = self.request
@ -277,7 +277,7 @@ class AddonViewSet(
or acl.is_unlisted_addons_viewer_or_reviewer(request.user)
or (obj and obj.authors.filter(pk=request.user.pk).exists())
):
return self.serializer_class_with_unlisted_data
return self.serializer_class_for_developers
return self.serializer_class
def get_lookup_field(self, identifier):