parent
719099a5af
commit
516455f482
|
@ -15,6 +15,7 @@ class IdentificationStageSerializer(ModelSerializer):
|
|||
"pk",
|
||||
"name",
|
||||
"user_fields",
|
||||
"case_insensitive_matching",
|
||||
"template",
|
||||
"enrollment_flow",
|
||||
"recovery_flow",
|
||||
|
|
|
@ -27,7 +27,14 @@ class IdentificationStageForm(forms.ModelForm):
|
|||
class Meta:
|
||||
|
||||
model = IdentificationStage
|
||||
fields = ["name", "user_fields", "template", "enrollment_flow", "recovery_flow"]
|
||||
fields = [
|
||||
"name",
|
||||
"user_fields",
|
||||
"case_insensitive_matching",
|
||||
"template",
|
||||
"enrollment_flow",
|
||||
"recovery_flow",
|
||||
]
|
||||
widgets = {
|
||||
"name": forms.TextInput(),
|
||||
"user_fields": FilteredSelectMultiple(
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
# Generated by Django 3.1.1 on 2020-09-30 21:44
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("passbook_stages_identification", "0003_auto_20200615_1641"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="identificationstage",
|
||||
name="case_insensitive_matching",
|
||||
field=models.BooleanField(
|
||||
default=True,
|
||||
help_text="When enabled, user fields are matched regardless of their casing.",
|
||||
),
|
||||
),
|
||||
]
|
|
@ -34,6 +34,13 @@ class IdentificationStage(Stage):
|
|||
)
|
||||
template = models.TextField(choices=Templates.choices)
|
||||
|
||||
case_insensitive_matching = models.BooleanField(
|
||||
default=True,
|
||||
help_text=_(
|
||||
"When enabled, user fields are matched regardless of their casing."
|
||||
),
|
||||
)
|
||||
|
||||
enrollment_flow = models.ForeignKey(
|
||||
Flow,
|
||||
on_delete=models.SET_DEFAULT,
|
||||
|
|
|
@ -70,7 +70,12 @@ class IdentificationStageView(FormView, StageView):
|
|||
current_stage: IdentificationStage = self.executor.current_stage
|
||||
query = Q()
|
||||
for search_field in current_stage.user_fields:
|
||||
query |= Q(**{search_field: uid_value})
|
||||
model_field = search_field
|
||||
if current_stage.case_insensitive_matching:
|
||||
model_field += "__iexact"
|
||||
else:
|
||||
model_field += "__exact"
|
||||
query |= Q(**{model_field: uid_value})
|
||||
users = User.objects.filter(query)
|
||||
if users.exists():
|
||||
LOGGER.debug("Found user", user=users.first(), query=query)
|
||||
|
|
Reference in New Issue