From e4d71f6f7dbca47c75e4ce4b5d311466dbb4c54f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 5 May 2015 23:44:40 +0200 Subject: [PATCH] backoffice: move management of submitted forms to a subdirectory (#7151) --- tests/test_backoffice_pages.py | 26 ++-- tests/test_formdata.py | 2 +- wcs/backoffice/root.py | 281 ++++++++++++++++++++++------------------- wcs/formdef.py | 2 +- 4 files changed, 167 insertions(+), 144 deletions(-) diff --git a/tests/test_backoffice_pages.py b/tests/test_backoffice_pages.py index 7a13bfc..d6ae7f0 100644 --- a/tests/test_backoffice_pages.py +++ b/tests/test_backoffice_pages.py @@ -134,11 +134,11 @@ def test_backoffice_listing(pub): create_superuser(pub) create_environment() app = login(get_app(pub)) - resp = app.get('/backoffice/form-title/') + resp = app.get('/backoffice/management/form-title/') assert resp.body.count('data-link') == 17 # check status filter - resp = app.get('/backoffice/form-title/') + resp = app.get('/backoffice/management/form-title/') resp.forms[0]['filter'] = 'done' resp = resp.forms[0].submit() if getattr(pub, 'pgconn', None): @@ -162,7 +162,7 @@ def test_backoffice_columns(pub): create_superuser(pub) create_environment() app = login(get_app(pub)) - resp = app.get('/backoffice/form-title/') + resp = app.get('/backoffice/management/form-title/') assert resp.body.count('') == 6 # five columns resp.forms[0]['1'].checked = False resp = resp.forms[0].submit() @@ -174,7 +174,7 @@ def test_backoffice_filter(pub): create_superuser(pub) create_environment() app = login(get_app(pub)) - resp = app.get('/backoffice/form-title/') + resp = app.get('/backoffice/management/form-title/') assert resp.forms[0]['filter-status'].checked == True resp.forms[0]['filter-status'].checked = False resp.forms[0]['filter-2'].checked = True @@ -200,12 +200,12 @@ def test_backoffice_csv(pub): create_superuser(pub) create_environment() app = login(get_app(pub)) - resp = app.get('/backoffice/form-title/') + resp = app.get('/backoffice/management/form-title/') resp = resp.click('CSV Export') assert resp.headers['content-type'].startswith('text/') assert len(resp.body.splitlines()) == 18 # 17 + header line - resp = app.get('/backoffice/form-title/') + resp = app.get('/backoffice/management/form-title/') resp.forms[0]['filter'] = 'all' resp = resp.forms[0].submit() resp = resp.click('CSV Export') @@ -215,7 +215,7 @@ def test_backoffice_ods(pub): create_superuser(pub) create_environment() app = login(get_app(pub)) - resp = app.get('/backoffice/form-title/') + resp = app.get('/backoffice/management/form-title/') resp = resp.click('Open Document Format Export') assert resp.headers['content-type'] == 'application/vnd.oasis.opendocument.spreadsheet' assert 'filename=form-title.ods' in resp.headers['content-disposition'] @@ -225,7 +225,7 @@ def test_backoffice_statistics(pub): create_superuser(pub) create_environment() app = login(get_app(pub)) - resp = app.get('/backoffice/form-title/') + resp = app.get('/backoffice/management/form-title/') resp = resp.click('Statistics') assert 'Total number of records: 50' in resp.body assert 'New: 17' in resp.body @@ -243,7 +243,7 @@ def test_backoffice_statistics_status_filter(pub): create_superuser(pub) create_environment() app = login(get_app(pub)) - resp = app.get('/backoffice/form-title/') + resp = app.get('/backoffice/management/form-title/') resp = resp.click('Statistics') assert 'filter' not in resp.forms[0].fields # status is not displayed by default @@ -273,7 +273,7 @@ def test_backoffice_statistics_status_select(pub): create_superuser(pub) create_environment() app = login(get_app(pub)) - resp = app.get('/backoffice/form-title/') + resp = app.get('/backoffice/management/form-title/') resp = resp.click('Statistics') resp.forms[0]['filter-2'].checked = True @@ -296,7 +296,7 @@ def test_backoffice_handling(pub): form_class = FormDef.get_by_urlname('form-title').data_class() number31 = [x for x in form_class.select() if x.data['1'] == 'FOO BAR 30'][0].id app = login(get_app(pub)) - resp = app.get('/backoffice/form-title/') + resp = app.get('/backoffice/management/form-title/') resp = resp.click(href='%s/' % number31) assert (' with the number %s.' % number31) in resp.body resp.forms[0]['comment'] = 'HELLO WORLD' @@ -343,7 +343,7 @@ def test_backoffice_submission(pub): assert new_formdata_count == formdata_count+1 formdata = [x for x in formdef.data_class().select() if x.data['1'] == 'XYZ'][0] - assert resp.location == 'http://example.net/backoffice/form-title/%s/' % formdata.id + assert resp.location == 'http://example.net/backoffice/management/form-title/%s/' % formdata.id resp = resp.follow() assert 'The form has been recorded' in resp.body assert 'XYZ' in resp.body diff --git a/tests/test_formdata.py b/tests/test_formdata.py index 34de23c..a7e99aa 100644 --- a/tests/test_formdata.py +++ b/tests/test_formdata.py @@ -56,7 +56,7 @@ def test_saved(pub): assert substvars.get('form_number') == '1' assert substvars.get('form_number_raw') == '1' assert substvars.get('form_url').endswith('/foobar/1/') - assert substvars.get('form_url_backoffice').endswith('/backoffice/foobar/1/') + assert substvars.get('form_url_backoffice').endswith('/backoffice/management/foobar/1/') assert substvars.get('form_status_url').endswith('/foobar/1/status') def test_display_id(pub): diff --git a/wcs/backoffice/root.py b/wcs/backoffice/root.py index ee4a659..f11e529 100644 --- a/wcs/backoffice/root.py +++ b/wcs/backoffice/root.py @@ -248,134 +248,14 @@ class WorkflowsDirectory(wcs.admin.workflows.WorkflowsDirectory): return is_accessible('workflows') -class RootDirectory(BackofficeRootDirectory): - _q_exports = ['', 'management', 'pending', 'statistics'] - - bounces = wcs.admin.bounces.BouncesDirectory() - categories = wcs.admin.categories.CategoriesDirectory() - forms = wcs.admin.forms.FormsDirectory() - logger = wcs.admin.logger.LoggerDirectory() - roles = wcs.admin.roles.RolesDirectory() - settings = wcs.admin.settings.SettingsDirectory() - users = wcs.admin.users.UsersDirectory() - workflows = wcs.admin.workflows.WorkflowsDirectory() - submission = submission.SubmissionDirectory() - - menu_items = [ - ('management', N_('Pending Forms')), - ('submission/', N_('Submission')), - ('forms/', N_('Forms Workshop')), - ('workflows/', N_('Workflows Workshop')), - ('users/', N_('Users')), - ('roles/', N_('Roles')), - ('categories/', N_('Categories')), - ('logger/', N_('Logs'), logger.is_visible), - ('bounces/', N_('Bounces'), bounces.is_visible), - ('settings/', N_('Settings')), - ('/', N_('WCS Form Server')) - ] - - def check_admin_for_all(self): - admin_for_all_file_path = os.path.join(get_publisher().app_dir, 'ADMIN_FOR_ALL') - if not os.path.exists(os.path.join(admin_for_all_file_path)): - return False - admin_for_all_contents = open(admin_for_all_file_path).read() - if not admin_for_all_contents: - # empty file, access is granted to everybody - return True - if get_request().get_environ('REMOTE_ADDR', '') in admin_for_all_contents.splitlines(): - # if the file is not empty it should contain the list of authorized - # IP addresses. - return True - return False +class ManagementDirectory(Directory): + _q_exports = ['', 'statistics'] - def _q_access(self): - get_response().breadcrumb.append( ('backoffice/', _('Back Office')) ) - req = get_request() - - if self.check_admin_for_all(): - get_response().filter['admin_for_all'] = True - return - - if get_publisher().user_class.count() > 0: - user = req.user - if not user: - raise errors.AccessUnauthorizedError( - public_msg = _('Access to backoffice is restricted to authorized persons only. '\ - 'Please login.')) - if not user.can_go_in_backoffice(): - raise errors.AccessForbiddenError() - - get_response().filter['in_backoffice'] = True - - def get_intro_text(self): - return _('''Welcome.''') - - def generate_header_menu(self, selected=None): - s = ['\n') - return ''.join(s) + def _q_traverse(self, path): + get_response().breadcrumb.append(('management/', _('Management'))) + return super(ManagementDirectory, self)._q_traverse(path) def _q_index(self): - html_top('/') - r = TemplateIO(html=True) - r += htmltext('

%s

') % self.get_intro_text() - - menu_items = self.get_menu_items() - r += htmltext('') - r += htmltext('
') - - r += htmltext('

') - - get_response().filter['sidebar'] = str(self.get_sidebar()) - - return r.getvalue() - - - def get_sidebar(self): - from qommon.admin.menu import get_vc_version - from wcs.admin.root import gpl - r = TemplateIO(html=True) - - r += htmltext('
') - r += htmltext('') - r += htmltext('
') - - version = get_vc_version() - if version: - r += htmltext('

') - r += _('Version:') - r += ' ' - r += version - r += htmltext('

') - - r += htmltext('
') - r += gpl() - r += htmltext('
') - - return r.getvalue() - - def management(self): - get_response().breadcrumb.append(('management', _('Pending Forms'))) html_top('management', _('Pending Forms')) get_response().filter['sidebar'] = self.get_sidebar() r = TemplateIO(html=True) @@ -430,6 +310,14 @@ class RootDirectory(BackofficeRootDirectory): return r.getvalue() + def get_sidebar(self): + r = TemplateIO(html=True) + r += htmltext('
') + r += htmltext('') + r += htmltext('
') + return r.getvalue() def get_stats_sidebar(self): get_response().add_javascript(['jquery.js']) @@ -466,7 +354,6 @@ class RootDirectory(BackofficeRootDirectory): return r.getvalue() - def statistics(self): html_top('management', _('Global statistics')) get_response().breadcrumb.append(('statistics', _('Global statistics'))) @@ -511,7 +398,6 @@ class RootDirectory(BackofficeRootDirectory): return r.getvalue() - def category_global_stats(self, title, category_formdefs, counts): r = TemplateIO(html=True) category_formdefs_ids = [x.id for x in category_formdefs] @@ -535,7 +421,6 @@ class RootDirectory(BackofficeRootDirectory): r += htmltext('') return r.getvalue() - def display_forms(self, forms_list): r = TemplateIO(html=True) r += htmltext('') return r.getvalue() + def _q_lookup(self, component): + return FormPage(component) + + +class RootDirectory(BackofficeRootDirectory): + _q_exports = ['', 'pending', 'statistics'] + + bounces = wcs.admin.bounces.BouncesDirectory() + categories = wcs.admin.categories.CategoriesDirectory() + forms = wcs.admin.forms.FormsDirectory() + logger = wcs.admin.logger.LoggerDirectory() + roles = wcs.admin.roles.RolesDirectory() + settings = wcs.admin.settings.SettingsDirectory() + users = wcs.admin.users.UsersDirectory() + workflows = wcs.admin.workflows.WorkflowsDirectory() + submission = submission.SubmissionDirectory() + management = ManagementDirectory() + + menu_items = [ + ('management/', N_('Pending Forms')), + ('submission/', N_('Submission')), + ('forms/', N_('Forms Workshop')), + ('workflows/', N_('Workflows Workshop')), + ('users/', N_('Users')), + ('roles/', N_('Roles')), + ('categories/', N_('Categories')), + ('logger/', N_('Logs'), logger.is_visible), + ('bounces/', N_('Bounces'), bounces.is_visible), + ('settings/', N_('Settings')), + ] + + def _q_traverse(self, path): + get_response().add_javascript(['jquery.js']) + return super(RootDirectory, self)._q_traverse(path) + + def check_admin_for_all(self): + admin_for_all_file_path = os.path.join(get_publisher().app_dir, 'ADMIN_FOR_ALL') + if not os.path.exists(os.path.join(admin_for_all_file_path)): + return False + admin_for_all_contents = open(admin_for_all_file_path).read() + if not admin_for_all_contents: + # empty file, access is granted to everybody + return True + if get_request().get_environ('REMOTE_ADDR', '') in admin_for_all_contents.splitlines(): + # if the file is not empty it should contain the list of authorized + # IP addresses. + return True + return False + + def _q_access(self): + get_response().breadcrumb.append( ('backoffice/', _('Back Office')) ) + req = get_request() + + if self.check_admin_for_all(): + get_response().filter['admin_for_all'] = True + return + + if get_publisher().user_class.count() > 0: + user = req.user + if not user: + raise errors.AccessUnauthorizedError( + public_msg = _('Access to backoffice is restricted to authorized persons only. '\ + 'Please login.')) + if not user.can_go_in_backoffice(): + raise errors.AccessForbiddenError() + + get_response().filter['in_backoffice'] = True + + def get_intro_text(self): + return _('''Welcome.''') + + def generate_header_menu(self, selected=None): + s = ['\n') + return ''.join(s) + + def _q_index(self): + html_top('/') + r = TemplateIO(html=True) + r += htmltext('

%s

') % self.get_intro_text() + + menu_items = self.get_menu_items() + r += htmltext('') + r += htmltext('
') + + r += htmltext('

') + + get_response().filter['sidebar'] = str(self.get_sidebar()) + + return r.getvalue() + + def get_sidebar(self): + from qommon.admin.menu import get_vc_version + from wcs.admin.root import gpl + r = TemplateIO(html=True) + + r += htmltext('
') + r += htmltext('') + r += htmltext('
') + + version = get_vc_version() + if version: + r += htmltext('

') + r += _('Version:') + r += ' ' + r += version + r += htmltext('

') + + r += htmltext('
') + r += gpl() + r += htmltext('
') + + return r.getvalue() + def pending(self): # kept as a redirection for compatibility with possible bookmarks return redirect('.') + def statistics(self): + return redirect('management/statistics') + def _q_lookup(self, component): if component in [str(x[0]).strip('/') for x in self.menu_items]: if not is_accessible(component): raise errors.AccessForbiddenError() return getattr(self, component) - return FormPage(component) + if FormDef.has_key(component): + return redirect('management/%s/' % component) + return super(RootDirectory, self)._q_lookup(component) def get_menu_items(self): if not get_request().user: diff --git a/wcs/formdef.py b/wcs/formdef.py index d2a2f02..ce23d88 100644 --- a/wcs/formdef.py +++ b/wcs/formdef.py @@ -331,7 +331,7 @@ class FormDef(StorableObject): def get_url(self, backoffice = False): if backoffice: - base_url = get_publisher().get_backoffice_url() + base_url = get_publisher().get_backoffice_url() + '/management' else: base_url = get_publisher().get_frontoffice_url() return '%s/%s/' % (base_url, self.url_name) -- 2.1.4