From 151f67d9d0a8308ba0c9a0af8b1868f85a224188 Mon Sep 17 00:00:00 2001 From: Rob Hudson Date: Wed, 5 Oct 2011 12:23:37 -0700 Subject: [PATCH] Added safer mirror check (bug 692178) - Guards against mirror path being None - Changes `is_public` to be a more explicit `is_mirrorable`, which is what the template is really asking. --- apps/files/models.py | 8 ++++++-- apps/files/tests/test_models.py | 12 ++++++++++++ apps/zadmin/templates/zadmin/addon_manage.html | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/apps/files/models.py b/apps/files/models.py index f371a7b9be9..aaecbb1bc43 100644 --- a/apps/files/models.py +++ b/apps/files/models.py @@ -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): diff --git a/apps/files/tests/test_models.py b/apps/files/tests/test_models.py index 7fda5002905..755835d6bc0 100644 --- a/apps/files/tests/test_models.py +++ b/apps/files/tests/test_models.py @@ -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'] diff --git a/apps/zadmin/templates/zadmin/addon_manage.html b/apps/zadmin/templates/zadmin/addon_manage.html index 64155a56643..859b4957b0f 100644 --- a/apps/zadmin/templates/zadmin/addon_manage.html +++ b/apps/zadmin/templates/zadmin/addon_manage.html @@ -46,7 +46,7 @@

Versions & Files

Recalc Hash - {% if file.is_public() %} + {% if file.is_mirrorable() %} {{ "Copied" if file.has_been_copied() else "Not Copied" }} {% endif %}