Read-only users cannot toggle channels on and off.

This commit is contained in:
Pēteris Caune 2020-08-26 12:50:02 +03:00
parent 024d0adb9c
commit c9baa2d8eb
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
5 changed files with 13 additions and 3 deletions

View File

@ -51,3 +51,11 @@ class SwitchChannelTestCase(BaseTestCase):
self.client.login(username="bob@example.org", password="password")
r = self.client.post(self.url, {"state": "on"})
self.assertEqual(r.status_code, 200)
def test_it_requires_rw_access(self):
self.bobs_membership.rw = False
self.bobs_membership.save()
self.client.login(username="bob@example.org", password="password")
r = self.client.post(self.url, {"state": "on"})
self.assertEqual(r.status_code, 403)

View File

@ -230,6 +230,8 @@ def status(request, code):
@require_POST
def switch_channel(request, code, channel_code):
check, rw = _get_check_for_user(request, code)
if not rw:
return HttpResponseForbidden()
channel = get_object_or_404(Channel, code=channel_code)
if channel.project_id != check.project_id:

View File

@ -73,7 +73,7 @@
background: #22bc66;
}
#details-integrations tr:hover th, #details-integrations tr:hover td {
#details-integrations.rw tr:hover th, #details-integrations.rw tr:hover td {
cursor: pointer;
background-color: #f5f5f5;
}

View File

@ -59,7 +59,7 @@ $(function () {
}, 300);
});
$("#details-integrations tr").click(function() {
$("#details-integrations.rw tr").click(function() {
var isOn = $(this).toggleClass("on").hasClass("on");
$(".label", this).text(isOn ? "ON" : "OFF");

View File

@ -206,7 +206,7 @@
<div class="details-block">
<h2>Notification Methods</h2>
{% if channels %}
<table id="details-integrations" class="table">
<table id="details-integrations" class="table {% if rw %}rw{% endif %}">
{% for channel in channels %}
<tr data-url="{% url 'hc-switch-channel' check.code channel.code %}" {% if channel in enabled_channels %}class="on"{% endif %}>
<th>