unhide files when enabling an addon (bug 651899)
This commit is contained in:
Родитель
64c9ff359b
Коммит
3fe0e774d3
|
@ -856,16 +856,6 @@ def update_name_table(sender, **kw):
|
|||
dbsignals.post_save.connect(update_name_table, sender=Addon)
|
||||
|
||||
|
||||
def check_addon_status(sender, instance, **kw):
|
||||
if kw.get('raw'):
|
||||
return
|
||||
if instance.is_disabled:
|
||||
for f in File.objects.filter(version__addon=instance.id):
|
||||
f.hide_disabled_file()
|
||||
dbsignals.post_save.connect(check_addon_status, sender=Addon,
|
||||
dispatch_uid='check_addon_status')
|
||||
|
||||
|
||||
def clear_name_table(sender, **kw):
|
||||
addon = kw['instance']
|
||||
ReverseNameLookup.delete(addon.id)
|
||||
|
@ -905,6 +895,18 @@ def watch_status(old_attr={}, new_attr={}, instance=None,
|
|||
pass
|
||||
|
||||
|
||||
@Addon.on_change
|
||||
def watch_disabled(old_attr={}, new_attr={}, instance=None, sender=None, **kw):
|
||||
attrs = dict((k,v) for k, v in old_attr.items()
|
||||
if k in ('disabled_by_user', 'status'))
|
||||
if Addon(**attrs).is_disabled and not instance.is_disabled:
|
||||
for f in File.objects.filter(version__addon=instance.id):
|
||||
f.unhide_disabled_file()
|
||||
if instance.is_disabled and not Addon(**attrs).is_disabled:
|
||||
for f in File.objects.filter(version__addon=instance.id):
|
||||
f.hide_disabled_file()
|
||||
|
||||
|
||||
class MiniAddonManager(AddonManager):
|
||||
|
||||
def get_query_set(self):
|
||||
|
|
|
@ -9,7 +9,7 @@ from django.core import mail
|
|||
from django.core.cache import cache
|
||||
from django.utils import translation
|
||||
|
||||
from mock import patch, patch_object
|
||||
from mock import patch, patch_object, Mock
|
||||
from nose.tools import eq_, assert_not_equal
|
||||
import test_utils
|
||||
|
||||
|
@ -1261,3 +1261,45 @@ class TestRemoveLocale(test_utils.TestCase):
|
|||
.values_list('locale', flat=True))
|
||||
eq_(sorted(qs.filter(id=a.name_id)), ['en-US'])
|
||||
eq_(sorted(qs.filter(id=a.description_id)), ['en-US', 'he'])
|
||||
|
||||
|
||||
class TestAddonWatchDisabled(test_utils.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.addon = Addon(type=amo.ADDON_THEME, disabled_by_user=False,
|
||||
status=amo.STATUS_PUBLIC)
|
||||
self.addon.save()
|
||||
|
||||
@patch('addons.models.File.objects.filter')
|
||||
def test_no_disabled_change(self, file_mock):
|
||||
mock = Mock()
|
||||
file_mock.return_value = [mock]
|
||||
self.addon.save()
|
||||
assert not mock.unhide_disabled_file.called
|
||||
assert not mock.hide_disabled_file.called
|
||||
|
||||
@patch('addons.models.File.objects.filter')
|
||||
def test_disable_addon(self, file_mock):
|
||||
mock = Mock()
|
||||
file_mock.return_value = [mock]
|
||||
self.addon.update(disabled_by_user=True)
|
||||
assert not mock.unhide_disabled_file.called
|
||||
assert mock.hide_disabled_file.called
|
||||
|
||||
@patch('addons.models.File.objects.filter')
|
||||
def test_admin_disable_addon(self, file_mock):
|
||||
mock = Mock()
|
||||
file_mock.return_value = [mock]
|
||||
self.addon.update(status=amo.STATUS_DISABLED)
|
||||
assert not mock.unhide_disabled_file.called
|
||||
assert mock.hide_disabled_file.called
|
||||
|
||||
@patch('addons.models.File.objects.filter')
|
||||
def test_enable_addon(self, file_mock):
|
||||
mock = Mock()
|
||||
file_mock.return_value = [mock]
|
||||
self.addon.update(status=amo.STATUS_DISABLED)
|
||||
mock.reset_mock()
|
||||
self.addon.update(status=amo.STATUS_PUBLIC)
|
||||
assert mock.unhide_disabled_file.called
|
||||
assert not mock.hide_disabled_file.called
|
||||
|
|
Загрузка…
Ссылка в новой задаче