Exemple #1
0
def bulk_add_tickets():
    """ Bulk add on tickets
    """
    body = request.get_json()
    if request.method == 'PUT':
        code, resp = TicketsController.bulk_update(body, g.user, request.method)
    else:
        code, resp = TicketsController.bulk_delete(body, g.user, request.method)
    return code, resp
Exemple #2
0
def update_ticket_proof(ticket=None, proof=None):
    """ Update ticket proof
    """
    if request.method == 'PUT':
        body = request.get_json()
        code, resp = TicketsController.update_proof(ticket, proof, body, g.user)
    else:
        code, resp = TicketsController.delete_proof(ticket, proof, g.user)
    return code, resp
Exemple #3
0
def get_ticket_proof(ticket=None):
    """ Get all proof for a given ticket
    """
    if request.method == 'GET':
        code, resp = TicketsController.get_proof(ticket)
    else:
        body = request.get_json()
        code, resp = TicketsController.add_proof(ticket, body, g.user)
    return code, resp
Exemple #4
0
def get_tickets():
    """ Get all abuse tickets

        Filtering is possible through "filters" query string, JSON double encoded format
    """
    if 'filters' in request.args:
        code, resp, nb_tickets = TicketsController.index(filters=request.args['filters'], user=g.user)
    else:
        code, resp, nb_tickets = TicketsController.index(user=g.user)
    return code, resp
Exemple #5
0
def get_user_tickets():
    """ Get abuse tickets for logged g.user

        Filtering is possible through "filters" query string, JSON double encoded format
    """
    if 'filters' in request.args:
        code, resp, nb_tickets = TicketsController.index(filters=request.args['filters'], treated_by=g.user.id, user=g.user)
    else:
        code, resp, nb_tickets = TicketsController.index(treated_by=g.user.id, user=g.user)
    return code, resp
def _update_status(body, report, user):
    """
        Update report status
    """
    if body['status'].lower() not in STATUS:
        return 400, {'status': 'Bad Request', 'code': 400, 'message': 'Invalid status'}

    # Detach report if requested status is "New"
    # If status in ['attached', 'validated'], try to attach to existing ticket
    #
    if body['status'].lower() == 'new':
        if report.ticket and report.ticket.reportTicket.count() == 1:  # Close corresponding ticket
            ticket = Ticket.objects.get(id=report.ticket.id)
            ticket.status = 'Closed'
            ticket.save()
        body['ticket'] = None
        report.status = 'New'
        report.save()
    elif report.status.lower() == 'tovalidate' and body['status'].lower() == 'attached':
        report.status = 'Attached'
        report.save()
        utils.email_queue.enqueue(
            'report.reparse_validated',
            report_id=report.id,
            user_id=user.id,
        )
        return 201, {'status': 'OK', 'code': 201, 'message': 'Report successfully updated'}
    elif body['status'].lower() == 'attached' and not report.ticket and all((report.category, report.defendant, report.service)):
        return TicketsController.create(body, user)

    return 200, body
def search(**kwargs):
    """ Global Search
    """
    filters = {}
    user = kwargs['user']

    if 'filters' in kwargs:
        try:
            filters = json.loads(unquote(unquote(kwargs['filters'])))
        except (ValueError, SyntaxError):
            return 400, {'status': 'Bad Request', 'code': 400, 'message': 'Unable to decode JSON'}

    custom_filters = {
        'ticket': {
            'fields': SEARCH_TICKET_FIELDS,
            'filters': deepcopy(filters),
        },
        'report': {
            'fields': SEARCH_REPORT_FIELDS,
            'filters': deepcopy(filters),
        },
    }

    try:
        for _, values in custom_filters.iteritems():
            for key, val in filters.iteritems():
                if key == 'queryFields':
                    values['filters'][key] = [q for q in val if q in values['fields']]
                if key == 'sortBy':
                    values['filters'][key] = {k: v for k, v in filters[key].iteritems() if k in values['fields']}
                if key == 'where':
                    for key2 in filters[key].keys():
                        values['filters'][key][key2] = [a for a in filters[key][key2] if a.keys()[0] in values['fields']]
    except AttributeError:
        return 400, {'status': 'Bad Request', 'code': 400, 'message': 'Invalid fields in body'}

    for _, values in custom_filters.iteritems():
        if 'where' in values['filters']:
            new_where = deepcopy(values['filters']['where'])
            for key, val in values['filters']['where'].iteritems():
                for field in values['filters']['where'][key]:
                    if field.keys()[0] in SEARCH_MAPPING:
                        for new_field in SEARCH_MAPPING[field.keys()[0]]:
                            new_where[key].append({new_field: field[field.keys()[0]]})
                        new_where[key].remove(field)
                    elif 'ticketTag' in field:
                        if Tag.objects.filter(name__in=field['ticketTag'], tagType='Report').count():
                            new_where[key].append({'reportsTag': field['ticketTag']})
                        else:
                            new_where[key].append({'ticketsTag': field['ticketTag']})
                        new_where[key].remove(field)
            values['filters']['where'] = new_where

    from api.controllers import ReportsController, TicketsController
    code1, reps, nb_reps = ReportsController.index(filters=json.dumps(custom_filters['report']['filters']), user=user)
    code2, ticks, nb_ticks = TicketsController.index(filters=json.dumps(custom_filters['ticket']['filters']), user=user)

    code = code1 if code1 > code2 else code2
    return code, {'tickets': ticks, 'reports': reps, 'ticketsCount': nb_ticks, 'reportsCount': nb_reps}
