Skip to content
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

BB2-3399: Add internal_application_labels to loggers #1306

Merged
merged 5 commits into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/logging/loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions apps/logging/tests/audit_logger_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
5 changes: 5 additions & 0 deletions apps/logging/tests/test_loggers_management_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
}
}
)
Expand All @@ -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"]
}
}
)
Expand Down Expand Up @@ -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"]
}
}
)
Expand Down Expand Up @@ -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"]
}
}
)
Expand Down
27 changes: 26 additions & 1 deletion apps/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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

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