parent
719099a5af
commit
516455f482
|
@ -15,6 +15,7 @@ class IdentificationStageSerializer(ModelSerializer):
|
||||||
"pk",
|
"pk",
|
||||||
"name",
|
"name",
|
||||||
"user_fields",
|
"user_fields",
|
||||||
|
"case_insensitive_matching",
|
||||||
"template",
|
"template",
|
||||||
"enrollment_flow",
|
"enrollment_flow",
|
||||||
"recovery_flow",
|
"recovery_flow",
|
||||||
|
|
|
@ -27,7 +27,14 @@ class IdentificationStageForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
model = IdentificationStage
|
model = IdentificationStage
|
||||||
fields = ["name", "user_fields", "template", "enrollment_flow", "recovery_flow"]
|
fields = [
|
||||||
|
"name",
|
||||||
|
"user_fields",
|
||||||
|
"case_insensitive_matching",
|
||||||
|
"template",
|
||||||
|
"enrollment_flow",
|
||||||
|
"recovery_flow",
|
||||||
|
]
|
||||||
widgets = {
|
widgets = {
|
||||||
"name": forms.TextInput(),
|
"name": forms.TextInput(),
|
||||||
"user_fields": FilteredSelectMultiple(
|
"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)
|
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(
|
enrollment_flow = models.ForeignKey(
|
||||||
Flow,
|
Flow,
|
||||||
on_delete=models.SET_DEFAULT,
|
on_delete=models.SET_DEFAULT,
|
||||||
|
|
|
@ -70,7 +70,12 @@ class IdentificationStageView(FormView, StageView):
|
||||||
current_stage: IdentificationStage = self.executor.current_stage
|
current_stage: IdentificationStage = self.executor.current_stage
|
||||||
query = Q()
|
query = Q()
|
||||||
for search_field in current_stage.user_fields:
|
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)
|
users = User.objects.filter(query)
|
||||||
if users.exists():
|
if users.exists():
|
||||||
LOGGER.debug("Found user", user=users.first(), query=query)
|
LOGGER.debug("Found user", user=users.first(), query=query)
|
||||||
|
|
Reference in New Issue