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

Disallow multiple single-use notes on a single object #11306

Open
wants to merge 2 commits into
base: bugfix
Choose a base branch
from
Open
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
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 @@ -1048,6 +1052,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 @@ -2048,6 +2057,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