Skip to content

Commit

Permalink
Fix for duplicate dashboards bug, closes #90
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed May 9, 2021
1 parent 02effcf commit fe7ff4e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django_sql_dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_visible_to_user(cls, user):
)
)
.order_by("-is_owner", "slug")
)
).distinct()


class DashboardQuery(models.Model):
Expand Down
19 changes: 19 additions & 0 deletions test_project/test_dashboard_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,25 @@ def test_get_visible_to_user(
), "Expected super user not to be able to see {}".format(dashboard)


def test_get_visible_to_user_no_dupes(db):
owner = User.objects.create(username="owner", is_staff=True)
group = Group.objects.create(name="group")
for i in range(3):
group.user_set.add(User.objects.create(username="user{}".format(i)))
Dashboard.objects.create(
owned_by=owner,
slug="example",
view_policy="public",
view_group=group,
)
dashboards = list(
Dashboard.get_visible_to_user(owner).values_list("slug", flat=True)
)
# This used to return ["example", "example", "example"]
# Until I fixed https://github.com/simonw/django-sql-dashboard/issues/90
assert dashboards == ["example"]


@pytest.mark.parametrize(
"dashboard,expected,expected_if_staff,expected_if_superuser",
(
Expand Down

0 comments on commit fe7ff4e

Please sign in to comment.