示例#1
0
def change_ticket_status():
    userInfo = session.get('userProfile')

    # Fetch all required information from the front end
    ticket_id = request.form.get('ticketid')
    project_id = request.form.get('projectid')
    status = request.form.get('status')
    t_date = DATE

    # Fetch the ticket from the backend by the ticket_id
    ticket = Ticket.query.get(ticket_id)

    # if status changed that record it to ticket_history, notification table and add a comment
    if ticket.t_status != status:
        new_id = db.session.query(func.max(Ticket_history.id))
        if new_id[0][0] == None:
            new_id[0][0] = 0

        ticket_history = Ticket_history(new_id[0][0] + 1, ticket_id,
                                        ticket.users_id, status, t_date,
                                        ticket.t_priority)
        try:
            ticket_history.insert()
        except:
            print(sys.exc_info())
            abort(500)

        project_user = Map_users_proj.query.with_entities(
            Map_users_proj.users_id).filter(
                Map_users_proj.p_id == project_id).all()
        for p in project_user:
            notify = Notification(ticket_id, p, type='update')
            try:
                notify.insert()
            except:
                print(sys.exc_info())
                abort(500)

        comment = "Status changed to " + status
        new_id = db.session.query(func.max(Comment.c_id))
        if new_id[0][0] == None:
            new_id[0][0] = 0

        comment = Comment(new_id[0][0] + 1, ticket_id, userInfo['id'], t_date,
                          comment)
        try:
            comment.insert()
        except:
            print(sys.exc_info())
            abort(500)

    # if updated status = closed than update the close_date in the ticket table
    if ticket.t_status != status and status == "closed":
        ticket.t_close_date = t_date

    # finally update the status in the ticket table
    ticket.t_status = status
    ticket.update()

    return redirect('/ticket-details/' + str(ticket_id))
示例#2
0
def assign_dev_ticket():

    userInfo = session.get('userProfile', 'not set')
    if userInfo['role'] != 'dev':
        abort(401)
    # Fetch the ticket that is to be assigned and assign the developer to it
    ticket = Ticket.query.get(request.form.get('ticket_id'))
    ticket.users_id = request.form.get('user_name')
    ticket.update()

    #insert Ticket History of assign the Devloper
    new_id = db.session.query(func.max(Ticket_history.id))
    if new_id[0][0] == None:
        new_id[0][0] = 0
    ticket_history = Ticket_history(new_id[0][0] + 1, ticket.t_id,
                                    ticket.users_id, ticket.t_status, DATE,
                                    ticket.t_priority)
    try:
        ticket_history.insert()
    except:
        print('error')

    #insert comment of which User assigned the Dev
    userInfo = session.get('userProfile', 'not set')
    user1 = userInfo['id']
    user2 = Users.query.with_entities(
        Users.users_name).filter(Users.users_id == ticket.users_id).one()
    text = user2[0] + ' assigned to this ticket'
    new_id = db.session.query(func.max(Comment.c_id))
    if new_id[0][0] == None:
        new_id[0][0] = 0
    comment = Comment(new_id[0][0] + 1, ticket.t_id, user1, DATE, text)
    try:
        comment.insert()
    except:
        print(sys.exc_info())

    #Insert notification for assignnig the Dev
    notify = Notification(ticket.t_id, ticket.users_id, 'assigned')
    try:
        notify.insert()
    except:
        print(sys.exc_info())

    return redirect('/ticket-details/' + request.form.get('ticket_id'))
示例#3
0
def add_comment():
    ticket_id = request.form.get('ticket_id')
    comment = request.form.get('comment')
    date = DATE
    users_id = Users.query.with_entities(Users.users_id).filter_by(
        users_email=session.get('userProfile')['email'])

    new_id = db.session.query(func.max(Comment.c_id))
    if new_id[0][0] == None:
        new_id[0][0] = 0

    comment = Comment(new_id[0][0] + 1, ticket_id, users_id, date, comment)
    try:
        comment.insert()
    except:
        print(sys.exc_info())
        abort(500)
    return redirect('/ticket-details/' + ticket_id)