Skip to content
Snippets Groups Projects
Commit 443ccd73 authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB
Browse files

Only allow contact deletion if it's not part of a notification

parent 9884735b
No related branches found
No related tags found
No related merge requests found
......@@ -225,11 +225,25 @@ class DeleteContactView(DeleteView):
return self.delete(request, *args, **kwargs)
def delete(self, request, *args, **kwargs):
response = super(DeleteContactView, self).delete(request, *args,
**kwargs)
# Get contact
self.object = self.get_object()
# Contacts can only be deleted if they aren't part of a notification -
# this will prevent cases where a user creates a notification, deletes
# the related contact(s), and then wonders why they aren't getting
# any notifications.
if self.object.notification_set.exists():
messages.error(request, ('Contact "{cname}" cannot be deleted '
'because it is part of a notification. Remove it from the '
'notification or delete the notification first.').format(
cname=self.object.description))
return HttpResponseRedirect(reverse('alerts:index'))
# Otherwise, delete the contact and show a corresponding message.
self.object.delete()
messages.info(request, 'Contact "{cname}" has been deleted.'.format(
cname=self.object.description))
return response
return HttpResponseRedirect(self.get_success_url())
def get_queryset(self):
# Queryset should only contain the user's contacts
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment