04/07 updated linking ticket

This commit is contained in:
2026-04-07 10:11:52 -04:00
parent 299bf2ca05
commit 56c65bfe4c
3 changed files with 225 additions and 13 deletions
+18 -8
View File
@@ -687,22 +687,32 @@ def link_ticket(ticket_id):
abort(403)
ticket = db.session.get(Ticket, ticket_id) or abort(404)
other_id = request.form.get('linked_ticket_id', type=int)
raw_input = request.form.get('linked_ticket_id', '').strip()
link_type = request.form.get('link_type', 'related')
if not other_id:
flash('Please specify a ticket to link.', 'danger')
if not raw_input:
flash('Please search for and select a ticket to link.', 'danger')
return redirect(url_for('tickets.ticket_detail', ticket_id=ticket_id))
# Resolve by ticket_number (e.g. TKT-20260406-0001) or numeric DB id
if raw_input.upper().startswith('TKT-'):
other = Ticket.query.filter_by(ticket_number=raw_input.upper()).first()
else:
try:
other = db.session.get(Ticket, int(raw_input))
except ValueError:
other = Ticket.query.filter_by(ticket_number=raw_input.upper()).first()
if not other:
flash(f'Ticket "{raw_input}" not found.', 'danger')
return redirect(url_for('tickets.ticket_detail', ticket_id=ticket_id))
other_id = other.id
if other_id == ticket_id:
flash('A ticket cannot be linked to itself.', 'danger')
return redirect(url_for('tickets.ticket_detail', ticket_id=ticket_id))
other = db.session.get(Ticket, other_id)
if not other:
flash(f'Ticket #{other_id} not found.', 'danger')
return redirect(url_for('tickets.ticket_detail', ticket_id=ticket_id))
# Enforce canonical ordering (smaller id first) for the uniqueness constraint
a, b = sorted([ticket_id, other_id])
existing = TicketLink.query.filter_by(ticket_id=a, linked_ticket_id=b).first()