forked from GithubBackups/healthchecks
Project code in URL for the "Integrations" and the "Add Email" pages. cc: #336
This commit is contained in:
parent
9e82cbb412
commit
ea423e5420
@ -8,7 +8,9 @@ from hc.test import BaseTestCase
|
|||||||
|
|
||||||
|
|
||||||
class AddEmailTestCase(BaseTestCase):
|
class AddEmailTestCase(BaseTestCase):
|
||||||
url = "/integrations/add_email/"
|
def setUp(self):
|
||||||
|
super(AddEmailTestCase, self).setUp()
|
||||||
|
self.url = "/projects/%s/add_email/" % self.project.code
|
||||||
|
|
||||||
def test_instructions_work(self):
|
def test_instructions_work(self):
|
||||||
self.client.login(username="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", password="password")
|
||||||
@ -21,7 +23,7 @@ class AddEmailTestCase(BaseTestCase):
|
|||||||
|
|
||||||
self.client.login(username="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", password="password")
|
||||||
r = self.client.post(self.url, form)
|
r = self.client.post(self.url, form)
|
||||||
self.assertRedirects(r, "/integrations/")
|
self.assertRedirects(r, "/projects/%s/integrations/" % self.project.code)
|
||||||
|
|
||||||
c = Channel.objects.get()
|
c = Channel.objects.get()
|
||||||
doc = json.loads(c.value)
|
doc = json.loads(c.value)
|
||||||
@ -77,7 +79,7 @@ class AddEmailTestCase(BaseTestCase):
|
|||||||
|
|
||||||
self.client.login(username="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", password="password")
|
||||||
r = self.client.post(self.url, form)
|
r = self.client.post(self.url, form)
|
||||||
self.assertRedirects(r, "/integrations/")
|
self.assertRedirects(r, "/projects/%s/integrations/" % self.project.code)
|
||||||
|
|
||||||
c = Channel.objects.get()
|
c = Channel.objects.get()
|
||||||
doc = json.loads(c.value)
|
doc = json.loads(c.value)
|
||||||
@ -93,7 +95,7 @@ class AddEmailTestCase(BaseTestCase):
|
|||||||
|
|
||||||
self.client.login(username="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", password="password")
|
||||||
r = self.client.post(self.url, form)
|
r = self.client.post(self.url, form)
|
||||||
self.assertRedirects(r, "/integrations/")
|
self.assertRedirects(r, "/projects/%s/integrations/" % self.project.code)
|
||||||
|
|
||||||
c = Channel.objects.get()
|
c = Channel.objects.get()
|
||||||
doc = json.loads(c.value)
|
doc = json.loads(c.value)
|
||||||
|
@ -24,7 +24,6 @@ check_urls = [
|
|||||||
|
|
||||||
channel_urls = [
|
channel_urls = [
|
||||||
path("", views.channels, name="hc-channels"),
|
path("", views.channels, name="hc-channels"),
|
||||||
path("add_email/", views.add_email, name="hc-add-email"),
|
|
||||||
path("add_webhook/", views.add_webhook, name="hc-add-webhook"),
|
path("add_webhook/", views.add_webhook, name="hc-add-webhook"),
|
||||||
path("add_shell/", views.add_shell, name="hc-add-shell"),
|
path("add_shell/", views.add_shell, name="hc-add-shell"),
|
||||||
path("add_pd/", views.add_pd, name="hc-add-pd"),
|
path("add_pd/", views.add_pd, name="hc-add-pd"),
|
||||||
@ -75,6 +74,8 @@ urlpatterns = [
|
|||||||
path("projects/<uuid:code>/metrics/<slug:key>", views.metrics, name="hc-metrics",),
|
path("projects/<uuid:code>/metrics/<slug:key>", views.metrics, name="hc-metrics",),
|
||||||
path("checks/<uuid:code>/", include(check_urls)),
|
path("checks/<uuid:code>/", include(check_urls)),
|
||||||
path("integrations/", include(channel_urls)),
|
path("integrations/", include(channel_urls)),
|
||||||
|
path("projects/<uuid:code>/integrations/", views.channels, name="hc-p-channels"),
|
||||||
|
path("projects/<uuid:code>/add_email/", views.add_email, name="hc-add-email"),
|
||||||
path("docs/", views.serve_doc, name="hc-docs"),
|
path("docs/", views.serve_doc, name="hc-docs"),
|
||||||
path("docs/api/", views.docs_api, name="hc-docs-api"),
|
path("docs/api/", views.docs_api, name="hc-docs-api"),
|
||||||
path("docs/cron/", views.docs_cron, name="hc-docs-cron"),
|
path("docs/cron/", views.docs_cron, name="hc-docs-cron"),
|
||||||
|
@ -629,11 +629,14 @@ def badges(request, code):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def channels(request):
|
def channels(request, code=None):
|
||||||
|
if code:
|
||||||
if not request.project:
|
project = _get_project_for_user(request, code)
|
||||||
# This can happen when the user deletes their only project.
|
else:
|
||||||
return redirect("hc-index")
|
project = request.project
|
||||||
|
if project is None:
|
||||||
|
# This can happen when the user deletes their only project.
|
||||||
|
return redirect("hc-index")
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
code = request.POST["channel"]
|
code = request.POST["channel"]
|
||||||
@ -641,7 +644,7 @@ def channels(request):
|
|||||||
channel = Channel.objects.get(code=code)
|
channel = Channel.objects.get(code=code)
|
||||||
except Channel.DoesNotExist:
|
except Channel.DoesNotExist:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
if channel.project_id != request.project.id:
|
if channel.project_id != project.id:
|
||||||
return HttpResponseForbidden()
|
return HttpResponseForbidden()
|
||||||
|
|
||||||
new_checks = []
|
new_checks = []
|
||||||
@ -652,21 +655,21 @@ def channels(request):
|
|||||||
check = Check.objects.get(code=code)
|
check = Check.objects.get(code=code)
|
||||||
except Check.DoesNotExist:
|
except Check.DoesNotExist:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
if check.project_id != request.project.id:
|
if check.project_id != project.id:
|
||||||
return HttpResponseForbidden()
|
return HttpResponseForbidden()
|
||||||
new_checks.append(check)
|
new_checks.append(check)
|
||||||
|
|
||||||
channel.checks.set(new_checks)
|
channel.checks.set(new_checks)
|
||||||
return redirect("hc-channels")
|
return redirect("hc-channels")
|
||||||
|
|
||||||
channels = Channel.objects.filter(project=request.project)
|
channels = Channel.objects.filter(project=project)
|
||||||
channels = channels.order_by("created")
|
channels = channels.order_by("created")
|
||||||
channels = channels.annotate(n_checks=Count("checks"))
|
channels = channels.annotate(n_checks=Count("checks"))
|
||||||
|
|
||||||
ctx = {
|
ctx = {
|
||||||
"page": "channels",
|
"page": "channels",
|
||||||
"project": request.project,
|
"project": project,
|
||||||
"profile": request.project.owner_profile,
|
"profile": project.owner_profile,
|
||||||
"channels": channels,
|
"channels": channels,
|
||||||
"enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None,
|
"enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None,
|
||||||
"enable_pushover": settings.PUSHOVER_API_TOKEN is not None,
|
"enable_pushover": settings.PUSHOVER_API_TOKEN is not None,
|
||||||
@ -803,11 +806,13 @@ def remove_channel(request, code):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def add_email(request):
|
def add_email(request, code):
|
||||||
|
project = _get_project_for_user(request, code)
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = AddEmailForm(request.POST)
|
form = AddEmailForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
channel = Channel(project=request.project, kind="email")
|
channel = Channel(project=project, kind="email")
|
||||||
channel.value = json.dumps(
|
channel.value = json.dumps(
|
||||||
{
|
{
|
||||||
"value": form.cleaned_data["value"],
|
"value": form.cleaned_data["value"],
|
||||||
@ -832,13 +837,13 @@ def add_email(request):
|
|||||||
else:
|
else:
|
||||||
channel.send_verify_link()
|
channel.send_verify_link()
|
||||||
|
|
||||||
return redirect("hc-channels")
|
return redirect("hc-p-channels", project.code)
|
||||||
else:
|
else:
|
||||||
form = AddEmailForm()
|
form = AddEmailForm()
|
||||||
|
|
||||||
ctx = {
|
ctx = {
|
||||||
"page": "channels",
|
"page": "channels",
|
||||||
"project": request.project,
|
"project": project,
|
||||||
"use_verification": settings.EMAIL_USE_VERIFICATION,
|
"use_verification": settings.EMAIL_USE_VERIFICATION,
|
||||||
"form": form,
|
"form": form,
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@
|
|||||||
|
|
||||||
{% with b=project.have_channel_issues %}
|
{% with b=project.have_channel_issues %}
|
||||||
<li {% if b %}id="broken-channels"{% endif %} {% if page == 'channels' %}class="active"{% endif %}>
|
<li {% if b %}id="broken-channels"{% endif %} {% if page == 'channels' %}class="active"{% endif %}>
|
||||||
<a href="{% url 'hc-channels' %}">
|
<a href="{% url 'hc-p-channels' project.code %}">
|
||||||
Integrations
|
Integrations
|
||||||
{% if b %}<span class="icon-grace"></span>{% endif %}
|
{% if b %}<span class="icon-grace"></span>{% endif %}
|
||||||
</a>
|
</a>
|
||||||
|
@ -179,7 +179,7 @@
|
|||||||
<h2>Email</h2>
|
<h2>Email</h2>
|
||||||
<p>Get an email message when a check goes up or down.</p>
|
<p>Get an email message when a check goes up or down.</p>
|
||||||
|
|
||||||
<a href="{% url 'hc-add-email' %}" class="btn btn-primary">Add Integration</a>
|
<a href="{% url 'hc-add-email' project.code %}" class="btn btn-primary">Add Integration</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
<h2>Integration Settings</h2>
|
<h2>Integration Settings</h2>
|
||||||
|
|
||||||
<form method="post" class="form-horizontal" action="{% url 'hc-add-email' %}">
|
<form method="post" class="form-horizontal">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="form-group {{ form.value.css_classes }}">
|
<div class="form-group {{ form.value.css_classes }}">
|
||||||
<label for="id_email" class="col-sm-2 control-label">Email</label>
|
<label for="id_email" class="col-sm-2 control-label">Email</label>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user