backoffice: add feature flag to hide statistics links (#74759) #180
|
@ -50,6 +50,27 @@ def test_backoffice_statistics_with_no_formdefs(pub):
|
|||
assert 'This site is currently empty.' in resp
|
||||
|
||||
|
||||
def test_backoffice_statistics_feature_flag(pub):
|
||||
create_superuser(pub)
|
||||
FormDef.wipe()
|
||||
formdef = FormDef()
|
||||
formdef.name = 'form title'
|
||||
formdef.store()
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/management/form-title/')
|
||||
assert 'Statistics' in resp.text
|
||||
|
||||
if not pub.site_options.has_section('options'):
|
||||
pub.site_options.add_section('options')
|
||||
|
||||
pub.site_options.set('options', 'disable-internal-statistics', 'true')
|
||||
with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
|
||||
pub.site_options.write(fd)
|
||||
resp = app.get('/backoffice/management/form-title/')
|
||||
assert 'Statistics' not in resp.text
|
||||
|
||||
|
||||
def test_backoffice_statistics_status_filter(pub):
|
||||
create_superuser(pub)
|
||||
create_environment(pub)
|
||||
|
@ -156,6 +177,15 @@ def test_global_statistics(pub):
|
|||
resp = resp.forms[0].submit()
|
||||
assert 'Total count: 20' in resp.text
|
||||
|
||||
if not pub.site_options.has_section('options'):
|
||||
pub.site_options.add_section('options')
|
||||
|
||||
pub.site_options.set('options', 'disable-internal-statistics', 'true')
|
||||
with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
|
||||
pub.site_options.write(fd)
|
||||
resp = app.get('/backoffice/management/forms')
|
||||
assert 'Global statistics' not in resp
|
||||
|
||||
|
||||
def test_backoffice_statistics(pub):
|
||||
create_superuser(pub)
|
||||
|
|
|
@ -251,11 +251,12 @@ class ManagementDirectory(Directory):
|
|||
def get_sidebar(self, formdefs):
|
||||
r = TemplateIO(html=True)
|
||||
r += self.get_lookup_sidebox()
|
||||
r += htmltext('<div class="bo-block">')
|
||||
r += htmltext('<ul id="sidebar-actions">')
|
||||
r += htmltext('<li class="stats"><a href="statistics">%s</a></li>') % _('Global statistics')
|
||||
r += htmltext('</ul>')
|
||||
r += htmltext('</div>')
|
||||
if not get_publisher().has_site_option('disable-internal-statistics'):
|
||||
r += htmltext('<div class="bo-block">')
|
||||
r += htmltext('<ul id="sidebar-actions">')
|
||||
r += htmltext('<li class="stats"><a href="statistics">%s</a></li>') % _('Global statistics')
|
||||
r += htmltext('</ul>')
|
||||
r += htmltext('</div>')
|
||||
return r.getvalue()
|
||||
|
||||
def lookup(self):
|
||||
|
@ -867,9 +868,13 @@ class FormPage(FormdefDirectoryBase):
|
|||
) % (qs, self.export_data_label)
|
||||
if self.formdef.geolocations:
|
||||
r += htmltext(' <li><a data-base-href="map" href="map%s">%s</a></li>') % (qs, _('Plot on a Map'))
|
||||
if 'stats' in self._q_exports and (
|
||||
not self.formdef.category
|
||||
or self.formdef.category.has_permission('statistics', get_request().user)
|
||||
if (
|
||||
'stats' in self._q_exports
|
||||
and not get_publisher().has_site_option('disable-internal-statistics')
|
||||
and (
|
||||
not self.formdef.category
|
||||
or self.formdef.category.has_permission('statistics', get_request().user)
|
||||
)
|
||||
):
|
||||
r += htmltext(' <li class="stats"><a href="stats">%s</a></li>') % _('Statistics')
|
||||
|
||||
|
|
Loading…
Reference in New Issue