backoffice: return a 404 on missing block (#55515)

This commit is contained in:
Frédéric Péters 2021-07-12 14:41:54 +02:00
parent ed1698d5b0
commit dc67aa7b1c
2 changed files with 14 additions and 1 deletions

View File

@ -36,6 +36,14 @@ def teardown_module(module):
clean_temporary_pub()
def test_block_404(pub, blocks_feature):
create_superuser(pub)
create_role(pub)
BlockDef.wipe()
app = login(get_app(pub))
app.get('/backoffice/forms/blocks/1/', status=404)
def test_block_new(pub, blocks_feature):
create_superuser(pub)
create_role(pub)

View File

@ -24,6 +24,7 @@ from wcs.backoffice.snapshots import SnapshotsDirectory
from wcs.blocks import BlockDef, BlockdefImportError
from wcs.qommon import _, misc, template
from wcs.qommon.backoffice.menu import html_top
from wcs.qommon.errors import TraversalError
from wcs.qommon.form import FileWidget, Form, HtmlWidget, StringWidget
@ -198,7 +199,11 @@ class BlocksDirectory(Directory):
return super()._q_traverse(path)
def _q_lookup(self, component):
return BlockDirectory(self.section, BlockDef.get(component))
try:
block = BlockDef.get(component)
except KeyError:
raise TraversalError()
return BlockDirectory(self.section, block)
def _q_index(self):
html_top(self.section, title=_('Fields Blocks'))