-
Notifications
You must be signed in to change notification settings - Fork 0
Prevent processing of datasets belonging to unapproved reporting organisations #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ade2c6d
b7895a1
9e3353d
814ee7a
5b0ed1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ def __init__(self, environment: dict, logger: logging.Logger, service_factory: I | |
| self._RUN_FOR_N_DATASETS = ( | ||
| int(self["run_for_n_datasets"]) if self.get("run_for_n_datasets") is not None else None | ||
| ) | ||
| self._RUN_FOR_SINGLE_REPORTING_ORG = self.get("run_for_single_reporting_org", None) | ||
| self._SEND_DATASET_CHECK_MESSAGES = self["SEND_DATASET_CHECK_RESULT_MESSAGES"] == "yes" | ||
| self._SKIP_SAFETY = self.get("skip_safety", False) | ||
|
|
||
|
|
@@ -51,6 +52,10 @@ def REDOWNLOAD_FROM_NON_HEAD_SERVERS_AFTER_HOURS(self) -> int: | |
| def RUN_FOR_N_DATASETS(self) -> int | None: | ||
| return self._RUN_FOR_N_DATASETS | ||
|
|
||
| @property | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not make it a bool? Similar remark on line 23?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes should be a string - it contains the short name of the reporting org. |
||
| def RUN_FOR_SINGLE_REPORTING_ORG(self) -> str | None: | ||
| return self._RUN_FOR_SINGLE_REPORTING_ORG | ||
|
|
||
| @property | ||
| def SEND_DATASET_CHECK_MESSAGES(self) -> bool: | ||
| return self._SEND_DATASET_CHECK_MESSAGES | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,8 @@ def fetch_datasets_metadata( | |
|
|
||
| crm.fetch_access_token() | ||
|
|
||
| context.logger.info("Fetching all dataset metadata using the libsuitecrm library...") | ||
|
|
||
| filters = Filter().equal("iati_visibility", "public") | ||
|
|
||
| suitecrm_dataset_records = [r for r in crm.get_all_records("IATI_Datasets", filters=filters)] | ||
|
|
@@ -51,6 +53,8 @@ def fetch_datasets_metadata( | |
| continue | ||
|
|
||
| owning_org = reporting_orgs.get(uuid.UUID(record["attributes"]["iati_dataset_owner_org_id"]), None) | ||
| if context.RUN_FOR_SINGLE_REPORTING_ORG is not None and owning_org is None: | ||
| continue | ||
| if owning_org is None: | ||
| context.logger.error( | ||
| f"SuiteCRM dataset id: {record['id']} has reporting org id: " | ||
|
|
@@ -63,6 +67,8 @@ def fetch_datasets_metadata( | |
| record, owning_org, refresh_timestamp | ||
| ) | ||
|
|
||
| context.logger.info("Fetched metadata for {} datasets".format(len(results))) | ||
|
|
||
| return results | ||
|
|
||
|
|
||
|
|
@@ -72,11 +78,22 @@ def fetch_reporting_orgs_metadata(context: BDSContext, refresh_timestamp: dateti | |
|
|
||
| crm.fetch_access_token() | ||
|
|
||
| context.logger.info("Fetching all reporting orgs using the libsuitecrm library...") | ||
| context.logger.info("Fetching all reporting org metadata using the libsuitecrm library...") | ||
|
|
||
| filters = Filter().equal("iati_registry_discoverable", "1") | ||
| filters = Filter().equal("iati_registry_discoverable", "1").equal("iati_registry_approved", 1) | ||
| suitecrm_reporting_org_records = [r for r in crm.get_all_records("Accounts", filters=filters)] | ||
|
|
||
| if context.RUN_FOR_SINGLE_REPORTING_ORG is not None: | ||
| suitecrm_reporting_org_records = [ | ||
| o | ||
| for o in suitecrm_reporting_org_records | ||
| if o.get("attributes", {}).get("iati_short_name", "") == context.RUN_FOR_SINGLE_REPORTING_ORG | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type hint is for this to be an integer - should it be a string? It's a string in the command line arguments.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, thanks! |
||
| ] | ||
| context.logger.info( | ||
| "--run-for-single-reporting-org is set so only " | ||
| f"processing reporting org '{context.RUN_FOR_SINGLE_REPORTING_ORG}'." | ||
| ) | ||
|
|
||
| crm.logout() | ||
|
|
||
| results = {} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| import json | ||
| from datetime import datetime | ||
| from uuid import UUID | ||
|
|
||
| import pytest | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a change for the command line argument addition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done