forked from GithubBackups/healthchecks
Clean up Pushover validation.
This commit is contained in:
parent
f6f2b18c5d
commit
26757c6785
@ -90,6 +90,28 @@ class AddOpsGenieForm(forms.Form):
|
|||||||
key = forms.CharField(max_length=40)
|
key = forms.CharField(max_length=40)
|
||||||
|
|
||||||
|
|
||||||
|
PRIO_CHOICES = [
|
||||||
|
("-2", "Lowest Priority"),
|
||||||
|
("-1", "Low Priority"),
|
||||||
|
("0", "Normal Priority"),
|
||||||
|
("1", "High Priority"),
|
||||||
|
("2", "Emergency Priority"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class AddPushoverForm(forms.Form):
|
||||||
|
error_css_class = "has-error"
|
||||||
|
pushover_user_key = forms.CharField()
|
||||||
|
prio = forms.ChoiceField(initial="0", choices=PRIO_CHOICES)
|
||||||
|
prio_up = forms.ChoiceField(initial="0", choices=PRIO_CHOICES)
|
||||||
|
|
||||||
|
def get_value(self):
|
||||||
|
key = self.cleaned_data["pushover_user_key"]
|
||||||
|
prio = self.cleaned_data["prio"]
|
||||||
|
prio_up = self.cleaned_data["prio_up"]
|
||||||
|
return "%s|%s|%s" % (key, prio, prio_up)
|
||||||
|
|
||||||
|
|
||||||
class AddEmailForm(forms.Form):
|
class AddEmailForm(forms.Form):
|
||||||
error_css_class = "has-error"
|
error_css_class = "has-error"
|
||||||
value = forms.EmailField(max_length=100)
|
value = forms.EmailField(max_length=100)
|
||||||
|
@ -41,6 +41,7 @@ from hc.front.forms import (
|
|||||||
AddMatrixForm,
|
AddMatrixForm,
|
||||||
AddOpsGenieForm,
|
AddOpsGenieForm,
|
||||||
AddPdForm,
|
AddPdForm,
|
||||||
|
AddPushoverForm,
|
||||||
AddShellForm,
|
AddShellForm,
|
||||||
AddSmsForm,
|
AddSmsForm,
|
||||||
AddUrlForm,
|
AddUrlForm,
|
||||||
@ -1254,7 +1255,6 @@ def add_pushover(request, code):
|
|||||||
project = _get_project_for_user(request, code)
|
project = _get_project_for_user(request, code)
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
# Initiate the subscription
|
|
||||||
state = token_urlsafe()
|
state = token_urlsafe()
|
||||||
|
|
||||||
failure_url = settings.SITE_ROOT + reverse("hc-p-channels", args=[project.code])
|
failure_url = settings.SITE_ROOT + reverse("hc-p-channels", args=[project.code])
|
||||||
@ -1288,27 +1288,17 @@ def add_pushover(request, code):
|
|||||||
if request.GET.get("state") != state:
|
if request.GET.get("state") != state:
|
||||||
return HttpResponseForbidden()
|
return HttpResponseForbidden()
|
||||||
|
|
||||||
key = request.GET.get("pushover_user_key")
|
|
||||||
if key is None:
|
|
||||||
return HttpResponseBadRequest()
|
|
||||||
|
|
||||||
# Validate priority
|
|
||||||
prio = request.GET.get("prio")
|
|
||||||
if prio not in ("-2", "-1", "0", "1", "2"):
|
|
||||||
return HttpResponseBadRequest()
|
|
||||||
|
|
||||||
prio_up = request.GET.get("prio_up")
|
|
||||||
if prio_up not in ("-2", "-1", "0", "1", "2"):
|
|
||||||
return HttpResponseBadRequest()
|
|
||||||
|
|
||||||
if request.GET.get("pushover_unsubscribed") == "1":
|
if request.GET.get("pushover_unsubscribed") == "1":
|
||||||
# Unsubscription: delete all Pushover channels for this project
|
# Unsubscription: delete all Pushover channels for this project
|
||||||
Channel.objects.filter(project=project, kind="po").delete()
|
Channel.objects.filter(project=project, kind="po").delete()
|
||||||
return redirect("hc-channels")
|
return redirect("hc-p-channels", project.code)
|
||||||
|
|
||||||
|
form = AddPushoverForm(request.GET)
|
||||||
|
if not form.is_valid():
|
||||||
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
# Subscription
|
|
||||||
channel = Channel(project=project, kind="po")
|
channel = Channel(project=project, kind="po")
|
||||||
channel.value = "%s|%s|%s" % (key, prio, prio_up)
|
channel.value = form.get_value()
|
||||||
channel.save()
|
channel.save()
|
||||||
channel.assign_all_checks()
|
channel.assign_all_checks()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user