Browse Source

Project code in URL for the "Add Webhook" page. cc: #336

pull/340/head
Pēteris Caune 5 years ago
parent
commit
59f5b7a5f5
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
6 changed files with 20 additions and 14 deletions
  1. +3
    -3
      hc/front/tests/test_add_email.py
  2. +7
    -5
      hc/front/tests/test_add_webhook.py
  3. +1
    -1
      hc/front/urls.py
  4. +6
    -4
      hc/front/views.py
  5. +2
    -0
      hc/test.py
  6. +1
    -1
      templates/front/channels.html

+ 3
- 3
hc/front/tests/test_add_email.py View File

@ -23,7 +23,7 @@ class AddEmailTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertRedirects(r, "/projects/%s/integrations/" % self.project.code)
self.assertRedirects(r, self.channels_url)
c = Channel.objects.get()
doc = json.loads(c.value)
@ -79,7 +79,7 @@ class AddEmailTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertRedirects(r, "/projects/%s/integrations/" % self.project.code)
self.assertRedirects(r, self.channels_url)
c = Channel.objects.get()
doc = json.loads(c.value)
@ -95,7 +95,7 @@ class AddEmailTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertRedirects(r, "/projects/%s/integrations/" % self.project.code)
self.assertRedirects(r, self.channels_url)
c = Channel.objects.get()
doc = json.loads(c.value)


+ 7
- 5
hc/front/tests/test_add_webhook.py View File

@ -3,7 +3,9 @@ from hc.test import BaseTestCase
class AddWebhookTestCase(BaseTestCase):
url = "/integrations/add_webhook/"
def setUp(self):
super(AddWebhookTestCase, self).setUp()
self.url = "/projects/%s/add_webhook/" % self.project.code
def test_instructions_work(self):
self.client.login(username="[email protected]", password="password")
@ -20,7 +22,7 @@ class AddWebhookTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertRedirects(r, "/integrations/")
self.assertRedirects(r, self.channels_url)
c = Channel.objects.get()
self.assertEqual(c.project, self.project)
@ -95,7 +97,7 @@ class AddWebhookTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertRedirects(r, "/integrations/")
self.assertRedirects(r, self.channels_url)
c = Channel.objects.get()
self.assertEqual(c.down_webhook_spec["body"], "hello")
@ -110,7 +112,7 @@ class AddWebhookTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertRedirects(r, "/integrations/")
self.assertRedirects(r, self.channels_url)
c = Channel.objects.get()
self.assertEqual(
@ -140,7 +142,7 @@ class AddWebhookTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertRedirects(r, "/integrations/")
self.assertRedirects(r, self.channels_url)
c = Channel.objects.get()
self.assertEqual(c.down_webhook_spec["headers"], {"test": "123"})


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

@ -24,7 +24,6 @@ check_urls = [
channel_urls = [
path("", views.channels, name="hc-channels"),
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"),
path("add_pdc/", views.add_pdc, name="hc-add-pdc"),
@ -76,6 +75,7 @@ urlpatterns = [
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("projects/<uuid:code>/add_webhook/", views.add_webhook, name="hc-add-webhook"),
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"),


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

@ -851,22 +851,24 @@ def add_email(request, code):
@login_required
def add_webhook(request):
def add_webhook(request, code):
project = _get_project_for_user(request, code)
if request.method == "POST":
form = AddWebhookForm(request.POST)
if form.is_valid():
channel = Channel(project=request.project, kind="webhook")
channel = Channel(project=project, kind="webhook")
channel.value = form.get_value()
channel.save()
channel.assign_all_checks()
return redirect("hc-channels")
return redirect("hc-p-channels", project.code)
else:
form = AddWebhookForm()
ctx = {
"page": "channels",
"project": request.project,
"project": project,
"form": form,
"now": timezone.now().replace(microsecond=0).isoformat(),
}


+ 2
- 0
hc/test.py View File

@ -50,3 +50,5 @@ class BaseTestCase(TestCase):
self.charlies_profile = Profile(user=self.charlie)
self.charlies_profile.current_project = self.charlies_project
self.charlies_profile.save()
self.channels_url = "/projects/%s/integrations/" % self.project.code

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

@ -189,7 +189,7 @@
<h2>Webhook</h2>
<p>Receive a HTTP callback when a check goes down.</p>
<a href="{% url 'hc-add-webhook' %}" class="btn btn-primary">Add Integration</a>
<a href="{% url 'hc-add-webhook' project.code %}" class="btn btn-primary">Add Integration</a>
</li>
{% if enable_apprise %}
<li>


Loading…
Cancel
Save