[MediaWiki-commits] [Gerrit] Allow reports to be rerun - change (analytics/wikimetrics)
Nuria has submitted this change and it was merged. Change subject: Allow reports to be rerun .. Allow reports to be rerun A few changes had to be made to make it possible to rerun reports. This patch does not add the ability to schedule recurring reports, it just makes it possible to create a RunReport object using only the data stored by the PersistentReport instance created during the initial run. The RunReport object can then be run on the Celery queue and it yields results based on the latest data. The report results are automatically available in the UI, but future commits that implement the recurring logic may choose to change the display to call out that this is a scheduled report result. Change-Id: I163d73bc0bd54276a4d12d915a63382bc592f848 Card: analytics 1378 --- M wikimetrics/controllers/forms/secure_form.py M wikimetrics/models/report_nodes/report.py M wikimetrics/models/report_nodes/run_report.py M wikimetrics/models/report_nodes/validate_report.py M wikimetrics/static/js/reportCreate.js 5 files changed, 57 insertions(+), 16 deletions(-) Approvals: Nuria: Looks good to me, approved diff --git a/wikimetrics/controllers/forms/secure_form.py b/wikimetrics/controllers/forms/secure_form.py index 7e06d19..b3aa219 100644 --- a/wikimetrics/controllers/forms/secure_form.py +++ b/wikimetrics/controllers/forms/secure_form.py @@ -19,6 +19,9 @@ This __init__ handles the problem with calling SessionSecureForm.__init__() outside of a flask request context. """ +# do not validate csrf if we are running tests +self.no_csrf = 'TESTING' in app.config and app.config['TESTING'] is True + csrf_context = {} # only access the session if we're in a request context if current_app: @@ -27,8 +30,11 @@ SessionSecureForm.__init__(self, csrf_context=csrf_context, *args, **kwargs) def validate_csrf_token(self, field): -# only validate if we are in a real request context -if app.config['TESTING']: -return True - -return SessionSecureForm.validate_csrf_token(self, field) +return self.no_csrf or SessionSecureForm.validate_csrf_token(self, field) + +def disable_csrf(self): +""" +Makes calls to validate_csrf_token always return True. Useful for scheduled +report runs when the metric is not configured on a form. +""" +self.no_csrf = True diff --git a/wikimetrics/models/report_nodes/report.py b/wikimetrics/models/report_nodes/report.py index eb55daa..c122ae8 100644 --- a/wikimetrics/models/report_nodes/report.py +++ b/wikimetrics/models/report_nodes/report.py @@ -61,7 +61,9 @@ queue_result_key=None, children=None, public=False, - parameters='{}'): + parameters='{}', + recurrent=False, + recurrent_parent_id=None): if children is None: children = [] diff --git a/wikimetrics/models/report_nodes/run_report.py b/wikimetrics/models/report_nodes/run_report.py index f38759b..868ab25 100644 --- a/wikimetrics/models/report_nodes/run_report.py +++ b/wikimetrics/models/report_nodes/run_report.py @@ -6,7 +6,7 @@ from wikimetrics.models.user import User from wikimetrics.models.cohort_user import CohortUser from wikimetrics.metrics import metric_classes -from wikimetrics.utils import deduplicate +from wikimetrics.utils import deduplicate, stringify from report import ReportNode from aggregate_report import AggregateReport from validate_report import ValidateReport @@ -24,18 +24,44 @@ show_in_ui = False -def __init__(self, desired_responses, user_id=0, *args, **kwargs): +def __init__(self, + desired_responses, + user_id=0, + recurrent=False, + recurrent_parent_id=None): """ +Parameters: +desired_responses : list of dictionaries of the form: +cohort: the cohort to run a metric on +metric: the metric to run +aggregation: the aggregation options to use +user_id : the user wishing to run this report +recurrent : whether this report should recur daily +recurrent_parent_id : the parent PersistentReport.id for a recurrent run +""" +super(RunReport, self).__init__( +user_id=user_id, +parameters=stringify({'responses': desired_responses}), +recurrent=recurrent, +recurrent_parent_id=recurrent_parent_id, +) +self.parse_request(desired_responses, recurrent_parent_id is None) + +def parse_request(self, desired_responses, validate_csrf): +""" +Takes an array of configured metric+cohort pairs from the u
[MediaWiki-commits] [Gerrit] Allow reports to be rerun - change (analytics/wikimetrics)
Milimetric has uploaded a new change for review. https://gerrit.wikimedia.org/r/111914 Change subject: Allow reports to be rerun .. Allow reports to be rerun A few changes had to be made to make it possible to rerun reports. This patch does not add the ability to schedule recurring reports, it just makes it possible to create a RunReport object using only the data stored by the PersistentReport instance created during the initial run. The RunReport object can then be run on the Celery queue and it yields results based on the latest data. The report results are automatically available in the UI, but future commits that implement the recurring logic may choose to change the display to call out that this is a scheduled report result. Change-Id: I163d73bc0bd54276a4d12d915a63382bc592f848 Card: analytics 1378 --- M wikimetrics/controllers/forms/secure_form.py M wikimetrics/models/report_nodes/report.py M wikimetrics/models/report_nodes/run_report.py M wikimetrics/models/report_nodes/validate_report.py M wikimetrics/static/js/reportCreate.js 5 files changed, 50 insertions(+), 16 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/analytics/wikimetrics refs/changes/14/111914/1 diff --git a/wikimetrics/controllers/forms/secure_form.py b/wikimetrics/controllers/forms/secure_form.py index 7e06d19..b3aa219 100644 --- a/wikimetrics/controllers/forms/secure_form.py +++ b/wikimetrics/controllers/forms/secure_form.py @@ -19,6 +19,9 @@ This __init__ handles the problem with calling SessionSecureForm.__init__() outside of a flask request context. """ +# do not validate csrf if we are running tests +self.no_csrf = 'TESTING' in app.config and app.config['TESTING'] is True + csrf_context = {} # only access the session if we're in a request context if current_app: @@ -27,8 +30,11 @@ SessionSecureForm.__init__(self, csrf_context=csrf_context, *args, **kwargs) def validate_csrf_token(self, field): -# only validate if we are in a real request context -if app.config['TESTING']: -return True - -return SessionSecureForm.validate_csrf_token(self, field) +return self.no_csrf or SessionSecureForm.validate_csrf_token(self, field) + +def disable_csrf(self): +""" +Makes calls to validate_csrf_token always return True. Useful for scheduled +report runs when the metric is not configured on a form. +""" +self.no_csrf = True diff --git a/wikimetrics/models/report_nodes/report.py b/wikimetrics/models/report_nodes/report.py index 67235d4..9ab8d2c 100644 --- a/wikimetrics/models/report_nodes/report.py +++ b/wikimetrics/models/report_nodes/report.py @@ -60,7 +60,8 @@ name=None, queue_result_key=None, children=None, - parameters='{}'): + parameters='{}', + recurrent_run=False): if children is None: children = [] diff --git a/wikimetrics/models/report_nodes/run_report.py b/wikimetrics/models/report_nodes/run_report.py index f38759b..843bfbf 100644 --- a/wikimetrics/models/report_nodes/run_report.py +++ b/wikimetrics/models/report_nodes/run_report.py @@ -6,7 +6,7 @@ from wikimetrics.models.user import User from wikimetrics.models.cohort_user import CohortUser from wikimetrics.metrics import metric_classes -from wikimetrics.utils import deduplicate +from wikimetrics.utils import deduplicate, stringify from report import ReportNode from aggregate_report import AggregateReport from validate_report import ValidateReport @@ -24,18 +24,38 @@ show_in_ui = False -def __init__(self, desired_responses, user_id=0, *args, **kwargs): +def __init__(self, desired_responses, user_id=0, recurrent_run=False): """ Parameters: -desired_responses : list of dictionaries of the form: +desired_responses : list of dictionaries of the form: cohort: the cohort to run a metric on metric: the metric to run aggregation: the aggregation options to use +user_id : the user wishing to run this report +recurrent_run : whether this run is a scheduled recurrent report """ -super(RunReport, self).__init__(user_id=user_id, *args, **kwargs) -self.parse_request(desired_responses) +super(RunReport, self).__init__( +user_id=user_id, +parameters=stringify({'responses': desired_responses}), +recurrent_run=recurrent_run, +) +self.parse_request(desired_responses, recurrent_run) -def parse_request(self, desired_responses): +def parse_request(self, desired_responses, recurrent_run=False): +""" +Takes