Skip to content

Commit

Permalink
add support for everyone option to is_active_for_user (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdoconnor authored Nov 24, 2023
1 parent be05c2c commit 21d7fad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions waffle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ def get_flush_keys(self, flush_keys: list[str] | None = None) -> list[str]:
return flush_keys

def is_active_for_user(self, user: AbstractBaseUser) -> bool | None:
if self.everyone:
return True

if self.authenticated and user.is_authenticated:
return True

Expand Down
6 changes: 6 additions & 0 deletions waffle/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
get_waffle_sample_model,
get_waffle_switch_model,
)
from django.contrib.auth.models import User


class ModelsTests(TestCase):
Expand All @@ -30,3 +31,8 @@ def test_natural_keys(self):
def test_flag_is_not_active_for_none_requests(self):
flag = get_waffle_flag_model().objects.create(name='test-flag')
self.assertEqual(flag.is_active(None), False)

def test_is_active_for_user_when_everyone_is_active(self):
flag = get_waffle_flag_model().objects.create(name='test-flag')
flag.everyone = True
self.assertEqual(flag.is_active_for_user(User()), True)

0 comments on commit 21d7fad

Please sign in to comment.