Skip to content

Commit

Permalink
Rename "hard" BlockVersion to "soft" to unify the conceptual flow of …
Browse files Browse the repository at this point in the history
…"soft" blocks (#22707)
  • Loading branch information
KevinMind authored Sep 27, 2024
1 parent 65ed2fc commit 2f74a72
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/olympia/blocklist/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,9 @@ def users(self, obj):

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 4.2.16 on 2024-09-27 08:29

from django.db import migrations, models


def populate_soft_field(apps, schema_editor):
BlockVersion = apps.get_model('blocklist', 'BlockVersion')
BlockVersion.objects.filter(hard=False).update(soft=True)


def reverse_populate_soft_field(apps, schema_editor):
BlockVersion = apps.get_model('blocklist', 'BlockVersion')
BlockVersion.objects.filter(soft=True).update(hard=False)
BlockVersion.objects.filter(soft=False).update(hard=True)


class Migration(migrations.Migration):

dependencies = [
('blocklist', '0033_remove_block_max_version_remove_block_min_version_and_more'),
]

operations = [
# Forward migration operations
migrations.AddField(
model_name='blockversion',
name='soft',
field=models.BooleanField(default=False),
),
migrations.RunPython(populate_soft_field, reverse_populate_soft_field),
migrations.RemoveField(
model_name='blockversion',
name='hard',
),
]
4 changes: 2 additions & 2 deletions src/olympia/blocklist/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ 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)
soft = models.BooleanField(default=False)

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


Expand Down
2 changes: 1 addition & 1 deletion src/olympia/blocklist/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def test_view_versions(self):
updated_by=user,
)
# Make one of the blocks soft.
block.blockversion_set.get(version=third_version).update(hard=False)
block.blockversion_set.get(version=third_version).update(soft=True)

response = self.client.get(
reverse('admin:blocklist_block_change', args=(block.id,)),
Expand Down

0 comments on commit 2f74a72

Please sign in to comment.