Skip to content

Commit eb64ae9

Browse files
BB2-4250: Initial commit - sorting out how to use the flag in different places
1 parent 744a8f5 commit eb64ae9

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

apps/dot_ext/views/authorization.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
from functools import wraps
55
from time import strftime
66

7+
from django.contrib.auth import get_user_model
78
from django.contrib.auth.views import redirect_to_login
89
from django.http import JsonResponse
910
from django.http.response import HttpResponse, HttpResponseBadRequest
1011
from django.template.response import TemplateResponse
12+
from django.core.exceptions import ObjectDoesNotExist
1113
from django.utils.decorators import method_decorator
1214
from django.views.decorators.csrf import csrf_exempt
1315
from django.views.decorators.debug import sensitive_post_parameters
@@ -20,7 +22,7 @@
2022
from oauth2_provider.views.introspect import (
2123
IntrospectTokenView as DotIntrospectTokenView,
2224
)
23-
from waffle import switch_is_active
25+
from waffle import switch_is_active, get_waffle_flag_model
2426
from oauth2_provider.models import get_application_model
2527
from oauthlib.oauth2 import AccessDeniedError
2628
from oauthlib.oauth2.rfc6749.errors import InvalidClientError, InvalidGrantError, InvalidRequestError
@@ -102,6 +104,19 @@ def _has_param(self, request, key):
102104
def _check_for_required_params(self, request):
103105
missing_params = []
104106
v3 = True if request.path.startswith('/v3/o/authorize') else False
107+
flag = get_waffle_flag_model().get("v3_early_adopter")
108+
req_meta = request.META
109+
url_query = parse_qs(req_meta.get('QUERY_STRING'))
110+
client_id = url_query.get('client_id', [None])
111+
try:
112+
app = get_application_model().objects.get(client_id=client_id[0])
113+
application_user = get_user_model().objects.get(id=app.user_id)
114+
if flag.id is not None and flag.is_active_for_user(application_user):
115+
print("flag is active for this user")
116+
else:
117+
print("flag is not active for this user")
118+
except ObjectDoesNotExist:
119+
print("object not found")
105120

106121
if switch_is_active('require_pkce'):
107122
if not request.GET.get('code_challenge', None):

apps/fhir/bluebutton/views/generic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def initial(self, request, resource_type, *args, **kwargs):
9696
if "HTTP_AUTHORIZATION" in req_meta:
9797
access_token = req_meta["HTTP_AUTHORIZATION"].split(" ")[1]
9898
try:
99+
# TODO-4250 is this a place we need a flag check as well?
99100
at = AccessToken.objects.get(token=access_token)
100101
log_message = {
101102
"name": "FHIR Endpoint AT Logging",

apps/fhir/bluebutton/views/read.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def initial(self, request, *args, **kwargs):
3131
return super().initial(request, self.resource_type, *args, **kwargs)
3232

3333
def get(self, request, *args, **kwargs):
34+
# 4250-TODO: Do we check for the flag here as well? Implement the same thing in search? In case of refresh token?
3435
return super().get(request, self.resource_type, *args, **kwargs)
3536

3637
def build_parameters(self, *args, **kwargs):

0 commit comments

Comments
 (0)