示例#1
0
文件: tools.py 项目: FranciscoMSM/ES
def archive_tickets(rt_object, ticket_id, ticket_email, user_email):
    """
    In this function we will apply the ticket action requested by user.
    It is possible to change the ticket priority, owner, etc.

    :param rt_object: rt object for querying (must be users authenticated)
    :param ticket_id: The ticket we want to see possible actions
    :param ticket_email: The ticket owner (we need this because of the special user dir, dir-inbox and unknown)
    :param user_email: the user email who is requesting this action (we need this to take a ticket)
    :return: RT result (I think we must change this output!)
    """
    # First of all, get the actual ticket information
    query = 'id = "%s"' % ticket_id

    # Get the information from the server.
    try:
        ticket_line = get_list_of_tickets(rt_object, query)[0]
    except NameError as e:
        return "Error:" + str(e)

    # There is so much to be done. So this is the default answer.
    result = "Still working on it... sorry for the inconvenience!"

    # INCREASE PRIORITY ##############################
    result = modify_ticket(rt_object, ticket_id, {"status": "archived"})

    dictReturn = {"archive_result": result}

    return dictReturn
示例#2
0
def archive_ticket(ticket_id,action):
	start_time = time()

	result = create_default_result()
	if request.query.o == '' or not user_auth.check_id(request.query.o):
		result.update({'message': ''})
		return template('auth', result)

	# Apply the action to the ticket
	result.update(ticket_actions(
		user_auth.get_rt_object_from_email(
		    user_auth.get_email_from_id(request.query.o)
		),
		ticket_id,
		action,
		request.query.email, user_auth.get_email_from_id(request.query.o)
	))

	# Update table for this user
	result.update(user_tickets_details(
		user_auth.get_rt_object_from_email(
		    user_auth.get_email_from_id(request.query.o)
		), request.query.email))

	result.update({'username': user_auth.get_email_from_id(request.query.o)})
	result.update({'email': request.query.email})
	result.update({'username_id': request.query.o})

	# Is there any URGENT ticket?
	result.update({'urgent': get_urgent_tickets(rt_object)})

	result.update({'time_spent': '%0.2f seconds' % (time() - start_time)})


	modify_ticket(
			rt_object,
			ticket_id,
			{
				'status': 'archived',
				
			}
		)

	return template('history', result)
示例#3
0
def justificacao_2(ticket_id,username_id,username):
	comment_ticket = {
		'id': ticket_id,
		'Action': "comment",
		'Text': request.forms.get('justificacao'),
	}
	content = ''
	for key in comment_ticket:
		content += '{0}: {1}\n'.format(key,comment_ticket[key])
	query = {
		'content':content
	}
	rt_object.get_data_from_rest('/ticket/'+ticket_id+'/comment', query)
	
	modify_ticket(
			rt_object,
			ticket_id,
			{
				'status': 'resolved',
				
			}
		)

	redirect("/detail/"+username+"?o="+username_id)
