From 4c1951ec1b836f42de6a4de91f2d1b5051fac8ef Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Wed, 30 Jun 2021 20:42:45 -0700 Subject: [PATCH] Fixed tests for changlist editable dashboards, refs #130, refs #131 --- django_sql_dashboard/models.py | 2 +- test_project/test_dashboard_permissions.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/django_sql_dashboard/models.py b/django_sql_dashboard/models.py index f4f1c1e..3dd7007 100644 --- a/django_sql_dashboard/models.py +++ b/django_sql_dashboard/models.py @@ -114,7 +114,7 @@ def get_editable_by_user(cls, user): cls.objects.filter( models.Q(owned_by=user) | models.Q(edit_policy__in=allowed_policies) - | models.Q(view_policy=cls.EditPolicies.GROUP, edit_group__user=user) + | models.Q(edit_policy=cls.EditPolicies.GROUP, edit_group__user=user) ) ).distinct() diff --git a/test_project/test_dashboard_permissions.py b/test_project/test_dashboard_permissions.py index 8f9d1c9..5a466ec 100644 --- a/test_project/test_dashboard_permissions.py +++ b/test_project/test_dashboard_permissions.py @@ -334,6 +334,24 @@ def test_user_can_edit( user.save() assert dashboard_obj.user_can_edit(user) == expected_if_staff assert can_user_edit_using_admin(client, user, dashboard_obj) == expected_if_staff + + # Confirm that staff user can see the correct dashboards listed + client.force_login(user) + dashboard_change_list_response = client.get( + "/admin/django_sql_dashboard/dashboard/" + ) + change_list_soup = BeautifulSoup(dashboard_change_list_response.content, "html5lib") + visible_in_change_list = [ + a.text for a in change_list_soup.select("th.field-slug a") + ] + assert set(visible_in_change_list) == { + "owned_by_other_staff", + "owned_by_other_group_member", + "owned_by_other_loggedin", + "owned_by_user", + } + + # Promote to superuser user.is_superuser = True user.save() assert dashboard_obj.user_can_edit(user) == expected_if_superuser