Browse Source

Fetch ping details using HTTP GET, not HTTP POST.

pull/193/head
Pēteris Caune 6 years ago
parent
commit
7e56eb883e
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
6 changed files with 11 additions and 34 deletions
  1. +4
    -4
      hc/front/tests/test_ping_details.py
  2. +0
    -1
      hc/front/views.py
  3. +2
    -9
      static/js/checks.js
  4. +3
    -8
      static/js/details.js
  5. +2
    -9
      static/js/log.js
  6. +0
    -3
      templates/front/log.html

+ 4
- 4
hc/front/tests/test_ping_details.py View File

@ -11,12 +11,12 @@ class LastPingTestCase(BaseTestCase):
Ping.objects.create(owner=check, body="this is body")
self.client.login(username="[email protected]", password="password")
r = self.client.post("/checks/%s/last_ping/" % check.code)
r = self.client.get("/checks/%s/last_ping/" % check.code)
self.assertContains(r, "this is body", status_code=200)
def test_it_requires_user(self):
check = Check.objects.create()
r = self.client.post("/checks/%s/last_ping/" % check.code)
r = self.client.get("/checks/%s/last_ping/" % check.code)
self.assertEqual(r.status_code, 403)
def test_it_accepts_n(self):
@ -29,8 +29,8 @@ class LastPingTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password")
r = self.client.post("/checks/%s/pings/1/" % check.code)
r = self.client.get("/checks/%s/pings/1/" % check.code)
self.assertContains(r, "foo-123", status_code=200)
r = self.client.post("/checks/%s/pings/2/" % check.code)
r = self.client.get("/checks/%s/pings/2/" % check.code)
self.assertContains(r, "bar-456", status_code=200)

+ 0
- 1
hc/front/views.py View File

@ -275,7 +275,6 @@ def cron_preview(request):
return render(request, "front/cron_preview.html", ctx)
@require_POST
def ping_details(request, code, n=None):
if not request.user.is_authenticated:
return HttpResponseForbidden()


+ 2
- 9
static/js/checks.js View File

@ -44,7 +44,6 @@ $(function () {
$(".last-ping").on("click", function() {
if (this.innerText == "Never") {
showUsage(this);
return false;
}
@ -53,14 +52,8 @@ $(function () {
var code = $(this).closest("tr.checks-row").attr("id");
var lastPingUrl = "/checks/" + code + "/last_ping/";
var token = $('input[name=csrfmiddlewaretoken]').val();
$.ajax({
url: lastPingUrl,
type: "post",
headers: {"X-CSRFToken": token},
success: function(data) {
$("#ping-details-body" ).html(data);
}
$.get(lastPingUrl, function(data) {
$("#ping-details-body" ).html(data);
});
var logUrl = "/checks/" + code + "/log/";


+ 3
- 8
static/js/details.js View File

@ -88,15 +88,10 @@ $(function () {
$("#ping-details-body").text("Updating...");
$('#ping-details-modal').modal("show");
var token = $('input[name=csrfmiddlewaretoken]').val();
$.ajax({
url: this.dataset.url,
type: "post",
headers: {"X-CSRFToken": token},
success: function(data) {
$("#ping-details-body" ).html(data);
$.get(this.dataset.url, function(data) {
$("#ping-details-body").html(data);
}
});
);
return false;
});


+ 2
- 9
static/js/log.js View File

@ -3,14 +3,8 @@ $(function () {
$("#ping-details-body").text("Updating...");
$('#ping-details-modal').modal("show");
var token = $('input[name=csrfmiddlewaretoken]').val();
$.ajax({
url: this.dataset.url,
type: "post",
headers: {"X-CSRFToken": token},
success: function(data) {
$("#ping-details-body" ).html(data);
}
$.get(this.dataset.url, function(data) {
$("#ping-details-body" ).html(data);
});
return false;
@ -26,7 +20,6 @@ $(function () {
})
}
$("#format-switcher").click(function(ev) {
var format = ev.target.getAttribute("data-format");
switchDateFormat(format);


+ 0
- 3
templates/front/log.html View File

@ -144,9 +144,6 @@
</div>
</div>
</div>
<form>
{% csrf_token %}
</form>
</div>
{% endblock %}


Loading…
Cancel
Save