allow anonymous installs via waffle flag (bug 757872)

This commit is contained in:
Matt Claypotch 2012-06-01 16:29:03 -07:00
Родитель c96c42ce48
Коммит 6830d71761
5 изменённых файлов: 44 добавлений и 25 удалений

Просмотреть файл

@ -8,7 +8,8 @@ var z = {
if (!z.prefix) return property;
return '-' + z.prefix + '-' + property;
},
canInstallApps: true
canInstallApps: true,
allowAnonInstalls: !!$('body').data('allow-anon-installs')
};
z.prefixUpper= z.prefix[0].toUpperCase() + z.prefix.substr(1);

Просмотреть файл

@ -11,7 +11,7 @@
}
function startInstall(product) {
if (z.anonymous) {
if (z.anonymous || (z.allowAnonInstalls && product.price)) {
localStorage.setItem('toInstall', product.manifestUrl);
$(window).trigger('login');
return;

Просмотреть файл

@ -0,0 +1,2 @@
INSERT INTO waffle_switch_mkt (name, active) VALUES ('anonymous-free-installs', 0);

Просмотреть файл

@ -4,6 +4,7 @@ from django.shortcuts import redirect
import jingo
from session_csrf import anonymous_csrf_exempt
from tower import ugettext as _
import waffle
from abuse.models import send_abuse_report
from access import acl
@ -12,6 +13,7 @@ import amo
import amo.log
from amo.decorators import json_view, login_required, post_required, write
from amo.forms import AbuseForm
from amo.urlresolvers import reverse
from amo.utils import memoize_get
from lib.metrics import send_request
from lib.crypto.receipt import cef, SigningError
@ -82,38 +84,51 @@ def abuse_recaptcha(request, addon):
@json_view
@addon_all_view
@login_required
@post_required
@write
def record(request, addon):
is_dev = request.check_ownership(addon, require_owner=False,
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'))
# 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()):
raise http.Http404
is_reviewer = acl.check_reviewer(request)
if not (addon.is_public() or is_reviewer or is_dev or
not addon.is_webapp()):
raise http.Http404
if (addon.is_premium() and not addon.has_purchased(request.amo_user) and
not is_reviewer and not is_dev):
return http.HttpResponseForbidden()
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 = ''
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.')
else:
if not addon.is_public() or not addon.is_webapp():
raise http.Http404
installed, c = Installed.objects.safer_get_or_create(addon=addon,
user=request.amo_user)
amo.log(amo.LOG.INSTALL_ADDON, addon)
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}

Просмотреть файл

@ -39,6 +39,7 @@
{% endif %}
</head>
<body class="html-{{ DIR }} {% block bodyclass %}{% endblock %}"
{% if waffle.switch('anonymous-free-installs') %}data-allow-anon-installs="true"{% endif %}
data-user="{{ user_data(amo_user)|json }}"
data-readonly="{{ settings.READ_ONLY|json }}"
data-media-url="{{ MEDIA_URL }}"