def change_status(ticket_id, status): ticket = FlicketTicket.query.filter_by(id=ticket_id).first() closed = FlicketStatus.query.filter_by(status=status).first() # Check to see if user is authorised to close ticket. edit = False if ticket.user == g.user: edit = True if ticket.assigned == g.user: edit = True if g.user.is_admin: edit = True if not edit: flash( gettext( "Only the person to which the ticket has been assigned, creator or Admin can close this ticket." ), category="warning", ) return redirect(url_for("flicket_bp.ticket_view", ticket_id=ticket_id)) # Check to see if the ticket is already closed. if ticket.current_status.status == "Closed": flash(gettext("Ticket is already closed."), category="warning") return redirect(url_for("flicket_bp.ticket_view", ticket_id=ticket.id)) f_mail = FlicketMail() f_mail.close_ticket(ticket) # add action record add_action(ticket, "close") ticket.current_status = closed ticket.assigned_id = None db.session.commit() flash( gettext("Ticket %(value)s closed.", value=str(ticket_id).zfill(5)), category="success", ) return redirect(url_for("flicket_bp.tickets"))
def change_status(ticket_id, status): ticket = FlicketTicket.query.filter_by(id=ticket_id).first() closed = FlicketStatus.query.filter_by(status=status).first() # Check to see if user is authorised to close ticket. edit = False if ticket.user == g.user: edit = True if ticket.assigned == g.user: edit = True if g.user.is_admin: edit = True if not edit: flash(gettext( 'Only the person to which the ticket has been assigned, creator or Admin can close this ticket.' ), category='warning') return redirect(url_for('flicket_bp.ticket_view', ticket_id=ticket_id)) # Check to see if the ticket is already closed. if ticket.current_status.status == 'Closed': flash(gettext('Ticket is already closed.'), category='warning') return redirect(url_for('flicket_bp.ticket_view', ticket_id=ticket.id)) f_mail = FlicketMail() f_mail.close_ticket(ticket) # add action record add_action(ticket, 'close') ticket.current_status = closed ticket.assigned_id = None ticket.last_updated = datetime.datetime.now() db.session.commit() flash(gettext('Ticket %(value)s closed.', value=str(ticket_id).zfill(5)), category='success') return redirect(url_for('flicket_bp.tickets'))