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

This commit is contained in:
Mathieu Pillard 2024-09-23 11:34:35 +02:00 коммит произвёл GitHub
Родитель 7f7b132f0c
Коммит b5fcf30e53
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 66 добавлений и 2 удалений

Просмотреть файл

@ -573,7 +573,10 @@ class BlockAdmin(BlockAdminAddMixin, AMOModelAdmin):
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):

Просмотреть файл

@ -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),
),
]

Просмотреть файл

@ -158,9 +158,11 @@ class Block(ModelBase):
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):

Просмотреть файл

@ -176,6 +176,31 @@ class TestBlockAdmin(TestCase):
status_code=301,
)
def test_view_versions(self):
user = user_factory(email='someone@mozilla.com')
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)