search: return 404 if cell does not exist (#49876)
gitea-wip/combo/pipeline/head Build started... Details
gitea/combo/pipeline/head Build started... Details

This commit is contained in:
Lauréline Guérin 2021-01-05 11:02:01 +01:00
parent f3f124e412
commit 53651ec33e
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 13 additions and 9 deletions

View File

@ -24,6 +24,7 @@ from django.http import HttpResponse
from django.core.exceptions import PermissionDenied
from django.utils.functional import cached_property
from django.utils.http import quote
from django.shortcuts import get_object_or_404
from django.template import RequestContext, Template
from jsonfield import JSONField
@ -172,7 +173,7 @@ class SearchCell(CellBase):
@classmethod
def ajax_results_view(cls, request, cell_pk, service_slug):
cell = cls.objects.get(pk=cell_pk)
cell = get_object_or_404(cls, pk=cell_pk)
if not cell.is_visible(user=request.user) or not cell.page.is_visible(request.user):
raise PermissionDenied

View File

@ -57,15 +57,18 @@ class SearchServices(object):
def test_search_cell(app):
page = Page(title='Search', slug='search_page', template_name='standard')
page.save()
cell = SearchCell(page=page, placeholder='content', order=0)
cell._search_services = {'data': ['search1']}
cell.input_placeholder = 'my placeholder'
cell.save()
# unknown cell pk
resp = app.get('/ajax/search/0/search1/?q=foo', status=404)
with SearchServices(SEARCH_SERVICES):
page = Page(title='Search', slug='search_page', template_name='standard')
page.save()
cell = SearchCell(page=page, placeholder='content', order=0)
cell._search_services = {'data': ['search1']}
cell.input_placeholder = 'my placeholder'
cell.save()
resp = cell.render({})
assert 'input' in resp
assert 'id="combo-search-input-%s"' % cell.pk in resp