Exemple #8
0
def get_ticket_attachment(ticket=None, attachment=None):
    """ Get `abuse.models.Ticket`'s `abuse.models.AttachedDocument`
    """
    code, resp = TicketsController.get_attachment(ticket, attachment)
    if code != 200:
        return make_response(json.dumps(resp), code, {'content-type': 'application/json'})

    bytes_io = BytesIO(resp['raw'])
    return send_file(bytes_io, attachment_filename=resp['filename'], mimetype=resp['filetype'], as_attachment=True)
Exemple #9
0
def schedule_job(ticket=None):
    """
        Schedule action
    """
    body = request.get_json()
    if not body.get('action') or not body.get('delay'):
        return 400, {'status': 'Bad Request', 'code': 400, 'message': 'Missing action or delay in body'}
    code, resp = TicketsController.schedule_asynchronous_job(ticket, body.get('action'), g.user, body.get('delay'))
    return code, resp
Exemple #10
0
def update_status(ticket=None, status=None):
    """ Update ticket status
    """
    if status and status.lower() == 'closed':
        return 400, {'status': 'Bad Request', 'code': 400, 'message': 'To close ticket, please use Interact'}

    body = request.get_json()
    code, resp = TicketsController.update_status(ticket, status, body, g.user)
    return code, resp
Exemple #11
0
def get_todo_tickets():
    """ Get all abuse todo tickets
    """
    code, resp = TicketsController.get_todo_tickets(filters=request.args.get('filters'), user=g.user)
    return code, resp
Exemple #12
0
def create_ticket():
    """ Post a new ticket
    """
    body = request.get_json()
    code, resp = TicketsController.create(body, g.user)
    return code, resp
Exemple #13
0
def get_timeline(ticket=None):
    """ Get ticket's timeline
    """
    code, resp = TicketsController.get_timeline(ticket, filters=request.args.get('filters'))
    return code, resp
Exemple #14
0
def update_ticket(ticket=None):
    """ Update an existing ticket
    """
    body = request.get_json()
    code, resp = TicketsController.update(ticket, body, g.user)
    return code, resp
Exemple #15
0
def get_providers(ticket=None):
    """ Get ticket's providers
    """
    code, resp = TicketsController.get_providers(ticket)
    return code, resp
Exemple #16
0
def get_mails(ticket=None):
    """ Get all emails sent and received for this ticket
    """
    code, resp = TicketsController.get_emails(ticket)
    return code, resp
Exemple #17
0
def update_ticket_pause(ticket=None):
    """ Update ticket pauseDuration
    """
    body = request.get_json()
    code, resp = TicketsController.update_pause_duration(ticket, body, g.user)
    return code, resp
Exemple #18
0
def interact(ticket=None):
    """ Magic endpoint to save operator's time
    """
    body = request.get_json()
    code, resp = TicketsController.interact(ticket, body, g.user)
    return code, resp
Exemple #19
0
def delete_ticket_tag(ticket=None, tag=None):
    """ Remove ticket tag
    """
    code, resp = TicketsController.remove_tag(ticket, tag, g.user)
    return code, resp
Exemple #20
0
def add_ticket_tag(ticket=None):
    """ Add tag to ticket
    """
    body = request.get_json()
    code, resp = TicketsController.add_tag(ticket, body, g.user)
    return code, resp
Exemple #21
0
def get_ticket(ticket=None):
    """ Get a given ticket
    """
    code, resp = TicketsController.show(ticket, g.user)
    return code, resp
Exemple #22
0
def cancel_job(ticket=None, job=None):
    """
        Cancel action
    """
    code, resp = TicketsController.cancel_asynchronous_job(ticket, job, g.user)
    return code, resp
Exemple #23
0
def get_actions(ticket=None):
    """
        List all available actions
    """
    code, resp = TicketsController.get_actions_list(ticket, g.user)
    return code, resp
Exemple #24
0
def update_ticket_defendant(ticket=None):
    """ Update ticket defendant
    """
    body = request.get_json()
    code, resp = TicketsController.update(ticket, body, g.user)
    return code, resp
Exemple #25
0
def get_ticket_priorities():
    """ Get list of ticket priorities
    """
    return 200, TicketsController.get_priorities()
Exemple #26
0
def get_jobs(ticket=None):
    """
        Get actions status
    """
    code, resp = TicketsController.get_jobs_status(ticket)
    return code, resp