Ejemplo n.º 1
0
def campaign_add(request, ctype, objectid):
    """
    Attribute a Campaign to a top-level object. Should be an AJAX POST.

    :param request: Django request object (Required)
    :type request: :class:`django.http.HttpRequest`
    :param ctype: CRITs type for the top-level object.
    :type ctype: str
    :param objectid: The ObjectId of the top-level object.
    :type objectid: str
    :returns: :class:`django.http.HttpResponse`
    """

    if request.method == "POST" and request.is_ajax():
        form = CampaignForm(request.POST)
        result = {}
        if form.is_valid():
            data = form.cleaned_data
            campaign = data["name"]
            confidence = data["confidence"]
            description = data["description"]
            related = data["related"]
            analyst = request.user.username
            result = campaign_addh(ctype, objectid, campaign, confidence, description, related, analyst)
            if result["success"]:
                return HttpResponse(json.dumps(result), mimetype="application/json")
        result["form"] = form.as_table()
        result["success"] = False
        return HttpResponse(json.dumps(result), mimetype="application/json")
    else:
        return HttpResponse(
            json.dumps({"success": False, "message": "Expected AJAX request."}), mimetype="application/json"
        )
Ejemplo n.º 2
0
def campaign_add(request, ctype, objectid):
    """
    Attribute a Campaign to a top-level object. Should be an AJAX POST.

    :param request: Django request object (Required)
    :type request: :class:`django.http.HttpRequest`
    :param ctype: CRITs type for the top-level object.
    :type ctype: str
    :param objectid: The ObjectId of the top-level object.
    :type objectid: str
    :returns: :class:`django.http.HttpResponse`
    """
    user = request.user

    if request.method == "POST" and request.is_ajax():
        form = CampaignForm(request.POST)
        result = {}
        acl = get_acl_object(ctype)

        if user.has_access_to(acl.CAMPAIGNS_ADD):
            if form.is_valid():
                data = form.cleaned_data
                campaign = data['name']
                confidence = data['confidence']
                description = data['description']
                related = data['related']
                analyst = request.user.username
                result = campaign_addh(campaign,
                                       confidence,
                                       description,
                                       related,
                                       analyst,
                                       ctype,
                                       objectid,
                                       update=False)
                if result['success']:
                    return HttpResponse(json.dumps(result),
                                        content_type="application/json")
            result['form'] = form.as_table()
            result['success'] = False
            return HttpResponse(json.dumps(result),
                                content_type="application/json")
        else:
            result['success'] = False
            result[
                'message'] = 'User does not have permission to add campaign to TLO.'
            return HttpResponse(json.dumps(result),
                                content_type="application/json")
    else:
        return HttpResponse(json.dumps({
            'success': False,
            'message': "Expected AJAX request."
        }),
                            content_type="application/json")
Ejemplo n.º 3
0
def campaign_add(request, ctype, objectid):
    """
    Attribute a Campaign to a top-level object. Should be an AJAX POST.

    :param request: Django request object (Required)
    :type request: :class:`django.http.HttpRequest`
    :param ctype: CRITs type for the top-level object.
    :type ctype: str
    :param objectid: The ObjectId of the top-level object.
    :type objectid: str
    :returns: :class:`django.http.HttpResponse`
    """
    user = request.user

    if request.method == "POST" and request.is_ajax():
        form = CampaignForm(request.POST)
        result = {}
        acl = get_acl_object(ctype)

        if user.has_access_to(acl.CAMPAIGNS_ADD):
            if form.is_valid():
                data = form.cleaned_data
                campaign = data['name']
                confidence = data['confidence']
                description = data['description']
                related = data['related']
                analyst= request.user.username
                result = campaign_addh(campaign,
                                       confidence,
                                       description,
                                       related,
                                       analyst,
                                       ctype,
                                       objectid,
                                       update=False)
                if result['success']:
                    return HttpResponse(json.dumps(result),
                                        content_type="application/json")
            result['form'] = form.as_table()
            result['success'] = False
            return HttpResponse(json.dumps(result),
                                content_type="application/json")
        else:
            result['success'] = False
            result['message'] = 'User does not have permission to add campaign to TLO.'
            return HttpResponse(json.dumps(result),
                                content_type="application/json")
    else:
        return HttpResponse(json.dumps({'success': False,
                                        'message': "Expected AJAX request."}),
                            content_type="application/json")