diff --git a/hc/front/tests/test_remove_channel.py b/hc/front/tests/test_remove_channel.py index 9ea87c9d..d6a94fd2 100644 --- a/hc/front/tests/test_remove_channel.py +++ b/hc/front/tests/test_remove_channel.py @@ -45,4 +45,4 @@ class RemoveChannelTestCase(BaseTestCase): self.client.login(username="alice@example.org", password="password") r = self.client.post(url) - assert r.status_code == 404 + assert r.status_code == 302 diff --git a/hc/front/views.py b/hc/front/views.py index be714ff9..c39b9350 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -336,11 +336,12 @@ def verify_email(request, code, token): def remove_channel(request, code): assert request.method == "POST" - channel = get_object_or_404(Channel, code=code) - if channel.user != request.user: - return HttpResponseForbidden() - - channel.delete() + # user may refresh the page during POST and cause two deletion attempts + channel = Channel.objects.filter(code=code).first() + if channel: + if channel.user != request.user: + return HttpResponseForbidden() + channel.delete() return redirect("hc-channels")