Only allow deletes for free addons (bug 699943)
This commit is contained in:
Родитель
838e549eae
Коммит
a1a2345cf8
|
@ -805,6 +805,11 @@ class Addon(amo.models.OnChangeMixin, amo.models.ModelBase):
|
||||||
def can_be_purchased(self):
|
def can_be_purchased(self):
|
||||||
return self.is_premium() and self.status in amo.REVIEWED_STATUSES
|
return self.is_premium() and self.status in amo.REVIEWED_STATUSES
|
||||||
|
|
||||||
|
def can_be_deleted(self):
|
||||||
|
"""Only incomplete or free addons can be deleted."""
|
||||||
|
return self.is_incomplete() or not (
|
||||||
|
self.is_premium() or self.is_webapp())
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def featured_random(cls, app, lang):
|
def featured_random(cls, app, lang):
|
||||||
return FeaturedManager.featured_ids(app, lang)
|
return FeaturedManager.featured_ids(app, lang)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `addons_categories` DROP FOREIGN KEY `addon_id_refs_id_206fde31`;
|
||||||
|
ALTER TABLE `addons_categories` ADD CONSTRAINT `addon_id_refs_id_206fde31` FOREIGN KEY (`addon_id`) REFERENCES `addons` (`id`) ON DELETE CASCADE;
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `addons_users` DROP FOREIGN KEY `addon_id_refs_id_2d0960a2`;
|
||||||
|
ALTER TABLE `addons_users` ADD CONSTRAINT `addon_id_refs_id_2d0960a2` FOREIGN KEY (`addon_id`) REFERENCES `addons` (`id`) ON DELETE CASCADE;
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `appsupport` DROP FOREIGN KEY `addon_id_refs_id_fd65824a`;
|
||||||
|
ALTER TABLE `appsupport` ADD CONSTRAINT `addon_id_refs_id_fd65824a` FOREIGN KEY (`addon_id`) REFERENCES `addons` (`id`) ON DELETE CASCADE;
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `submit_step` DROP FOREIGN KEY `submit_step_ibfk_1`;
|
||||||
|
ALTER TABLE `submit_step` ADD CONSTRAINT `submit_step_ibfk_1` FOREIGN KEY (`addon_id`) REFERENCES `addons` (`id`) ON DELETE CASCADE;
|
|
@ -8,7 +8,7 @@
|
||||||
{{ _('Resume') }}</a>
|
{{ _('Resume') }}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if check_addon_ownership(request, addon) %}
|
{% if check_addon_ownership(request, addon) and addon.can_be_deleted() %}
|
||||||
<li>
|
<li>
|
||||||
<a href="#" class="delete-addon tooltip"
|
<a href="#" class="delete-addon tooltip"
|
||||||
title="{{ _('Delete this add-on.') }}">{{ _('Delete') }}</a>
|
title="{{ _('Delete this add-on.') }}">{{ _('Delete') }}</a>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
{{ _('Resume') }}</a>
|
{{ _('Resume') }}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if check_addon_ownership(request, addon) %}
|
{% if check_addon_ownership(request, addon) and addon.can_be_deleted() %}
|
||||||
<li>
|
<li>
|
||||||
<a href="#" class="delete-addon tooltip"
|
<a href="#" class="delete-addon tooltip"
|
||||||
title="{{ _('Delete this app.') }}">{{ _('Delete') }}</a>
|
title="{{ _('Delete this app.') }}">{{ _('Delete') }}</a>
|
||||||
|
|
|
@ -80,11 +80,13 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if check_addon_ownership(request, addon) %}
|
{% if check_addon_ownership(request, addon) %}
|
||||||
{% if addon.disabled_by_user and addon.status != amo.STATUS_DISABLED %}
|
{% if addon.disabled_by_user and addon.status != amo.STATUS_DISABLED %}
|
||||||
<a href="{{ url('devhub.addons.enable', addon.slug) }}" id="enable-addon">{{ _('Enable Add-on') }}</a> ·
|
<a href="{{ url('devhub.addons.enable', addon.slug) }}" id="enable-addon">{{ _('Enable Add-on') }}</a>
|
||||||
{% elif not addon.is_disabled %}
|
{% elif not addon.is_disabled %}
|
||||||
<a href="#" id="disable-addon">{{ _('Disable Add-on') }}</a> ·
|
<a href="#" id="disable-addon">{{ _('Disable Add-on') }}</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if addon.can_be_deleted() %}
|
||||||
|
· <a href="#" id="delete-addon">{{ _('Delete Add-on') }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="#" id="delete-addon">{{ _('Delete Add-on') }}</a>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% set current = addon.current_version %}
|
{% set current = addon.current_version %}
|
||||||
{% if current %}
|
{% if current %}
|
||||||
|
|
|
@ -1109,6 +1109,45 @@ class TestMarketplace(MarketplaceMixin, amo.tests.TestCase):
|
||||||
res = self.client.get(url)
|
res = self.client.get(url)
|
||||||
eq_(res.status_code, 403)
|
eq_(res.status_code, 403)
|
||||||
|
|
||||||
|
def test_no_delete_link_premium_addon(self):
|
||||||
|
self.setup_premium()
|
||||||
|
doc = pq(self.client.get(reverse('devhub.versions',
|
||||||
|
args=[self.addon.slug])).content)
|
||||||
|
eq_(len(doc('#delete-addon')), 0)
|
||||||
|
|
||||||
|
def test_no_delete_premium_addon(self):
|
||||||
|
self.setup_premium()
|
||||||
|
res = self.client.post(reverse('devhub.addons.delete',
|
||||||
|
args=[self.addon.slug]),
|
||||||
|
{'password': 'password'})
|
||||||
|
eq_(res.status_code, 302)
|
||||||
|
assert Addon.objects.filter(pk=self.addon.id).exists(), (
|
||||||
|
"Unexpected: Addon should exist")
|
||||||
|
|
||||||
|
def test_no_delete_link_app(self):
|
||||||
|
self.addon.update(type=amo.ADDON_WEBAPP)
|
||||||
|
doc = pq(self.client.get(reverse('devhub.versions',
|
||||||
|
args=[self.addon.slug])).content)
|
||||||
|
eq_(len(doc('#delete-addon')), 0)
|
||||||
|
|
||||||
|
def test_no_delete_app(self):
|
||||||
|
self.addon.update(type=amo.ADDON_WEBAPP)
|
||||||
|
res = self.client.post(reverse('devhub.addons.delete',
|
||||||
|
args=[self.addon.slug]),
|
||||||
|
{'password': 'password'})
|
||||||
|
eq_(res.status_code, 302)
|
||||||
|
assert Addon.objects.filter(pk=self.addon.id).exists(), (
|
||||||
|
"Unexpected: Addon should exist")
|
||||||
|
|
||||||
|
def test_incomplete_app_delete(self):
|
||||||
|
waffle.models.Flag.objects.create(name='accept-webapps', everyone=True)
|
||||||
|
self.addon.update(type=amo.ADDON_WEBAPP, status=amo.STATUS_NULL)
|
||||||
|
res = self.client.post(reverse('devhub.addons.delete',
|
||||||
|
args=[self.addon.slug]),
|
||||||
|
{'password': 'password'})
|
||||||
|
assert not Addon.objects.filter(pk=self.addon.id).exists(), (
|
||||||
|
"Unexpected: Addon shouldn't exist")
|
||||||
|
|
||||||
|
|
||||||
class TestDelete(amo.tests.TestCase):
|
class TestDelete(amo.tests.TestCase):
|
||||||
fixtures = ('base/apps', 'base/users', 'base/addon_3615',
|
fixtures = ('base/apps', 'base/users', 'base/addon_3615',
|
||||||
|
|
|
@ -280,6 +280,12 @@ def edit(request, addon_id, addon):
|
||||||
|
|
||||||
@dev_required(owner_for_post=True)
|
@dev_required(owner_for_post=True)
|
||||||
def delete(request, addon_id, addon):
|
def delete(request, addon_id, addon):
|
||||||
|
# Database deletes only allowed for free or incomplete addons.
|
||||||
|
if not addon.can_be_deleted():
|
||||||
|
messages.error(request, _(
|
||||||
|
'Add-on cannot be deleted. Disable this add-on instead.'))
|
||||||
|
return redirect('devhub.versions', addon.slug)
|
||||||
|
|
||||||
form = forms.DeleteForm(request)
|
form = forms.DeleteForm(request)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
addon.delete('Removed via devhub')
|
addon.delete('Removed via devhub')
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `files` DROP FOREIGN KEY `version_id_refs_id_be9125ee`;
|
||||||
|
ALTER TABLE `files` ADD CONSTRAINT `version_id_refs_id_be9125ee` FOREIGN KEY (`version_id`) REFERENCES `versions` (`id`) ON DELETE CASCADE;
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `applications_versions` DROP FOREIGN KEY `version_id_refs_id_284c630`;
|
||||||
|
ALTER TABLE `applications_versions` ADD CONSTRAINT `version_id_refs_id_284c630` FOREIGN KEY (`version_id`) REFERENCES `versions` (`id`) ON DELETE CASCADE;
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `versions` DROP FOREIGN KEY `addon_id_refs_id_8420fd09`;
|
||||||
|
ALTER TABLE `versions` ADD CONSTRAINT `addon_id_refs_id_8420fd09` FOREIGN KEY (`addon_id`) REFERENCES `addons` (`id`) ON DELETE CASCADE;
|
|
@ -0,0 +1,15 @@
|
||||||
|
ALTER TABLE `addons_categories` DROP FOREIGN KEY `addons_categories_ibfk_3`;
|
||||||
|
ALTER TABLE `addons_categories` ADD CONSTRAINT `addons_categories_ibfk_3` FOREIGN KEY (`addon_id`) REFERENCES `addons` (`id`) ON DELETE CASCADE;
|
||||||
|
ALTER TABLE `addons_users` DROP FOREIGN KEY `addons_users_ibfk_1`;
|
||||||
|
ALTER TABLE `addons_users` ADD CONSTRAINT `addons_users_ibfk_1` FOREIGN KEY (`addon_id`) REFERENCES `addons` (`id`) ON DELETE CASCADE;
|
||||||
|
-- Table `appsupport` doesn't have a FK constraint on server currently. The below may fail, which is ok.
|
||||||
|
ALTER TABLE `appsupport` DROP FOREIGN KEY `addon_id_refs_id_fd65824a`;
|
||||||
|
ALTER TABLE `appsupport` ADD CONSTRAINT `addon_id_refs_id_fd65824a` FOREIGN KEY (`addon_id`) REFERENCES `addons` (`id`) ON DELETE CASCADE;
|
||||||
|
ALTER TABLE `submit_step` DROP FOREIGN KEY `submit_step_ibfk_1`;
|
||||||
|
ALTER TABLE `submit_step` ADD CONSTRAINT `submit_step_ibfk_1` FOREIGN KEY (`addon_id`) REFERENCES `addons` (`id`) ON DELETE CASCADE;
|
||||||
|
ALTER TABLE `files` DROP FOREIGN KEY `files_ibfk_1`;
|
||||||
|
ALTER TABLE `files` ADD CONSTRAINT `files_ibfk_1` FOREIGN KEY (`version_id`) REFERENCES `versions` (`id`) ON DELETE CASCADE;
|
||||||
|
ALTER TABLE `applications_versions` DROP FOREIGN KEY `applications_versions_ibfk_4`;
|
||||||
|
ALTER TABLE `applications_versions` ADD CONSTRAINT `applications_versions_ibfk_4` FOREIGN KEY (`version_id`) REFERENCES `versions` (`id`) ON DELETE CASCADE;
|
||||||
|
ALTER TABLE `versions` DROP FOREIGN KEY `versions_ibfk_1`;
|
||||||
|
ALTER TABLE `versions` ADD CONSTRAINT `versions_ibfk_1` FOREIGN KEY (`addon_id`) REFERENCES `addons` (`id`) ON DELETE CASCADE;
|
Загрузка…
Ссылка в новой задаче