Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix clean function / improve iso27001 [CA-82] #17

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ciso_assistant/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.1
0.9.2
14 changes: 6 additions & 8 deletions core/base_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,14 @@ def get_scope(self):
def clean(self) -> None:
scope = self.get_scope()
field_errors = {}
_fields_to_check = self.fields_to_check if hasattr(self, 'fields_to_check') else []
_fields_to_check = self.fields_to_check if hasattr(self, 'fields_to_check') else ['name']
if not self.is_unique_in_scope(scope=scope, fields_to_check=_fields_to_check):
print(_fields_to_check, self)
for field in _fields_to_check:
if not self.is_unique_in_scope(scope=scope, fields_to_check=[field]):
field_errors[field] = ValidationError(
_(
f"{getattr(self, field)} is already in use in this scope. Please choose another value."
),
code="unique",
)
field_errors[field] = ValidationError(
_("Value already used in this scope."),
code="unique",
)
super().clean()
if field_errors:
raise ValidationError(field_errors)
Expand Down
5 changes: 5 additions & 0 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class Meta:
verbose_name = _("Framework")
verbose_name_plural = _("Frameworks")

fields_to_check = ['urn']

def get_next_order_id(self, obj_type: models.Model, _parent_urn: str = None) -> int:
"""
Returns the next order id for a given object type
Expand Down Expand Up @@ -117,6 +119,7 @@ class RequirementGroup(AbstractBaseModel, I18nMixin, NameDescriptionMixin, Folde
)
order_id = models.IntegerField(null=True, blank=True, verbose_name=_("Order ID"))
level = models.IntegerField(null=True, blank=True, verbose_name=_("Level"))
fields_to_check = ['urn']


class RequirementLevel(AbstractBaseModel, I18nMixin, FolderMixin):
Expand All @@ -132,6 +135,7 @@ class RequirementLevel(AbstractBaseModel, I18nMixin, FolderMixin):
)
level = models.IntegerField(null=False, blank=False, verbose_name=_("Level"))
description = models.TextField(null=True, blank=True, verbose_name=_("Description"))
fields_to_check = ['urn']


class Requirement(AbstractBaseModel, I18nMixin, NameDescriptionMixin, FolderMixin):
Expand Down Expand Up @@ -165,6 +169,7 @@ class Requirement(AbstractBaseModel, I18nMixin, NameDescriptionMixin, FolderMixi
blank=True,
verbose_name=_("Informative reference"),
)
fields_to_check = ['urn']

class Meta:
verbose_name = _("Requirement")
Expand Down
Loading