Merge pull request #34 from BetterWorks/removeCHannel

remove channel should always redirect even if removal fails
This commit is contained in:
Pēteris Caune 2016-01-20 22:56:09 +02:00
commit 37817fe9b0
2 changed files with 7 additions and 6 deletions

View File

@ -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

View File

@ -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")