Commit dbd271f3 authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB

api: remove non-existent label from event = 404

Trying to remove a label that was not associated with an event
gave a 400 HTTP response. Fixed to be 404. It was already correct
for superevents.
parent bb509317
......@@ -40,7 +40,7 @@ from core.vfile import VersionedFile
from events.buildVOEvent import buildVOEvent, VOEventBuilderException
from events.forms import CreateEventForm
from events.models import Event, Group, Search, Pipeline, EventLog, Tag, \
Label, EMGroup, EMBBEventLog, EMSPECTRUM, VOEvent
Label, Labelling, EMGroup, EMBBEventLog, EMSPECTRUM, VOEvent
from events.permission_utils import user_has_perm, filter_events_for_user, \
is_external, check_external_file_access
from events.translator import handle_uploaded_data
......@@ -730,11 +730,13 @@ class EventLabel(InheritPermissionsAPIView):
@event_and_auth_required
def delete(self, request, event, label):
try:
rv = delete_label(event, request, label)
except Labelling.DoesNotExist as e:
return Response(e.message, status=status.HTTP_404_NOT_FOUND)
except (ValueError, Label.ProtectedLabelError) as e:
return Response(e.message,
status=status.HTTP_400_BAD_REQUEST)
return Response(e.message, status=status.HTTP_400_BAD_REQUEST)
return Response(status=status.HTTP_204_NO_CONTENT)
......
......@@ -240,9 +240,9 @@ def delete_label(event, request, labelName, can_remove_protected=False,
# Next, check if the label is in the list of labels for the event. Throw out an
# error if it isn't. There might be a more elegant way of doing this.
if label not in event.labels.all():
d['warning'] = "No label '%s' associated with event %s" % (labelName, event.graceid)
raise ValueError("No label '%s' associated with event %s" % (labelName, event.graceid))
if not event.labelling_set.filter(label__name=labelName).exists():
d['warning'] = "No label '%s' associated with event %s" % (labelName, event.graceid)
raise Labelling.DoesNotExist("No label '%s' associated with event %s" % (labelName, event.graceid))
else:
this_label = Labelling.objects.get(
event = event,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment