From 204025bb842c03bd888b6f3b7ae8552eccf3f556 Mon Sep 17 00:00:00 2001 From: Ashley Date: Tue, 29 Oct 2024 01:24:57 +0000 Subject: [PATCH] Update: queries using email now use iexact to account for instances in ledger with capitalisation --- mooringlicensing/components/approvals/api.py | 5 ++--- mooringlicensing/components/proposals/email.py | 4 ++-- mooringlicensing/components/proposals/serializers.py | 2 +- mooringlicensing/components/proposals/utils.py | 2 +- mooringlicensing/utils/mooring_licence_migrate_pd.py | 8 ++++---- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/mooringlicensing/components/approvals/api.py b/mooringlicensing/components/approvals/api.py index 2854f13c..f4cd9071 100755 --- a/mooringlicensing/components/approvals/api.py +++ b/mooringlicensing/components/approvals/api.py @@ -756,7 +756,6 @@ def add_comms_log(self, request, *args, **kwargs): class DcvAdmissionViewSet(viewsets.GenericViewSet, mixins.RetrieveModelMixin): queryset = DcvAdmission.objects.all().order_by('id') serializer_class = DcvAdmissionSerializer - permission_classes=[IsAuthenticated] def get_queryset(self): user = self.request.user @@ -835,7 +834,7 @@ def create(self, request, *args, **kwargs): if email_address and email_address_confirmation: if email_address == email_address_confirmation: if skipper: - this_user = EmailUser.objects.filter(email=email_address) + this_user = EmailUser.objects.filter(email__iexact=email_address) if this_user: new_user = this_user.first() else: @@ -962,7 +961,7 @@ def create(self, request, *args, **kwargs): if email_address and email_address_confirmation: if email_address == email_address_confirmation: if skipper: - this_user = EmailUser.objects.filter(email=email_address) + this_user = EmailUser.objects.filter(email__iexact=email_address) if this_user: new_user = this_user.first() else: diff --git a/mooringlicensing/components/proposals/email.py b/mooringlicensing/components/proposals/email.py index ff00d07a..37c0ef8c 100755 --- a/mooringlicensing/components/proposals/email.py +++ b/mooringlicensing/components/proposals/email.py @@ -512,7 +512,7 @@ def send_endorser_reminder_email(proposal, request=None): msgs = [] for site_licensee_mooring in proposal.site_licensee_mooring_request.filter(enabled=True,endorser_reminder_sent=False): try: - endorser = EmailUser.objects.get(email=site_licensee_mooring.site_licensee_email) + endorser = EmailUser.objects.get(email__iexact=site_licensee_mooring.site_licensee_email) except: # Should not reach here continue @@ -1432,7 +1432,7 @@ def send_endorsement_of_authorised_user_application_email(request, proposal): for site_licensee_mooring_request in proposal.site_licensee_mooring_request.filter(enabled=True,declined_by_endorser=False,approved_by_endorser=False): #replace with multiple site licensee emails try: - endorser = EmailUser.objects.get(email=site_licensee_mooring_request.site_licensee_email) + endorser = EmailUser.objects.get(email__iexact=site_licensee_mooring_request.site_licensee_email) except: # Should not reach here return diff --git a/mooringlicensing/components/proposals/serializers.py b/mooringlicensing/components/proposals/serializers.py index e7ffb39c..a5f250fa 100644 --- a/mooringlicensing/components/proposals/serializers.py +++ b/mooringlicensing/components/proposals/serializers.py @@ -986,7 +986,7 @@ def get_site_licensee_moorings(self, obj): checked = item['checked'] site_licensee = "" - site_licensee_system_user = su_qs.filter(email=i.site_licensee_email) + site_licensee_system_user = su_qs.filter(email__iexact=i.site_licensee_email) if site_licensee_system_user.exists(): site_licensee = get_user_name(site_licensee_system_user.first())["full_name"] endorsement = "Not Actioned" diff --git a/mooringlicensing/components/proposals/utils.py b/mooringlicensing/components/proposals/utils.py index fc0a8883..ec6d5bce 100644 --- a/mooringlicensing/components/proposals/utils.py +++ b/mooringlicensing/components/proposals/utils.py @@ -874,7 +874,7 @@ def update_proposal_applicant(proposal, request): proposal_applicant.email = proposal_applicant_data['email'] try: if proposal_applicant.email: - email_user = EmailUserRO.objects.get(email=proposal_applicant.email) + email_user = EmailUserRO.objects.get(email__iexact=proposal_applicant.email) proposal_applicant.email_user_id = email_user.id except: proposal_applicant.email_user_id = None diff --git a/mooringlicensing/utils/mooring_licence_migrate_pd.py b/mooringlicensing/utils/mooring_licence_migrate_pd.py index a77e7d2f..2091b2cc 100644 --- a/mooringlicensing/utils/mooring_licence_migrate_pd.py +++ b/mooringlicensing/utils/mooring_licence_migrate_pd.py @@ -921,7 +921,7 @@ def try_except(value): self.no_email.append(user_row.pers_no) continue - users = EmailUser.objects.filter(email=email) + users = EmailUser.objects.filter(email__iexact=email) if users.count() == 0: print(f'wl - email not found: {email}') @@ -1069,7 +1069,7 @@ def create_mooring_licences(self): self.no_email.append(user_row.pers_no) continue - users = EmailUser.objects.filter(email=email) + users = EmailUser.objects.filter(email__iexact=email) if users.count() == 0: print(f'ml - email not found: {email}') @@ -1647,7 +1647,7 @@ def create_dcv(self): first_name = row.first_name.lower().title().strip() last_name = row.last_name.lower().title().strip() try: - user = EmailUser.objects.get(email=email.lower()) + user = EmailUser.objects.get(email__iexact=email.lower()) user.first_name = first_name user.last_name = last_name user.save() @@ -1810,7 +1810,7 @@ def create_annual_admissions(self): vessel_length = row['vessel_length'] try: - user = EmailUser.objects.get(email=email.lower().strip()) + user = EmailUser.objects.get(email__iexact=email.lower().strip()) except Exception as e: errors.append("User with email " + str(email.lower()) + " does not exist") continue