Browse Source

Read-only users cannot copy, transfer or remove checks.

pull/419/head
Pēteris Caune 4 years ago
parent
commit
024d0adb9c
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
6 changed files with 38 additions and 2 deletions
  1. +8
    -0
      hc/front/tests/test_copy.py
  2. +3
    -0
      hc/front/tests/test_details.py
  3. +8
    -0
      hc/front/tests/test_remove_check.py
  4. +10
    -0
      hc/front/tests/test_transfer.py
  5. +7
    -0
      hc/front/views.py
  6. +2
    -2
      templates/front/details.html

+ 8
- 0
hc/front/tests/test_copy.py View File

@ -33,3 +33,11 @@ class CopyCheckTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.copy_url)
self.assertEqual(r.status_code, 400)
def test_it_requires_rw_access(self):
self.bobs_membership.rw = False
self.bobs_membership.save()
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.copy_url)
self.assertEqual(r.status_code, 403)

+ 3
- 0
hc/front/tests/test_details.py View File

@ -58,3 +58,6 @@ class DetailsTestCase(BaseTestCase):
self.assertNotContains(r, "Filtering Rules")
self.assertNotContains(r, "pause-btn")
self.assertNotContains(r, "Change Schedule")
self.assertNotContains(r, "Create a Copy…")
self.assertNotContains(r, "transfer-btn")
self.assertNotContains(r, "details-remove-check")

+ 8
- 0
hc/front/tests/test_remove_check.py View File

@ -51,3 +51,11 @@ class RemoveCheckTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.remove_url)
self.assertRedirects(r, self.redirect_url)
def test_it_requires_rw_access(self):
self.bobs_membership.rw = False
self.bobs_membership.save()
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.remove_url)
self.assertEqual(r.status_code, 403)

+ 10
- 0
hc/front/tests/test_transfer.py View File

@ -63,3 +63,13 @@ class TransferTestCase(BaseTestCase):
payload = {"project": self.charlies_project.code}
r = self.client.post(self.url, payload)
self.assertEqual(r.status_code, 404)
def test_it_requires_rw_access(self):
self.bobs_membership.rw = False
self.bobs_membership.save()
payload = {"project": self.project.code}
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, payload)
self.assertEqual(r.status_code, 403)

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

@ -500,6 +500,9 @@ def resume(request, code):
@login_required
def remove_check(request, code):
check, rw = _get_check_for_user(request, code)
if not rw:
return HttpResponseForbidden()
project = check.project
check.delete()
return redirect("hc-checks", project.code)
@ -579,6 +582,8 @@ def details(request, code):
@login_required
def transfer(request, code):
check, rw = _get_check_for_user(request, code)
if not rw:
return HttpResponseForbidden()
if request.method == "POST":
target_project, rw = _get_project_for_user(request, request.POST["project"])
@ -600,6 +605,8 @@ def transfer(request, code):
@login_required
def copy(request, code):
check, rw = _get_check_for_user(request, code)
if not rw:
return HttpResponseForbidden()
if check.project.num_checks_available() <= 0:
return HttpResponseBadRequest()


+ 2
- 2
templates/front/details.html View File

@ -232,6 +232,7 @@
{% endif %}
</div>
{% if rw %}
<div class="details-block">
<h2>Danger Zone</h2>
<p>Copy, Transfer, or permanently remove this check.</p>
@ -239,7 +240,6 @@
<div class="text-right">
{% if project.num_checks_available > 0 %}
<button
id="copy-btn"
data-toggle="modal"
data-target="#copy-modal"
class="btn btn-sm btn-default">Create a Copy&hellip;</button>
@ -260,7 +260,7 @@
class="btn btn-sm btn-default">Remove</button>
</div>
</div>
{% endif %}
</div>
<div id="events" class="col-sm-7" data-status-url="{% url 'hc-status-single' check.code %}">


Loading…
Cancel
Save