Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
wrap up anonymous free installs behind waffle switch (bug 757872)
Browse files Browse the repository at this point in the history
  • Loading branch information
cvan committed Jun 2, 2012
1 parent 751e20f commit 1cb7644
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
3 changes: 2 additions & 1 deletion media/js/mkt/install.js
Expand Up @@ -11,7 +11,8 @@
}

function startInstall(product) {
if (z.anonymous || (z.allowAnonInstalls && product.price)) {
if ((!z.allowAnonInstalls && z.anonymous) ||
(z.allowAnonInstalls && product.price)) {
localStorage.setItem('toInstall', product.manifestUrl);
$(window).trigger('login');
return;
Expand Down
8 changes: 7 additions & 1 deletion mkt/detail/urls.py
@@ -1,5 +1,7 @@
from django.conf.urls.defaults import include, patterns, url

import waffle

import addons.views
from mkt.ratings.urls import review_patterns
from . import views
Expand All @@ -10,7 +12,11 @@
url('^abuse$', views.abuse, name='detail.abuse'),
url('^abuse/recaptcha$', views.abuse_recaptcha,
name='detail.abuse.recaptcha'),
url('^record$', views.record, name='detail.record'),
url('^record$',
(views.record_anon
if waffle.switch_is_active('anonymous-free-installs')
else views.record),
name='detail.record'),
url('^privacy$', views.privacy, name='detail.privacy'),

('^purchase/', include('mkt.purchase.urls')),
Expand Down
40 changes: 29 additions & 11 deletions mkt/detail/views.py
Expand Up @@ -82,11 +82,7 @@ def abuse_recaptcha(request, addon):
{'product': addon, 'abuse_form': form})


@json_view
@addon_all_view
@post_required
@write
def record(request, addon):
def _record(request, addon):
logged = request.user.is_authenticated()
premium = addon.is_premium()
allow_anon_install = waffle.switch_is_active('anonymous-free-installs')
Expand All @@ -95,13 +91,15 @@ def record(request, addon):
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_public() or is_reviewer or is_dev or
not addon.is_webapp()):
if (not addon.is_webapp() or not addon.is_public() and
not (is_reviewer or is_dev)):
raise http.Http404

if (premium and
Expand All @@ -110,7 +108,7 @@ def record(request, addon):
return http.HttpResponseForbidden()

installed, c = Installed.objects.safer_get_or_create(addon=addon,
user=request.amo_user)
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)
Expand All @@ -122,13 +120,33 @@ def record(request, addon):
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})
'app-domain': addon.domain_from_url(addon.origin),
'app-id': addon.pk
})

return ctx


return {'addon': addon.pk, 'receipt': receipt, 'error': error}
@anonymous_csrf_exempt
@json_view
@addon_all_view
@post_required
@write
def record_anon(request, addon):
return _record(request, addon)


@json_view
@addon_all_view
@post_required
@write
def record(request, addon):
return _record(request, addon)

0 comments on commit 1cb7644

Please sign in to comment.