예제 #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 __create__(cls, user, title, message, category, event_uuid, icon=None):
     ''' Create a notification and save it to the database '''
     notification = Notification(
         user_id=user.id,
         event_uuid=event_uuid,
         title=unicode(title),
         message=unicode(message),
         category=category,
     )
     if icon is not None:
         notification.icon = icon
     dbsession.add(notification)
     dbsession.commit()
예제 #3
0
 def __anonymous__(cls, title, message, category, event_uuid, icon=None):
     ''' Creates anonysmous notification where user_id = NULL '''
     notification = Notification(
         user_id=None,
         event_uuid=event_uuid,
         title=unicode(title),
         message=unicode(message),
         category=category,
     )
     if icon is not None:
         notification.icon = icon
     dbsession.add(notification)
     dbsession.commit()
예제 #4
0
def notifyUser(user_id, message):
    """
    How to use this method:
        from socket_events import notifyUser
        notifyUser(1, "sample notification message")
    """
    new_notification = Notification(user_id, message)
    new_notification.save()
    ser_notification = NotificationSchema().dump(new_notification)
    socketid = online_users.get(user_id)
    if socketid:
        emit('new notification',
             ser_notification,
             room=socketid,
             namespace='/')
    return ser_notification
예제 #5
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'))
예제 #6
0
def create_ticket():

    #Get all values from the ticket form
    action = request.form.get('action')
    userInfo = session.get('userProfile')
    t_title = request.form.get('t_title', '')
    t_desc = request.form.get('t_desc', '')
    users_id = 0
    submitter_email = userInfo['email']
    p_id = request.form.get('project')
    t_priority = request.form.get('t_priority', '')
    t_type = request.form.get('t_type', '')
    t_create_date = DATE
    t_close_date = "N/A"

    ticketid = ""
    new_id = db.session.query(func.max(Ticket.t_id))
    if new_id[0][0] == None:
        new_id[0][0] = 0

    # Genrate a new ticket
    if action == 'new':
        ticket = Ticket(new_id[0][0] + 1, t_title, t_desc, users_id,
                        submitter_email, p_id, t_priority, 'open', t_type,
                        t_create_date, t_close_date)
        try:
            ticket.insert()
        except:
            print(sys.exc_info())
            abort(500)

        ticketid = ticket.t_id

        # Add entry to history table
        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,
                                        users_id, 'open', t_create_date,
                                        t_priority)
        try:
            ticket_history.insert()
        except:
            print(sys.exc_info())
            abort(500)

    # Authorize Admin
    if userInfo['role'] == 'admin':

        if action == 'update':
            ticketid = request.form.get('ticketid')
            ticket = Ticket.query.get(ticketid)
            t_date = t_create_date
            t_status = request.form.get('t_status')

            # status/priority changed add to ticket_history table
            if ticket.t_status != t_status or ticket.t_priority != t_priority:
                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, ticketid,
                                                ticket.users_id, t_status,
                                                t_date, t_priority)
                try:
                    ticket_history.insert()
                except:
                    print(sys.exc_info())
                    abort(500)

            # status=closed, update the close_date
            if ticket.t_status != 'closed' and t_status == 'closed':
                ticket.t_close_date = t_create_date

            # update the ticket in the ticket table
            ticket.t_title = t_title
            ticket.t_desc = t_desc
            ticket.t_status = t_status
            ticket.t_priority = t_priority
            ticket.t_status = t_status
            ticket.t_type = t_type

            ticket.update()
            ticketid = ticket.t_id
    else:
        abort(401)

    # Fetch the people in the project
    project_user = Map_users_proj.query.with_entities(
        Map_users_proj.users_id).filter(Map_users_proj.p_id == p_id).all()

    # insert a notification record for each individual
    for p in project_user:
        notify = Notification(ticketid, p, type=action)
        try:
            notify.insert()
        except:
            print(sys.exc_info())
            abort(500)

    # Based on the role redirect to specific view ticket table end point
    if userInfo['role'] == 'dev':
        return redirect(url_for('get_project_tickets'))
    elif userInfo['role'] == 'user':
        return redirect(url_for('get_tickets'))
    elif action == 'update':
        return redirect('/ticket-details/' + str(ticketid))
    elif userInfo['role'] == 'manager':
        return redirect(url_for('get_manager_tickets'))
    elif userInfo['role'] == 'admin':
        return redirect(url_for('get_all_tickets'))
예제 #7
0
 def addNotification(self):
     notification = Notification()
     notification.employee_id = 10
     notification.message = "Fucc a"
     notification.active = "Y"
     print Notification.add(notification)
예제 #8
0
    chef = User(f'chef{i}', f'chef{i}@chef.com', 'p@ssword1')
    chef.isChef = True
    chef.chefCuisine = random.choice(cuisines)
    db.session.add(chef)

#create 10 users
for i in range(1, 11):
    user = User(f'user{i}', f'user{i}@user.com', 'p@ssword1')
    db.session.add(user)

db.session.commit()

# add notifications for first 3 users:
for i in range(1, 4):
    new_notification3 = Notification(
        i, "A reallly really really really long read notification message",
        True)
    new_notification4 = Notification(i, "A read notification message", True)
    new_notification1 = Notification(i, "An unread notification message")
    new_notification2 = Notification(
        i, "A really really really really long unread notification message")
    db.session.add(new_notification1)
    db.session.add(new_notification2)
    db.session.add(new_notification3)
    db.session.add(new_notification4)

#create meal_items for chefs
for i in range(1, 11):
    userId = User.query.filter_by(email=f'chef{i}@chef.com').first().id

    for j in range(1, 11):