04/08 fixed survey email issue
This commit is contained in:
+20
-5
@@ -564,12 +564,27 @@ class TicketSatisfaction(db.Model):
|
||||
|
||||
@classmethod
|
||||
def create_for_ticket(cls, ticket):
|
||||
"""Create a survey row for a newly-resolved ticket.
|
||||
Returns None if a survey already exists. Caller must commit.
|
||||
"""Return a survey row ready for emailing.
|
||||
|
||||
Behaviour:
|
||||
- No existing row → create and return a new one.
|
||||
- Existing row, not yet submitted (rating is NULL) → return it so
|
||||
the email can be re-sent. This covers the case where the row was
|
||||
created but the email thread crashed before sending.
|
||||
- Existing row, already submitted → return None (survey is complete).
|
||||
|
||||
Caller is responsible for committing the session.
|
||||
"""
|
||||
import secrets
|
||||
if cls.query.filter_by(ticket_id=ticket.id).first():
|
||||
return None
|
||||
existing = cls.query.filter_by(ticket_id=ticket.id).first()
|
||||
if existing:
|
||||
if existing.submitted:
|
||||
# Employee already rated — do not re-send
|
||||
return None
|
||||
# Row exists but email was never sent (prior crash) — re-use it
|
||||
# Regenerate the token so any stale links in old emails are invalidated
|
||||
existing.survey_token = secrets.token_urlsafe(32)
|
||||
return existing
|
||||
row = cls(
|
||||
ticket_id = ticket.id,
|
||||
user_id = ticket.created_by_id,
|
||||
@@ -583,4 +598,4 @@ class TicketSatisfaction(db.Model):
|
||||
return self.rating is not None
|
||||
|
||||
def __repr__(self):
|
||||
return f'<TicketSatisfaction ticket={self.ticket_id} rating={self.rating}>'
|
||||
return f'<TicketSatisfaction ticket={self.ticket_id} rating={self.rating}>'
|
||||
Reference in New Issue
Block a user