delete versions (bug 611203)
This commit is contained in:
Родитель
4165f1a7cf
Коммит
6de2bead03
|
@ -117,7 +117,7 @@ class EDIT_VERSION:
|
|||
|
||||
class DELETE_VERSION:
|
||||
id = 18
|
||||
format = _(u'{user.name} deleted version {0.version} from {addon}')
|
||||
format = _(u'{user.name} deleted version {0} from {addon}')
|
||||
keep = True
|
||||
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@
|
|||
</div>
|
||||
|
||||
<div id="modal-delete-version" class="modal modal_delete">
|
||||
<form method="post" action="">
|
||||
<form method="post" action="{{ url('devhub.versions.delete', addon.id) }}">
|
||||
<h2>{{ _('Delete Add-on Version') }}</h2>
|
||||
<p>
|
||||
{% trans %}
|
||||
|
@ -143,6 +143,7 @@
|
|||
{% endtrans %}
|
||||
</p>
|
||||
{{ csrf() }}
|
||||
<input type="hidden" name="version_id" class="version_id">
|
||||
<input type="hidden" name="addon_id" class="addon_id" value="{{ addon.id }}">
|
||||
<button type="submit">{{ _('Delete Add-on Version') }}</button>
|
||||
{{ _('or') }} <a href="#" class="close">{{ _('Cancel') }}</a>
|
||||
|
|
|
@ -1421,9 +1421,13 @@ class TestVersion(test_utils.TestCase):
|
|||
def setUp(self):
|
||||
assert self.client.login(username='del@icio.us', password='password')
|
||||
self.addon = Addon.objects.get(id=3615)
|
||||
self.version = Version.objects.get(id=81551)
|
||||
self.url = reverse('devhub.versions', args=[3615])
|
||||
|
||||
def testVersionStatusPublic(self):
|
||||
self.delete_url = reverse('devhub.versions.delete', args=[3615])
|
||||
self.delete_data = {'addon_id': self.addon.pk, 'version_id': self.version.pk}
|
||||
|
||||
def test_version_status_public(self):
|
||||
res = self.client.get(self.url)
|
||||
doc = pq(res.content)
|
||||
assert doc('.version-status')
|
||||
|
@ -1434,6 +1438,15 @@ class TestVersion(test_utils.TestCase):
|
|||
doc = pq(res.content)
|
||||
assert doc('.version-status.version-disabled')
|
||||
|
||||
def test_delete_version(self):
|
||||
res = self.client.post(self.delete_url, self.delete_data)
|
||||
assert not Version.objects.filter(pk=81551).exists()
|
||||
|
||||
def test_cant_delete_version(self):
|
||||
self.client.logout()
|
||||
res = self.client.post(self.delete_url, self.delete_data)
|
||||
eq_(res.status_code, 302)
|
||||
assert Version.objects.filter(pk=81551).exists()
|
||||
|
||||
class TestVersionEdit(test_utils.TestCase):
|
||||
fixtures = ['base/apps', 'base/users', 'base/addon_3615',
|
||||
|
|
|
@ -35,6 +35,8 @@ detail_patterns = patterns('',
|
|||
views.addons_section, name='devhub.addons.section'),
|
||||
|
||||
url('^versions/$', views.version_list, name='devhub.versions'),
|
||||
url('^versions/delete$', views.version_delete,
|
||||
name='devhub.versions.delete'),
|
||||
url('^versions/add$', views.version_add, name='devhub.versions.add'),
|
||||
url('^versions/(?P<version_id>\d+)$', views.version_edit,
|
||||
name='devhub.versions.edit'),
|
||||
|
|
|
@ -518,6 +518,15 @@ def version_edit(request, addon_id, addon, version_id):
|
|||
return jingo.render(request, 'devhub/versions/edit.html', data)
|
||||
|
||||
|
||||
@dev_required
|
||||
@post_required
|
||||
def version_delete(request, addon_id, addon):
|
||||
version_id = request.POST.get('version_id')
|
||||
version = get_object_or_404(Version, pk=version_id, addon=addon)
|
||||
version.delete()
|
||||
return redirect('devhub.versions', addon_id)
|
||||
|
||||
|
||||
@dev_required
|
||||
def version_add(request, addon_id, addon):
|
||||
if request.method == 'POST':
|
||||
|
|
|
@ -77,7 +77,7 @@ class Version(amo.models.ModelBase):
|
|||
return reverse('addons.versions', args=(self.addon.id, self.version,))
|
||||
|
||||
def delete(self):
|
||||
amo.log(amo.LOG.DELETE_VERSION, self.addon, self)
|
||||
amo.log(amo.LOG.DELETE_VERSION, self.addon, str(self.version))
|
||||
super(Version, self).delete()
|
||||
|
||||
@amo.cached_property(writable=True)
|
||||
|
|
|
@ -9,7 +9,9 @@ from pyquery import PyQuery
|
|||
import amo
|
||||
from amo.urlresolvers import reverse
|
||||
from addons.models import Addon
|
||||
from devhub.models import ActivityLog
|
||||
from files.models import File, Platform
|
||||
from users.models import UserProfile
|
||||
from versions import views, utils
|
||||
from versions.models import Version
|
||||
from versions.compare import version_int, dict_from_int
|
||||
|
@ -39,7 +41,7 @@ def test_dict_from_int():
|
|||
|
||||
|
||||
class TestVersion(test_utils.TestCase):
|
||||
fixtures = ['base/addon_3615']
|
||||
fixtures = ['base/addon_3615', 'base/admin']
|
||||
|
||||
def test_compatible_apps(self):
|
||||
v = Version.objects.get(pk=81551)
|
||||
|
@ -93,6 +95,25 @@ class TestVersion(test_utils.TestCase):
|
|||
assert self._get_version(amo.STATUS_PENDING).is_unreviewed
|
||||
assert not self._get_version(amo.STATUS_PUBLIC).is_unreviewed
|
||||
|
||||
def test_version_delete(self):
|
||||
version = Version.objects.get(pk=81551)
|
||||
version.delete()
|
||||
assert Addon.uncached.get(pk=3615)
|
||||
|
||||
def test_version_delete_files(self):
|
||||
version = Version.objects.get(pk=81551)
|
||||
eq_(version.files.count(), 1)
|
||||
version.delete()
|
||||
eq_(version.files.count(), 0)
|
||||
|
||||
def test_version_delete_logs(self):
|
||||
user = UserProfile.objects.get(pk=55021)
|
||||
amo.set_user(user)
|
||||
version = Version.objects.get(pk=81551)
|
||||
eq_(ActivityLog.objects.count(), 0)
|
||||
version.delete()
|
||||
eq_(ActivityLog.objects.count(), 1)
|
||||
|
||||
|
||||
class TestViews(test_utils.TestCase):
|
||||
fixtures = ['addons/eula+contrib-addon', 'base/apps']
|
||||
|
|
Загрузка…
Ссылка в новой задаче