Skip to content

Commit

Permalink
Disallow multiple single-use notes on a single object (#11306)
Browse files Browse the repository at this point in the history
* do not allow two single use

* note type can be null
  • Loading branch information
hblankenship authored Dec 3, 2024
1 parent dd85ea3 commit 0882320
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions dojo/api_v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,10 @@ def notes(self, request, pk=None):
new_note.errors, status=status.HTTP_400_BAD_REQUEST,
)

notes = engagement.notes.filter(note_type=note_type).first()
if notes and note_type and note_type.is_single:
return Response("Only one instance of this note_type allowed on an engagement.", status=status.HTTP_400_BAD_REQUEST)

author = request.user
note = Notes(
entry=entry,
Expand Down Expand Up @@ -1078,6 +1082,11 @@ def notes(self, request, pk=None):
new_note.errors, status=status.HTTP_400_BAD_REQUEST,
)

if finding.notes:
notes = finding.notes.filter(note_type=note_type).first()
if notes and note_type and note_type.is_single:
return Response("Only one instance of this note_type allowed on a finding.", status=status.HTTP_400_BAD_REQUEST)

author = request.user
note = Notes(
entry=entry,
Expand Down Expand Up @@ -2131,6 +2140,10 @@ def notes(self, request, pk=None):
new_note.errors, status=status.HTTP_400_BAD_REQUEST,
)

notes = test.notes.filter(note_type=note_type).first()
if notes and note_type and note_type.is_single:
return Response("Only one instance of this note_type allowed on a test.", status=status.HTTP_400_BAD_REQUEST)

author = request.user
note = Notes(
entry=entry,
Expand Down

0 comments on commit 0882320

Please sign in to comment.