def record(request, addon): is_dev = request.check_ownership(addon, require_owner=False, ignore_disabled=True) if (not (addon.is_public() or acl.check_reviewer(request) or is_dev or not addon.is_webapp())): raise http.Http404 if addon.is_premium() and not addon.has_purchased(request.amo_user): return http.HttpResponseForbidden() installed, c = Installed.objects.safer_get_or_create(addon=addon, user=request.amo_user) send_request('install', request, { 'app-domain': addon.domain_from_url(addon.origin), 'app-id': addon.pk}) # Look up to see if its in the receipt cache and log if we have # to recreate it. receipt = memoize_get('create-receipt', installed.pk) error = '' cef(request, addon, 'request', 'Receipt requested') if not receipt: cef(request, addon, 'sign', 'Receipt signing') try: receipt = create_receipt(installed.pk) except SigningError: error = _('There was a problem installing the app.') return {'addon': addon.pk, 'receipt': receipt, 'error': error}
def record(request, addon): if addon.is_webapp(): installed, c = Installed.objects.safer_get_or_create(addon=addon, user=request.amo_user) send_request('install', request, { 'app-domain': addon.domain_from_url(addon.origin), 'app-id': addon.pk}) return {'addon': addon.pk, 'receipt': installed.receipt if installed else ''}
def test_send_request(self, urlopen): request = mock.Mock() request.GET = {'src': 'foo'} request.LANG = 'en' request.META = {'HTTP_USER_AGENT': 'py'} send_request('install', request, {}) data = json.loads(urlopen.call_args[0][0].data) eq_(data['user-agent'], 'py') eq_(data['locale'], 'en') eq_(data['src'], 'foo')
def _record(request, addon): # TODO(andym): simplify this. logged = request.user.is_authenticated() premium = addon.is_premium() allow_anon_install = waffle.switch_is_active('anonymous-free-installs') # Require login for premium. if not logged and (premium or not allow_anon_install): return redirect(reverse('users.login')) ctx = {'addon': addon.pk} # Don't generate receipts if we're allowing logged-out install. if logged or not allow_anon_install: is_dev = request.check_ownership(addon, require_owner=False, ignore_disabled=True) is_reviewer = acl.check_reviewer(request) if (not addon.is_webapp() or not addon.is_public() and not (is_reviewer or is_dev)): raise http.Http404 if (premium and not addon.has_purchased(request.amo_user) and not is_reviewer and not is_dev): return http.HttpResponseForbidden() installed, c = Installed.objects.safer_get_or_create( addon=addon, user=request.amo_user) # Look up to see if its in the receipt cache and log if we have # to recreate it. receipt = memoize_get('create-receipt', installed.pk) error = '' receipt_cef.log(request, addon, 'request', 'Receipt requested') if not receipt: receipt_cef.log(request, addon, 'sign', 'Receipt signing') try: receipt = create_receipt(installed.pk) except SigningError: error = _('There was a problem installing the app.') ctx.update(receipt=receipt, error=error) else: if not addon.is_public() or not addon.is_webapp(): raise http.Http404 amo.log(amo.LOG.INSTALL_ADDON, addon) send_request('install', request, { 'app-domain': addon.domain_from_url(addon.origin), 'app-id': addon.pk }) return ctx
def _record(request, addon): # TODO(andym): simplify this. logged = request.user.is_authenticated() premium = addon.is_premium() allow_anon_install = waffle.switch_is_active('anonymous-free-installs') # Require login for premium. if not logged and (premium or not allow_anon_install): return redirect(reverse('users.login')) ctx = {'addon': addon.pk} # Don't generate receipts if we're allowing logged-out install. if logged or not allow_anon_install: is_dev = request.check_ownership(addon, require_owner=False, ignore_disabled=True) is_reviewer = acl.check_reviewer(request) if (not addon.is_webapp() or not addon.is_public() and not (is_reviewer or is_dev)): raise http.Http404 if (premium and not addon.has_purchased(request.amo_user) and not is_reviewer and not is_dev): return http.HttpResponseForbidden() installed, c = Installed.objects.safer_get_or_create(addon=addon, user=request.amo_user) # Look up to see if its in the receipt cache and log if we have # to recreate it. receipt = memoize_get('create-receipt', installed.pk) error = '' receipt_cef.log(request, addon, 'request', 'Receipt requested') if not receipt: receipt_cef.log(request, addon, 'sign', 'Receipt signing') try: receipt = create_receipt(installed.pk) except SigningError: error = _('There was a problem installing the app.') ctx.update(receipt=receipt, error=error) else: if not addon.is_public() or not addon.is_webapp(): raise http.Http404 amo.log(amo.LOG.INSTALL_ADDON, addon) send_request('install', request, { 'app-domain': addon.domain_from_url(addon.origin), 'app-id': addon.pk }) return ctx
def record(request, addon): if not (addon.is_public() or acl.check_reviewer(request)): raise http.Http404 if addon.is_webapp(): installed, c = Installed.objects.safer_get_or_create(addon=addon, user=request.amo_user) send_request("install", request, {"app-domain": addon.domain_from_url(addon.origin), "app-id": addon.pk}) # Look up to see if its in the receipt cache and log if we have # to recreate it. receipt = memoize_get("create-receipt", installed.pk) error = "" cef(request, addon, "request", "Receipt requested") if not receipt: cef(request, addon, "sign", "Receipt signing") try: receipt = create_receipt(installed.pk) except SigningError: error = _("There was a problem installing the app.") return {"addon": addon.pk, "receipt": receipt, "error": error}
def _record(request, addon): # TODO(andym): simplify this. logged = request.user.is_authenticated() premium = addon.is_premium() allow_anon_install = waffle.switch_is_active('anonymous-free-installs') # Require login for premium. if not logged and (premium or not allow_anon_install): return redirect(reverse('users.login')) ctx = {'addon': addon.pk} # Don't generate receipts if we're allowing logged-out install. if logged or not allow_anon_install: is_dev = request.check_ownership(addon, require_owner=False, ignore_disabled=True) is_reviewer = acl.check_reviewer(request) if (not addon.is_webapp() or not addon.is_public() and not (is_reviewer or is_dev)): raise http.Http404 if (premium and not addon.has_purchased(request.amo_user) and not is_reviewer and not is_dev): return http.HttpResponseForbidden() # Log the install. installed, c = Installed.objects.safer_get_or_create(addon=addon, user=request.amo_user) # Get download source from GET if it exists, if so get the download # source object if it exists. Then grab a client data object to hook up # with the Installed object. download_source = DownloadSource.objects.filter( name=request.REQUEST.get('src', None)) download_source = download_source[0] if download_source else None try: region = request.REGION.id except AttributeError: region = mkt.regions.WORLDWIDE.id client_data, c = ClientData.objects.get_or_create( download_source=download_source, device_type=request.POST.get('device_type', ''), user_agent=request.META.get('HTTP_USER_AGENT', ''), is_chromeless=request.POST.get('chromeless', False), language=request.LANG, region=region) installed.update(client_data=client_data) # Look up to see if its in the receipt cache and log if we have # to recreate it. receipt = memoize_get('create-receipt', installed.pk) error = '' receipt_cef.log(request, addon, 'request', 'Receipt requested') if not receipt: receipt_cef.log(request, addon, 'sign', 'Receipt signing') try: receipt = create_receipt(installed.pk) except SigningError: error = _('There was a problem installing the app.') ctx.update(receipt=receipt, error=error) else: if not addon.is_public() or not addon.is_webapp(): raise http.Http404 amo.log(amo.LOG.INSTALL_ADDON, addon) send_request('install', request, { 'app-domain': addon.domain_from_url(addon.origin), 'app-id': addon.pk }) return ctx
def _record(request, addon): # TODO(andym): simplify this. logged = request.user.is_authenticated() premium = addon.is_premium() allow_anon_install = waffle.switch_is_active('anonymous-free-installs') # Require login for premium. if not logged and (premium or not allow_anon_install): return http.HttpResponseRedirect(reverse('users.login')) ctx = {'addon': addon.pk} # Don't generate receipts if we're allowing logged-out install. if logged or not allow_anon_install: is_dev = request.check_ownership(addon, require_owner=False, ignore_disabled=True) is_reviewer = acl.check_reviewer(request) if (not addon.is_webapp() or not addon.is_public() and not (is_reviewer or is_dev)): raise http.Http404 if (premium and not addon.has_purchased(request.amo_user) and not is_reviewer and not is_dev): raise PermissionDenied # Log the install. installed, c = Installed.objects.safer_get_or_create(addon=addon, user=request.amo_user) # Get download source from GET if it exists, if so get the download # source object if it exists. Then grab a client data object to hook up # with the Installed object. download_source = DownloadSource.objects.filter( name=request.REQUEST.get('src', None)) download_source = download_source[0] if download_source else None try: region = request.REGION.id except AttributeError: region = mkt.regions.WORLDWIDE.id client_data, c = ClientData.objects.get_or_create( download_source=download_source, device_type=request.POST.get('device_type', ''), user_agent=request.META.get('HTTP_USER_AGENT', ''), is_chromeless=request.POST.get('chromeless', False), language=request.LANG, region=region) installed.update(client_data=client_data) # Look up to see if its in the receipt cache and log if we have # to recreate it. receipt = memoize_get('create-receipt', installed.pk) error = '' receipt_cef.log(request, addon, 'request', 'Receipt requested') if not receipt: receipt_cef.log(request, addon, 'sign', 'Receipt signing') try: receipt = create_receipt(installed.pk) except SigningError: error = _('There was a problem installing the app.') ctx.update(receipt=receipt, error=error) else: if not addon.is_public() or not addon.is_webapp(): raise http.Http404 amo.log(amo.LOG.INSTALL_ADDON, addon) send_request('install', request, { 'app-domain': addon.domain_from_url(addon.origin), 'app-id': addon.pk }) return ctx