Skip to content

Commit

Permalink
Fixed up dashboard templates
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Mar 27, 2024
1 parent 92f0b40 commit 3e91e51
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ee/api/rbac/test/test_access_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ def test_query_counts(self):
# We call this endpoint as we don't want to include all the extra queries that rendering the project uses
self.client.get("/api/projects/@current/is_generating_demo_data")

# When accessing the list of notebooks we have extra queries due to checking for role based access and filtering out items
baseline = 9
with self.assertNumQueries(baseline + 4): # 1 roles, 1 project, 1 global, 1 for listing what to filter out
self.client.get("/api/projects/@current/notebooks/")


class TestAccessControlFiltering(BaseAccessControlTest):
def setUp(self):
Expand Down
7 changes: 5 additions & 2 deletions posthog/api/dashboards/dashboard_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,17 @@ class DashboardTemplateViewSet(TeamAndOrgViewSetMixin, ForbidDestroyModel, views
scope_object = "dashboard_template"
permission_classes = [OnlyStaffCanEditDashboardTemplate]
serializer_class = DashboardTemplateSerializer
queryset = DashboardTemplate.objects.all()

@method_decorator(cache_page(60 * 2)) # cache for 2 minutes
@action(methods=["GET"], detail=False)
def json_schema(self, request: request.Request, **kwargs) -> response.Response:
# Could switch from this being a static file to being dynamically generated from the serializer
return response.Response(dashboard_template_schema)

def get_queryset(self, *args, **kwargs):
def filter_queryset(self, queryset):
# NOTE: We override the default filtering as we don't want parent based filtering here

filters = self.request.GET.dict()
scope = filters.pop("scope", None)
search = filters.pop("search", None)
Expand All @@ -100,4 +103,4 @@ def get_queryset(self, *args, **kwargs):
Q(template_name__search=search) | Q(dashboard_description__search=search) | Q(tags__contains=[search])
)

return DashboardTemplate.objects.filter(query_condition)
return queryset.filter(query_condition)

0 comments on commit 3e91e51

Please sign in to comment.