bottleneckcrm/backend/cases/tasks.py
ashwin31 cbcab8636a fix: resolve setup and Docker issues preventing project from running
Use shared_task instead of standalone Celery apps so celery -A crm worker
discovers all tasks. Add safe defaults for all required env vars in
settings.py so missing .env no longer crashes Django. Create idempotent
management command to bootstrap a superuser in Docker. Populate
.env.example with working dev defaults.

Fixes #490, #493, #508, #388, #383, #382, #381, #441, #519

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 10:27:47 +05:30

34 lines
1.2 KiB
Python

from celery import shared_task
from django.conf import settings
from django.core.mail import EmailMessage
from django.template.loader import render_to_string
from cases.models import Case
from common.models import Profile
from common.tasks import set_rls_context
@shared_task
def send_email_to_assigned_user(recipients, case_id, org_id):
"""Send Mail To Users When they are assigned to a case"""
set_rls_context(org_id)
case = Case.objects.get(id=case_id)
created_by = case.created_by
for profile_id in recipients:
recipients_list = []
profile = Profile.objects.filter(id=profile_id, is_active=True).first()
if profile:
recipients_list.append(profile.user.email)
context = {}
context["url"] = settings.DOMAIN_NAME
context["user"] = profile.user
context["case"] = case
context["created_by"] = created_by
subject = "Assigned to case."
html_content = render_to_string(
"assigned_to/cases_assigned.html", context=context
)
msg = EmailMessage(subject, html_content, to=recipients_list)
msg.content_subtype = "html"
msg.send()