Error checking for attachment model type (#7506)

This commit is contained in:
Oliver 2024-06-25 11:48:00 +10:00 committed by GitHub
parent c6ad902ccc
commit 4989e86349
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 2 deletions

View File

@ -3241,6 +3241,6 @@ class Attachment(InvenTree.models.MetadataMixin, InvenTree.models.InvenTreeModel
)
if not issubclass(model_class, InvenTreeAttachmentMixin):
raise ValueError(_('Invalid model type specified for attachment'))
raise ValidationError(_('Invalid model type specified for attachment'))
return model_class.check_attachment_permission(permission, user)

View File

@ -29,11 +29,14 @@ def attachment_model_options():
def attachment_model_class_from_label(label: str):
"""Return the model class for the given label."""
if not label:
raise ValidationError(_('No attachment model type provided'))
for model in attachment_model_types():
if model.__name__.lower() == label.lower():
return model
raise ValueError(f'Invalid attachment model label: {label}')
raise ValidationError(_('Invalid attachment model type') + f": '{label}'")
def validate_attachment_model_type(value):