Browse Source

Project code in URL for the "Integrations" and the "Add Email" pages. cc: #336

pull/340/head
Pēteris Caune 5 years ago
parent
commit
ea423e5420
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
6 changed files with 30 additions and 22 deletions
  1. +6
    -4
      hc/front/tests/test_add_email.py
  2. +2
    -1
      hc/front/urls.py
  3. +19
    -14
      hc/front/views.py
  4. +1
    -1
      templates/base.html
  5. +1
    -1
      templates/front/channels.html
  6. +1
    -1
      templates/integrations/add_email.html

+ 6
- 4
hc/front/tests/test_add_email.py View File

@ -8,7 +8,9 @@ from hc.test import 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):
self.client.login(username="[email protected]", password="password")
@ -21,7 +23,7 @@ class AddEmailTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertRedirects(r, "/integrations/")
self.assertRedirects(r, "/projects/%s/integrations/" % self.project.code)
c = Channel.objects.get()
doc = json.loads(c.value)
@ -77,7 +79,7 @@ class AddEmailTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertRedirects(r, "/integrations/")
self.assertRedirects(r, "/projects/%s/integrations/" % self.project.code)
c = Channel.objects.get()
doc = json.loads(c.value)
@ -93,7 +95,7 @@ class AddEmailTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertRedirects(r, "/integrations/")
self.assertRedirects(r, "/projects/%s/integrations/" % self.project.code)
c = Channel.objects.get()
doc = json.loads(c.value)


+ 2
- 1
hc/front/urls.py View File

@ -24,7 +24,6 @@ check_urls = [
channel_urls = [
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_shell/", views.add_shell, name="hc-add-shell"),
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("checks/<uuid:code>/", include(check_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/api/", views.docs_api, name="hc-docs-api"),
path("docs/cron/", views.docs_cron, name="hc-docs-cron"),


+ 19
- 14
hc/front/views.py View File

@ -629,11 +629,14 @@ def badges(request, code):
@login_required
def channels(request):
if not request.project:
# This can happen when the user deletes their only project.
return redirect("hc-index")
def channels(request, code=None):
if code:
project = _get_project_for_user(request, code)
else:
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":
code = request.POST["channel"]
@ -641,7 +644,7 @@ def channels(request):
channel = Channel.objects.get(code=code)
except Channel.DoesNotExist:
return HttpResponseBadRequest()
if channel.project_id != request.project.id:
if channel.project_id != project.id:
return HttpResponseForbidden()
new_checks = []
@ -652,21 +655,21 @@ def channels(request):
check = Check.objects.get(code=code)
except Check.DoesNotExist:
return HttpResponseBadRequest()
if check.project_id != request.project.id:
if check.project_id != project.id:
return HttpResponseForbidden()
new_checks.append(check)
channel.checks.set(new_checks)
return redirect("hc-channels")
channels = Channel.objects.filter(project=request.project)
channels = Channel.objects.filter(project=project)
channels = channels.order_by("created")
channels = channels.annotate(n_checks=Count("checks"))
ctx = {
"page": "channels",
"project": request.project,
"profile": request.project.owner_profile,
"project": project,
"profile": project.owner_profile,
"channels": channels,
"enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None,
"enable_pushover": settings.PUSHOVER_API_TOKEN is not None,
@ -803,11 +806,13 @@ def remove_channel(request, code):
@login_required
def add_email(request):
def add_email(request, code):
project = _get_project_for_user(request, code)
if request.method == "POST":
form = AddEmailForm(request.POST)
if form.is_valid():
channel = Channel(project=request.project, kind="email")
channel = Channel(project=project, kind="email")
channel.value = json.dumps(
{
"value": form.cleaned_data["value"],
@ -832,13 +837,13 @@ def add_email(request):
else:
channel.send_verify_link()
return redirect("hc-channels")
return redirect("hc-p-channels", project.code)
else:
form = AddEmailForm()
ctx = {
"page": "channels",
"project": request.project,
"project": project,
"use_verification": settings.EMAIL_USE_VERIFICATION,
"form": form,
}


+ 1
- 1
templates/base.html View File

@ -99,7 +99,7 @@
{% with b=project.have_channel_issues %}
<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
{% if b %}<span class="icon-grace"></span>{% endif %}
</a>


+ 1
- 1
templates/front/channels.html View File

@ -179,7 +179,7 @@
<h2>Email</h2>
<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>


+ 1
- 1
templates/integrations/add_email.html View File

@ -20,7 +20,7 @@
<h2>Integration Settings</h2>
<form method="post" class="form-horizontal" action="{% url 'hc-add-email' %}">
<form method="post" class="form-horizontal">
{% csrf_token %}
<div class="form-group {{ form.value.css_classes }}">
<label for="id_email" class="col-sm-2 control-label">Email</label>


Loading…
Cancel
Save