04/06 adding some additional functions

This commit is contained in:
2026-04-06 18:02:16 -04:00
parent bc236a3d19
commit 299bf2ca05
12 changed files with 1142 additions and 9 deletions
+46 -4
View File
@@ -335,12 +335,18 @@ def notify_comment_added(comment):
def notify_assignment(ticket, assigned_by):
"""Notify newly assigned IT staff member."""
"""Notify newly assigned IT staff member AND the ticket creator (employee).
The employee who submitted the ticket (or on whose behalf it was filed)
receives a confirmation that their issue has been picked up, giving
them visibility without requiring them to poll the ticket page.
"""
if not ticket.assigned_to_id:
return
base_url = current_app.config.get('APP_BASE_URL', '')
base_url = current_app.config.get('APP_BASE_URL', '')
ticket_url = f"{base_url}/tickets/{ticket.id}"
# ── Notify the IT staff assignee ──────────────────────────────────────────
create_notification(
user_id = ticket.assigned_to_id,
notif_type= NotificationType.TICKET_ASSIGNED,
@@ -349,7 +355,6 @@ def notify_assignment(ticket, assigned_by):
ticket_id = ticket.id,
link = f'/tickets/{ticket.id}',
)
db.session.commit()
if ticket.assignee and ticket.assignee.email_notif:
html = render_template_string(_STATUS_UPDATE_EMAIL,
ticket_number = ticket.ticket_number,
@@ -362,4 +367,41 @@ def notify_assignment(ticket, assigned_by):
[ticket.assignee.email],
html,
)
logger.info(f'[TICKET ASSIGN] ticket_id={ticket.id} assigned_to={ticket.assigned_to_id} by={assigned_by.id}')
# ── Notify the ticket creator (employee) ──────────────────────────────────
# Only notify if the creator is not the assignee — avoids a redundant
# self-notification when IT staff file and assign their own tickets.
if ticket.created_by_id != ticket.assigned_to_id:
assignee_name = ticket.assignee.full_name if ticket.assignee else 'an IT staff member'
employee_msg = (
f'Your ticket "{ticket.title}" has been picked up by {assignee_name}. '
f'You will be notified as soon as there is an update.'
)
create_notification(
user_id = ticket.created_by_id,
notif_type= NotificationType.TICKET_ASSIGNED,
title = f'Ticket {ticket.ticket_number} — Now Being Worked On',
message = employee_msg,
ticket_id = ticket.id,
link = f'/tickets/{ticket.id}',
)
creator = db.session.get(User, ticket.created_by_id)
if creator and creator.email_notif:
html = render_template_string(_STATUS_UPDATE_EMAIL,
ticket_number = ticket.ticket_number,
title = ticket.title,
message = employee_msg,
ticket_url = ticket_url,
)
send_email(
f'[Ticket Update] {ticket.ticket_number} — Now Being Worked On',
[creator.email],
html,
)
db.session.commit()
logger.info(
f'[TICKET ASSIGN] ticket_id={ticket.id} '
f'assigned_to={ticket.assigned_to_id} by={assigned_by.id} '
f'employee_notified={ticket.created_by_id != ticket.assigned_to_id}'
)