Skip to content

Commit 8ff3fd2

Browse files
Jimmyfagan/bb2-3549-Remove feature flag calls from web-server (#1278)
* Initial pass at removing logic for waffle switch limit_data_access * fix a pre-exist typo in command help. * fix linting --------- Co-authored-by: jimmyfagan <jimmyfagan@navapbc.com>
1 parent e5d8003 commit 8ff3fd2

File tree

11 files changed

+40
-404
lines changed

11 files changed

+40
-404
lines changed

apps/authorization/models.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from django.utils import timezone
99
from oauth2_provider.settings import oauth2_settings
1010
from oauth2_provider.models import get_access_token_model
11-
from waffle import get_waffle_flag_model
1211

1312

1413
class DataAccessGrant(models.Model):
@@ -41,22 +40,17 @@ def user(self):
4140

4241
def update_expiration_date(self):
4342
# For THIRTEEN_MONTH type update expiration_date
44-
if self.application:
45-
flag = get_waffle_flag_model().get("limit_data_access")
46-
if flag.rollout or (flag.id is not None and flag.is_active_for_user(self.application.user)):
47-
if self.application.data_access_type == "THIRTEEN_MONTH":
48-
self.expiration_date = datetime.now().replace(
49-
tzinfo=pytz.UTC
50-
) + relativedelta(months=+13)
51-
self.save()
43+
if self.application and self.application.data_access_type == "THIRTEEN_MONTH":
44+
self.expiration_date = datetime.now().replace(
45+
tzinfo=pytz.UTC
46+
) + relativedelta(months=+13)
47+
self.save()
5248

5349
def has_expired(self):
54-
flag = get_waffle_flag_model().get("limit_data_access")
55-
if flag.rollout or (flag.id is not None and flag.is_active_for_user(self.application.user)):
56-
if self.application.data_access_type == "THIRTEEN_MONTH":
57-
if self.expiration_date:
58-
if self.expiration_date < datetime.now().replace(tzinfo=pytz.UTC):
59-
return True
50+
if self.application.data_access_type == "THIRTEEN_MONTH":
51+
if self.expiration_date:
52+
if self.expiration_date < datetime.now().replace(tzinfo=pytz.UTC):
53+
return True
6054

6155
return False
6256

apps/authorization/tests/test_data_access_grant.py

Lines changed: 2 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818
get_access_token_model,
1919
)
2020

21-
from apps.test import BaseApiTest, flag_is_active
21+
from apps.test import BaseApiTest
2222
from apps.authorization.models import (
2323
DataAccessGrant,
2424
ArchivedDataAccessGrant,
2525
check_grants,
2626
update_grants,
2727
)
28-
from waffle import get_waffle_flag_model
29-
from waffle.testutils import override_flag, override_switch
28+
from waffle.testutils import override_switch
3029

3130
Application = get_application_model()
3231
AccessToken = get_access_token_model()
@@ -95,66 +94,14 @@ def test_create_update_delete(self):
9594
# Verify expiration_date copied OK.
9695
self.assertEqual("2030-01-15 00:00:00+00:00", str(arch_dag.expiration_date))
9796

