Skip to content

Commit

Permalink
Start removing viewer role perms and updating tests accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Jan 15, 2025
1 parent f6edf47 commit d77ded8
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 152 deletions.
4 changes: 2 additions & 2 deletions temba/api/internal/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_locations(self):
)
self.assertGet(
endpoint_url + "?level=district",
[self.user],
[self.editor],
results=[
{"osm_id": "R1711131", "name": "Gatsibo", "path": "Rwanda > Eastern Province > Gatsibo"},
{"osm_id": "1711163", "name": "Kayônza", "path": "Rwanda > Eastern Province > Kayônza"},
Expand Down Expand Up @@ -251,7 +251,7 @@ def test_templates(self):
# no filtering
self.assertGet(
endpoint_url,
[self.user, self.editor],
[self.editor, self.admin],
results=[
{
"uuid": str(tpl2.uuid),
Expand Down
228 changes: 103 additions & 125 deletions temba/channels/tests.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions temba/classifiers/tests/test_classifiercrudl.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_read(self):
read_url = reverse("classifiers.classifier_read", args=[self.c1.uuid])

self.assertRequestDisallowed(read_url, [None, self.agent, self.admin2])
response = self.assertReadFetch(read_url, [self.user, self.editor, self.admin], context_object=self.c1)
response = self.assertReadFetch(read_url, [self.editor, self.admin], context_object=self.c1)

# lists active intents
self.assertContains(response, "book_flight")
Expand All @@ -91,7 +91,7 @@ def test_read(self):
def test_delete(self):
delete_url = reverse("classifiers.classifier_delete", args=[self.c2.uuid])

self.assertRequestDisallowed(delete_url, [None, self.user, self.editor, self.agent, self.admin2])
self.assertRequestDisallowed(delete_url, [None, self.editor, self.agent, self.admin2])

# fetch delete modal
response = self.assertDeleteFetch(delete_url, [self.admin])
Expand Down
12 changes: 6 additions & 6 deletions temba/globals/tests/test_globalcrudl.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_list_and_unused(self):

self.assertRequestDisallowed(list_url, [None, self.agent])
response = self.assertListFetch(
list_url, [self.user, self.editor, self.admin], context_objects=[self.global2, self.global1]
list_url, [self.editor, self.admin], context_objects=[self.global2, self.global1]
)
self.assertContains(response, "Acme Ltd")
self.assertContains(response, "23464373")
Expand All @@ -31,14 +31,14 @@ def test_list_and_unused(self):
response = self.client.get(list_url + "?search=access")
self.assertEqual(list(response.context["object_list"]), [self.global2])

self.assertListFetch(unused_url, [self.user, self.editor, self.admin], context_objects=[self.global2])
self.assertListFetch(unused_url, [self.editor, self.admin], context_objects=[self.global2])
self.assertContentMenu(list_url, self.admin, ["New"])

@override_settings(ORG_LIMIT_DEFAULTS={"globals": 4})
def test_create(self):
create_url = reverse("globals.global_create")

self.assertRequestDisallowed(create_url, [None, self.user, self.agent])
self.assertRequestDisallowed(create_url, [None, self.agent])
self.assertCreateFetch(create_url, [self.editor, self.admin], form_fields=["name", "value"])

# try to submit with invalid name and missing value
Expand Down Expand Up @@ -90,7 +90,7 @@ def test_create(self):
def test_update(self):
update_url = reverse("globals.global_update", args=[self.global1.id])

self.assertRequestDisallowed(update_url, [None, self.user, self.agent, self.admin2])
self.assertRequestDisallowed(update_url, [None, self.agent, self.admin2])
self.assertUpdateFetch(update_url, [self.editor, self.admin], form_fields=["value"])

# try to submit with missing value
Expand Down Expand Up @@ -121,14 +121,14 @@ def test_usages(self):
detail_url = reverse("globals.global_usages", args=[self.global1.uuid])

self.assertRequestDisallowed(detail_url, [None, self.agent, self.admin2])
response = self.assertReadFetch(detail_url, [self.user, self.editor, self.admin], context_object=self.global1)
response = self.assertReadFetch(detail_url, [self.editor, self.admin], context_object=self.global1)

self.assertEqual({"flow": [self.flow]}, {t: list(qs) for t, qs in response.context["dependents"].items()})

def test_delete(self):
delete_url = reverse("globals.global_delete", args=[self.global2.uuid])

self.assertRequestDisallowed(delete_url, [None, self.user, self.agent, self.admin2])
self.assertRequestDisallowed(delete_url, [None, self.agent, self.admin2])

# fetch delete modal
response = self.assertDeleteFetch(delete_url, [self.editor, self.admin])
Expand Down
2 changes: 1 addition & 1 deletion temba/ivr/tests/test_callcrudl.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ def test_list(self):
self.client.get(list_url)

self.assertRequestDisallowed(list_url, [None, self.agent])
self.assertListFetch(list_url, [self.user, self.editor, self.admin], context_objects=[call2, call1])
self.assertListFetch(list_url, [self.editor, self.admin], context_objects=[call2, call1])
2 changes: 1 addition & 1 deletion temba/notifications/tests/test_incidentcrudl.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_list(self):
incident4 = Incident.objects.create(org=self.org, incident_type="webhooks:unhealthy", scope="")

# main list items are the ended incidents
self.assertRequestDisallowed(list_url, [None, self.user, self.editor, self.agent])
self.assertRequestDisallowed(list_url, [None, self.editor, self.agent])
response = self.assertListFetch(list_url, [self.admin], context_objects=[incident3, incident1])

# with ongoing ones in separate list
Expand Down
11 changes: 0 additions & 11 deletions temba/settings_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,6 @@
"triggers.trigger.*",
),
"Viewers": (
"channels.channel_list",
"channels.channel_read",
"channels.channelevent_list",
"classifiers.classifier_list",
"classifiers.classifier_read",
"contacts.contact_export",
"contacts.contact_history",
"contacts.contact_list",
Expand All @@ -602,9 +597,6 @@
"flows.flow_results",
"flows.flowrun_list",
"flows.flowstart_list",
"globals.global_list",
"globals.global_read",
"ivr.call_list",
"locations.adminboundary_alias",
"locations.adminboundary_boundaries",
"locations.adminboundary_geometry",
Expand All @@ -617,15 +609,12 @@
"msgs.msg_list",
"msgs.msg_menu",
"msgs.optin_list",
"notifications.notification_list",
"orgs.export_download",
"orgs.org_download",
"orgs.org_export",
"orgs.org_menu",
"orgs.org_read",
"orgs.org_workspace",
"templates.template_list",
"templates.template_read",
"tickets.ticket_export",
"tickets.ticket_list",
"tickets.ticket_menu",
Expand Down
6 changes: 2 additions & 4 deletions temba/templates/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,7 @@ def test_list(self):
)

self.assertRequestDisallowed(list_url, [None, self.agent])
response = self.assertListFetch(
list_url, [self.user, self.editor, self.admin], context_objects=[template2, template1]
)
response = self.assertListFetch(list_url, [self.editor, self.admin], context_objects=[template2, template1])

self.assertContains(response, "goodbye")
self.assertContains(response, "1 language,")
Expand Down Expand Up @@ -449,7 +447,7 @@ def test_read(self):
read_url = reverse("templates.template_read", args=[template1.uuid])

self.assertRequestDisallowed(read_url, [None, self.agent, self.admin2])
response = self.assertReadFetch(read_url, [self.user, self.editor, self.admin], context_object=template1)
response = self.assertReadFetch(read_url, [self.editor, self.admin], context_object=template1)

self.assertContains(response, "Hello <code>{{1}}</code>")
self.assertContains(response, "Hola <code>{{1}}</code>")
Expand Down

0 comments on commit d77ded8

Please sign in to comment.