diff --git a/ckanext/data_qld/reporting/helpers/helpers.py b/ckanext/data_qld/reporting/helpers/helpers.py index 73cdc49c..0ab9b666 100644 --- a/ckanext/data_qld/reporting/helpers/helpers.py +++ b/ckanext/data_qld/reporting/helpers/helpers.py @@ -265,6 +265,9 @@ def gather_engagement_metrics(org_id, start_date, end_date, comment_no_reply_max def gather_admin_metrics(org_id, permission): """Collect admin statistics metrics for the provided organisation""" + # get the current authentication info for our API calls + context = {'auth_user_obj': tk.current_user, 'user': tk.current_user.name} + data_dict = { 'org_id': org_id, 'return_count_only': True, @@ -272,12 +275,12 @@ def gather_admin_metrics(org_id, permission): } return { - 'de_identified_datasets': tk.get_action('de_identified_datasets')({}, data_dict), - 'de_identified_datasets_no_schema': tk.get_action('de_identified_datasets_no_schema')({}, data_dict), - 'overdue_datasets': tk.get_action('overdue_datasets')({}, data_dict), - 'datasets_no_groups': tk.get_action('datasets_no_groups')({}, data_dict), - 'datasets_no_tags': tk.get_action('datasets_no_tags')({}, data_dict), - 'pending_privacy_assessment': tk.get_action('datasets_pending_privacy_assessment')({}, data_dict), + 'de_identified_datasets': tk.get_action('de_identified_datasets')(context, data_dict), + 'de_identified_datasets_no_schema': tk.get_action('de_identified_datasets_no_schema')(context, data_dict), + 'overdue_datasets': tk.get_action('overdue_datasets')(context, data_dict), + 'datasets_no_groups': tk.get_action('datasets_no_groups')(context, data_dict), + 'datasets_no_tags': tk.get_action('datasets_no_tags')(context, data_dict), + 'pending_privacy_assessment': tk.get_action('datasets_pending_privacy_assessment')(context, data_dict), } diff --git a/ckanext/data_qld/tests/test_reporting.py b/ckanext/data_qld/tests/test_reporting.py index 631af57e..012e3676 100644 --- a/ckanext/data_qld/tests/test_reporting.py +++ b/ckanext/data_qld/tests/test_reporting.py @@ -105,6 +105,7 @@ def test_as_regular_user_is_unauthorised(self, app): app.get('/', extra_environ={"REMOTE_USER": str(user["name"])}) org_id = factories.Organization()["id"] + tk.current_user = model.User.get(user['id']) with pytest.raises(tk.NotAuthorized): helpers.gather_admin_metrics(org_id, "admin") @@ -123,6 +124,7 @@ def test_as_sysadmin(self, app, dataset_factory, resource_factory): id=dataset["id"], notes="test") + tk.current_user = model.User.get(sysadmin['id']) result = helpers.gather_admin_metrics(org_id, "admin") assert result["datasets_no_groups"] == 3 @@ -147,6 +149,7 @@ def test_set_de_identified_count_from_in_future(self, app, dataset_factory, de_identified_data="YES") resource_factory(package_id=dataset["id"]) + tk.current_user = model.User.get(sysadmin['id']) result = helpers.gather_admin_metrics(org_id, "admin") assert result["de_identified_datasets_no_schema"] == 0 @@ -179,6 +182,7 @@ def test_de_identified_parametrize(self, app, dataset_factory, value=count_from, key="data_last_updated") model.Session.commit() + tk.current_user = model.User.get(sysadmin['id']) result = helpers.gather_admin_metrics(org_id, "admin") assert result[u"de_identified_datasets_no_schema"] == pkg_counter