Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/olympia/addons/management/commands/process_addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ def get_recalc_needed_filters():
],
'allowed_kwargs': ('with_deleted',),
},
'disable_opensearch_addons': {
# We're re-using the `delete_addons` method but don't allow for hard
# deletes
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we allow for hard deletes? At some point in the next few months we will want to hard-delete all the opensearch addons we'll be soft deleting this time. (And any soft-deleted opensearch add-ons in the database currently).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be me being overly cautious but we may want to hard delete them at some point but not in the immediate future and we'll soft-delete first. That's why I separated them, not sure the cautiousness is appropriate.

Happy to change that if you think it isn't.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand why we don't want to hard-delete them now, but I don't understand why you explicitly don't want the --with_deleted option available, so they can be hard deleted in the future without a further patch.

'method': delete_addons,
'qs': [
Q(type=amo.ADDON_SEARCH)
],
'allowed_kwargs': ('with_deleted',),
}
}


Expand Down
34 changes: 34 additions & 0 deletions src/olympia/addons/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,3 +738,37 @@ def test_normal(self):
assert Addon.objects.get(id=self.extension.id)
assert Addon.objects.get(id=self.static_theme.id)
assert Addon.objects.get(id=self.dictionary.id)


class TestDeleteOpenSearchAddons(TestCase):
def setUp(self):
# Some add-ons that shouldn't be deleted
self.extension = addon_factory()
self.dictionary = addon_factory(type=amo.ADDON_DICT)

# And some opensearch plugins
addon_factory(type=amo.ADDON_SEARCH)
addon_factory(type=amo.ADDON_SEARCH)

assert Addon.objects.count() == 4
assert Addon.unfiltered.count() == 4

def test_basic(self):
call_command(
'process_addons', task='disable_opensearch_addons')

assert Addon.objects.count() == 2
# They have only been disabled and not hard deleted
assert Addon.unfiltered.count() == 4
assert Addon.objects.get(id=self.extension.id)
assert Addon.objects.get(id=self.dictionary.id)

def test_hard(self):
call_command(
'process_addons', task='disable_opensearch_addons',
with_deleted=True)

assert Addon.objects.count() == 2
assert Addon.unfiltered.count() == 2
assert Addon.objects.get(id=self.extension.id)
assert Addon.objects.get(id=self.dictionary.id)