05/22 Enhance codes and fix bugs 3

This commit is contained in:
2026-05-22 15:19:34 -04:00
parent 12b5fd9ce0
commit 5c9a124a71
11 changed files with 665 additions and 36 deletions
+22 -3
View File
@@ -425,10 +425,14 @@ def all_tickets():
.distinct()
)
tickets = q.order_by(Ticket.created_at.desc()).paginate(page=page, per_page=25)
tickets = q.order_by(Ticket.created_at.desc()).paginate(page=page, per_page=25)
it_staff = User.query.filter(
User.role.in_([UserRole.IT_STAFF, UserRole.ADMIN]),
User.is_active == True
).order_by(User.full_name).all()
return render_template('admin/tickets.html', tickets=tickets,
status=status, priority=priority, assigned=assigned,
search=search)
search=search, it_staff=it_staff)
@admin_bp.route('/tickets/<int:ticket_id>/delete', methods=['POST'])
@@ -993,11 +997,16 @@ def bulk_ticket_action():
flash('No tickets selected.', 'warning')
return redirect(url_for('admin.all_tickets'))
valid_actions = ('resolve', 'close', 'assign_me', 'unassign', 'delete')
valid_actions = ('resolve', 'close', 'assign_me', 'unassign', 'assign_to', 'delete')
if action not in valid_actions:
flash('Invalid action.', 'danger')
return redirect(url_for('admin.all_tickets'))
assign_to_id = request.form.get('assign_to_id', type=int)
if action == 'assign_to' and not assign_to_id:
flash('Please select a staff member to assign to.', 'warning')
return redirect(url_for('admin.all_tickets'))
# Bulk delete is admin-only
if action == 'delete' and not current_user.is_admin:
flash('Only administrators may delete tickets.', 'danger')
@@ -1071,6 +1080,15 @@ def bulk_ticket_action():
current_user.full_name, current_user.id)
changed = True
elif action == 'assign_to' and ticket.assigned_to_id != assign_to_id:
target = db.session.get(User, assign_to_id)
if target:
ticket.assigned_to_id = assign_to_id
log_ticket_history(ticket, 'assigned_to',
old_assigned or 'Unassigned',
target.full_name, current_user.id)
changed = True
elif action == 'unassign' and ticket.assigned_to_id is not None:
ticket.assigned_to_id = None
log_ticket_history(ticket, 'assigned_to',
@@ -1095,6 +1113,7 @@ def bulk_ticket_action():
'resolve': 'resolved',
'close': 'closed',
'assign_me': 'assigned to you',
'assign_to': f'assigned to {db.session.get(User, assign_to_id).full_name if assign_to_id else "staff"}',
'unassign': 'unassigned',
}
flash(f'{count} ticket{"s" if count != 1 else ""} {action_labels[action]}.', 'success')