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

Commit 99cd8a7

Browse files
committed
update install buttons for navigator.mozApps.installPackage w/ mini manifests (bug 792146)
1 parent 60b77c8 commit 99cd8a7

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed

media/js/mkt/apps.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,18 @@ exports.install = function(product, opt) {
3939
var self = apps,
4040
errSummary,
4141
manifestUrl = product.manifestUrl,
42-
package_url = product.package_url,
4342
$def = $.Deferred();
4443

4544
/* Try and install the app. */
4645
if (manifestUrl && opt.navigator.mozApps && opt.navigator.mozApps.install) {
4746
/* TODO: combine the following check with the above. But don't stop
4847
* clients without installPackage from using apps for now.
4948
*/
50-
if (product.is_packaged && !opt.navigator.mozApps.installPackage && !package_url) {
49+
if (product.is_packaged && !opt.navigator.mozApps.installPackage && !manifestUrl) {
5150
$def.reject();
5251
}
5352
var installRequest = product.is_packaged ?
54-
opt.navigator.mozApps.installPackage(package_url, opt.data) :
53+
opt.navigator.mozApps.installPackage(manifestUrl, opt.data) :
5554
opt.navigator.mozApps.install(manifestUrl, opt.data);
5655
installRequest.onsuccess = function() {
5756
$def.resolve(product);

mkt/developers/templates/developers/apps/edit/basic.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ <h2>
5454
<th class="label">{{ _('Manifest URL') }}</th>
5555
<td>
5656
{% if addon.is_packaged %}
57-
<a href="{{ addon.get_detail_url('manifest')|absolutify }}" target="_blank">{{ addon.get_detail_url('manifest')|absolutify }}</a>
57+
<a href="{{ addon.get_manifest_url() }}" target="_blank">{{ addon.get_manifest_url() }}</a>
5858
{% else %}
5959
{% if editable %}
6060
<input type="text" name="manifest_url"{{ ' readonly' if not action_allowed('Admin', '%') }} value="{{ addon.manifest_url }}">

mkt/site/helpers.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,25 +106,20 @@ def product_as_dict(request, product, purchased=None, receipt_type=None):
106106
url = (reverse('receipt.issue', args=[product.app_slug])
107107
if receipt_type else product.get_detail_url('record'))
108108
src = request.GET.get('src', '')
109-
if product.is_packaged and product.current_version:
110-
package_url = product.current_version.all_files[0].get_url_path(src)
111-
else:
112-
package_url = ''
113109

114110
ret = {
115111
'id': product.id,
116112
'name': product.name,
117113
'categories': [unicode(cat.name) for cat in
118114
product.categories.all()],
119-
'manifestUrl': product.manifest_url,
115+
'manifestUrl': product.get_manifest_url(),
120116
'preapprovalUrl': reverse('detail.purchase.preapproval',
121117
args=[product.app_slug]),
122118
'recordUrl': urlparams(url, src=src),
123119
'author': author,
124120
'author_url': author_url,
125121
'iconUrl': product.get_icon_url(64),
126122
'is_packaged': product.is_packaged,
127-
'package_url': package_url,
128123
}
129124

130125
# Add in previews to the dict.

mkt/site/tests/test_helpers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,20 @@ def test_category(self):
138138
eq_(data['categories'],
139139
[str(cat.name) for cat in self.webapp.categories.all()])
140140

141+
@mock.patch.object(settings, 'SITE_URL', 'http://omg.org/yes')
141142
def test_is_packaged(self):
142143
self.webapp.update(is_packaged=True)
143144
doc = pq(market_tile(self.context, self.webapp))
144145
data = json.loads(doc('a').attr('data-product'))
145146
eq_(data['is_packaged'], True)
146-
assert data['package_url'].startswith('/downloads')
147+
eq_(data['manifestUrl'],
148+
'http://omg.org/yes' + self.webapp.get_detail_url('manifest'))
147149

148150
def test_is_not_packaged(self):
149151
doc = pq(market_tile(self.context, self.webapp))
150152
data = json.loads(doc('a').attr('data-product'))
151153
eq_(data['is_packaged'], False)
152-
eq_(data['package_url'], '')
154+
eq_(data['manifestUrl'], self.webapp.manifest_url)
153155

154156
def test_packaged_no_valid_status(self):
155157
self.webapp.update(is_packaged=True)
@@ -160,7 +162,7 @@ def test_packaged_no_valid_status(self):
160162
doc = pq(market_tile(self.context, self.webapp))
161163
data = json.loads(doc('a').attr('data-product'))
162164
eq_(data['is_packaged'], True)
163-
eq_(data['package_url'], '')
165+
eq_(data['manifestUrl'], '')
164166
# The install button should not be shown if no current_version.
165167
eq_(doc('.product button').length, 0)
166168

mkt/webapps/models.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
update_name_table, update_search_index)
2929
from addons.signals import version_changed
3030
from amo.decorators import skip_cache
31+
from amo.helpers import absolutify
3132
from amo.storage_utils import copy_stored_file
3233
from amo.urlresolvers import reverse
3334
from amo.utils import JSONEncoder, smart_path
@@ -259,6 +260,22 @@ def origin(self):
259260
parsed = urlparse.urlparse(self.manifest_url)
260261
return '%s://%s' % (parsed.scheme, parsed.netloc)
261262

263+
def get_manifest_url(self):
264+
"""
265+
Hosted apps: a URI to an external manifest.
266+
Packaged apps: a URI to a mini manifest on m.m.o.
267+
"""
268+
if self.is_packaged:
269+
if self.current_version:
270+
return absolutify(self.get_detail_url('manifest'))
271+
else:
272+
# Invalid statuses don't have `current_version`.
273+
# TODO: Ask Rob about reviewers being able to install
274+
# disabled apps?
275+
return ''
276+
else:
277+
return self.manifest_url
278+
262279
def has_icon_in_manifest(self):
263280
data = self.get_manifest_json()
264281
return 'icons' in data
@@ -683,7 +700,7 @@ class Meta:
683700
def add_uuid(sender, **kw):
684701
if not kw.get('raw'):
685702
install = kw['instance']
686-
if not install.uuid and install.premium_type == None:
703+
if not install.uuid and install.premium_type is None:
687704
install.uuid = ('%s-%s' % (install.pk, str(uuid.uuid4())))
688705
install.premium_type = install.addon.premium_type
689706
install.save()

0 commit comments

Comments
 (0)