From 4dffc450c4a784b1e11c74e88d547b5acc47cd67 Mon Sep 17 00:00:00 2001 From: ashwin31 Date: Tue, 17 Feb 2026 09:18:27 +0530 Subject: [PATCH 1/5] fix: send lead assignment email after assignees are set Move email dispatch to after assigned_to.add() in post(), put(), and patch() so recipients are properly populated. Add guard to skip sending when there are no assignees. Notify only newly assigned users on update, and all assignees on conversion. Fixes #575 Co-Authored-By: Claude Opus 4.6 --- backend/leads/views/lead_views.py | 92 ++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 25 deletions(-) diff --git a/backend/leads/views/lead_views.py b/backend/leads/views/lead_views.py index 31c3a381..98bfb140 100644 --- a/backend/leads/views/lead_views.py +++ b/backend/leads/views/lead_views.py @@ -1,3 +1,5 @@ +import json + from django.contrib.contenttypes.models import ContentType from django.db.models import Q from django.shortcuts import get_object_or_404 @@ -210,6 +212,7 @@ class LeadListView(APIView, LimitOffsetPagination): }, ) def post(self, request, *args, **kwargs): + """Create a new lead, optionally converting it to an account immediately.""" data = request.data serializer = LeadCreateSerializer(data=data, request_obj=request) if serializer.is_valid(): @@ -229,13 +232,6 @@ class LeadListView(APIView, LimitOffsetPagination): ) lead_obj.contacts.add(*obj_contact) - recipients = list(lead_obj.assigned_to.all().values_list("id", flat=True)) - send_email_to_assigned_user.delay( - recipients, - lead_obj.id, - str(request.profile.org.id), - ) - if request.FILES.get("lead_attachment"): attachment = Attachments() attachment.created_by = request.profile.user @@ -271,6 +267,17 @@ class LeadListView(APIView, LimitOffsetPagination): ) lead_obj.assigned_to.add(*profiles) + # Send email to assigned users (after assignees are set) + # Skip if status is "converted" - that branch handles its own email + if data.get("status") != "converted": + recipients = list(lead_obj.assigned_to.all().values_list("id", flat=True)) + if recipients: + send_email_to_assigned_user.delay( + recipients, + lead_obj.id, + str(request.profile.org.id), + ) + if data.get("status") == "converted": from leads.services import convert_lead_to_account @@ -278,10 +285,11 @@ class LeadListView(APIView, LimitOffsetPagination): lead_obj, request ) - if data.get("assigned_to", None): - assigned_to_list = data.getlist("assigned_to") + # Send email to assigned users for converted leads + recipients = list(lead_obj.assigned_to.all().values_list("id", flat=True)) + if recipients: send_email_to_assigned_user.delay( - assigned_to_list, + recipients, lead_obj.id, str(request.profile.org.id), ) @@ -546,6 +554,7 @@ class LeadDetailView(APIView): }, ) def put(self, request, pk, **kwargs): + """Fully update a lead, optionally converting it to an account.""" params = request.data self.lead_obj = self.get_object(pk) if self.lead_obj.org != request.profile.org: @@ -556,6 +565,9 @@ class LeadDetailView(APIView): }, status=status.HTTP_403_FORBIDDEN, ) + previous_assigned_to_users = list( + self.lead_obj.assigned_to.all().values_list("id", flat=True) + ) serializer = LeadCreateSerializer( data=params, instance=self.lead_obj, @@ -563,9 +575,6 @@ class LeadDetailView(APIView): ) if serializer.is_valid(): lead_obj = serializer.save() - previous_assigned_to_users = list( - lead_obj.assigned_to.all().values_list("id", flat=True) - ) lead_obj.tags.clear() if params.get("tags"): tags = params.get("tags") @@ -574,15 +583,6 @@ class LeadDetailView(APIView): ) lead_obj.tags.add(*tag_objs) - assigned_to_list = list( - lead_obj.assigned_to.all().values_list("id", flat=True) - ) - recipients = list(set(assigned_to_list) - set(previous_assigned_to_users)) - send_email_to_assigned_user.delay( - recipients, - lead_obj.id, - str(request.profile.org.id), - ) if request.FILES.get("lead_attachment"): attachment = Attachments() attachment.created_by = request.profile.user @@ -635,6 +635,21 @@ class LeadDetailView(APIView): ) lead_obj.assigned_to.add(*profiles) + # Send email to newly assigned users (after assignees are updated) + # Skip if status is "converted" - that branch handles its own email + if params.get("status") != "converted": + current_assigned_users = list( + lead_obj.assigned_to.all().values_list("id", flat=True) + ) + # Only email users who were newly assigned + recipients = list(set(current_assigned_users) - set(previous_assigned_to_users)) + if recipients: + send_email_to_assigned_user.delay( + recipients, + lead_obj.id, + str(request.profile.org.id), + ) + if params.get("status") == "converted": from leads.services import convert_lead_to_account @@ -642,10 +657,11 @@ class LeadDetailView(APIView): lead_obj, request ) - if params.get("assigned_to"): - assigned_to_list = params.get("assigned_to") + # Send email to all assigned users for converted leads + recipients = list(lead_obj.assigned_to.all().values_list("id", flat=True)) + if recipients: send_email_to_assigned_user.delay( - assigned_to_list, + recipients, lead_obj.id, str(request.profile.org.id), ) @@ -726,6 +742,15 @@ class LeadDetailView(APIView): self.lead_obj, request ) + # Send email to assigned users for converted leads + recipients = list(self.lead_obj.assigned_to.all().values_list("id", flat=True)) + if recipients: + send_email_to_assigned_user.delay( + recipients, + self.lead_obj.id, + str(request.profile.org.id), + ) + return Response( { "error": False, @@ -738,6 +763,11 @@ class LeadDetailView(APIView): ) # Handle regular partial updates + # Capture previous assignees for email notification + previous_assigned_to_users = list( + self.lead_obj.assigned_to.all().values_list("id", flat=True) + ) + serializer = LeadCreateSerializer( data=params, instance=self.lead_obj, @@ -812,6 +842,18 @@ class LeadDetailView(APIView): ) lead_obj.assigned_to.add(*profiles) + # Send email to newly assigned users (after assignees are updated) + current_assigned_users = list( + lead_obj.assigned_to.all().values_list("id", flat=True) + ) + recipients = list(set(current_assigned_users) - set(previous_assigned_to_users)) + if recipients: + send_email_to_assigned_user.delay( + recipients, + lead_obj.id, + str(request.profile.org.id), + ) + return Response( {"error": False, "message": "Lead updated Successfully"}, status=status.HTTP_200_OK, From 90b8596fb1b2b3ff710b2e51ba77334e475b5988 Mon Sep 17 00:00:00 2001 From: ashwin31 Date: Tue, 17 Feb 2026 12:56:18 +0530 Subject: [PATCH 2/5] security: remove leaked Google API key from repository Remove google-services.json from tracking and add it to .gitignore. Add a .json.template placeholder with dummy values so developers know the file structure. See mobile/FIREBASE_SETUP.md for setup instructions. The leaked key (AIzaSyDsA2wgQIw-bVgwODNMIF482gVRn5xdANU) must still be revoked in Google Cloud Console by the project owner. Co-Authored-By: Claude Opus 4.6 --- mobile/.gitignore | 4 ++ mobile/android/app/google-services.json | 63 ------------------- .../android/app/google-services.json.template | 25 ++++++++ 3 files changed, 29 insertions(+), 63 deletions(-) delete mode 100644 mobile/android/app/google-services.json create mode 100644 mobile/android/app/google-services.json.template diff --git a/mobile/.gitignore b/mobile/.gitignore index 3820a95c..f7e92b58 100644 --- a/mobile/.gitignore +++ b/mobile/.gitignore @@ -43,3 +43,7 @@ app.*.map.json /android/app/debug /android/app/profile /android/app/release + +# Firebase / Google Services — contains API keys +**/google-services.json +**/GoogleService-Info.plist diff --git a/mobile/android/app/google-services.json b/mobile/android/app/google-services.json deleted file mode 100644 index 2cb23402..00000000 --- a/mobile/android/app/google-services.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "project_info": { - "project_number": "1072513761792", - "project_id": "bottlecrm-io", - "storage_bucket": "bottlecrm-io.firebasestorage.app" - }, - "client": [ - { - "client_info": { - "mobilesdk_app_id": "1:1072513761792:android:c170ae72445200ecd74ee5", - "android_client_info": { - "package_name": "io.bottlecrm" - } - }, - "oauth_client": [ - { - "client_id": "1072513761792-6cnavnfp5p4me4peah0vgoc477ndkd3h.apps.googleusercontent.com", - "client_type": 1, - "android_info": { - "package_name": "io.bottlecrm", - "certificate_hash": "5227cfe6b33aceb349e54aaf1ea3cfc191aef324" - } - }, - { - "client_id": "1072513761792-r70ldlpqkbkb654tdpu41sqqrs5b4uf4.apps.googleusercontent.com", - "client_type": 1, - "android_info": { - "package_name": "io.bottlecrm", - "certificate_hash": "f980d3a3e81564ea45f3634dd706eb5261ec222b" - } - }, - { - "client_id": "1072513761792-vp1nq9690h2v94oge513ejr7d01rh0e8.apps.googleusercontent.com", - "client_type": 1, - "android_info": { - "package_name": "io.bottlecrm", - "certificate_hash": "67c4be5a9739470b402c1405f181abc7e6cfa7df" - } - }, - { - "client_id": "1072513761792-p59rct7b1c3go7l58e51r3geuqff2tfl.apps.googleusercontent.com", - "client_type": 3 - } - ], - "api_key": [ - { - "current_key": "AIzaSyDsA2wgQIw-bVgwODNMIF482gVRn5xdANU" - } - ], - "services": { - "appinvite_service": { - "other_platform_oauth_client": [ - { - "client_id": "1072513761792-dvcv8cj147oj6nav40u7jfjp1r3f0a1d.apps.googleusercontent.com", - "client_type": 3 - } - ] - } - } - } - ], - "configuration_version": "1" -} \ No newline at end of file diff --git a/mobile/android/app/google-services.json.template b/mobile/android/app/google-services.json.template new file mode 100644 index 00000000..7ad4605f --- /dev/null +++ b/mobile/android/app/google-services.json.template @@ -0,0 +1,25 @@ +{ + "project_info": { + "project_number": "YOUR_PROJECT_NUMBER", + "project_id": "YOUR_PROJECT_ID", + "storage_bucket": "YOUR_PROJECT_ID.firebasestorage.app" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "YOUR_MOBILE_SDK_APP_ID", + "android_client_info": { + "package_name": "io.bottlecrm" + } + }, + "oauth_client": [], + "api_key": [ + { + "current_key": "YOUR_GOOGLE_API_KEY" + } + ], + "services": {} + } + ], + "configuration_version": "1" +} From 1058ca85b477693c85e6ffc1a0406de41954f518 Mon Sep 17 00:00:00 2001 From: ashwin31 Date: Tue, 17 Feb 2026 12:59:09 +0530 Subject: [PATCH 3/5] security: stop leaking exception details in API responses Replace str(e) in error responses with generic messages and log the actual exceptions server-side. Fixes all 9 CodeQL "information exposure through an exception" alerts. - auth_views.py: Google OAuth token validation error - invoices/public_views.py: invoice and estimate PDF generation (4 sites) - invoices/api_views.py: invoice and estimate PDF generation (4 sites) Co-Authored-By: Claude Opus 4.6 --- backend/common/views/auth_views.py | 8 ++++++-- backend/invoices/api_views.py | 27 +++++++++++++++++---------- backend/invoices/public_views.py | 24 ++++++++++++++++-------- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/backend/common/views/auth_views.py b/backend/common/views/auth_views.py index 87f97f54..4928eae3 100644 --- a/backend/common/views/auth_views.py +++ b/backend/common/views/auth_views.py @@ -1,4 +1,5 @@ import json +import logging import secrets import requests @@ -16,6 +17,8 @@ from rest_framework_simplejwt.tokens import RefreshToken from common import serializer from common.models import Org, Profile, User + +logger = logging.getLogger(__name__) from common.serializer import OrgAwareRefreshToken @@ -192,9 +195,10 @@ class GoogleIdTokenView(APIView): ) email = idinfo.get("email") picture = idinfo.get("picture", "") - except ValueError as e: + except ValueError: + logger.warning("Google OAuth token validation failed", exc_info=True) return Response( - {"error": f"Invalid token: {str(e)}"}, + {"error": "Invalid token"}, status=status.HTTP_400_BAD_REQUEST, ) diff --git a/backend/invoices/api_views.py b/backend/invoices/api_views.py index 0b81167a..b7f1b838 100644 --- a/backend/invoices/api_views.py +++ b/backend/invoices/api_views.py @@ -1,3 +1,4 @@ +import logging from decimal import Decimal from django.conf import settings @@ -14,6 +15,8 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView +logger = logging.getLogger(__name__) + from common.models import Attachments, Comment from common.permissions import HasOrgContext from common.serializer import AttachmentsSerializer, CommentSerializer @@ -561,14 +564,16 @@ class InvoicePDFView(APIView): response = HttpResponse(pdf_content, content_type="application/pdf") response["Content-Disposition"] = f'attachment; filename="{filename}"' return response - except ImportError as e: + except ImportError: + logger.exception("PDF generation library not available") return Response( - {"error": True, "message": str(e)}, - status=status.HTTP_500_INTERNAL_SERVER_ERROR, + {"error": True, "message": "PDF generation unavailable"}, + status=status.HTTP_503_SERVICE_UNAVAILABLE, ) - except Exception as e: + except Exception: + logger.exception("Failed to generate invoice PDF") return Response( - {"error": True, "message": f"Error generating PDF: {str(e)}"}, + {"error": True, "message": "Failed to generate PDF"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR, ) @@ -1197,14 +1202,16 @@ class EstimatePDFView(APIView): response = HttpResponse(pdf_content, content_type="application/pdf") response["Content-Disposition"] = f'attachment; filename="{filename}"' return response - except ImportError as e: + except ImportError: + logger.exception("PDF generation library not available") return Response( - {"error": True, "message": str(e)}, - status=status.HTTP_500_INTERNAL_SERVER_ERROR, + {"error": True, "message": "PDF generation unavailable"}, + status=status.HTTP_503_SERVICE_UNAVAILABLE, ) - except Exception as e: + except Exception: + logger.exception("Failed to generate estimate PDF") return Response( - {"error": True, "message": f"Error generating PDF: {str(e)}"}, + {"error": True, "message": "Failed to generate PDF"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR, ) diff --git a/backend/invoices/public_views.py b/backend/invoices/public_views.py index e9db3004..6617198e 100644 --- a/backend/invoices/public_views.py +++ b/backend/invoices/public_views.py @@ -4,12 +4,16 @@ Public views for client portal. These views do not require authentication and are accessed via public tokens. """ +import logging + from django.http import HttpResponse from django.utils import timezone from rest_framework import status from rest_framework.response import Response from rest_framework.views import APIView +logger = logging.getLogger(__name__) + from invoices.models import Invoice, Estimate, InvoiceTemplate from invoices.pdf import ( generate_invoice_pdf, @@ -147,14 +151,16 @@ class PublicInvoicePDFView(APIView): response = HttpResponse(pdf_content, content_type="application/pdf") response["Content-Disposition"] = f'attachment; filename="{filename}"' return response - except ImportError as e: + except ImportError: + logger.exception("PDF generation library not available") return Response( - {"error": True, "message": f"PDF generation unavailable: {str(e)}"}, + {"error": True, "message": "PDF generation unavailable"}, status=status.HTTP_503_SERVICE_UNAVAILABLE, ) - except Exception as e: + except Exception: + logger.exception("Failed to generate invoice PDF") return Response( - {"error": True, "message": f"Failed to generate PDF: {str(e)}"}, + {"error": True, "message": "Failed to generate PDF"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR, ) @@ -278,14 +284,16 @@ class PublicEstimatePDFView(APIView): response = HttpResponse(pdf_content, content_type="application/pdf") response["Content-Disposition"] = f'attachment; filename="{filename}"' return response - except ImportError as e: + except ImportError: + logger.exception("PDF generation library not available") return Response( - {"error": True, "message": f"PDF generation unavailable: {str(e)}"}, + {"error": True, "message": "PDF generation unavailable"}, status=status.HTTP_503_SERVICE_UNAVAILABLE, ) - except Exception as e: + except Exception: + logger.exception("Failed to generate estimate PDF") return Response( - {"error": True, "message": f"Failed to generate PDF: {str(e)}"}, + {"error": True, "message": "Failed to generate PDF"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR, ) From 658692756303f7d06b4df152c3234b70f1d7eff8 Mon Sep 17 00:00:00 2001 From: ashwin31 Date: Tue, 17 Feb 2026 13:16:28 +0530 Subject: [PATCH 4/5] chore: update Python dependencies to latest versions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bump 6 packages and pin 5 previously unpinned ones: - django 5.2.9 → 5.2.11 (latest 5.x LTS) - celery 5.6.0 → 5.6.2 - django-ses 4.4.0 → 4.7.1 - sentry-sdk 2.47.0 → 2.53.0 - redis 7.1.0 → 7.2.0 - faker 33.1.0 → 40.4.0 - python-dateutil, google-auth, weasyprint, cairocffi, gunicorn pinned to latest for reproducible builds Co-Authored-By: Claude Opus 4.6 --- backend/requirements.txt | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/backend/requirements.txt b/backend/requirements.txt index 6a8356e5..6cd8ed41 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,27 +1,27 @@ -django==5.2.9 -celery==5.6.0 +django==5.2.11 +celery==5.6.2 python-dotenv==1.2.1 django-cors-headers==4.9.0 djangorestframework==3.16.1 djangorestframework-simplejwt==5.5.1 drf-spectacular==0.29.0 -django-ses==4.4.0 +django-ses==4.7.1 psycopg2-binary==2.9.11 whitenoise==6.11.0 -sentry-sdk==2.47.0 +sentry-sdk==2.53.0 django_storages==1.14.6 django-crum==0.7.9 -redis==7.1.0 +redis==7.2.0 pytz==2025.2 requests==2.32.5 -faker==33.1.0 -python-dateutil>=2.8.0 -google-auth>=2.0.0 +faker==40.4.0 +python-dateutil==2.9.0.post0 +google-auth==2.48.0 # PDF Generation -weasyprint>=60.0 -cairocffi>=1.6.0 +weasyprint==68.1 +cairocffi==1.7.1 # Production server -gunicorn>=23.0.0 \ No newline at end of file +gunicorn==25.1.0 \ No newline at end of file From 4161cf0ef0d6e0b4c7bdff59c62c63a0ebb27816 Mon Sep 17 00:00:00 2001 From: ashwin31 Date: Tue, 17 Feb 2026 13:17:19 +0530 Subject: [PATCH 5/5] chore: update frontend dependencies to latest versions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update 19 packages via ncu: - svelte 5.46.1 → 5.51.2 - @sveltejs/kit 2.49.2 → 2.52.0 - eslint 9.39.2 → 10.0.0 - vite 7.3.0 → 7.3.1 - bits-ui 2.14.4 → 2.15.6 - prettier 3.7.4 → 3.8.1 - axios 1.13.2 → 1.13.5 - and 12 other minor/patch bumps Co-Authored-By: Claude Opus 4.6 --- frontend/package.json | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index 1e86f43b..7122ffa3 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -14,30 +14,30 @@ "lint": "prettier --check . && eslint ." }, "devDependencies": { - "@eslint/compat": "^2.0.0", - "@eslint/js": "^9.39.2", - "@internationalized/date": "^3.10.1", - "@lucide/svelte": "^0.562.0", - "@sveltejs/adapter-node": "^5.4.0", - "@sveltejs/kit": "^2.49.2", - "@sveltejs/vite-plugin-svelte": "^6.2.1", + "@eslint/compat": "^2.0.2", + "@eslint/js": "^10.0.1", + "@internationalized/date": "^3.11.0", + "@lucide/svelte": "^0.567.0", + "@sveltejs/adapter-node": "^5.5.3", + "@sveltejs/kit": "^2.52.0", + "@sveltejs/vite-plugin-svelte": "^6.2.4", "@tailwindcss/typography": "^0.5.19", "@tailwindcss/vite": "^4.1.18", - "bits-ui": "^2.14.4", - "eslint": "^9.39.2", + "bits-ui": "^2.15.6", + "eslint": "^10.0.0", "eslint-config-prettier": "^10.1.8", - "eslint-plugin-svelte": "^3.13.1", - "globals": "^16.5.0", + "eslint-plugin-svelte": "^3.15.0", + "globals": "^17.3.0", "mode-watcher": "^1.1.0", - "prettier": "^3.7.4", + "prettier": "^3.8.1", "prettier-plugin-svelte": "^3.4.1", "prettier-plugin-tailwindcss": "^0.7.2", - "svelte": "^5.46.1", - "svelte-check": "^4.3.5", + "svelte": "^5.51.2", + "svelte-check": "^4.4.0", "svelte-sonner": "^1.0.7", "tailwindcss": "^4.1.18", "typescript": "^5.9.3", - "vite": "^7.3.0" + "vite": "^7.3.1" }, "pnpm": { "onlyBuiltDependencies": [ @@ -45,12 +45,12 @@ ] }, "dependencies": { - "axios": "^1.13.2", + "axios": "^1.13.5", "clsx": "^2.1.1", "date-fns": "^4.1.0", - "libphonenumber-js": "^1.12.33", - "svelte-dnd-action": "^0.9.68", - "tailwind-merge": "^3.4.0", + "libphonenumber-js": "^1.12.36", + "svelte-dnd-action": "^0.9.69", + "tailwind-merge": "^3.4.1", "tailwind-variants": "^3.2.2", "tw-animate-css": "^1.4.0" }