Skip to content

Commit

Permalink
Merge branch 'master' into ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss authored Mar 26, 2024
2 parents 344bf58 + 63444d6 commit 0f8860e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Waffle Changelog
================

v4.1.0
======
- Updated `is_active_for_user` method to account for `everyone` option
- Added `--testing` option to waffle_flag management command

v4.0.0
======
- Added support for Django 4.2 and Python 3.11
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
# built documents.
#
# The short X.Y version.
version = '4.0'
version = '4.1'
# The full version, including alpha/beta/rc tags.
release = '4.0.0'
release = '4.1.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion waffle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
if TYPE_CHECKING:
from waffle.models import AbstractBaseFlag, AbstractBaseSample, AbstractBaseSwitch

__version__ = '4.0.0'
__version__ = '4.1.0'


def flag_is_active(request: HttpRequest, flag_name: str, read_only: bool = False) -> bool | None:
Expand Down
7 changes: 7 additions & 0 deletions waffle/management/commands/waffle_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ def add_arguments(self, parser: CommandParser) -> None:
dest='rollout',
default=False,
help='Turn on rollout mode.')
parser.add_argument(
'--testing', '-t',
action='store_true',
dest='testing',
default=False,
help='Turn on testing mode, allowing the flag to be specified via '
'a querystring parameter.')
parser.add_argument(
'--create',
action='store_true',
Expand Down
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
3 changes: 2 additions & 1 deletion waffle/tests/test_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ def test_create(self):
name = 'test'
percent = 20
Group.objects.create(name='waffle_group')
call_command('waffle_flag', name, percent=percent,
call_command('waffle_flag', name, percent=percent, testing=True,
superusers=True, staff=True, authenticated=True,
rollout=True, create=True, group=['waffle_group'])

flag = get_waffle_flag_model().objects.get(name=name)
self.assertEqual(flag.percent, percent)
self.assertIsNone(flag.everyone)
self.assertTrue(flag.testing)
self.assertTrue(flag.superusers)
self.assertTrue(flag.staff)
self.assertTrue(flag.authenticated)
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 0f8860e

Please sign in to comment.