fixed team membership views to work non-POST

This commit is contained in:
Brian Rosner 2012-09-15 17:32:43 -06:00
parent 7c102aefa3
commit bb2ffd2df0

View file

@ -1,4 +1,4 @@
from django.http import Http404 from django.http import Http404, HttpResponseNotAllowed
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import render, redirect, get_object_or_404
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
@ -140,51 +140,55 @@ def team_apply(request, slug):
@login_required @login_required
def team_promote(request, pk): def team_promote(request, pk):
if request.method == "POST": if request.method != "POST":
membership = get_object_or_404(Membership, pk=pk) return HttpResponseNotAllowed(["POST"])
state = membership.team.get_state_for_user(request.user) membership = get_object_or_404(Membership, pk=pk)
if request.user.is_staff or state == "manager": state = membership.team.get_state_for_user(request.user)
if membership.state == "member": if request.user.is_staff or state == "manager":
membership.state = "manager" if membership.state == "member":
membership.save() membership.state = "manager"
messages.success(request, "Promoted to manager.") membership.save()
messages.success(request, "Promoted to manager.")
return redirect("team_detail", slug=membership.team.slug) return redirect("team_detail", slug=membership.team.slug)
@login_required @login_required
def team_demote(request, pk): def team_demote(request, pk):
if request.method == "POST": if request.method != "POST":
membership = get_object_or_404(Membership, pk=pk) return HttpResponseNotAllowed(["POST"])
state = membership.team.get_state_for_user(request.user) membership = get_object_or_404(Membership, pk=pk)
if request.user.is_staff or state == "manager": state = membership.team.get_state_for_user(request.user)
if membership.state == "manager": if request.user.is_staff or state == "manager":
membership.state = "member" if membership.state == "manager":
membership.save() membership.state = "member"
messages.success(request, "Demoted from manager.") membership.save()
messages.success(request, "Demoted from manager.")
return redirect("team_detail", slug=membership.team.slug) return redirect("team_detail", slug=membership.team.slug)
@login_required @login_required
def team_accept(request, pk): def team_accept(request, pk):
if request.method == "POST": if request.method != "POST":
membership = get_object_or_404(Membership, pk=pk) return HttpResponseNotAllowed(["POST"])
state = membership.team.get_state_for_user(request.user) membership = get_object_or_404(Membership, pk=pk)
if request.user.is_staff or state == "manager": state = membership.team.get_state_for_user(request.user)
if membership.state == "applied": if request.user.is_staff or state == "manager":
membership.state = "member" if membership.state == "applied":
membership.save() membership.state = "member"
messages.success(request, "Accepted application.") membership.save()
messages.success(request, "Accepted application.")
return redirect("team_detail", slug=membership.team.slug) return redirect("team_detail", slug=membership.team.slug)
@login_required @login_required
def team_reject(request, pk): def team_reject(request, pk):
if request.method == "POST": if request.method != "POST":
membership = get_object_or_404(Membership, pk=pk) return HttpResponseNotAllowed(["POST"])
state = membership.team.get_state_for_user(request.user) membership = get_object_or_404(Membership, pk=pk)
if request.user.is_staff or state == "manager": state = membership.team.get_state_for_user(request.user)
if membership.state == "applied": if request.user.is_staff or state == "manager":
membership.state = "rejected" if membership.state == "applied":
membership.save() membership.state = "rejected"
messages.success(request, "Rejected application.") membership.save()
messages.success(request, "Rejected application.")
return redirect("team_detail", slug=membership.team.slug) return redirect("team_detail", slug=membership.team.slug)