admin: warn about missing roles in site import (#41252)

This commit is contained in:
Frédéric Péters 2020-05-06 18:40:28 +02:00
parent 252551daba
commit 735b7cce0a
2 changed files with 16 additions and 2 deletions

View File

@ -4577,6 +4577,16 @@ def test_settings_export_import(pub, studio):
filelist = zipf.namelist()
assert len([x for x in filelist if 'roles/' in x]) == 0
# check an error is displayed if such an import is then used and roles are
# missing.
FormDef.wipe()
Workflow.wipe()
Role.wipe()
resp = app.get('/backoffice/settings/import')
resp.form['file'] = Upload('export.wcs', zip_content.getvalue())
resp = resp.form.submit('submit')
assert 'Unknown referenced role (qux)' in resp
def test_settings_themes(pub):
create_superuser(pub)

View File

@ -54,7 +54,7 @@ from wcs.qommon import ident
from wcs.formdef import FormDef
from wcs.carddef import CardDef
from wcs.workflows import Workflow
from wcs.workflows import Workflow, WorkflowImportError
from wcs.roles import Role
from wcs.backoffice.studio import StudioDirectory
@ -998,6 +998,10 @@ class SettingsDirectory(QommonSettingsDirectory):
results = self.import_submit(form)
except zipfile.BadZipfile:
results = None
reason = _('Not a valid export file')
except WorkflowImportError as e:
results = None
reason = _(e) % e.msg_args
html_top('settings', title = _('Import'))
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Import')
@ -1024,7 +1028,7 @@ class SettingsDirectory(QommonSettingsDirectory):
r += htmltext('<li>%d %s</li>') % (results['wscalls'], _('webservice calls'))
r += htmltext('</ul>')
else:
r += htmltext('<p>%s</p>') % _('Error: Not a valid export file')
r += htmltext('<p>%s %s</p>') % (_('Error:'), reason)
r += htmltext('<a href=".">%s</a>') % _('Back')
return r.getvalue()