From dc577364cf08f3a018a7bb0b78152b61dd5f9964 Mon Sep 17 00:00:00 2001 From: Michal Kolodziejski Date: Tue, 17 Oct 2017 15:36:30 +0200 Subject: [PATCH] Piwik: Hide event integration if site_id missing --- piwik/indico_piwik/controllers.py | 15 ++++++++++++--- piwik/indico_piwik/plugin.py | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/piwik/indico_piwik/controllers.py b/piwik/indico_piwik/controllers.py index 54edd83..cdc82e1 100644 --- a/piwik/indico_piwik/controllers.py +++ b/piwik/indico_piwik/controllers.py @@ -15,6 +15,7 @@ # along with Indico; if not, see . from flask import jsonify, request +from werkzeug.exceptions import NotFound from indico.modules.events.management.controllers import RHManageEventBase @@ -23,7 +24,15 @@ from indico_piwik.reports import (ReportCountries, ReportDevices, ReportDownload from indico_piwik.views import WPStatistics -class RHStatistics(RHManageEventBase): +class RHPiwikBase(RHManageEventBase): + def _process_args(self): + from indico_piwik.plugin import PiwikPlugin + RHManageEventBase._process_args(self) + if not PiwikPlugin.settings.get('site_id_events'): + raise NotFound + + +class RHStatistics(RHPiwikBase): def _process(self): report = ReportGeneral.get(event_id=self.event.id, contrib_id=request.args.get('contrib_id'), @@ -32,11 +41,11 @@ class RHStatistics(RHManageEventBase): return WPStatistics.render_template('statistics.html', self.event, report=report) -class RHApiBase(RHManageEventBase): +class RHApiBase(RHPiwikBase): ALLOW_LOCKED = True def _process_args(self): - RHManageEventBase._process_args(self) + RHPiwikBase._process_args(self) self._report_params = {'start_date': request.args.get('start_date'), 'end_date': request.args.get('end_date')} diff --git a/piwik/indico_piwik/plugin.py b/piwik/indico_piwik/plugin.py index 8d7c86e..485f2d4 100644 --- a/piwik/indico_piwik/plugin.py +++ b/piwik/indico_piwik/plugin.py @@ -74,7 +74,7 @@ class PiwikPlugin(IndicoPlugin): **event_tracking_params) def add_sidemenu_item(self, sender, event, **kwargs): - if not event.can_manage(session.user): + if not event.can_manage(session.user) or not PiwikPlugin.settings.get('site_id_events'): return return SideMenuItem(u'statistics', _(u"Statistics"), url_for_plugin(u'piwik.view', event), section=u'reports')