Fixes #4702: Catch IntegrityError exception when adding a non-unique secret

This commit is contained in:
Jeremy Stretch 2020-06-01 10:00:32 -04:00
parent d23b18beb5
commit edf15532d2
2 changed files with 18 additions and 0 deletions

View File

@ -1,5 +1,13 @@
# NetBox v2.8
## v2.8.6 (FUTURE)
### Bug Fixes
* [#4702](https://github.com/netbox-community/netbox/issues/4702) - Catch IntegrityError exception when adding a non-unique secret
---
## v2.8.5 (2020-05-26)
**Note:** The minimum required version of PostgreSQL is now 9.6.

View File

@ -115,6 +115,16 @@ class SecretForm(BootstrapMixin, CustomFieldModelForm):
'plaintext2': "The two given plaintext values do not match. Please check your input."
})
# Validate uniqueness
if Secret.objects.filter(
device=self.cleaned_data['device'],
role=self.cleaned_data['role'],
name=self.cleaned_data['name']
).exists():
raise forms.ValidationError(
"Each secret assigned to a device must have a unique combination of role and name"
)
class SecretCSVForm(CustomFieldModelCSVForm):
device = CSVModelChoiceField(