mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 10:53:28 -05:00
Added a validator so that the key name is unique per service.
This commit is contained in:
@@ -238,4 +238,14 @@ class ConfirmMobileNumberForm(Form):
|
||||
|
||||
|
||||
class CreateKeyForm(Form):
|
||||
key_name = StringField(u'Description of key')
|
||||
def __init__(self, existing_key_names=[], *args, **kwargs):
|
||||
self.existing_key_names = existing_key_names
|
||||
super(CreateKeyForm, self).__init__(*args, **kwargs)
|
||||
|
||||
key_name = StringField(u'Description of key', validators=[
|
||||
DataRequired(message='You need to give the key a name')
|
||||
])
|
||||
|
||||
def validate_key_name(self, key_name):
|
||||
if key_name.data in self.existing_key_names:
|
||||
raise ValidationError('A key with this name already exists')
|
||||
|
||||
Reference in New Issue
Block a user