示例#4
0
def ticket_actions(rt_object, ticket_id, action, ticket_email, user_email):
    """
    In this function we will apply the ticket action requested by user.
    It is possible to change the ticket priority, owner, etc.

    :param rt_object: rt object for querying (must be users authenticated)
    :param ticket_id: The ticket we want to see possible actions
    :param action: the action requested.
    :param ticket_email: The ticket owner (we need this because of the special user dir, dir-inbox and unknown)
    :param user_email: the user email who is requesting this action (we need this to take a ticket)
    :return: RT result (I think we must change this output!)
    """
    # First of all, get the actual ticket information
    query = 'id = "%s"' % ticket_id

    # Get the information from the server.
    try:
        ticket_line = get_list_of_tickets(rt_object, query)[0]
    except NameError as e:
        return 'Error:' + str(e)

    # There is so much to be done. So this is the default answer.
    result = 'Still working on it... sorry for the inconvenience!'

    # INCREASE PRIORITY ##############################
    if action == 'increase_priority':
        result = modify_ticket(
            rt_object, ticket_id,
            {'priority': str(int(ticket_line['priority']) + 1)})

    # DECREASE PRIORITY ##############################
    elif action == 'decrease_priority':
        result = modify_ticket(
            rt_object, ticket_id,
            {'priority': str(int(ticket_line['priority']) - 1)})

    # BACK ##############################
    elif action == 'back':
        if ticket_email == 'dir-inbox':
            result = modify_ticket(rt_object, ticket_id, {
                'cf.{is - informatica e sistemas}': 'dir',
            })
        elif ticket_line['status'] == 'new':
            result = modify_ticket(
                rt_object, ticket_id, {
                    'owner': 'nobody',
                    'cf.{is - informatica e sistemas}': 'dir-inbox',
                })
        elif ticket_line['status'] == 'open':
            result = modify_ticket(
                rt_object, ticket_id, {
                    'timeworked':
                    calculate_time_worked(ticket_line) + ' minutes',
                    'starts': '0',
                    'status': 'new',
                    'cf.{is - informatica e sistemas}': 'in',
                })
        elif ticket_line['status'] == 'stalled':
            result = modify_ticket(
                rt_object, ticket_id, {
                    'starts': ctime(time()),
                    'status': 'new',
                    'cf.{is - informatica e sistemas}': 'in',
                })

    # FORWARD ##############################
    elif action == 'forward':
        if ticket_email == 'dir':
            result = modify_ticket(
                rt_object, ticket_id, {
                    'cf.{is - informatica e sistemas}': 'dir-inbox',
                })
        elif ticket_line['status'] == 'new':
            result = modify_ticket(
                rt_object, ticket_id, {
                    'starts': ctime(time()),
                    'status': 'open',
                    'cf.{is - informatica e sistemas}': 'active',
                })
        elif ticket_line['status'] == 'open':
            print "status open, action forward"
            result = modify_ticket(
                rt_object, ticket_id, {
                    'timeworked':
                    calculate_time_worked(ticket_line) + ' minutes',
                    'starts': '0',
                    'status': 'resolved',
                    'cf.{is - informatica e sistemas}': 'done',
                })

    # STALLED ##############################
    elif action == 'stalled':
        if ticket_line['status'] == 'open':
            result = modify_ticket(
                rt_object, ticket_id, {
                    'timeworked':
                    calculate_time_worked(ticket_line) + ' minutes',
                    'starts': '0',
                    'status': 'stalled',
                    'cf.{is - informatica e sistemas}': 'stalled',
                })

    # TAKE ##############################
    elif action == 'take':
        result = modify_ticket(
            rt_object, ticket_id, {
                'owner': user_email,
                'status': 'new',
                'cf.{is - informatica e sistemas}': 'in',
            })

    # URGENT ##############################
    elif action == 'set_urgent':
        result = modify_ticket(rt_object, ticket_id, {
            'cf.{DITIC-Urgent}': 'yes',
        })
    elif action == 'unset_urgent':
        result = modify_ticket(rt_object, ticket_id, {
            'cf.{DITIC-Urgent}': 'no',
        })

    # Interrupted ##############################
    elif action == 'interrupted':
        if ticket_line['cf.{ditic-interrupted}']:
            interrupted = int(ticket_line['cf.{ditic-interrupted}']) + 1
        else:
            interrupted = 1
        result = modify_ticket(rt_object, ticket_id, {
            'cf.{DITIC-Interrupted}': str(interrupted),
        })
        return ticket_actions(rt_object, ticket_id, 'back', ticket_email,
                              user_email)

    return {'action_result': result}
