diff --git a/posthog/api/dashboards/dashboard.py b/posthog/api/dashboards/dashboard.py index 100e8745b8db1..a89d41814d616 100644 --- a/posthog/api/dashboards/dashboard.py +++ b/posthog/api/dashboards/dashboard.py @@ -398,23 +398,25 @@ class DashboardsViewSet( viewsets.ModelViewSet, ): scope_object = "dashboard" - queryset = Dashboard.objects.order_by("name") + queryset = Dashboard.objects_including_soft_deleted.order_by("name") permission_classes = [CanEditDashboard] def get_serializer_class(self) -> Type[BaseSerializer]: return DashboardBasicSerializer if self.action == "list" else DashboardSerializer def get_queryset(self) -> QuerySet: - if ( + queryset = super().get_queryset() + + include_deleted = ( self.action == "partial_update" and "deleted" in self.request.data and not self.request.data.get("deleted") and len(self.request.data) == 1 - ): + ) + + if not include_deleted: # a dashboard can be un-deleted by patching {"deleted": False} - queryset = Dashboard.objects_including_soft_deleted - else: - queryset = super().get_queryset() + queryset = queryset.filter(deleted=False) queryset = queryset.prefetch_related("sharingconfiguration_set").select_related( "team__organization", diff --git a/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr b/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr index 2f3da77b65e0e..a120ce5c58068 100644 --- a/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr +++ b/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr @@ -390,8 +390,8 @@ INNER JOIN "posthog_team" ON ("posthog_dashboard"."team_id" = "posthog_team"."id") INNER JOIN "posthog_organization" ON ("posthog_team"."organization_id" = "posthog_organization"."id") LEFT OUTER JOIN "posthog_user" ON ("posthog_dashboard"."created_by_id" = "posthog_user"."id") - WHERE (NOT ("posthog_dashboard"."deleted") - AND "posthog_dashboard"."team_id" = 2 + WHERE ("posthog_dashboard"."team_id" = 2 + AND NOT "posthog_dashboard"."deleted" AND "posthog_dashboard"."id" = 2) LIMIT 21 ''' @@ -2615,8 +2615,8 @@ ''' SELECT COUNT(*) AS "__count" FROM "posthog_dashboard" - WHERE (NOT ("posthog_dashboard"."deleted") - AND "posthog_dashboard"."team_id" = 2) + WHERE ("posthog_dashboard"."team_id" = 2 + AND NOT "posthog_dashboard"."deleted") ''' # --- # name: TestDashboard.test_listing_dashboards_is_not_nplus1.55 @@ -2738,8 +2738,8 @@ INNER JOIN "posthog_team" ON ("posthog_dashboard"."team_id" = "posthog_team"."id") INNER JOIN "posthog_organization" ON ("posthog_team"."organization_id" = "posthog_organization"."id") LEFT OUTER JOIN "posthog_user" ON ("posthog_dashboard"."created_by_id" = "posthog_user"."id") - WHERE (NOT ("posthog_dashboard"."deleted") - AND "posthog_dashboard"."team_id" = 2) + WHERE ("posthog_dashboard"."team_id" = 2 + AND NOT "posthog_dashboard"."deleted") ORDER BY "posthog_dashboard"."name" ASC LIMIT 300 ''' @@ -6929,8 +6929,8 @@ INNER JOIN "posthog_team" ON ("posthog_dashboard"."team_id" = "posthog_team"."id") INNER JOIN "posthog_organization" ON ("posthog_team"."organization_id" = "posthog_organization"."id") LEFT OUTER JOIN "posthog_user" ON ("posthog_dashboard"."created_by_id" = "posthog_user"."id") - WHERE (NOT ("posthog_dashboard"."deleted") - AND "posthog_dashboard"."team_id" = 2 + WHERE ("posthog_dashboard"."team_id" = 2 + AND NOT "posthog_dashboard"."deleted" AND "posthog_dashboard"."id" = 2) LIMIT 21 ''' @@ -10687,8 +10687,8 @@ INNER JOIN "posthog_team" ON ("posthog_dashboard"."team_id" = "posthog_team"."id") INNER JOIN "posthog_organization" ON ("posthog_team"."organization_id" = "posthog_organization"."id") LEFT OUTER JOIN "posthog_user" ON ("posthog_dashboard"."created_by_id" = "posthog_user"."id") - WHERE (NOT ("posthog_dashboard"."deleted") - AND "posthog_dashboard"."team_id" = 2 + WHERE ("posthog_dashboard"."team_id" = 2 + AND NOT "posthog_dashboard"."deleted" AND "posthog_dashboard"."id" = 2) LIMIT 21 ''' @@ -11797,8 +11797,8 @@ ''' SELECT COUNT(*) AS "__count" FROM "posthog_dashboard" - WHERE (NOT ("posthog_dashboard"."deleted") - AND "posthog_dashboard"."team_id" = 2) + WHERE ("posthog_dashboard"."team_id" = 2 + AND NOT "posthog_dashboard"."deleted") ''' # --- # name: TestDashboard.test_retrieve_dashboard_list.3 @@ -11931,8 +11931,8 @@ INNER JOIN "posthog_team" ON ("posthog_dashboard"."team_id" = "posthog_team"."id") INNER JOIN "posthog_organization" ON ("posthog_team"."organization_id" = "posthog_organization"."id") LEFT OUTER JOIN "posthog_user" ON ("posthog_dashboard"."created_by_id" = "posthog_user"."id") - WHERE (NOT ("posthog_dashboard"."deleted") - AND "posthog_dashboard"."team_id" = 2) + WHERE ("posthog_dashboard"."team_id" = 2 + AND NOT "posthog_dashboard"."deleted") ORDER BY "posthog_dashboard"."name" ASC LIMIT 100 '''