Multi-platform: support multiple files per version #201
@ -165,9 +165,14 @@ class ExtensionNameManifestValidator:
|
||||
|
||||
|
||||
class ExtensionVersionManifestValidator:
|
||||
"""Validates version."""
|
||||
"""Validates version existence in db and available platforms.
|
||||
|
||||
def __init__(self, manifest, extension_to_be_updated, allow_existing_version):
|
||||
allow_existing_version is meant to be used from API and UploadVersionFileNew
|
||||
when a version either may exist or definitely exists.
|
||||
TODO? create separate flags for these scenarios?
|
||||
"""
|
||||
|
||||
def __init__(self, manifest, extension_to_be_updated, allow_existing_version=False):
|
||||
|
||||
# If the extension wasn't created yet, any version is valid
|
||||
if not extension_to_be_updated:
|
||||
@ -190,8 +195,9 @@ class ExtensionVersionManifestValidator:
|
||||
)
|
||||
|
||||
# check for platforms
|
||||
if platforms := manifest.get('platforms', None):
|
||||
# TODO test coverage
|
||||
available_platforms = version.get_available_platforms()
|
||||
if platforms := manifest.get('platforms', None):
|
||||
if diff := set(platforms) - available_platforms:
|
||||
raise ValidationError(
|
||||
{
|
||||
@ -199,6 +205,27 @@ class ExtensionVersionManifestValidator:
|
||||
},
|
||||
code='invalid',
|
||||
)
|
||||
else:
|
||||
if available_platforms:
|
||||
raise ValidationError(
|
||||
{
|
||||
'source': [
|
||||
f'File upload for {version} is allowed only for remaining platforms: '
|
||||
f'{", ".join(available_platforms)}'
|
||||
],
|
||||
},
|
||||
code='invalid',
|
||||
)
|
||||
else:
|
||||
raise ValidationError(
|
||||
{
|
||||
'source': [
|
||||
f'The version {escape(manifest_version)} was already uploaded for this '
|
||||
f'extension ({extension_to_be_updated.name})'
|
||||
],
|
||||
},
|
||||
code='invalid',
|
||||
)
|
||||
|
||||
|
||||
class ManifestFieldValidator:
|
||||
|
Loading…
Reference in New Issue
Block a user