98-
@override_flag("limit_data_access", active=False)
99-
def test_thirteen_month_app_type_without_switch_limit_data_access(self):
100-
assert not flag_is_active("limit_data_access")
101-
102-
# 1. Create bene and app for tests
103-
dev_user = self._create_user("developer_test", "123456")
104-
bene_user = self._create_user("test_beneficiary", "123456")
105-
test_app = self._create_application(
106-
"test_app", user=dev_user, data_access_type="THIRTEEN_MONTH"
107-
)
108-
109-
flag = get_waffle_flag_model().get("limit_data_access")
110-
assert flag.id is None or flag.is_active_for_user(dev_user) is False
111-
112-
# 2. Create grant with expiration date in future.
113-
dag = DataAccessGrant.objects.create(
114-
application=test_app, beneficiary=bene_user
115-
)
116-
117-
# 3. Test expiration_date not set
118-
self.assertEqual(dag.expiration_date, None)
119-
# Test has_expired() with None is false
120-
self.assertEqual(dag.has_expired(), False)
121-
122-
# 4. Test has_expired() true for -1 hour ago is false w/o switch enabled
123-
dag.expiration_date = datetime.now().replace(tzinfo=pytz.UTC) + relativedelta(
124-
hours=-1
125-
)
126-
self.assertEqual(dag.has_expired(), False)
127-
128-
# 5. Test has_expired() false for +1 hour in future.
129-
dag.expiration_date = datetime.now().replace(tzinfo=pytz.UTC) + relativedelta(
130-
hours=+1
131-
)
132-
self.assertEqual(dag.has_expired(), False)
133-
134-
# 6. Test has_expired() false for ONE_TIME type
135-
test_app.data_access_type = "ONE_TIME"
136-
test_app.save()
137-
self.assertEqual(dag.has_expired(), False)
138-
139-
# 7. Test has_expired() false for RESEARCH_STUDY type
140-
test_app.data_access_type = "RESEARCH_STUDY"
141-
test_app.save()
142-
self.assertEqual(dag.has_expired(), False)
143-
144-
@override_flag("limit_data_access", active=True)
14597
def test_thirteen_month_app_type_with_switch_limit_data_access(self):
146-
assert flag_is_active("limit_data_access")
147-
14898
# 1. Create bene and app for tests
14999
dev_user = self._create_user("developer_test", "123456")
150100
bene_user = self._create_user("test_beneficiary", "123456")
151101
test_app = self._create_application(
152102
"test_app", user=dev_user, data_access_type="THIRTEEN_MONTH"
153103
)
154104

155-
flag = get_waffle_flag_model().get("limit_data_access")
156-
assert flag.id is not None and flag.is_active_for_user(dev_user)
157-
158105
# 2. Create grant with expiration date in future.
159106
dag = DataAccessGrant.objects.create(
160107
application=test_app, beneficiary=bene_user
@@ -463,40 +410,3 @@ def test_permission_deny_on_app_or_org_disabled(self):
463410
# set back app and user to active - not to affect other tests
464411
application.active = True
465412
application.save()
466-
467-
def test_thirteen_month_app_needs_limit_data_access_set(self):
468-
469-
# 1. Create benes
470-
dev_user = self._create_user("developer_test", "123456")
471-
bene_user = self._create_user("test_beneficiary", "123456")
472-
flag_bene_user = self._create_user("flag_beneficiary", "123456")
473-
test_app = self._create_application(
474-
"test_app", user=dev_user, data_access_type="THIRTEEN_MONTH"
475-
)
476-
477-
# 2. Create flag and show is not set for dev_user
478-
flag = get_waffle_flag_model().objects.create(name="limit_data_access")
479-
assert flag.id is not None
480-
assert not flag.is_active_for_user(dev_user)
481-
482-
# 3. Create grant and expire expiration to show it doesn't matter
483-
dag = DataAccessGrant.objects.create(
484-
application=test_app, beneficiary=bene_user
485-
)
486-
# 4. Test has_expired() true for -1 hour ago
487-
dag.expiration_date = datetime.now().replace(tzinfo=pytz.UTC) + relativedelta(
488-
hours=-1
489-
)
490-
self.assertEqual(dag.has_expired(), False)
491-
492-
# 4. Add dev_user to flag
493-
flag.users.add(dev_user)
494-
495-
# 5. Create new grant and show expiration is working
496-
flag_dag = DataAccessGrant.objects.create(
497-
application=test_app, beneficiary=flag_bene_user
498-
)
499-
flag_dag.expiration_date = datetime.now().replace(
500-
tzinfo=pytz.UTC
501-
) + relativedelta(hours=-1)
502-
self.assertEqual(dag.has_expired(), True)

0 commit comments

Comments
 (0)