Ejemplo n.º 1
0
def user_get_resolved_tickets(rt_object, email):
    config = DITICConfig()

    # Check if user is known...
    if not config.check_if_email_exist(email):
        raise ValueError("Unknown email/user:"******"%s" AND Queue = "general" AND  Status = "resolved"' % (email)

    # Get the information from the server.
    try:
        response = get_list_of_tickets(rt_object, query)
    except NameError as e:
        raise ValueError("Error: " + str(e))

    number_tickets_per_status = {email: len(response)}
    for line in response:
        try:
            auxiliary_date = strptime(line["lastupdated"])
            auxiliary_date = "%02d/%02d" % (auxiliary_date.tm_mon, auxiliary_date.tm_mday)
        except ValueError:
            auxiliary_date = 0
        line["auxiliary_date"] = auxiliary_date
        create_ticket_possible_actions(config, line, email, number_tickets_per_status)
    result = group_result_by(response, "auxiliary_date")

    email_limit = config.get_email_limits(email)

    return {"tickets": result}
Ejemplo n.º 2
0
def search_tickets(rt_object, search):
    """
    Search for tickets that match those criteria.
    The search will focus on those fields:
        - Requestors.EmailAddress
        - Subject
        - cf{servico}
        - cc
        - admincc
        - Requestor.Name
        - Requestor.RealName

    The tickets must be under the following restrictions:
        - Belongs to Queue General
        - Must have "CF.{IS - Informatica e Sistemas}" equal to DIR or DIR-INBOX
        - Must be created or updated on the last 90 days

    :param rt_object: RTApi object
    :param search: the search criteria
    :return:
    """
    config = DITICConfig()

    # Search last 30 days.
    previous_date = (date.today() - timedelta(90)).isoformat()

    # The search string
    query = (
        'Queue = "General" AND ( "CF.{IS - Informatica e Sistemas}" = "DIR" '
        'OR "CF.{IS - Informatica e Sistemas}" = "DIR-INBOX" ) AND '
        '( Lastupdated > "' + previous_date + '" OR Created > "' + previous_date + '") '
        'AND ( Requestor.EmailAddress LIKE "%' + search + '%" '
    )
    for query_items in ["Subject", "cf.{servico}", "cc", "admincc", "Requestor.Name", "Requestor.RealName"]:
        query += ' OR %s LIKE "%%%s%%" ' % (query_items, search)
    query += ")"

    # Get the information from the server.
    try:
        response = get_list_of_tickets(rt_object, query)
    except NameError as e:
        raise ValueError("Error: " + str(e))
    except ValueError:
        return {"no_result": True, "number_tickets": "No results...", "tickets": {}}

    number_tickets = len(response)
    for line in response:
        try:
            auxiliary_date = strptime(line["lastupdated"])
            auxiliary_date = "%02d/%02d" % (auxiliary_date.tm_mon, auxiliary_date.tm_mday)
        except ValueError:
            auxiliary_date = 0
        line["auxiliary_date"] = auxiliary_date
    result = group_result_by(response, "auxiliary_date")

    email_limit = config.get_email_limits(search)

    return {"no_result": False, "tickets": result, "number_tickets": number_tickets, "email_limit": email_limit}
Ejemplo n.º 3
0
def test_get_email_limits_unknown_email():
    test_config = DITICConfig()
    test_config.email_to_user = {
        '*****@*****.**': 'Vapi',
        '*****@*****.**': 'Alex',
    }
    test_config.email_limits = {
        '*****@*****.**': {
            'new': 7,
            'open': 1,
            'rejected': 7,
        }
    }
    response = test_config.get_email_limits('*****@*****.**')
    assert response == {}
Ejemplo n.º 4
0
def user_closed_tickets(rt_object, email):
    """
    Get the closed tickets on the last X days. (X = 60)

    :param rt_object: RTApi object
    :param email: the user email (it must exist in the config)
    :return:
    """
    config = DITICConfig()

    # Check if user is known...
    if not config.check_if_email_exist(email):
        raise ValueError('Unknown email/user:'******'Owner = "%s" AND Queue = "general" AND  Status = "resolved" AND LastUpdated > "%s"' % (
        email, previous_date)

    # Get the information from the server.
    try:
        response = get_list_of_tickets(rt_object, query)

    except NameError as e:
        raise ValueError('Error: ' + str(e))

    number_tickets_per_status = {email: len(response)}
    for line in response:
        try:
            auxiliary_date = strptime(line['lastupdated'])
            auxiliary_date = '%02d/%02d' % (auxiliary_date.tm_mon,
                                            auxiliary_date.tm_mday)
        except ValueError:
            auxiliary_date = 0
        line['auxiliary_date'] = auxiliary_date
        create_ticket_possible_actions(config, line, email,
                                       number_tickets_per_status)
    result = group_result_by(response, 'auxiliary_date')

    email_limit = config.get_email_limits(email)

    return {
        'tickets': result,
        'number_tickets_per_status': number_tickets_per_status,
        'email_limit': email_limit,
    }
Ejemplo n.º 5
0
def user_closed_tickets(rt_object, email):
    """
    Get the closed tickets on the last X days. (X = 60)

    :param rt_object: RTApi object
    :param email: the user email (it must exist in the config)
    :return:
    """
    config = DITICConfig()

    # Check if user is known...
    if not config.check_if_email_exist(email):
        raise ValueError('Unknown email/user:'******'Owner = "%s" AND Queue = "general" AND  Status = "resolved" AND LastUpdated > "%s"' % (email,
                                                                                                    previous_date)

    # Get the information from the server.
    try:
        response = get_list_of_tickets(rt_object, query)
        
    except NameError as e:
        raise ValueError('Error: '+str(e))

    number_tickets_per_status = {email: len(response)}
    for line in response:
        try:
            auxiliary_date = strptime(line['lastupdated'])
            auxiliary_date = '%02d/%02d' % (auxiliary_date.tm_mon, auxiliary_date.tm_mday)
        except ValueError:
            auxiliary_date = 0
        line['auxiliary_date'] = auxiliary_date
        create_ticket_possible_actions(config, line, email, number_tickets_per_status)
    result = group_result_by(response, 'auxiliary_date')

    email_limit = config.get_email_limits(email)

    return {
        'tickets': result,
        'number_tickets_per_status': number_tickets_per_status,
        'email_limit': email_limit,
    }
Ejemplo n.º 6
0
def user_tickets_details(rt_object, email):

    query = 'Owner = "' + email + '" AND Queue = "general" '

    config = DITICConfig()

    # If the user is dir, then build the search
    if email == 'dir':
        query = 'Queue = "general" AND "CF.{IS - Informatica e Sistemas}" = "DIR" AND Owner = "Nobody"  AND ' \
                'Status != "deleted" '

    # If the user is dir-inbox, then search for it
    elif email == 'dir-inbox':
        query = 'Queue = "general" AND "CF.{IS - Informatica e Sistemas}" = "DIR-INBOX" AND Owner = "Nobody"  AND ' \
                'Status != "deleted" '

    # If the user is unknown, then search all users but those that we already know
    elif email == 'unknown':
        query = 'Queue = "general" AND "CF.{IS - Informatica e Sistemas}" LIKE "DIR%"  AND ' \
                'Status != "deleted" '
        for user in config.get_email_to_user().keys():
            query += 'AND Owner != "' + user + '" '
        query += 'AND Owner != "Nobody"'

    # Otherwise, check if user is not known...
    elif not config.check_if_email_exist(email):
        raise ValueError('Unknown email/user:'******' AND Status != "deleted" '

    # Get the information from the server.
    try:
        response = get_list_of_tickets(rt_object, query)
    except ValueError as e:
        response = []

    if email == 'dir' or email == 'dir-inbox' or email == 'unknown':
        number_tickets_per_status = {email: len(response)}
        result = group_result_by(response, 'priority')
        for priority in result:
            for line in result[priority]:
                create_ticket_possible_actions(config, line, email,
                                               number_tickets_per_status)
    else:
        # Get some statistics
        response_grouped_by_status = group_result_by(response, 'status')
        number_tickets_per_status = {}
        for status in response_grouped_by_status:
            number_tickets_per_status[status] = len(
                response_grouped_by_status[status])

        result = {}
        for status in response_grouped_by_status:
            grouped_by_priority = group_result_by(
                response_grouped_by_status[status], 'priority')
            result[status] = grouped_by_priority
            for priority in grouped_by_priority:
                for line in grouped_by_priority[priority]:
                    create_ticket_possible_actions(config, line, email,
                                                   number_tickets_per_status)

    # The user limits...
    email_limit = config.get_email_limits(email)

    return {
        'tickets': result,
        'number_tickets_per_status': number_tickets_per_status,
        'email_limit': email_limit,
    }
Ejemplo n.º 7
0
def search_tickets(rt_object, search):
    """
    Search for tickets that match those criteria.
    The search will focus on those fields:
        - Requestors.EmailAddress
        - Subject
        - cf{servico}
        - cc
        - admincc
        - Requestor.Name
        - Requestor.RealName

    The tickets must be under the following restrictions:
        - Belongs to Queue General
        - Must have "CF.{IS - Informatica e Sistemas}" equal to DIR or DIR-INBOX
        - Must be created or updated on the last 90 days

    :param rt_object: RTApi object
    :param search: the search criteria
    :return:
    """
    config = DITICConfig()

    # Search last 30 days.
    previous_date = (date.today() - timedelta(90)).isoformat()

    # The search string
    query = 'Queue = "General" AND ( "CF.{IS - Informatica e Sistemas}" = "DIR" ' \
            'OR "CF.{IS - Informatica e Sistemas}" = "DIR-INBOX" ) AND ' \
            '( Lastupdated > "'+previous_date+'" OR Created > "'+previous_date+'") ' \
            'AND ( Requestor.EmailAddress LIKE "%'+search+'%" '
    for query_items in [
            'Subject', 'cf.{servico}', 'cc', 'admincc', 'Requestor.Name',
            'Requestor.RealName'
    ]:
        query += ' OR %s LIKE "%%%s%%" ' % (query_items, search)
    query += ')'

    # Get the information from the server.
    try:
        response = get_list_of_tickets(rt_object, query)
    except NameError as e:
        raise ValueError('Error: ' + str(e))
    except ValueError:
        return {
            'no_result': True,
            'number_tickets': 'No results...',
            'tickets': {},
        }

    number_tickets = len(response)
    for line in response:
        try:
            auxiliary_date = strptime(line['lastupdated'])
            auxiliary_date = '%02d/%02d' % (auxiliary_date.tm_mon,
                                            auxiliary_date.tm_mday)
        except ValueError:
            auxiliary_date = 0
        line['auxiliary_date'] = auxiliary_date
    result = group_result_by(response, 'auxiliary_date')

    email_limit = config.get_email_limits(search)

    return {
        'no_result': False,
        'tickets': result,
        'number_tickets': number_tickets,
        'email_limit': email_limit,
    }
Ejemplo n.º 8
0
def user_tickets_details(rt_object, email):

    query = 'Owner = "'+email+'" AND Queue = "general" '

    config = DITICConfig()

    # If the user is dir, then build the search
    if email == 'dir':
        query = 'Queue = "general" AND "CF.{IS - Informatica e Sistemas}" = "DIR" AND Owner = "Nobody"  AND ' \
                'Status != "deleted" '

    # If the user is dir-inbox, then search for it
    elif email == 'dir-inbox':
        query = 'Queue = "general" AND "CF.{IS - Informatica e Sistemas}" = "DIR-INBOX" AND Owner = "Nobody"  AND ' \
                'Status != "deleted" '

    # If the user is unknown, then search all users but those that we already know
    elif email == 'unknown':
        query = 'Queue = "general" AND "CF.{IS - Informatica e Sistemas}" LIKE "DIR%"  AND ' \
                'Status != "deleted" '
        for user in config.get_email_to_user().keys():
            query += 'AND Owner != "'+user+'" '
        query += 'AND Owner != "Nobody"'

    # Otherwise, check if user is not known...
    elif not config.check_if_email_exist(email):
        raise ValueError('Unknown email/user:'******' AND Status != "deleted" '

    # Get the information from the server.
    try:
        response = get_list_of_tickets(rt_object, query)
    except ValueError as e:
        response = []

    if email == 'dir' or email == 'dir-inbox' or email == 'unknown':
        number_tickets_per_status = {email: len(response)}
        result = group_result_by(response, 'priority')
        for priority in result:
            for line in result[priority]:
                create_ticket_possible_actions(config, line, email, number_tickets_per_status)
    else:
        # Get some statistics
        response_grouped_by_status = group_result_by(response, 'status')
        number_tickets_per_status = {}
        for status in response_grouped_by_status:
            number_tickets_per_status[status] = len(response_grouped_by_status[status])

        result = {}
        for status in response_grouped_by_status:
            grouped_by_priority = group_result_by(response_grouped_by_status[status], 'priority')
            result[status] = grouped_by_priority
            for priority in grouped_by_priority:
                for line in grouped_by_priority[priority]:
                    create_ticket_possible_actions(config, line, email, number_tickets_per_status)

    # The user limits...
    email_limit = config.get_email_limits(email)

    return {
        'tickets': result,
        'number_tickets_per_status': number_tickets_per_status,
        'email_limit': email_limit,
    }
Ejemplo n.º 9
0
def search_tickets(rt_object, search):
    """
    Search for tickets that match those criteria.
    The search will focus on those fields:
        - Requestors.EmailAddress
        - Subject
        - cf{servico}
        - cc
        - admincc
        - Requestor.Name
        - Requestor.RealName

    The tickets must be under the following restrictions:
        - Belongs to Queue General
        - Must have "CF.{IS - Informatica e Sistemas}" equal to DIR or DIR-INBOX
        - Must be created or updated on the last 90 days

    :param rt_object: RTApi object
    :param search: the search criteria
    :return:
    """
    config = DITICConfig()

    # Search last 30 days.
    previous_date = (date.today() - timedelta(90)).isoformat()

    # The search string
    query = 'Queue = "General" AND ( "CF.{IS - Informatica e Sistemas}" = "DIR" ' \
            'OR "CF.{IS - Informatica e Sistemas}" = "DIR-INBOX" ) AND ' \
            '( Lastupdated > "'+previous_date+'" OR Created > "'+previous_date+'") ' \
            'AND ( Requestor.EmailAddress LIKE "%'+search+'%" '
    for query_items in ['Subject', 'cf.{servico}', 'cc', 'admincc', 'Requestor.Name', 'Requestor.RealName']:
        query += ' OR %s LIKE "%%%s%%" ' % (query_items, search)
    query += ')'

    # Get the information from the server.
    try:
        response = get_list_of_tickets(rt_object, query)
    except NameError as e:
        raise ValueError('Error: '+str(e))
    except ValueError:
        return {
            'no_result': True,
            'number_tickets': 'No results...',
            'tickets': {},
        }

    number_tickets = len(response)
    for line in response:
        try:
            auxiliary_date = strptime(line['lastupdated'])
            auxiliary_date = '%02d/%02d' % (auxiliary_date.tm_mon, auxiliary_date.tm_mday)
        except ValueError:
            auxiliary_date = 0
        line['auxiliary_date'] = auxiliary_date
    result = group_result_by(response, 'auxiliary_date')

    email_limit = config.get_email_limits(search)

    return {
        'no_result': False,
        'tickets': result,
        'number_tickets': number_tickets,
        'email_limit': email_limit,
    }