Example #1
0
 def check_perm(*args, **kwargs):
     if 'report' in kwargs:
         code, resp = GeneralController.check_perms(method=request.method, user=g.user, report=kwargs['report'])
         if code != 200:
             return code, resp
     if 'ticket' in kwargs:
         code, resp = GeneralController.check_perms(method=request.method, user=g.user, ticket=kwargs['ticket'])
         if code != 200:
             return code, resp
     if 'defendant' in kwargs and request.method != 'GET':
         code, resp = GeneralController.check_perms(method=request.method, user=g.user, defendant=kwargs['defendant'])
         if code != 200:
             return code, resp
     return func(*args, **kwargs)
Example #2
0
def bulk_delete(body, user, method):
    """ Delete infos from multiple tickets
    """
    if not body.get('reports') or not body.get('properties'):
        transaction.rollback()
        return 400, {'status': 'Bad Request', 'code': 400, 'message': 'Missing reports or properties in body'}

    try:
        reports = Report.objects.filter(id__in=list(body['reports']))
    except (TypeError, ValueError):
        transaction.rollback()
        return 400, {'status': 'Bad Request', 'code': 400, 'message': 'Invalid report(s) id'}

    for report in reports:
        code, resp = GeneralController.check_perms(method=method, user=user, ticket=report.id)
        if code != 200:
            transaction.rollback()
            return code, resp

    # Update tags
    try:
        if 'tags' in body['properties'] and isinstance(body['properties']['tags'], list):
            for report in reports:
                for tag in body['properties']['tags']:
                    code, resp = remove_tag(report.id, tag['id'])
                    if code != 200:
                        transaction.rollback()
                        return code, resp
    except (KeyError, TypeError, ValueError):
        transaction.rollback()
        return 400, {'status': 'Bad Request', 'code': 400, 'message': 'Invalid or missing tag(s) id'}

    transaction.commit()
    return 200, {'status': 'OK', 'code': 200, 'message': 'Report(s) successfully updated'}
Example #3
0
def bulk_add(body, user, method):
    """ Update multiple reports
    """
    if not body.get('reports') or not body.get('properties'):
        transaction.rollback()
        return 400, {'status': 'Bad Request', 'code': 400, 'message': 'Missing reports or properties in body'}

    try:
        reports = Report.objects.filter(id__in=list(body['reports']))
    except (TypeError, ValueError):
        transaction.rollback()
        return 400, {'status': 'Bad Request', 'code': 400, 'message': 'Invalid report(s) id'}

    for report in reports:
        code, resp = GeneralController.check_perms(method=method, user=user, report=report.id)
        if code != 200:
            transaction.rollback()
            return code, resp

    if 'status' in body['properties'] and body['properties']['status'].lower() not in STATUS:
        transaction.rollback()
        return 400, {'status': 'Bad Request', 'code': 400, 'message': 'Status not supported'}

    # Update tags
    if 'tags' in body['properties'] and isinstance(body['properties']['tags'], list):
        for report in reports:
            for tag in body['properties']['tags']:
                code, resp = add_tag(report.id, tag)
                if code != 200:
                    transaction.rollback()
                    return code, resp

    valid_fields = ['category', 'status', 'ticket']
    properties = {k: v for k, v in body['properties'].iteritems() if k in valid_fields}

    # Update general fields
    for report in reports:
        code, resp = update(report.id, properties, user)
        if code != 200:
            transaction.rollback()
            return code, resp

    transaction.commit()
    return 200, {'status': 'OK', 'code': 200, 'message': 'Report(s) successfully updated'}