示例#5
0
def ticket_actions(rt_object, ticket_id, action, ticket_email, user_email):
    """
    In this function we will apply the ticket action requested by user.
    It is possible to change the ticket priority, owner, etc.

    :param rt_object: rt object for querying (must be users authenticated)
    :param ticket_id: The ticket we want to see possible actions
    :param action: the action requested.
    :param ticket_email: The ticket owner (we need this because of the special user dir, dir-inbox and unknown)
    :param user_email: the user email who is requesting this action (we need this to take a ticket)
    :return: RT result (I think we must change this output!)
    """
    # First of all, get the actual ticket information
    query = 'id = "%s"' % ticket_id

    # Get the information from the server.
    try:
        ticket_line = get_list_of_tickets(rt_object, query)[0]
    except NameError as e:
        return 'Error:'+str(e)

    # There is so much to be done. So this is the default answer.
    result = 'Still working on it... sorry for the inconvenience!'

    # INCREASE PRIORITY ##############################
    if action == 'increase_priority':
        result = modify_ticket(
            rt_object,
            ticket_id,
            {
                'priority': str(int(ticket_line['priority']) + 1)
            }
        )

    # DECREASE PRIORITY ##############################
    elif action == 'decrease_priority':
        result = modify_ticket(
            rt_object,
            ticket_id,
            {
                'priority': str(int(ticket_line['priority']) - 1)
            }
        )

    # BACK ##############################
    elif action == 'back':
        if ticket_email == 'dir-inbox':
            result = modify_ticket(
                rt_object,
                ticket_id,
                {
                    'cf.{is - informatica e sistemas}': 'dir',
                }
            )
        elif ticket_line['status'] == 'new':
            result = modify_ticket(
                rt_object,
                ticket_id,
                {
                    'owner': 'nobody',
                    'cf.{is - informatica e sistemas}': 'dir-inbox',
                }
            )
        elif ticket_line['status'] == 'open':
            result = modify_ticket(
                rt_object,
                ticket_id,
                {
                    'timeworked': calculate_time_worked(ticket_line) + ' minutes',
                    'starts': '0',
                    'status': 'new',
                    'cf.{is - informatica e sistemas}': 'in',
                }
            )
        elif ticket_line['status'] == 'stalled':
            result = modify_ticket(
                rt_object,
                ticket_id,
                {
                    'starts': ctime(time()),
                    'status': 'new',
                    'cf.{is - informatica e sistemas}': 'in',
                }
            )

    # FORWARD ##############################
    elif action == 'forward':
        if ticket_email == 'dir':
            result = modify_ticket(
                rt_object,
                ticket_id,
                {
                    'cf.{is - informatica e sistemas}': 'dir-inbox',
                }
            )
        elif ticket_line['status'] == 'new':
            result = modify_ticket(
                rt_object,
                ticket_id,
                {
                    'starts': ctime(time()),
                    'status': 'open',
                    'cf.{is - informatica e sistemas}': 'active',
                }
            )
        elif ticket_line['status'] == 'open':
            print "status open, action forward"
            result = modify_ticket(
                rt_object,
                ticket_id,
                {
                    'timeworked': calculate_time_worked(ticket_line) + ' minutes',
                    'starts': '0',
                    'status': 'resolved',
                    'cf.{is - informatica e sistemas}': 'done',
                }
            )

    # STALLED ##############################
    elif action == 'stalled':
        if ticket_line['status'] == 'open':
            result = modify_ticket(
                rt_object,
                ticket_id,
                {
                    'timeworked': calculate_time_worked(ticket_line) + ' minutes',
                    'starts': '0',
                    'status': 'stalled',
                    'cf.{is - informatica e sistemas}': 'stalled',
                }
            )

    # TAKE ##############################
    elif action == 'take':
        result = modify_ticket(
            rt_object,
            ticket_id,
            {
                'owner': user_email,
                'status': 'new',
                'cf.{is - informatica e sistemas}': 'in',
            }
        )

    # URGENT ##############################
    elif action == 'set_urgent':
        result = modify_ticket(
            rt_object,
            ticket_id,
            {
                'cf.{DITIC-Urgent}': 'yes',
            }
        )
    elif action == 'unset_urgent':
        result = modify_ticket(
            rt_object,
            ticket_id,
            {
                'cf.{DITIC-Urgent}': 'no',
            }
        )


    # Interrupted ##############################
    elif action == 'interrupted':
        if ticket_line['cf.{ditic-interrupted}']:
            interrupted = int(ticket_line['cf.{ditic-interrupted}']) + 1
        else:
            interrupted = 1
        result = modify_ticket(
            rt_object,
            ticket_id,
            {
                'cf.{DITIC-Interrupted}': str(interrupted),
            }
        )
        return ticket_actions(rt_object, ticket_id, 'back', ticket_email, user_email)

    return {
        'action_result': result
    }
