Implements extensions license updates #236 #237

Merged
Dalai Felinto merged 1 commits from gpl3-addons into main 2024-08-22 17:54:30 +02:00
17 changed files with 53 additions and 15 deletions

View File

@ -482,11 +482,34 @@ class ValidateManifestFields(TestCase):
self.assertEqual(1, len(e.exception.messages))
self.assertIn('version', e.exception.messages[0])
def test_licenses(self):
def test_licenses_addons(self):
data = {
**self.mandatory_fields,
**self.optional_fields,
}
data['license'] = ['SPDX:GPL-3.0-or-later']
ManifestValidator(data)
data['license'] = ['SPDX:GPL-3.0-or-later', 'SPDX:CC0-1.0']
ManifestValidator(data)
message_begin = "Manifest value error: <code>license</code> expects a list of"
for license in ['SPDX:GPL-2.0-or-later', 'SPDX:MIT', 'SPDX:ZLIB']:
data['license'] = [license]
with self.assertRaises(ValidationError) as e:
ManifestValidator(data)
self.assertNotIn(message_begin, e.exception.messages[0])
self.assertIn('SPDX:GPL-3.0-or-later', e.exception.messages[0])
self.assertIn('for add-ons must be', e.exception.messages[0])
def test_licenses_themes(self):
data = {
**self.mandatory_fields,
**self.optional_fields,
}
data['type'] = 'theme'
data['tags'] = ['Dark']
del data['permissions']
data['license'] = ['SPDX:GPL-2.0-or-later']
ManifestValidator(data)
@ -497,7 +520,7 @@ class ValidateManifestFields(TestCase):
message_begin = "Manifest value error: <code>license</code> expects a list of"
self.assertIn(message_begin, e.exception.messages[0])
self.assertIn('[\'SPDX:GPL-2.0-or-later\']', e.exception.messages[0])
self.assertIn('[\'SPDX:GPL-3.0-or-later\']', e.exception.messages[0])
data['license'] = ['SPDX:GPL-2.0-only']
with self.assertRaises(ValidationError) as e:

View File

@ -27,7 +27,7 @@ EXPECTED_EXTENSION_DATA = {
'type': 'add-on',
'schema_version': "1.0.0",
},
'file_hash': 'sha256:28313858b9be34e6ecd15a63e28f626fb914dbdcc74c6d21c6536c9fad9de426',
'file_hash': 'sha256:31c7489479d268af8622d3468dc40feee2287510dfa1f3adf6cbff37154d2e06',
'size_bytes': 53969,
'tags': ['Sequencer'],
'version_str': '0.1.0',
@ -42,8 +42,8 @@ EXPECTED_EXTENSION_DATA = {
'blender_version_min': '4.2.0',
'type': 'add-on',
},
'file_hash': 'sha256:fb71280e43400b1fd343a6b5a1421dcb63c4fa69935963429bd6cae965dad2db',
'size_bytes': 434471,
'file_hash': 'sha256:67d6259eb99ae60d2abbcdfe312e7677621d8ac4f674158a91a5fde69e751548',
'size_bytes': 434477,
'tags': ['3D View'],
'version_str': '2.2.8',
'slug': 'blender-gis',
@ -57,8 +57,8 @@ EXPECTED_EXTENSION_DATA = {
'blender_version_min': '4.2.0',
'type': 'add-on',
},
'file_hash': 'sha256:09dcc1f0f9bc7103c48974da1d81f85b13326172fa008b2651cc4e77198654ed',
'size_bytes': 72865,
'file_hash': 'sha256:c218c1b7d13436be59706081adeb4125cb2e3118c5c2a45576ede1bbf61d3ec6',
'size_bytes': 72868,
'tags': [],
'version_str': '1.0.8',
'slug': 'amaranth',
@ -74,8 +74,8 @@ EXPECTED_EXTENSION_DATA = {
'permissions': {'files': 'reading files', 'network': 'talking to server'},
'platforms': ['linux-x64'],
},
'file_hash': 'sha256:0431dac17d6e4d20c17a799dcc5ee915c12ea6d5b9a58a26b7850dea4aecc58c',
'size_bytes': 765,
'file_hash': 'sha256:7bcc6730049373856a8f1a801ddf4577e8e6948393b82db032514f0ec44945fc',
'size_bytes': 767,
'tags': [],
'version_str': '0.1.0',
'slug': 'some-addon',
@ -92,8 +92,8 @@ EXPECTED_EXTENSION_DATA = {
'platforms': ['linux-x64', 'windows-x64'],
'build': {'generated': {'platforms': ['linux-x64']}},
},
'file_hash': 'sha256:b592384240eb04fb0f5e57741d93d8e15456d3fc27c837e2246422d6512ae002',
'size_bytes': 791,
'file_hash': 'sha256:719069cb27188e57600250fb3a8dcfb671b4c35a2996fb81b1f24943aa17f9ac',
'size_bytes': 793,
'tags': [],
'version_str': '0.1.0',
'slug': 'some-addon',
@ -447,7 +447,7 @@ class SubmitFinaliseTest(CheckFilePropertiesMixin, TestCase):
get_status_display='Awaiting Review',
get_type_display='Add-on',
hash=version.files.first().original_hash,
original_hash='sha256:2831385',
original_hash='sha256:31c7489',
)
# We cannot check for the ManyToMany yet (tags, licences, permissions)

View File

@ -10,7 +10,7 @@ class UtilsTest(TestCase):
'description': 'my description',
'permissions': [],
'tags': ['foo', 'bar'],
'license': ['SPDX:GPL-2.0-or-later'],
'license': ['SPDX:GPL-3.0-or-later'],
'blender_version_min': "2.9.3",
'blender_version_max': None,
}
@ -18,7 +18,7 @@ class UtilsTest(TestCase):
'tagline': '',
'description': 'my description',
'tags': ['foo', 'bar'],
'license': ['SPDX:GPL-2.0-or-later'],
'license': ['SPDX:GPL-3.0-or-later'],
'blender_version_min': "2.9.3",
}
cleaned_dictionary = clean_json_dictionary_from_optional_fields(test_dictionary)

View File

@ -248,13 +248,14 @@ class ListValidator(SimpleValidator):
class LicenseValidator(ListValidator):
example = ['SPDX:GPL-2.0-or-later']
example = ['SPDX:GPL-3.0-or-later']
@classmethod
def validate(cls, *, name: str, value: list[str], manifest: dict) -> str:
"""Return error message if there is any license that is not accepted by the site"""
is_error = False
error_message = ""
gnu_gpl3_slug = "SPDX:GPL-3.0-or-later"
if type(value) != list:
is_error = True
@ -267,6 +268,20 @@ class LicenseValidator(ListValidator):
unknown_value = license
break
if (
type(value) is list
and (manifest.get("type") == EXTENSION_TYPE_SLUGS_SINGULAR[EXTENSION_TYPE_CHOICES.BPY])
and gnu_gpl3_slug not in value
):
return mark_safe(
f'Manifest value error: <code>license</code> for add-ons must be '
f'<a href="https://spdx.org/licenses/GPL-3.0-or-later.html">GPL v3.0 or later</a>. '
f'Additional license are possible, read the '
f'<a href="https://docs.blender.org/manual/en/latest/'
f'advanced/extensions/licenses.html">'
f'documentation</a>. e.g., {cls.example}.'
)
if not is_error:
return