From fd496d1c7c4ad2e5893d5512ea90e22215ba1cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Mon, 11 Jan 2016 12:41:47 +0100 Subject: [PATCH] backoffice: don't let new forms be created when welco is deployed (#9500) --- tests/conftest.py | 16 +++++++++++----- tests/test_backoffice_pages.py | 31 +++++++++++++++++++++++++++++++ wcs/backoffice/submission.py | 12 +++++++++++- wcs/ctl/check_hobos.py | 11 ++++++----- 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 077eafc..1374c75 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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') diff --git a/tests/test_backoffice_pages.py b/tests/test_backoffice_pages.py index 098b8c8..200e431 100644 --- a/tests/test_backoffice_pages.py +++ b/tests/test_backoffice_pages.py @@ -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) diff --git a/wcs/backoffice/submission.py b/wcs/backoffice/submission.py index b4b89ad..5006674 100644 --- a/wcs/backoffice/submission.py +++ b/wcs/backoffice/submission.py @@ -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('
') r += htmltext('

%s

') % { 'create': _('Submission'), @@ -215,6 +222,9 @@ class SubmissionDirectory(Directory): r += htmltext('') r += htmltext('
') + if empty and welco_url: + return redirect(welco_url) + return r.getvalue() def form_list(self, formdefs, title=None, mode='create'): diff --git a/wcs/ctl/check_hobos.py b/wcs/ctl/check_hobos.py index c73ebc6..a302a76 100644 --- a/wcs/ctl/check_hobos.py +++ b/wcs/ctl/check_hobos.py @@ -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') -- 2.7.0.rc3