From ed651123d6c48644ae17e5e8fe513fd9f6b61bd0 Mon Sep 17 00:00:00 2001 From: Lenka Segura Date: Oct 15 2018 07:40:18 +0000 Subject: Add validators for the API field types --- diff --git a/pagure/lib/model.py b/pagure/lib/model.py index 2725665..90a8cd2 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -470,6 +470,43 @@ class Project(BASE): viewonly=True, ) + @validates('name') + def validate_name(self, key, name): + if not name: + raise AssertionError('No username provided') + if type(name) != six.text_type: + raise AssertionError('Name must be a string') + return name + + @validates('description') + def validate_description(self, key, description): + if not description: + raise AssertionError('No description provided') + if type(description) != six.text_type: + raise AssertionError('Description must be a string {0}'.format(type(description))) + return description + + @validates('namespace') + def validate_namespace(self, key, namespace): + if namespace: + if type(namespace) != six.text_type: + raise AssertionError('If you type namespace, please make it a string') + return namespace + + @validates('url') + def validate_url(self, key, url): + if url: + if type(url) != six.text_type: + raise AssertionError('If you type url, please make it a string') + return url + + @validates('avatar_email') + def validates_avatar_email(self, key, avatar_email): + if avatar_email: + if not re.match("[^@]+@[^@]+\.[^@]+", avatar_email): + raise AssertionError('If you type avatar_email, please make it a real email') + return avatar_email + @property def isa(self): """ A string to allow finding out that this is a project. """