api: strip white spaces and dots from received phone numbers (#82889)
gitea/chrono/pipeline/head This commit looks good
Details
gitea/chrono/pipeline/head This commit looks good
Details
This commit is contained in:
parent
a548753f2a
commit
78928bc760
|
@ -1,5 +1,6 @@
|
|||
import collections
|
||||
import datetime
|
||||
import re
|
||||
|
||||
from django.contrib.auth.models import Group
|
||||
from django.db import models, transaction
|
||||
|
@ -42,6 +43,15 @@ class StringOrListField(serializers.ListField):
|
|||
return super().to_internal_value(data)
|
||||
|
||||
|
||||
class PhoneNumbersStringOrListField(serializers.ListField):
|
||||
def to_internal_value(self, data):
|
||||
if isinstance(data, str):
|
||||
data = [s.strip() for s in data.split(',') if s.strip()]
|
||||
# strip white spaces and dots
|
||||
data = [re.sub(r'[\s\.]', '', x) for x in data]
|
||||
return super().to_internal_value(data)
|
||||
|
||||
|
||||
class CommaSeparatedStringField(serializers.ListField):
|
||||
def get_value(self, dictionary):
|
||||
return super(serializers.ListField, self).get_value(dictionary)
|
||||
|
@ -91,7 +101,7 @@ class FillSlotSerializer(serializers.Serializer):
|
|||
extra_emails = StringOrListField(
|
||||
required=False, child=serializers.EmailField(max_length=250, allow_blank=False)
|
||||
)
|
||||
extra_phone_numbers = StringOrListField(
|
||||
extra_phone_numbers = PhoneNumbersStringOrListField(
|
||||
required=False, child=serializers.CharField(max_length=16, allow_blank=False)
|
||||
)
|
||||
check_overlaps = serializers.BooleanField(default=False)
|
||||
|
|
|
@ -79,7 +79,7 @@ def test_booking_api(app, user):
|
|||
'user_phone_number': '+33 (0) 6 12 34 56 78', # long phone number
|
||||
'form_url': 'http://example.net/',
|
||||
'extra_emails': ['baz@baz.com', 'hop@hop.com'],
|
||||
'extra_phone_numbers': ['+33123456789', '+33123456789'],
|
||||
'extra_phone_numbers': ['+33123456789', '+33 1 23 45 67 89'],
|
||||
'presence_callback_url': 'http://example.net/jump/trigger2/',
|
||||
'absence_callback_url': 'http://example.net/jump/trigger3/',
|
||||
},
|
||||
|
@ -292,7 +292,7 @@ def test_booking_api_extra_emails(app, user):
|
|||
fillslot_url,
|
||||
params={
|
||||
'extra_emails': 'bar.com',
|
||||
'extra_phone_numbers': 'too loooooooooong',
|
||||
'extra_phone_numbers': 'too loooooooooooong',
|
||||
},
|
||||
status=400,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue