Revert "Revert "manage packaged-app submission for Android and Desktop via waffle flag (bug 907203, bug 910778)""
This reverts commit 5726ed74aa
.
This commit is contained in:
Родитель
5726ed74aa
Коммит
22e2061245
|
@ -54,7 +54,7 @@
|
|||
// When a big device button is clicked, update the form.
|
||||
var $upload_form = $('#upload-webapp'),
|
||||
$qhd = $('#id_has_qhd');
|
||||
$(document.body).on('change', '#upload-webapp select', function() {
|
||||
z.body.on('change', '#upload-webapp select', function() {
|
||||
// IT'S FINE. IT'S FINE.
|
||||
if (!$upload_form.find('option[value$="-desktop"]:selected, option[value$="-tablet"]:selected').length) {
|
||||
$qhd.prop('checked', true).trigger('change');
|
||||
|
@ -102,11 +102,29 @@
|
|||
|
||||
// Condition to show packaged tab...ugly but works.
|
||||
function showPackagedTab() {
|
||||
// If the Android flag is disabled, and you tried to select
|
||||
// Android Mobile or Tablet... no packaged apps for you.
|
||||
// (This lets us prevent you from marking your app as compatible
|
||||
// with both Firefox OS *and* Android when Android support
|
||||
// hasn't landed yet.)
|
||||
if (!$('[data-packaged-platforms~="android"]').length &&
|
||||
$('option[value*="-android-"]:selected').length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the Desktop flag is disabled, and you tried to select
|
||||
// Desktop... no packaged apps for you.
|
||||
if (!$('[data-packaged-platforms~="desktop"]').length &&
|
||||
$('option[value$="-desktop"]:selected').length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ($('#id_free_platforms option[value="free-firefoxos"]:selected').length &&
|
||||
$('#id_free_platforms option:selected').length == 1) ||
|
||||
$('#id_paid_platforms option[value="paid-firefoxos"]:selected').length ||
|
||||
$('option[value*=android]:selected').length ||
|
||||
allTabsDeselected();
|
||||
$('#id_free_platforms option:selected').length == 1) ||
|
||||
$('#id_paid_platforms option[value="paid-firefoxos"]:selected').length ||
|
||||
$('[data-packaged-platforms~="android"] option[value*="-android-"]:selected').length ||
|
||||
$('[data-packaged-platforms~="desktop"] option[value$="-desktop"]:selected').length ||
|
||||
allTabsDeselected();
|
||||
}
|
||||
|
||||
// Toggle packaged/hosted tab state.
|
||||
|
@ -124,7 +142,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
$(document).on('tabs-changed', function(e, tab) {
|
||||
z.body.on('tabs-changed', function(e, tab) {
|
||||
if (tab.id == 'packaged-tab-header') {
|
||||
$('.learn-mdn.active').removeClass('active');
|
||||
$('.learn-mdn.packaged').addClass('active');
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
INSERT INTO waffle_flag_mkt (name, everyone, percent, superusers, staff, authenticated, rollout, testing, languages, note, created, modified)
|
||||
VALUES ('android-packaged', 0, NULL, 0, 0, 0, 0, 0, '', 'ON: packaged apps for Android can be submitted and show up in search results; OFF: packaged apps for Android are disallowed', NOW(), NOW());
|
||||
|
||||
INSERT INTO waffle_flag_mkt (name, everyone, percent, superusers, staff, authenticated, rollout, testing, languages, note, created, modified)
|
||||
VALUES ('desktop-packaged', 0, NULL, 0, 0, 0, 0, 0, '', 'ON: packaged apps for Desktop can be submitted and show up in search results; OFF: packaged apps for Desktop are disallowed', NOW(), NOW());
|
|
@ -170,14 +170,14 @@ class PremiumForm(DeviceTypeForm, happyforms.Form):
|
|||
return value if value in ('free', 'paid') else False
|
||||
|
||||
def clean(self):
|
||||
|
||||
is_toggling = self.is_toggling()
|
||||
|
||||
if self.addon.is_packaged and 'desktop' in self._get_combined():
|
||||
self._errors['free_platforms'] = self._errors['paid_platforms'] = (
|
||||
self.ERRORS['packaged'])
|
||||
if self.addon.is_packaged:
|
||||
self._set_packaged_errors()
|
||||
if self._errors.get('free_platforms'):
|
||||
return self.cleaned_data
|
||||
|
||||
elif not is_toggling:
|
||||
if not is_toggling:
|
||||
# If a platform wasn't selected, raise an error.
|
||||
if not self.cleaned_data[
|
||||
'%s_platforms' % ('paid' if self.is_paid() else 'free')]:
|
||||
|
@ -198,7 +198,6 @@ class PremiumForm(DeviceTypeForm, happyforms.Form):
|
|||
return self.cleaned_data
|
||||
|
||||
def clean_price(self):
|
||||
|
||||
price_value = self.cleaned_data.get('price')
|
||||
premium_type = self.cleaned_data.get('premium_type')
|
||||
if ((premium_type in amo.ADDON_PREMIUMS
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
from django.conf import settings
|
||||
|
||||
import mock
|
||||
from nose.tools import eq_, ok_
|
||||
from pyquery import PyQuery as pq
|
||||
|
@ -224,8 +222,11 @@ class TestPremiumForm(amo.tests.TestCase):
|
|||
Price.objects.create(price='1.00', method=PAYMENT_METHOD_ALL)
|
||||
Price.objects.create(price='2.00', method=PAYMENT_METHOD_ALL)
|
||||
form = forms_payments.PremiumForm(self.platforms, **self.kwargs)
|
||||
# 1 x Free with inapp + 1 x price tier 0 + 3 x values grouped by billing +
|
||||
# 1 x 'Please select' = 6.
|
||||
# 1 x Free with inapp
|
||||
# + 1 x price tier 0
|
||||
# + 3 x values grouped by billing
|
||||
# + 1 x 'Please select'
|
||||
# = 6
|
||||
eq_(len(form.fields['price'].choices), 6)
|
||||
html = form.as_p()
|
||||
eq_(len(pq(html)('#id_price optgroup')), 3, 'Should be 3 optgroups')
|
||||
|
@ -247,6 +248,13 @@ class TestPremiumForm(amo.tests.TestCase):
|
|||
form = forms_payments.PremiumForm(data=self.platforms, **self.kwargs)
|
||||
assert not form.is_valid()
|
||||
|
||||
def test_can_set_desktop_for_packaged_app(self):
|
||||
self.create_flag('desktop-packaged')
|
||||
self.platforms = {'free_platforms': ['free-desktop']}
|
||||
self.addon.update(is_packaged=True)
|
||||
form = forms_payments.PremiumForm(data=self.platforms, **self.kwargs)
|
||||
assert form.is_valid(), form.errors
|
||||
|
||||
def test_can_change_devices_for_hosted_app(self):
|
||||
# Specify the free and paid. It shouldn't fail because you can't change
|
||||
# payment types without explicitly specifying that.
|
||||
|
@ -258,7 +266,17 @@ class TestPremiumForm(amo.tests.TestCase):
|
|||
|
||||
self.assertSetEqual(self.addon.device_types, [amo.DEVICE_DESKTOP])
|
||||
|
||||
def test_can_change_devices_for_packaged_app(self):
|
||||
def test_cannot_change_android_devices_for_packaged_app(self):
|
||||
self.platforms = {'free_platforms': ['free-android-mobile'],
|
||||
'paid_platforms': ['paid-firefoxos']} # Ignored.
|
||||
self.addon.update(is_packaged=True)
|
||||
form = forms_payments.PremiumForm(data=self.platforms, **self.kwargs)
|
||||
assert not form.is_valid()
|
||||
|
||||
self.assertSetEqual(self.addon.device_types, [amo.DEVICE_GAIA])
|
||||
|
||||
def test_can_change_devices_for_packaged_app_behind_flag(self):
|
||||
self.create_flag('android-packaged')
|
||||
self.platforms = {'free_platforms': ['free-android-mobile'],
|
||||
'paid_platforms': ['paid-firefoxos']} # Ignored.
|
||||
self.addon.update(is_packaged=True)
|
||||
|
@ -506,7 +524,7 @@ class TestPaidRereview(amo.tests.TestCase):
|
|||
eq_(RereviewQueue.objects.count(), 1)
|
||||
|
||||
form = forms_payments.BangoAccountListForm(None, **self.kwargs)
|
||||
assert form.fields['accounts'].empty_label == None
|
||||
eq_(form.fields['accounts'].empty_label, None)
|
||||
|
||||
@mock.patch('mkt.developers.models.client')
|
||||
def test_disagreed_tos_rereview(self, client):
|
||||
|
|
|
@ -47,8 +47,8 @@ class DeviceTypeForm(happyforms.Form):
|
|||
ERRORS = {
|
||||
'both': _lazy(u'Cannot be free and paid.'),
|
||||
'none': _lazy(u'Please select a device.'),
|
||||
'packaged': _lazy(u'Packaged apps are valid for only Firefox OS '
|
||||
'and Android.'),
|
||||
'packaged': _lazy(u'Packaged apps are not yet supported for those '
|
||||
u'platforms.'),
|
||||
}
|
||||
|
||||
free_platforms = forms.MultipleChoiceField(
|
||||
|
@ -85,6 +85,21 @@ class DeviceTypeForm(happyforms.Form):
|
|||
self.cleaned_data.get('paid_platforms', []))
|
||||
return set(d.split('-', 1)[1] for d in devices)
|
||||
|
||||
def _set_packaged_errors(self):
|
||||
"""Add packaged-app submission errors for incompatible platforms."""
|
||||
devices = self._get_combined()
|
||||
bad_android = (
|
||||
not waffle.flag_is_active(self.request, 'android-packaged') and
|
||||
('android-mobile' in devices or 'android-tablet' in devices)
|
||||
)
|
||||
bad_desktop = (
|
||||
not waffle.flag_is_active(self.request, 'desktop-packaged') and
|
||||
'desktop' in devices
|
||||
)
|
||||
if bad_android or bad_desktop:
|
||||
self._errors['free_platforms'] = self._errors['paid_platforms'] = (
|
||||
self.ERRORS['packaged'])
|
||||
|
||||
def clean(self):
|
||||
data = self.cleaned_data
|
||||
paid = data.get('paid_platforms', [])
|
||||
|
@ -161,13 +176,11 @@ class NewWebappVersionForm(happyforms.Form):
|
|||
del self.fields['paid_platforms']
|
||||
|
||||
def clean(self):
|
||||
|
||||
data = self.cleaned_data
|
||||
if 'upload' not in self.cleaned_data:
|
||||
self._errors['upload'] = self.upload_error
|
||||
return
|
||||
|
||||
# Packaged apps are only valid for firefox os.
|
||||
if self.is_packaged():
|
||||
# Now run the packaged app check, done in clean, because
|
||||
# clean_packaged needs to be processed first.
|
||||
|
@ -220,7 +233,8 @@ class NewWebappForm(DeviceTypeForm, NewWebappVersionForm):
|
|||
self.request = kwargs.pop('request', None)
|
||||
super(NewWebappForm, self).__init__(*args, **kwargs)
|
||||
if 'paid_platforms' in self.fields:
|
||||
self.fields['paid_platforms'].choices = PAID_PLATFORMS(self.request)
|
||||
self.fields['paid_platforms'].choices = PAID_PLATFORMS(
|
||||
self.request)
|
||||
|
||||
def _add_error(self, msg):
|
||||
self._errors['free_platforms'] = self._errors['paid_platforms'] = (
|
||||
|
@ -231,11 +245,10 @@ class NewWebappForm(DeviceTypeForm, NewWebappVersionForm):
|
|||
if not data:
|
||||
return
|
||||
|
||||
combined_platforms = self._get_combined()
|
||||
if self.is_packaged() and 'desktop' in combined_platforms:
|
||||
self._errors['free_platforms'] = self._errors['paid_platforms'] = (
|
||||
self.ERRORS['packaged'])
|
||||
return
|
||||
if self.is_packaged():
|
||||
self._set_packaged_errors()
|
||||
if self._errors.get('free_platforms'):
|
||||
return
|
||||
|
||||
return data
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
{{ progress(request, addon=None, step=step) }}
|
||||
</header>
|
||||
|
||||
|
||||
<section id="submit-payment-type" class="island tabbable">
|
||||
<div class="free tab active">
|
||||
{% if waffle.flag('allow-b2g-paid-submission') %}
|
||||
|
@ -51,7 +50,8 @@
|
|||
{% endif %}
|
||||
</section>
|
||||
|
||||
<section id="upload-file" class="island tabbable spacer">
|
||||
<section id="upload-file" class="island tabbable spacer"
|
||||
data-packaged-platforms="{{ 'android' if waffle.flag('android-packaged') }} {{ 'desktop' if waffle.flag('desktop-packaged') }}">
|
||||
<div class="hosted tab active">
|
||||
<h2 id="hosted-tab-header"><a href="#">{{ _('Hosted') }}</a></h2>
|
||||
<h3>{{ _("Submit your app manifest URL") }}</h3>
|
||||
|
|
|
@ -96,32 +96,33 @@ class TestNewWebappForm(amo.tests.TestCase):
|
|||
assert form.is_valid(), form.errors
|
||||
assert not form.is_packaged()
|
||||
|
||||
@mock.patch('mkt.submit.forms.parse_addon')
|
||||
def test_packaged_allowed(self, parse_addon):
|
||||
parse_addon.return_value = {}
|
||||
form = forms.NewWebappForm({'free_platforms': ['free-firefoxos'],
|
||||
'upload': self.file.uuid,
|
||||
'packaged': True})
|
||||
assert form.is_valid(), form.errors
|
||||
assert form.is_packaged()
|
||||
|
||||
@mock.patch('mkt.submit.forms.parse_addon')
|
||||
def test_packaged_allowed_android(self, parse_addon):
|
||||
parse_addon.return_value = {}
|
||||
form = forms.NewWebappForm({'free_platforms': ['free-android-mobile'],
|
||||
'upload': self.file.uuid,
|
||||
'packaged': True})
|
||||
assert form.is_valid(), form.errors
|
||||
assert form.is_packaged()
|
||||
@mock.patch('mkt.submit.forms.parse_addon',
|
||||
lambda *args: {'version': None})
|
||||
def test_packaged_disallowed_behind_flag(self):
|
||||
for device in ('free-desktop',
|
||||
'free-android-mobile',
|
||||
'free-android-tablet'):
|
||||
form = forms.NewWebappForm({'free_platforms': [device],
|
||||
'upload': self.file.uuid,
|
||||
'packaged': True})
|
||||
assert not form.is_valid(), form.errors
|
||||
eq_(form.ERRORS['packaged'], form.errors['paid_platforms'])
|
||||
|
||||
@mock.patch('mkt.submit.forms.parse_addon',
|
||||
lambda *args: {'version': None})
|
||||
def test_packaged_wrong_device(self):
|
||||
form = forms.NewWebappForm({'free_platforms': ['free-desktop'],
|
||||
'upload': self.file.uuid,
|
||||
'packaged': True})
|
||||
assert not form.is_valid(), form.errors
|
||||
eq_(form.ERRORS['packaged'], form.errors['paid_platforms'])
|
||||
def test_packaged_allowed_everywhere(self):
|
||||
self.create_flag('android-packaged')
|
||||
self.create_flag('desktop-packaged')
|
||||
for device in ('free-firefoxos',
|
||||
'free-desktop',
|
||||
'free-android-tablet',
|
||||
'free-android-mobile'):
|
||||
form = forms.NewWebappForm({'free_platforms': [device],
|
||||
'upload': self.file.uuid,
|
||||
'packaged': True},
|
||||
request=self.request)
|
||||
assert form.is_valid(), form.errors
|
||||
assert form.is_packaged()
|
||||
|
||||
|
||||
class TestNewWebappVersionForm(amo.tests.TestCase):
|
||||
|
|
Загрузка…
Ссылка в новой задаче