Skip to content

Commit

Permalink
Merge pull request #583 from magopian/1172037-standalone-validator-un…
Browse files Browse the repository at this point in the history
…listed-addons

Can now submit unlisted addons to the standalone validator (bug 1172037)
  • Loading branch information
magopian committed Jun 16, 2015
2 parents 83d149a + e3f853d commit 6337872
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
31 changes: 29 additions & 2 deletions apps/devhub/templates/devhub/validate_addon.html
Expand Up @@ -7,7 +7,8 @@
{{ dev_breadcrumbs(addon, items=[(None, title)]) }}
<h2>{{ title }}</h2>
</header>
<form method="post" id="create-addon" class="item">
<form method="post" id="create-addon" class="item new-addon-file"
data-unlisted-addons="{% if waffle.flag('unlisted-addons') %}true{% else %}false{% endif %}">
{{ csrf() }}
<p>
{% trans %}
Expand Down Expand Up @@ -38,8 +39,34 @@ <h2>{{ title }}</h2>
</p>
{% endif %}
<section id="upload-file" class="validate-addon">
{% if waffle.flag('unlisted-addons') %}
<div class="list-addon">
<label>{{ _('Do you want your add-on to be distributed on this site?') }}</label>
<div>
<label for="{{ new_addon_form.is_unlisted.auto_id }}">
{{ new_addon_form.is_unlisted }}
{{ new_addon_form.is_unlisted.label }}
<span class="tip tooltip"
title="{{ new_addon_form.is_unlisted.help_text }}">?</span>
<span class="beta-warning"><br /><em>{{ _('Warning:') }}</em>
{% trans bugzilla_url='https://bugzilla.mozilla.org/enter_bug.cgi?product=addons.mozilla.org&component=Developer%20Pages' %}
Submission of unlisted add-ons for signing is currently in an
open beta. Manual review may still be required for a large
number of add-ons. Please
<a href="{{ bugzilla_url }}" target="_blank">report any bugs</a> that you encounter.
{% endtrans %}
</span>
</label>
</div>
</div>
{% endif %}

<input type="file" id="upload-addon" data-upload-url="{{ upload_url }}">
<input type="file" id="upload-addon"
data-upload-url="{{ url('devhub.standalone_upload') }}"
{% if waffle.flag('unlisted-addons') %}
data-upload-url-listed="{{ url('devhub.standalone_upload') }}"
data-upload-url-unlisted="{{ url('devhub.standalone_upload_unlisted') }}"
{% endif %}>

</section>
</form>
Expand Down
15 changes: 15 additions & 0 deletions apps/devhub/tests/test_views_validation.py
Expand Up @@ -194,11 +194,26 @@ def test_login_required(self):
eq_(r.status_code, 302)

def test_context(self):
self.create_flag('unlisted-addons')
r = self.client.get(reverse('devhub.validate_addon'))
eq_(r.status_code, 200)
doc = pq(r.content)
eq_(doc('#upload-addon').attr('data-upload-url'),
reverse('devhub.standalone_upload'))
eq_(doc('#upload-addon').attr('data-upload-url-listed'),
reverse('devhub.standalone_upload'))
eq_(doc('#upload-addon').attr('data-upload-url-unlisted'),
reverse('devhub.standalone_upload_unlisted'))

@mock.patch('validator.validate.validate')
def test_upload_unlisted_addon(self, validate_mock):
"""Unlisted addons are validated as "self hosted" addons."""
validate_mock.return_value = '{}'
self.url = reverse('devhub.upload_unlisted')
data = open(get_image_path('animated.png'), 'rb')
self.client.post(self.url, {'upload': data})
# Make sure it was called with listed=False.
assert not validate_mock.call_args[1]['listed']


class TestValidateFile(BaseUploadTest):
Expand Down
2 changes: 2 additions & 0 deletions apps/devhub/urls.py
Expand Up @@ -178,6 +178,8 @@
name='devhub.upload_detail'),
url('^standalone-upload$', views.standalone_upload,
name='devhub.standalone_upload'),
url('^standalone-upload-unlisted$', views.standalone_upload_unlisted,
name='devhub.standalone_upload_unlisted'),
url('^standalone-upload/([^/]+)$', views.standalone_upload_detail,
name='devhub.standalone_upload_detail'),

Expand Down
14 changes: 12 additions & 2 deletions apps/devhub/views.py
Expand Up @@ -577,7 +577,9 @@ def compat_application_versions(request):
def validate_addon(request):
return render(request, 'devhub/validate_addon.html',
{'title': _('Validate Add-on'),
'upload_url': reverse('devhub.standalone_upload')})
# Hack: we just need the "is_unlisted" field from this form.
'new_addon_form': forms.NewAddonForm(
None, None, request=request)})


@login_required
Expand All @@ -586,7 +588,9 @@ def check_addon_compatibility(request):
return render(request, 'devhub/validate_addon.html',
{'appversion_form': form,
'title': _('Check Add-on Compatibility'),
'upload_url': reverse('devhub.standalone_upload')})
# Hack: we just need the "is_unlisted" field from this form.
'new_addon_form': forms.NewAddonForm(
None, None, request=request)})


@dev_required
Expand Down Expand Up @@ -672,6 +676,12 @@ def standalone_upload(request):
return upload(request, is_standalone=True)


@login_required
@post_required
def standalone_upload_unlisted(request):
return upload(request, is_standalone=True, is_listed=False)


@login_required
@json_view
def standalone_upload_detail(request, uuid):
Expand Down

0 comments on commit 6337872

Please sign in to comment.