From 6314e065a1674cf24dbae6f320bdba878518c244 Mon Sep 17 00:00:00 2001 From: Christian Hess Date: Tue, 20 Feb 2024 15:51:59 -0300 Subject: [PATCH] fix: make is_active_for_user consider when everyone is False fixes #401 --- waffle/models.py | 3 +++ waffle/tests/test_models.py | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/waffle/models.py b/waffle/models.py index ffa58e7d..8c3c5ba3 100644 --- a/waffle/models.py +++ b/waffle/models.py @@ -233,6 +233,9 @@ def is_active_for_user(self, user: AbstractBaseUser) -> bool | None: if self.everyone: return True + if self.everyone is False: + return False + if self.authenticated and user.is_authenticated: return True diff --git a/waffle/tests/test_models.py b/waffle/tests/test_models.py index 7ec9b4a7..1afc97f2 100644 --- a/waffle/tests/test_models.py +++ b/waffle/tests/test_models.py @@ -35,4 +35,9 @@ def test_flag_is_not_active_for_none_requests(self): 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) \ No newline at end of file + self.assertEqual(flag.is_active_for_user(User()), True) + + def test_is_active_for_user_when_everyone_is_disabled(self): + flag = get_waffle_flag_model().objects.create(name='test-flag') + flag.everyone = False + self.assertEqual(flag.is_active_for_user(User()), False)