Skip to content

Commit 4481822

Browse files
authored
Introduce waffle switch for coverage-only, coverage-only logic (#1365)
* Introduce waffle switch for coverage-only, coverage-only logic * Use slug instead of label for internal logic * Retrigger CI checks
1 parent 2066cb4 commit 4481822

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

apps/capabilities/permissions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import re
33

4+
from apps.dot_ext.scopes import CapabilitiesScopes
45
from rest_framework import permissions, status
56
from rest_framework.exceptions import APIException, ParseError
67
from waffle import switch_is_active
@@ -33,6 +34,11 @@ def has_permission(self, request, view):
3334

3435
if hasattr(token, "scope"): # OAuth 2
3536
token_scopes = token.scope.split()
37+
38+
if switch_is_active("enable_coverage_only"):
39+
if "coverage-eligibility" in request.auth.application.get_internal_application_labels():
40+
token_scopes = CapabilitiesScopes().remove_eob_scopes(token_scopes)
41+
3642
scopes = list(ProtectedCapability.objects.filter(
3743
slug__in=token_scopes
3844
).values_list('protected_resources', flat=True).all())

apps/core/management/commands/create_test_feature_switches.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
("bfd_v3_connectathon", True, "This enables the bfd v3 features for connectathon demo"),
2121
("require_state", True, "This enforces the presence of the state parameter when authorizing"),
2222
("require_pkce", True, "This enforces the presence of the PKCE parameters code_challenge and code_challenge_method when authorizing"),
23+
("enable_coverage_only", True, "This enables the coverage-only use case."),
2324
)
2425

2526
WAFFLE_FEATURE_FLAGS = (

apps/dot_ext/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def scopes(self):
212212
return " ".join(scope_list).strip()
213213

214214
def get_internal_application_labels(self):
215-
return "\n".join([lb.label for lb in self.internal_application_labels.all()])
215+
return "\n".join([lb.slug for lb in self.internal_application_labels.all()])
216216

217217
def is_valid(self, scopes=None):
218218
return self.active and self.allow_scopes(scopes)

apps/dot_ext/scopes.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.db.models import Q
33
from oauth2_provider.scopes import BaseScopes
44
from apps.capabilities.models import ProtectedCapability
5+
from waffle import switch_is_active
56

67

78
class CapabilitiesScopes(BaseScopes):
@@ -29,6 +30,10 @@ def get_available_scopes(self, application=None, request=None, *args, **kwargs):
2930
ProtectedCapability.objects.filter(Q(default=True) | Q(application=application))
3031
.values_list('slug', flat=True).distinct())
3132

33+
if switch_is_active("enable_coverage_only"):
34+
if "coverage-eligibility" in application.get_internal_application_labels():
35+
app_scopes_avail = self.remove_eob_scopes(app_scopes_avail)
36+
3237
# Set scopes based on application choice. Default behavior is True, if it hasn't been set yet.
3338
if application.require_demographic_scopes in [True, None]:
3439
# Return all scopes
@@ -49,6 +54,10 @@ def get_default_scopes(self, application=None, request=None, *args, **kwargs):
4954
app_scopes_default = list(ProtectedCapability.objects.filter(default=True)
5055
.values_list('slug', flat=True))
5156

57+
if switch_is_active("enable_coverage_only"):
58+
if "coverage-eligibility" in application.get_internal_application_labels():
59+
app_scopes_default = self.remove_eob_scopes(app_scopes_default)
60+
5261
# Set scopes based on application choice. Default behavior is True, if it hasn't been set yet.
5362
if application.require_demographic_scopes in [True, None]:
5463
# Return all scopes
@@ -89,3 +98,14 @@ def remove_demographic_scopes(self, scopes):
8998
if s not in settings.BENE_PERSONAL_INFO_SCOPES:
9099
out_scopes.append(s)
91100
return out_scopes
101+
102+
def remove_eob_scopes(self, scopes):
103+
"""
104+
Returns a list based on the provided list of scopes with eob scopes removed
105+
"""
106+
out_scopes = set(scopes)
107+
out_scopes.discard("patient/ExplanationOfBenefit.r")
108+
out_scopes.discard("patient/ExplanationOfBenefit.s")
109+
out_scopes.discard("patient/ExplanationOfBenefit.rs")
110+
out_scopes.discard("patient/ExplanationOfBenefit.read")
111+
return out_scopes

apps/dot_ext/tests/test_models.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,10 @@ def test_internal_application_labels_getter(self):
252252
l11 = internal_labels[10]
253253
test_app.internal_application_labels.add(l1, l3, l5)
254254
labels = test_app.get_internal_application_labels()
255-
self.assertTrue(l1.label in labels)
256-
self.assertTrue(l3.label in labels)
257-
self.assertTrue(l5.label in labels)
258-
self.assertTrue(not (l11.label in labels))
255+
self.assertTrue(l1.slug in labels)
256+
self.assertTrue(l3.slug in labels)
257+
self.assertTrue(l5.slug in labels)
258+
self.assertTrue(not (l11.slug in labels))
259259

260260
def test_internal_application_labels_admin(self):
261261
"""
@@ -290,7 +290,7 @@ def test_internal_application_labels_admin(self):
290290
self.assertIn('internal_application_labels', str(field_sets))
291291

292292
internal_labels = app_admin.get_internal_application_labels(test_app)
293-
self.assertTrue(l1.label in internal_labels)
294-
self.assertTrue(l3.label in internal_labels)
295-
self.assertTrue(l5.label in internal_labels)
296-
self.assertTrue(l11.label not in internal_labels)
293+
self.assertTrue(l1.slug in internal_labels)
294+
self.assertTrue(l3.slug in internal_labels)
295+
self.assertTrue(l5.slug in internal_labels)
296+
self.assertTrue(l11.slug not in internal_labels)

0 commit comments

Comments
 (0)