Browse Source

Merge pull request #34 from BetterWorks/removeCHannel

remove channel should always redirect even if removal fails
pull/36/head
Pēteris Caune 9 years ago
parent
commit
37817fe9b0
2 changed files with 7 additions and 6 deletions
  1. +1
    -1
      hc/front/tests/test_remove_channel.py
  2. +6
    -5
      hc/front/views.py

+ 1
- 1
hc/front/tests/test_remove_channel.py View File

@ -45,4 +45,4 @@ class RemoveChannelTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.post(url) r = self.client.post(url)
assert r.status_code == 404
assert r.status_code == 302

+ 6
- 5
hc/front/views.py View File

@ -336,11 +336,12 @@ def verify_email(request, code, token):
def remove_channel(request, code): def remove_channel(request, code):
assert request.method == "POST" 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") return redirect("hc-channels")


Loading…
Cancel
Save