misc: totally ignore unknown config json cell (#24190)

This commit is contained in:
Frédéric Péters 2018-05-31 08:53:08 +02:00
parent 594f5c0e3f
commit c505e6bb37
2 changed files with 24 additions and 0 deletions

View File

@ -1151,8 +1151,16 @@ class JsonCell(JsonCellBase):
return [vn.strip() for vn in self.varnames_str.split(',') if vn.strip()]
class ConfigJsonCellManager(models.Manager):
def get_queryset(self):
queryset = super(ConfigJsonCellManager, self).get_queryset()
return queryset.filter(key__in=settings.JSON_CELL_TYPES.keys())
@register_cell_class
class ConfigJsonCell(JsonCellBase):
objects = ConfigJsonCellManager()
key = models.CharField(max_length=50)
parameters = JSONField(blank=True)

View File

@ -586,6 +586,22 @@ def test_config_json_cell_additional_url(app):
assert 'plop2_status' not in context
assert 'plop2_error' not in context
def test_config_json_invalid_key_cell():
page = Page(title='example page', slug='example-page')
page.save()
request = RequestFactory().get('/')
with override_settings(JSON_CELL_TYPES={'foobar': {'name': 'Foobar', 'url': 'http://test/'}}):
cell = ConfigJsonCell()
cell.key = 'foobar'
cell.parameters = {'blah': 'plop'}
cell.page = page
cell.order = 0
cell.save()
assert len(page.get_cells()) == 1
assert len(page.get_cells()) == 0
def test_page_cell_placeholder_restricted_visibility(app, admin_user):
page = Page(title='Test', slug='test', template_name='standard')