misc: raise 404 on applications that do not exist (#71961)

This commit is contained in:
Frédéric Péters 2022-12-02 11:00:09 +01:00
parent 7e6a13320b
commit 1d5794ef2a
2 changed files with 8 additions and 3 deletions

View File

@ -66,7 +66,7 @@ class ManifestView(TemplateView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['app'] = Application.objects.get(slug=self.kwargs['app_slug'])
context['app'] = get_object_or_404(Application, slug=self.kwargs['app_slug'])
context['relations'] = context['app'].relation_set.all().select_related('element')
context['last_version'] = context['app'].version_set.order_by('last_update_timestamp').last()
@ -101,7 +101,7 @@ class VersionsView(ListView):
template_name = 'hobo/applications/versions.html'
def get_queryset(self):
self.app = Application.objects.get(slug=self.kwargs['app_slug'])
self.app = get_object_or_404(Application, slug=self.kwargs['app_slug'])
return self.app.version_set.order_by('-last_update_timestamp').prefetch_related(
Prefetch('asyncjob_set', queryset=AsyncJob.objects.order_by('-creation_timestamp'))
)
@ -275,7 +275,7 @@ generate = GenerateView.as_view()
def download(request, app_slug, version_pk=None):
app = Application.objects.get(slug=app_slug)
app = get_object_or_404(Application, slug=app_slug)
if version_pk is None:
version = app.version_set.order_by('last_update_timestamp').last()
else:

View File

@ -743,6 +743,11 @@ def test_delete_application(app, admin_user, settings):
assert Application.objects.first().name == 'OtherApp'
def test_404_unknown_app(app, admin_user, settings):
login(app)
app.get('/applications/manifest/xxx/', status=404)
@pytest.fixture
def app_bundle():
return get_bundle()