Beispiel #1
0
def install(request):
    form = ReceiptForm(request.DATA)

    if not form.is_valid():
        return Response({'error_message': form.errors}, status=400)

    obj = form.cleaned_data['app']
    type_ = install_type(request, obj)

    if type_ == apps.INSTALL_TYPE_DEVELOPER:
        receipt = install_record(obj, request,
                                 apps.INSTALL_TYPE_DEVELOPER)
    else:
        # The app must be public and if its a premium app, you
        # must have purchased it.
        if not obj.is_public():
            log.info('App not public: %s' % obj.pk)
            return Response('App not public.', status=403)

        if (obj.is_premium() and
            not obj.has_purchased(request.amo_user)):
            # Apps that are premium but have no charge will get an
            # automatic purchase record created. This will ensure that
            # the receipt will work into the future if the price changes.
            if obj.premium and not obj.premium.price.price:
                log.info('Create purchase record: {0}'.format(obj.pk))
                AddonPurchase.objects.get_or_create(addon=obj,
                    user=request.amo_user, type=CONTRIB_NO_CHARGE)
            else:
                log.info('App not purchased: %s' % obj.pk)
                return Response('You have not purchased this app.', status=402)
        receipt = install_record(obj, request, type_)
    record(request, obj)
    return Response({'receipt': receipt}, status=201)
Beispiel #2
0
def install(request):
    form = ReceiptForm(request.DATA)

    if not form.is_valid():
        return Response({'error_message': form.errors}, status=400)

    obj = form.cleaned_data['app']
    type_ = install_type(request, obj)

    if type_ == apps.INSTALL_TYPE_DEVELOPER:
        receipt = install_record(obj, request,
                                 apps.INSTALL_TYPE_DEVELOPER)
    else:
        # The app must be public and if its a premium app, you
        # must have purchased it.
        if not obj.is_public():
            log.info('App not public: %s' % obj.pk)
            return Response('App not public.', status=403)

        if (obj.is_premium() and
            not obj.has_purchased(request.amo_user)):
            # Apps that are premium but have no charge will get an
            # automatic purchase record created. This will ensure that
            # the receipt will work into the future if the price changes.
            if obj.premium and not obj.premium.price.price:
                log.info('Create purchase record: {0}'.format(obj.pk))
                AddonPurchase.objects.get_or_create(addon=obj,
                    user=request.amo_user, type=CONTRIB_NO_CHARGE)
            else:
                log.info('App not purchased: %s' % obj.pk)
                return Response('You have not purchased this app.', status=402)
        receipt = install_record(obj, request, type_)
    record(request, obj)
    return Response({'receipt': receipt}, status=201)
Beispiel #3
0
def install(request):
    request._request.CORS = ['POST']
    form = InstallForm(request.DATA, request=request)

    if form.is_valid():
        app = form.cleaned_data['app']
        type_ = install_type(request, app)

        # Users can't install non-public apps. Developers can though.
        if not app.is_public() and type_ == INSTALL_TYPE_USER:
            log.info('App not public: {0}'.format(app.pk))
            raise PermissionDenied

        if not request.amo_user:
            record(request, app)
        else:
            installed, created = Installed.objects.get_or_create(
                addon=app, user=request.amo_user, install_type=type_)
            record(request, app)
            if not created:
                return Response(status=202)

        return Response(status=201)

    return Response(status=400)
Beispiel #4
0
def install(request):
    request._request.CORS = ['POST']
    form = InstallForm(request.DATA, request=request)

    if form.is_valid():
        app = form.cleaned_data['app']
        type_ = install_type(request, app)

        # Users can't install non-public apps. Developers can though.
        if not app.is_public() and type_ == INSTALL_TYPE_USER:
            log.info('App not public: {0}'.format(app.pk))
            raise PermissionDenied

        if not request.amo_user:
            record(request, app)
        else:
            installed, created = Installed.objects.get_or_create(
                addon=app, user=request.amo_user, install_type=type_)
            record(request, app)
            if not created:
                return Response(status=202)

        return Response(status=201)

    return Response(status=400)
Beispiel #5
0
 def obj_create(self, bundle, request=None, **kwargs):
     bundle.data["receipt"] = self.handle(bundle, request=request, **kwargs)
     record(request, bundle.obj)
     return bundle
Beispiel #6
0
 def obj_create(self, bundle, request=None, **kwargs):
     bundle.data['receipt'] = self.handle(bundle, request=request, **kwargs)
     record(request, bundle.obj)
     return bundle