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

Commit

Permalink
Revert "manage packaged-app submission for Android and Desktop via wa…
Browse files Browse the repository at this point in the history
…ffle flag (bug 907203, bug 910778)"

This reverts commit a5a9b3d.
  • Loading branch information
cvan committed Sep 3, 2013
1 parent d5fd85d commit 2c3f67a
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 107 deletions.
30 changes: 6 additions & 24 deletions media/js/devreg/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
// When a big device button is clicked, update the form.
var $upload_form = $('#upload-webapp'),
$qhd = $('#id_has_qhd');
z.body.on('change', '#upload-webapp select', function() {
$(document.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');
Expand Down Expand Up @@ -102,29 +102,11 @@

// 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 ||
$('[data-packaged-platforms~="android"] option[value*="-android-"]:selected').length ||
$('[data-packaged-platforms~="desktop"] option[value$="-desktop"]:selected').length ||
allTabsDeselected();
$('#id_free_platforms option:selected').length == 1) ||
$('#id_paid_platforms option[value="paid-firefoxos"]:selected').length ||
$('option[value*=android]:selected').length ||
allTabsDeselected();
}

// Toggle packaged/hosted tab state.
Expand All @@ -142,7 +124,7 @@
}
}

z.body.on('tabs-changed', function(e, tab) {
$(document).on('tabs-changed', function(e, tab) {
if (tab.id == 'packaged-tab-header') {
$('.learn-mdn.active').removeClass('active');
$('.learn-mdn.packaged').addClass('active');
Expand Down
5 changes: 0 additions & 5 deletions migrations/655-waffle-packaged-apps.sql

This file was deleted.

11 changes: 6 additions & 5 deletions mkt/developers/forms_payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ def is_toggling(self):
return value if value in ('free', 'paid') else False

def clean(self):

is_toggling = self.is_toggling()

if self.addon.is_packaged:
self._set_packaged_errors()
if self._errors.get('free_platforms'):
return self.cleaned_data
if self.addon.is_packaged and 'desktop' in self._get_combined():
self._errors['free_platforms'] = self._errors['paid_platforms'] = (
self.ERRORS['packaged'])

if not is_toggling:
elif 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')]:
Expand All @@ -198,6 +198,7 @@ def clean(self):
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
Expand Down
30 changes: 6 additions & 24 deletions mkt/developers/tests/test_forms_payments.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.conf import settings

import mock
from nose.tools import eq_, ok_
from pyquery import PyQuery as pq
Expand Down Expand Up @@ -222,11 +224,8 @@ def test_optgroups_in_price_choices(self):
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')
Expand All @@ -248,13 +247,6 @@ def test_cannot_set_desktop_for_packaged_app(self):
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.
Expand All @@ -266,17 +258,7 @@ def test_can_change_devices_for_hosted_app(self):

self.assertSetEqual(self.addon.device_types, [amo.DEVICE_DESKTOP])

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')
def test_can_change_devices_for_packaged_app(self):
self.platforms = {'free_platforms': ['free-android-mobile'],
'paid_platforms': ['paid-firefoxos']} # Ignored.
self.addon.update(is_packaged=True)
Expand Down Expand Up @@ -524,7 +506,7 @@ def test_rereview(self, client):
eq_(RereviewQueue.objects.count(), 1)

form = forms_payments.BangoAccountListForm(None, **self.kwargs)
eq_(form.fields['accounts'].empty_label, None)
assert form.fields['accounts'].empty_label == None

@mock.patch('mkt.developers.models.client')
def test_disagreed_tos_rereview(self, client):
Expand Down
33 changes: 10 additions & 23 deletions mkt/submit/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 not yet supported for those '
u'platforms.'),
'packaged': _lazy(u'Packaged apps are valid for only Firefox OS '
'and Android.'),
}

free_platforms = forms.MultipleChoiceField(
Expand Down Expand Up @@ -85,21 +85,6 @@ def _get_combined(self):
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', [])
Expand Down Expand Up @@ -176,11 +161,13 @@ def __init__(self, *args, **kw):
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.
Expand Down Expand Up @@ -233,8 +220,7 @@ def __init__(self, *args, **kwargs):
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'] = (
Expand All @@ -245,10 +231,11 @@ def clean(self):
if not data:
return

if self.is_packaged():
self._set_packaged_errors()
if self._errors.get('free_platforms'):
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

return data

Expand Down
4 changes: 2 additions & 2 deletions mkt/submit/templates/submit/manifest.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ <h1>{{ _('Submit an App') }}</h1>
{{ 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') %}
Expand All @@ -50,8 +51,7 @@ <h2 id="paid-tab-header"><a href="#">{{ _('Paid / In-app') }}</a></h2>
{% endif %}
</section>

<section id="upload-file" class="island tabbable spacer"
data-packaged-platforms="{{ 'android' if waffle.flag('android-packaged') }} {{ 'desktop' if waffle.flag('desktop-packaged') }}">
<section id="upload-file" class="island tabbable spacer">
<div class="hosted tab active">
<h2 id="hosted-tab-header"><a href="#">{{ _('Hosted') }}</a></h2>
<h3>{{ _("Submit your app manifest URL") }}</h3>
Expand Down
47 changes: 23 additions & 24 deletions mkt/submit/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,33 +96,32 @@ def test_not_packaged_allowed(self):
assert form.is_valid(), form.errors
assert not 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')
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_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()
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'])


class TestNewWebappVersionForm(amo.tests.TestCase):
Expand Down

0 comments on commit 2c3f67a

Please sign in to comment.