Skip to content

Commit 66dd322

Browse files
stiwarisemanticbitsShivam Tiwari
andauthored
BB2-3399: Add internal_application_labels to loggers (#1306)
* BB2-3399: Add internal_application_labels to loggers * test commit * test commit --------- Co-authored-by: Shivam Tiwari <shivam.tiwari@icf.com>
1 parent 496ed5f commit 66dd322

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

apps/logging/loggers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ def log_global_state_metrics(group_timestamp=None, report_flag=True):
350350
"first_active": format_timestamp(app.first_active),
351351
"last_active": format_timestamp(app.last_active),
352352
"data_access_type": app.data_access_type,
353+
"internal_application_labels": ", ".join(sorted([label.slug for label in app.internal_application_labels.all()])),
353354
"require_demographic_scopes": app.require_demographic_scopes,
354355
"real_bene_cnt": grant_counts.get(
355356
"real", None

apps/logging/tests/audit_logger_schemas.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ def get_pre_fetch_fhir_log_entry_schema(version):
803803
"first_active": {"type": "null"},
804804
"last_active": {"type": "null"},
805805
"data_access_type": {"type": "string"},
806+
"internal_application_labels": {"type": "string"},
806807
"require_demographic_scopes": {"type": "boolean"},
807808
"real_bene_cnt": {"type": "integer"},
808809
"synth_bene_cnt": {"type": "integer"},

apps/logging/tests/test_loggers_management_command.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def _validate_global_state_per_app_metrics_log(self, validate_apps_dict):
269269
"token_archived_table_count",
270270
"user_limit_data_access",
271271
"data_access_type",
272+
"internal_application_labels"
272273
]
273274

274275
# Update Json Schema
@@ -523,6 +524,7 @@ def test_management_command_logging(self):
523524
"token_archived_table_count": 0,
524525
"user_limit_data_access": [True],
525526
"data_access_type": ["THIRTEEN_MONTH"],
527+
"internal_application_labels": ["research-app-multiple-studies", "data-sharing"]
526528
}
527529
}
528530
)
@@ -547,6 +549,7 @@ def test_management_command_logging(self):
547549
"token_archived_table_count": 0,
548550
"user_limit_data_access": [True],
549551
"data_access_type": ["THIRTEEN_MONTH"],
552+
"internal_application_labels": ["research-app-multiple-studies", "data-sharing"]
550553
}
551554
}
552555
)
@@ -625,6 +628,7 @@ def test_management_command_logging(self):
625628
"token_archived_table_count": 0,
626629
"user_limit_data_access": [True],
627630
"data_access_type": ["THIRTEEN_MONTH"],
631+
"internal_application_labels": ["research-app-multiple-studies", "data-sharing"]
628632
}
629633
}
630634
)
@@ -868,6 +872,7 @@ def test_management_command_logging(self):
868872
"token_archived_table_count": 0,
869873
"user_limit_data_access": [True],
870874
"data_access_type": ["THIRTEEN_MONTH"],
875+
"internal_application_labels": ["research-app-multiple-studies", "data-sharing"]
871876
}
872877
}
873878
)

apps/test.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from apps.accounts.models import UserProfile
1515
from apps.authorization.models import DataAccessGrant
1616
from apps.capabilities.models import ProtectedCapability
17-
from apps.dot_ext.models import Application
17+
from apps.dot_ext.models import Application, InternalApplicationLabels
1818
from apps.dot_ext.utils import (
1919
remove_application_user_pair_tokens_data_access,
2020
)
@@ -109,6 +109,13 @@ def _create_application(
109109
**kwargs
110110
)
111111

112+
label = self._create_internal_application_labels(
113+
label="Research app - multiple studies",
114+
slug="research-app-multiple-studies",
115+
description="Desc: place holder")
116+
117+
application.internal_application_labels.add(label)
118+
112119
if data_access_type:
113120
application.data_access_type = data_access_type
114121

@@ -142,6 +149,24 @@ def _create_capability(self, name, urls, group=None, default=True):
142149
)
143150
return capability
144151

152+
def _create_internal_application_labels(self, label, slug, description):
153+
"""
154+
Helper method that creates a InternalApplicationLabels instance
155+
"""
156+
# Create capability, if does not already exist
157+
try:
158+
label = InternalApplicationLabels.objects.get(slug=slug)
159+
return label
160+
except InternalApplicationLabels.DoesNotExist:
161+
pass
162+
163+
label = InternalApplicationLabels.objects.create(
164+
label=label,
165+
slug=slug,
166+
description=description,
167+
)
168+
return label
169+
145170
def _get_access_token(self, username, password, application=None, **extra_fields):
146171
"""
147172
Helper method that creates an access_token using the password grant.

0 commit comments

Comments
 (0)