Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce the concept of soft-blocked versions, expose in the admin #22690

Merged
merged 1 commit into from
Sep 23, 2024
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
5 changes: 4 additions & 1 deletion src/olympia/blocklist/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,10 @@ def users(self, obj):

def blocked_versions(self, obj):
return ', '.join(
sorted(obj.blockversion_set.values_list('version__version', flat=True))
f'{version} ({"hard" if hard else "soft"})'
for version, hard in sorted(
obj.blockversion_set.values_list('version__version', 'hard')
)
)

def block_history(self, obj):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 4.2.16 on 2024-09-20 14:16

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('blocklist', '0032_alter_blocklistsubmission_reason_url_null_true'),
]

operations = [
migrations.RemoveField(
model_name='block',
name='max_version',
),
migrations.RemoveField(
model_name='block',
name='min_version',
),
migrations.RemoveField(
model_name='blocklistsubmission',
name='max_version',
),
migrations.RemoveField(
model_name='blocklistsubmission',
name='min_version',
),
migrations.AddField(
model_name='blockversion',
name='hard',
field=models.BooleanField(default=True),
),
]
4 changes: 3 additions & 1 deletion src/olympia/blocklist/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,11 @@ def get_blocks_from_guids(cls, guids):
class BlockVersion(ModelBase):
version = models.OneToOneField(Version, on_delete=models.CASCADE)
block = models.ForeignKey(Block, on_delete=models.CASCADE)
hard = models.BooleanField(default=True)

def __str__(self) -> str:
return f'Block.id={self.block_id} -> Version.id={self.version_id}'
blocktype = 'hard' if self.hard else 'soft'
return f'Block.id={self.block_id} ({blocktype}) -> Version.id={self.version_id}'


class BlocklistSubmissionQuerySet(BaseQuerySet):
Expand Down
25 changes: 25 additions & 0 deletions src/olympia/blocklist/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,31 @@ def test_guid_redirects(self):
status_code=301,
)

def test_view_versions(self):
user = user_factory(email='[email protected]')
self.grant_permission(user, 'Blocklist:Create')
self.client.force_login(user)

addon = addon_factory(version_kw={'version': '1.0'})
second_version = version_factory(addon=addon, version='2.0')
third_version = version_factory(addon=addon, version='3.0')
block = block_factory(
addon=addon,
version_ids=[second_version.id, third_version.id],
updated_by=user,
)
# Make one of the blocks soft.
block.blockversion_set.get(version=third_version).update(hard=False)

response = self.client.get(
reverse('admin:blocklist_block_change', args=(block.id,)),
)
assert response.status_code == 200
doc = pq(response.content)
assert doc('.field-blocked_versions').text() == (
'Blocked versions:\n2.0 (hard), 3.0 (soft)'
)


def check_checkbox(checkbox, version, is_checked, is_disabled):
assert checkbox.attrib['value'] == str(version.id)
Expand Down
Loading