Customer accounts: Only link orders by email if wanted

This commit is contained in:
Raphael Michel
2021-05-25 15:09:35 +02:00
parent 538dd933fb
commit ea514948b5
6 changed files with 24 additions and 5 deletions

View File

@@ -273,6 +273,7 @@ class TeamMemberSerializer(serializers.ModelSerializer):
class OrganizerSettingsSerializer(SettingsSerializer):
default_fields = [
'customer_accounts',
'customer_accounts_link_by_email',
'contact_mail',
'imprint_url',
'organizer_info_text',

View File

@@ -118,6 +118,17 @@ DEFAULTS = {
"advanced features like memberships.")
)
},
'customer_accounts_link_by_email': {
'default': 'False',
'type': bool,
'form_class': forms.BooleanField,
'serializer_class': serializers.BooleanField,
'form_kwargs': dict(
label=_("Match orders based on email address"),
help_text=_("This will allow registered customers to access orders made with the same email address, even if the customer "
"was not logged in during the purchase.")
)
},
'max_items_per_order': {
'default': '10',
'type': int,

View File

@@ -285,6 +285,7 @@ class OrganizerSettingsForm(SettingsForm):
)
auto_fields = [
'customer_accounts',
'customer_accounts_link_by_email',
'contact_mail',
'imprint_url',
'organizer_info_text',

View File

@@ -55,6 +55,7 @@
<fieldset>
<legend>{% trans "Customer accounts" %}</legend>
{% bootstrap_field sform.customer_accounts layout="control" %}
{% bootstrap_field sform.customer_accounts_link_by_email layout="control" %}
{% bootstrap_field sform.name_scheme layout="control" %}
{% bootstrap_field sform.name_scheme_titles layout="control" %}
</fieldset>

View File

@@ -1747,9 +1747,12 @@ class CustomerDetailView(OrganizerDetailViewMixin, OrganizerPermissionRequiredMi
context_object_name = 'orders'
def get_queryset(self):
q = Q(customer=self.customer)
if self.request.organizer.settings.customer_accounts_link_by_email:
# This is safe because we only let customers with verified emails log in
q |= Q(email__iexact=self.customer.email)
qs = Order.objects.filter(
Q(customer=self.customer)
| Q(email__iexact=self.customer.email)
q
).select_related('event').order_by('-datetime')
return qs

View File

@@ -277,10 +277,12 @@ class ProfileView(CustomerRequiredMixin, ListView):
paginate_by = 20
def get_queryset(self):
qs = Order.objects.filter(
Q(customer=self.request.customer)
| Q(email__iexact=self.request.customer.email)
q = Q(customer=self.request.customer)
if self.request.organizer.settings.customer_accounts_link_by_email:
# This is safe because we only let customers with verified emails log in
q |= Q(email__iexact=self.request.customer.email)
qs = Order.objects.filter(
q
).select_related('event').order_by('-datetime')
return qs