diff --git a/apps/logging/loggers.py b/apps/logging/loggers.py index 15446198f..1e71e7f84 100644 --- a/apps/logging/loggers.py +++ b/apps/logging/loggers.py @@ -350,6 +350,7 @@ def log_global_state_metrics(group_timestamp=None, report_flag=True): "first_active": format_timestamp(app.first_active), "last_active": format_timestamp(app.last_active), "data_access_type": app.data_access_type, + "internal_application_labels": ", ".join(sorted([label.slug for label in app.internal_application_labels.all()])), "require_demographic_scopes": app.require_demographic_scopes, "real_bene_cnt": grant_counts.get( "real", None diff --git a/apps/logging/tests/audit_logger_schemas.py b/apps/logging/tests/audit_logger_schemas.py index 4fffffecc..8d607b4f5 100755 --- a/apps/logging/tests/audit_logger_schemas.py +++ b/apps/logging/tests/audit_logger_schemas.py @@ -803,6 +803,7 @@ def get_pre_fetch_fhir_log_entry_schema(version): "first_active": {"type": "null"}, "last_active": {"type": "null"}, "data_access_type": {"type": "string"}, + "internal_application_labels": {"type": "string"}, "require_demographic_scopes": {"type": "boolean"}, "real_bene_cnt": {"type": "integer"}, "synth_bene_cnt": {"type": "integer"}, diff --git a/apps/logging/tests/test_loggers_management_command.py b/apps/logging/tests/test_loggers_management_command.py index 4d95ee70b..e3d17443b 100644 --- a/apps/logging/tests/test_loggers_management_command.py +++ b/apps/logging/tests/test_loggers_management_command.py @@ -269,6 +269,7 @@ def _validate_global_state_per_app_metrics_log(self, validate_apps_dict): "token_archived_table_count", "user_limit_data_access", "data_access_type", + "internal_application_labels" ] # Update Json Schema @@ -523,6 +524,7 @@ def test_management_command_logging(self): "token_archived_table_count": 0, "user_limit_data_access": [True], "data_access_type": ["THIRTEEN_MONTH"], + "internal_application_labels": ["research-app-multiple-studies", "data-sharing"] } } ) @@ -547,6 +549,7 @@ def test_management_command_logging(self): "token_archived_table_count": 0, "user_limit_data_access": [True], "data_access_type": ["THIRTEEN_MONTH"], + "internal_application_labels": ["research-app-multiple-studies", "data-sharing"] } } ) @@ -625,6 +628,7 @@ def test_management_command_logging(self): "token_archived_table_count": 0, "user_limit_data_access": [True], "data_access_type": ["THIRTEEN_MONTH"], + "internal_application_labels": ["research-app-multiple-studies", "data-sharing"] } } ) @@ -868,6 +872,7 @@ def test_management_command_logging(self): "token_archived_table_count": 0, "user_limit_data_access": [True], "data_access_type": ["THIRTEEN_MONTH"], + "internal_application_labels": ["research-app-multiple-studies", "data-sharing"] } } ) diff --git a/apps/test.py b/apps/test.py index 304ee4dc6..302f69f39 100644 --- a/apps/test.py +++ b/apps/test.py @@ -14,7 +14,7 @@ from apps.accounts.models import UserProfile from apps.authorization.models import DataAccessGrant from apps.capabilities.models import ProtectedCapability -from apps.dot_ext.models import Application +from apps.dot_ext.models import Application, InternalApplicationLabels from apps.dot_ext.utils import ( remove_application_user_pair_tokens_data_access, ) @@ -109,6 +109,13 @@ def _create_application( **kwargs ) + label = self._create_internal_application_labels( + label="Research app - multiple studies", + slug="research-app-multiple-studies", + description="Desc: place holder") + + application.internal_application_labels.add(label) + if data_access_type: application.data_access_type = data_access_type @@ -142,6 +149,24 @@ def _create_capability(self, name, urls, group=None, default=True): ) return capability + def _create_internal_application_labels(self, label, slug, description): + """ + Helper method that creates a InternalApplicationLabels instance + """ + # Create capability, if does not already exist + try: + label = InternalApplicationLabels.objects.get(slug=slug) + return label + except InternalApplicationLabels.DoesNotExist: + pass + + label = InternalApplicationLabels.objects.create( + label=label, + slug=slug, + description=description, + ) + return label + def _get_access_token(self, username, password, application=None, **extra_fields): """ Helper method that creates an access_token using the password grant.