custom-views: remove digest on deletion (#73775)
gitea-wip/wcs/pipeline/pr-main This commit looks good Details

This commit is contained in:
Lauréline Guérin 2023-01-26 17:24:43 +01:00
parent aa6ce7c35d
commit 204ba88ba8
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 49 additions and 1 deletions

View File

@ -455,7 +455,7 @@ def test_backoffice_custom_view_status_filter(pub):
def test_backoffice_custom_view_delete(pub):
create_superuser(pub)
user = create_superuser(pub)
FormDef.wipe()
pub.custom_view_class.wipe()
@ -481,6 +481,42 @@ def test_backoffice_custom_view_delete(pub):
resp = resp.follow()
assert 'custom test view' not in resp.text
CardDef.wipe()
carddef = CardDef()
carddef.name = 'foo'
carddef.fields = [
fields.StringField(id='1', label='Test', type='string', varname='foo'),
]
carddef.backoffice_submission_roles = user.roles
carddef.workflow_roles = {'_editor': user.roles[0]}
carddef.digest_templates = {
'default': 'plop',
'custom-view:custom-test-view': 'FOO {{ form_var_foo }}',
'custom-view:another-view': '{{ form_var_foo }}',
}
carddef.store()
custom_view = pub.custom_view_class()
custom_view.title = 'custom test view'
custom_view.formdef = carddef
custom_view.visibility = 'datasource'
custom_view.columns = {'list': [{'id': 'id'}]}
custom_view.filters = {}
custom_view.store()
resp = app.get('/backoffice/data/foo/custom-test-view/')
resp = resp.click('Delete')
resp = resp.form.submit()
assert resp.location.endswith('/data/foo/')
resp = resp.follow()
assert 'custom test view' not in resp.text
carddef.refresh_from_storage()
assert carddef.digest_templates == {
'default': 'plop',
'custom-view:another-view': '{{ form_var_foo }}',
}
def test_backoffice_custom_map_view(pub):
user = create_superuser(pub)

View File

@ -65,6 +65,18 @@ class CustomView(StorableObject):
self.formdef_id = str(value.id)
self.formdef_type = value.xml_root_node
def remove_self(self):
try:
formdef = self.formdef
except KeyError:
pass
else:
view_digest_key = 'custom-view:%s' % self.get_url_slug()
if view_digest_key in (formdef.digest_templates or {}):
del formdef.digest_templates[view_digest_key]
formdef.store()
super().remove_self()
def match(self, user, formdef):
if self.formdef_type != formdef.xml_root_node:
return False