Add asset groups and restrictions

This commit is contained in:
2023-02-10 14:33:17 +00:00
parent 7938bffc8d
commit f81d632df3
7 changed files with 230 additions and 32 deletions

View File

@@ -6,6 +6,7 @@ from django.forms import ModelForm
from .models import (
Account,
AssetGroup,
AssetRestriction,
Hook,
NotificationSettings,
RiskModel,
@@ -342,3 +343,37 @@ class AssetGroupForm(RestrictedFormMixin, ModelForm):
"description": "Description of the asset group. Informational only.",
"account": "Account to pull assets from.",
}
class AssetRestrictionForm(RestrictedFormMixin, ModelForm):
class Meta:
model = AssetRestriction
fields = (
"name",
"description",
"pairs",
)
help_texts = {
"name": "Name of the asset restriction group. Informational only.",
"description": "Description of the asset restriction group. Informational only.",
"pairs": "Comma-separated list of pairs to restrict.",
}
def clean(self):
cleaned_data = super(AssetRestrictionForm, self).clean()
if "pairs" in cleaned_data and cleaned_data["pairs"]:
new_pairs = []
pair_split = cleaned_data["pairs"].split(",")
if not pair_split:
self.add_error("pairs", "You must specify at least one pair.")
return
for pair in pair_split:
if pair:
new_pairs.append(pair.strip())
else:
self.add_error("pairs", f"You cannot have an empty pair: {pair}")
return
cleaned_data["pairs_parsed"] = new_pairs
return cleaned_data