Don't treat permission name as a machine readable field, use slug instead #115

Merged
Oleg-Komarov merged 2 commits from permissions-use-slug into main 2024-05-06 17:40:07 +02:00
2 changed files with 11 additions and 16 deletions
Showing only changes of commit c82e3522fd - Show all commits

View File

@ -384,7 +384,7 @@ class VersionPermission(CreatedModifiedMixin, models.Model):
@classmethod
def get_by_slug(cls, slug: str):
return cls.objects.filter(slug=slug).first()
return cls.objects.get(slug=slug)
class Tag(CreatedModifiedMixin, models.Model):
@ -515,11 +515,6 @@ class Version(CreatedModifiedMixin, RatingMixin, TrackChangesMixin, models.Model
for permission_name in _permissions:
permission = VersionPermission.get_by_slug(permission_name)
# Just ignore versions that are incompatible.
if not permission:
continue
self.permissions.add(permission)
def set_initial_licenses(self, _licenses):

View File

@ -54,8 +54,7 @@ class FileMIMETypeValidator:
class ExtensionIDManifestValidator:
"""
Make sure the extension id is valid:
"""Make sure the extension id is valid:
* Extension id consists of Unicode letters, numbers or underscores.
* Neither hyphens nor spaces are supported.
* Each extension id most be unique across all extensions.
@ -307,8 +306,9 @@ class PermissionsValidator:
is_error = True
else:
for permission in value:
if VersionPermission.get_by_slug(permission):
continue
try:
VersionPermission.get_by_slug(permission)
except VersionPermission.DoesNotExist:
is_error = True
logger.info(f'Permission unavailable: {permission}')