Don't include staff and inactive users when counting matched users
This commit is contained in:
@ -39,7 +39,7 @@ class SegmentAdminForm(WagtailAdminModelForm):
|
||||
return count
|
||||
|
||||
User = get_user_model()
|
||||
users = User.objects.all()
|
||||
users = User.objects.filter(is_active=True, is_staff=False)
|
||||
|
||||
for user in users.iterator():
|
||||
if match_any:
|
||||
|
@ -286,6 +286,48 @@ def test_count_users_matching_static_rules(site, client, django_user_model):
|
||||
assert form.count_matching_users([rule], True) is 2
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_count_matching_users_excludes_staff(site, client, django_user_model):
|
||||
class TestStaticRule(AbstractBaseRule):
|
||||
static = True
|
||||
|
||||
class Meta:
|
||||
app_label = 'wagtail_personalisation'
|
||||
|
||||
def test_user(self, request, user):
|
||||
return True
|
||||
|
||||
django_user_model.objects.create(username='first')
|
||||
django_user_model.objects.create(username='second', is_staff=True)
|
||||
|
||||
segment = SegmentFactory.build(type=Segment.TYPE_STATIC)
|
||||
rule = TestStaticRule()
|
||||
form = form_with_data(segment, rule)
|
||||
|
||||
assert form.count_matching_users([rule], True) is 1
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_count_matching_users_excludes_inactive(site, client, django_user_model):
|
||||
class TestStaticRule(AbstractBaseRule):
|
||||
static = True
|
||||
|
||||
class Meta:
|
||||
app_label = 'wagtail_personalisation'
|
||||
|
||||
def test_user(self, request, user):
|
||||
return True
|
||||
|
||||
django_user_model.objects.create(username='first')
|
||||
django_user_model.objects.create(username='second', is_active=False)
|
||||
|
||||
segment = SegmentFactory.build(type=Segment.TYPE_STATIC)
|
||||
rule = TestStaticRule()
|
||||
form = form_with_data(segment, rule)
|
||||
|
||||
assert form.count_matching_users([rule], True) is 1
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_count_matching_users_only_counts_static_rules(site, client, django_user_model):
|
||||
class TestStaticRule(AbstractBaseRule):
|
||||
|
Reference in New Issue
Block a user