Skip to content

Commit

Permalink
[QOLDEV-1070] ensure the admin metrics helper passed authentication i…
Browse files Browse the repository at this point in the history
…nformation through
  • Loading branch information
ThrawnCA committed Feb 19, 2025
1 parent f559ccd commit c2fb036
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ckanext/data_qld/reporting/helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,22 @@ 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,
'permission': 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),
}


Expand Down
4 changes: 4 additions & 0 deletions ckanext/data_qld/tests/test_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c2fb036

Please sign in to comment.