Skip to content

Commit

Permalink
Added safer mirror check (bug 692178)
Browse files Browse the repository at this point in the history
- Guards against mirror path being None
- Changes `is_public` to be a more explicit `is_mirrorable`, which is
  what the template is really asking.
  • Loading branch information
robhudson committed Oct 5, 2011
1 parent d2432ab commit 151f67d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
8 changes: 6 additions & 2 deletions apps/files/models.py
Expand Up @@ -78,11 +78,15 @@ def has_been_validated(self):
else:
return True

def is_public(self):
return self.status == amo.STATUS_PUBLIC
def is_mirrorable(self):
if self.version.addon.is_premium():
return False
return self.status in amo.MIRROR_STATUSES

def has_been_copied(self):
"""Checks if file has been copied to mirror"""
if not self.mirror_file_path:
return False
return os.path.isfile(self.mirror_file_path)

def can_be_perf_tested(self):
Expand Down
12 changes: 12 additions & 0 deletions apps/files/tests/test_models.py
Expand Up @@ -271,6 +271,18 @@ def test_webapp_is_not_testable(self):
f.version.addon.update(type=amo.ADDON_WEBAPP)
eq_(f.can_be_perf_tested(), False)

def test_file_is_mirrorable(self):
f = File.objects.get(pk=67442)
eq_(f.is_mirrorable(), True)

f.update(status=amo.STATUS_DISABLED)
eq_(f.is_mirrorable(), False)

def test_premium_addon_not_mirrorable(self):
f = File.objects.get(pk=67442)
f.version.addon.premium_type = amo.ADDON_PREMIUM
eq_(f.is_mirrorable(), False)


class TestParseXpi(amo.tests.TestCase):
fixtures = ['base/apps']
Expand Down
2 changes: 1 addition & 1 deletion apps/zadmin/templates/zadmin/addon_manage.html
Expand Up @@ -46,7 +46,7 @@ <h3>Versions &amp; Files</h3>
</td>
<td><a href="/admin/addons/hash/{{ addon.id }}/{{ file.id }}" title="{{ file.hash }}">Recalc Hash</a></td>
<td>
{% if file.is_public() %}
{% if file.is_mirrorable() %}
{{ "Copied" if file.has_been_copied() else "Not Copied" }}
{% endif %}
</td>
Expand Down

0 comments on commit 151f67d

Please sign in to comment.