Browse Source

Allow simultaneous access to dashboards from different teams

pull/211/head
Pēteris Caune 6 years ago
parent
commit
19ef8b3f7b
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
5 changed files with 50 additions and 8 deletions
  1. +18
    -1
      hc/front/tests/test_status.py
  2. +1
    -1
      hc/front/urls.py
  3. +18
    -2
      hc/front/views.py
  4. +9
    -3
      static/js/checks.js
  5. +4
    -1
      templates/front/my_checks_desktop.html

+ 18
- 1
hc/front/tests/test_status.py View File

@ -12,7 +12,8 @@ class MyChecksTestCase(BaseTestCase):
def test_it_works(self): def test_it_works(self):
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.get("/checks/status/")
r = self.client.get("/teams/alice/checks/status/")
self.assertEqual(r.status_code, 200)
doc = r.json() doc = r.json()
self.assertEqual(doc["tags"]["foo"], "up") self.assertEqual(doc["tags"]["foo"], "up")
@ -21,3 +22,19 @@ class MyChecksTestCase(BaseTestCase):
self.assertEqual(detail["code"], str(self.check.code)) self.assertEqual(detail["code"], str(self.check.code))
self.assertEqual(detail["status"], "new") self.assertEqual(detail["status"], "new")
self.assertIn("Never", detail["last_ping"]) self.assertIn("Never", detail["last_ping"])
def test_it_allows_cross_team_access(self):
self.bobs_profile.current_team = None
self.bobs_profile.save()
self.client.login(username="[email protected]", password="password")
r = self.client.get("/teams/alice/checks/status/")
self.assertEqual(r.status_code, 200)
def test_it_checks_ownership(self):
self.bobs_profile.current_team = None
self.bobs_profile.save()
self.client.login(username="[email protected]", password="password")
r = self.client.get("/teams/alice/checks/status/")
self.assertEqual(r.status_code, 404)

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

@ -51,7 +51,7 @@ urlpatterns = [
path('checks/', views.my_checks, name="hc-checks"), path('checks/', views.my_checks, name="hc-checks"),
path('checks/add/', views.add_check, name="hc-add-check"), path('checks/add/', views.add_check, name="hc-add-check"),
path('checks/cron_preview/', views.cron_preview), path('checks/cron_preview/', views.cron_preview),
path('checks/status/', views.status),
path('teams/<str:username>/checks/status/', views.status, name="hc-status"),
path('checks/<uuid:code>/', include(check_urls)), path('checks/<uuid:code>/', include(check_urls)),
path('integrations/', include(channel_urls)), path('integrations/', include(channel_urls)),


+ 18
- 2
hc/front/views.py View File

@ -77,6 +77,19 @@ def _get_check_for_user(request, code):
raise Http404("not found") raise Http404("not found")
def _has_access(request, username):
""" Return true if current user has access to the specified account. """
if request.user.username == username:
return True
if request.user.is_superuser:
return True
mq = request.user.memberships
return mq.filter(team__user__username=username).exists()
@login_required @login_required
def my_checks(request): def my_checks(request):
if request.GET.get("sort") in VALID_SORT_VALUES: if request.GET.get("sort") in VALID_SORT_VALUES:
@ -130,8 +143,11 @@ def my_checks(request):
@login_required @login_required
def status(request):
checks = list(Check.objects.filter(user_id=request.team.user_id))
def status(request, username):
if not _has_access(request, username):
raise Http404("not found")
checks = list(Check.objects.filter(user__username=username))
details = [] details = []
for check in checks: for check in checks:


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

@ -159,9 +159,10 @@ $(function () {
// is active, every 60s otherwise // is active, every 60s otherwise
var lastStatus = {}; var lastStatus = {};
var lastPing = {}; var lastPing = {};
adaptiveSetInterval(function() {
var statusUrl = $("#checks-table").data("status-url");
function refreshStatus() {
$.ajax({ $.ajax({
url: "/checks/status/",
url: statusUrl,
dataType: "json", dataType: "json",
timeout: 2000, timeout: 2000,
success: function(data) { success: function(data) {
@ -192,7 +193,12 @@ $(function () {
} }
} }
}); });
});
}
// Schedule regular status updates:
if (statusUrl) {
adaptiveSetInterval(refreshStatus);
}
// Copy to clipboard // Copy to clipboard
var clipboard = new Clipboard('button.copy-link'); var clipboard = new Clipboard('button.copy-link');


+ 4
- 1
templates/front/my_checks_desktop.html View File

@ -1,5 +1,8 @@
{% load hc_extras %} {% load hc_extras %}
<table id="checks-table" class="table">
<table
id="checks-table"
class="table"
data-status-url="{% url 'hc-status' request.team.user.username %}">
<tr> <tr>
<th></th> <th></th>
<th class="th-name"> <th class="th-name">


Loading…
Cancel
Save