Skip to content

Commit 504637d

Browse files
committed
Extract dataset queryset based on permissions
1 parent 3559814 commit 504637d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

datashow/views.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
from .table import RowQueryset, get_facets, get_row
1010

1111

12-
def get_dataset(request, slug: str) -> Dataset:
13-
qs = Dataset.objects.all()
12+
def get_viewable_datasets(request, queryset):
1413
if not request.user.has_perm("datashow.view_dataset"):
15-
qs = qs.filter(public=True)
16-
return get_object_or_404(qs.select_related("default_table"), slug=slug)
14+
queryset = queryset.filter(public=True)
15+
return queryset
16+
17+
18+
def get_dataset(request, slug: str) -> Dataset:
19+
queryset = get_viewable_datasets(request, Dataset.objects.all())
20+
return get_object_or_404(queryset.select_related("default_table"), slug=slug)
1721

1822

1923
def get_table(dataset: Dataset, table_slug: str) -> Table:

0 commit comments

Comments
 (0)