backoffice: don't let new forms be created when welco is deployed (#9500)
This commit is contained in:
parent
728697c013
commit
0ab8fc4876
|
@ -11,16 +11,14 @@ def pytest_runtest_setup(item):
|
|||
if 'postgresql' in item.keywords and item.config.option.without_postgresql_tests is True:
|
||||
pytest.skip('skipped (PostgreSQL are disabled on command line)')
|
||||
|
||||
@pytest.fixture
|
||||
def fargo_url(request, pub):
|
||||
def variable_url(request, pub, variable, url):
|
||||
config = ConfigParser.ConfigParser()
|
||||
path = os.path.join(pub.app_dir, 'site-options.cfg')
|
||||
url = 'http://fargo.example.net/'
|
||||
if os.path.exists(path):
|
||||
config.read([path])
|
||||
if not config.has_section('options'):
|
||||
config.add_section('options')
|
||||
config.set('options', 'fargo_url', url)
|
||||
config.set('options', variable, url)
|
||||
with file(path, 'w') as site_option:
|
||||
config.write(site_option)
|
||||
|
||||
|
@ -28,8 +26,16 @@ def fargo_url(request, pub):
|
|||
config = ConfigParser.ConfigParser()
|
||||
if os.path.exists(path):
|
||||
config.read([path])
|
||||
config.remove_option('options', 'fargo_url')
|
||||
config.remove_option('options', variable)
|
||||
with file(path, 'w') as site_option:
|
||||
config.write(site_option)
|
||||
request.addfinalizer(fin)
|
||||
return url
|
||||
|
||||
@pytest.fixture
|
||||
def fargo_url(request, pub):
|
||||
return variable_url(request, pub, 'fargo_url', 'http://fargo.example.net')
|
||||
|
||||
@pytest.fixture
|
||||
def welco_url(request, pub):
|
||||
return variable_url(request, pub, 'welco_url', 'http://welco.example.net')
|
||||
|
|
|
@ -756,6 +756,37 @@ def test_backoffice_submission(pub):
|
|||
resp = resp.form.submit('cancel')
|
||||
assert resp.location == 'http://example.net/backoffice/submission/'
|
||||
|
||||
def test_backoffice_submission_welco(pub, welco_url):
|
||||
user = create_user(pub)
|
||||
create_environment(pub)
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/')
|
||||
assert not 'Submission' in resp.body
|
||||
app.get('/backoffice/submission/', status=403)
|
||||
|
||||
formdef = FormDef.get_by_urlname('form-title')
|
||||
formdef.backoffice_submission_roles = user.roles[:]
|
||||
formdef.store()
|
||||
|
||||
# if it's empty, redirect to welco
|
||||
resp = app.get('/backoffice/')
|
||||
assert 'Submission' in resp.body
|
||||
resp = app.get('/backoffice/submission/')
|
||||
assert resp.location == 'http://welco.example.net'
|
||||
|
||||
# if there are pending submissions, display them
|
||||
formdata = formdef.data_class()()
|
||||
formdata.data = {}
|
||||
formdata.status = 'draft'
|
||||
formdata.backoffice_submission = True
|
||||
formdata.store()
|
||||
|
||||
resp = app.get('/backoffice/')
|
||||
assert 'Submission' in resp.body
|
||||
resp = app.get('/backoffice/submission/')
|
||||
assert 'Submission to complete' in resp.body
|
||||
|
||||
def test_backoffice_submission_dispatch(pub):
|
||||
user = create_user(pub)
|
||||
create_environment(pub)
|
||||
|
|
|
@ -195,8 +195,14 @@ class SubmissionDirectory(Directory):
|
|||
misc_cat.formdefs = [x for x in list_forms if not x.category]
|
||||
cats.append(misc_cat)
|
||||
|
||||
welco_url = get_publisher().get_site_option('welco_url', 'options')
|
||||
|
||||
r = TemplateIO(html=True)
|
||||
for mode in ['empty', 'create', 'existing']:
|
||||
modes = ['empty', 'create', 'existing']
|
||||
if welco_url:
|
||||
modes.remove('create')
|
||||
empty = True
|
||||
for mode in modes:
|
||||
list_content = TemplateIO()
|
||||
for cat in cats:
|
||||
if not cat.formdefs:
|
||||
|
@ -204,6 +210,7 @@ class SubmissionDirectory(Directory):
|
|||
list_content += self.form_list(cat.formdefs, title=cat.name, mode=mode)
|
||||
if not list_content.getvalue().strip():
|
||||
continue
|
||||
empty = False
|
||||
r += htmltext('<div class="bo-block">')
|
||||
r += htmltext('<h2>%s</h2>') % {
|
||||
'create': _('Submission'),
|
||||
|
@ -215,6 +222,9 @@ class SubmissionDirectory(Directory):
|
|||
r += htmltext('</ul>')
|
||||
r += htmltext('</div>')
|
||||
|
||||
if empty and welco_url:
|
||||
return redirect(welco_url)
|
||||
|
||||
return r.getvalue()
|
||||
|
||||
def form_list(self, formdefs, title=None, mode='create'):
|
||||
|
|
|
@ -304,12 +304,13 @@ class CmdCheckHobos(Command):
|
|||
|
||||
if 'options' not in config.sections():
|
||||
config.add_section('options')
|
||||
|
||||
# add known services
|
||||
for service in self.all_services.get('services', []):
|
||||
if service.get('service-id') != 'fargo':
|
||||
continue
|
||||
config.set('options', 'fargo_url', service.get('base_url'))
|
||||
# Use the first fargo found and stop
|
||||
break
|
||||
if service.get('service-id') == 'fargo':
|
||||
config.set('options', 'fargo_url', service.get('base_url'))
|
||||
if service.get('service-id') == 'welco':
|
||||
config.set('options', 'welco_url', service.get('base_url'))
|
||||
|
||||
try:
|
||||
portal_agent_url = config.get('variables', 'portal_agent_url')
|
||||
|
|
Loading…
Reference in New Issue