示例#6
0
文件: tools.py 项目: FranciscoMSM/ES
def ticket_actions(rt_object, ticket_id, action, ticket_email, user_email):
    """
    In this function we will apply the ticket action requested by user.
    It is possible to change the ticket priority, owner, etc.

    :param rt_object: rt object for querying (must be users authenticated)
    :param ticket_id: The ticket we want to see possible actions
    :param action: the action requested.
    :param ticket_email: The ticket owner (we need this because of the special user dir, dir-inbox and unknown)
    :param user_email: the user email who is requesting this action (we need this to take a ticket)
    :return: RT result (I think we must change this output!)
    """
    # First of all, get the actual ticket information
    query = 'id = "%s"' % ticket_id

    # Get the information from the server.
    try:
        ticket_line = get_list_of_tickets(rt_object, query)[0]
    except NameError as e:
        return "Error:" + str(e)

    # There is so much to be done. So this is the default answer.
    result = "Still working on it... sorry for the inconvenience!"

    # INCREASE PRIORITY ##############################
    if action == "increase_priority":
        result = modify_ticket(rt_object, ticket_id, {"priority": str(int(ticket_line["priority"]) + 1)})

    # DECREASE PRIORITY ##############################
    elif action == "decrease_priority":
        result = modify_ticket(rt_object, ticket_id, {"priority": str(int(ticket_line["priority"]) - 1)})

    # BACK ##############################
    elif action == "back":
        if ticket_email == "dir-inbox":
            result = modify_ticket(rt_object, ticket_id, {"cf.{is - informatica e sistemas}": "dir"})
        elif ticket_line["status"] == "new":
            result = modify_ticket(
                rt_object, ticket_id, {"owner": "nobody", "cf.{is - informatica e sistemas}": "dir-inbox"}
            )
        elif ticket_line["status"] == "open":
            result = modify_ticket(
                rt_object,
                ticket_id,
                {"timeworked": calculate_time_worked(ticket_line) + " minutes", "starts": "0", "status": "new"},
            )
        elif ticket_line["status"] == "rejected":
            result = modify_ticket(rt_object, ticket_id, {"starts": ctime(time()), "status": "open"})
        elif ticket_line["status"] == "stalled":
            result = modify_ticket(rt_object, ticket_id, {"starts": ctime(time()), "status": "open"})
        elif ticket_line["status"] == "resolved":
            result = modify_ticket(rt_object, ticket_id, {"starts": ctime(time()), "status": "open"})

    # FORWARD ##############################
    elif action == "forward":
        if ticket_email == "dir":
            result = modify_ticket(rt_object, ticket_id, {"cf.{is - informatica e sistemas}": "dir-inbox"})
        elif ticket_line["status"] == "new":
            result = modify_ticket(rt_object, ticket_id, {"starts": ctime(time()), "status": "open"})
        elif ticket_line["status"] == "open":
            result = modify_ticket(
                rt_object,
                ticket_id,
                {"timeworked": calculate_time_worked(ticket_line) + " minutes", "starts": "0", "status": "resolved"},
            )
        elif ticket_line["status"] == "resolved":
            result = modify_ticket(rt_object, ticket_id, {"status": "archived"})

    # STALLED ##############################
    elif action == "stalled":
        if ticket_line["status"] == "open":
            result = modify_ticket(
                rt_object,
                ticket_id,
                {"timeworked": calculate_time_worked(ticket_line) + " minutes", "starts": "0", "status": "stalled"},
            )

    # TAKE ##############################
    elif action == "take":
        result = modify_ticket(rt_object, ticket_id, {"owner": user_email, "status": "new"})

    # URGENT ##############################
    elif action == "set_urgent":
        result = modify_ticket(rt_object, ticket_id, {"cf.{DITIC-Urgent}": "yes"})
    elif action == "unset_urgent":
        result = modify_ticket(rt_object, ticket_id, {"cf.{DITIC-Urgent}": ""})

    # Interrupted ##############################
    elif action == "interrupt":
        print "Interrupt!"
        a = datetime.datetime.now()
        if ticket_line["cf.{ditic-interrupted}"]:
            interrupted = int(ticket_line["cf.{ditic-interrupted}"]) + 1
        else:
            interrupted = 1
        result = modify_ticket(
            rt_object,
            ticket_id,
            {
                "cf.{DITIC-Interrupted}": str(interrupted),
                "cf.{DITIC-interrupted-time}": "%s %s %s %s %s %s"
                % (a.year, a.month, a.day, a.hour, a.minute, a.second),
            },
        )
    elif action == "back_interrupt":
        print "BackInterrupt!-> %s" % ticket_line["cf.{ditic-interrupted-time}"]
        if ticket_line["cf.{ditic-interrupted}"]:
            interrupted = int(ticket_line["cf.{ditic-interrupted}"]) + 1

        tempo = calculaTempo(ticket_line["cf.{ditic-total-interrupt}"], ticket_line["cf.{ditic-interrupted-time}"])
        result = modify_ticket(
            rt_object, ticket_id, {"cf.{DITIC-Interrupted}": str(interrupted), "cf.{DITIC-total-interrupt}": tempo}
        )
        # return ticket_actions(rt_object, ticket_id, 'back', ticket_email, user_email)

    return {"action_result": result}
示例#7
0
def test_modify_ticket():
    rt_object = RTApiMock()
    rt_object.set_return([u'rt/4.0.6 200 ok', u'', u'# ticket 887677 updated.', u''])
    result = modify_ticket(rt_object, '881188', {'Owner': '*****@*****.**'})
    assert result == [u'rt/4.0.6 200 ok', u'', u'# ticket 887677 updated.', u'']