Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for everyone option to is_active_for_user #491

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading