Skip to content

Commit c38d05a

Browse files
Merge pull request #608 from python-discord/voicemute
2 parents 41fac4c + d9ccf84 commit c38d05a

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Generated by Django 3.0.14 on 2021-10-09 18:52
2+
from django.apps.registry import Apps
3+
from django.db import migrations, models
4+
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
5+
6+
7+
def migrate_infractions(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:
8+
Infraction = apps.get_model("api", "Infraction")
9+
10+
for infraction in Infraction.objects.filter(type="voice_ban"):
11+
infraction.type = "voice_mute"
12+
infraction.save()
13+
14+
15+
def unmigrate_infractions(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:
16+
Infraction = apps.get_model("api", "Infraction")
17+
18+
for infraction in Infraction.objects.filter(type="voice_mute"):
19+
infraction.type = "voice_ban"
20+
infraction.save()
21+
22+
23+
class Migration(migrations.Migration):
24+
25+
dependencies = [
26+
('api', '0073_otn_allow_GT_and_LT'),
27+
]
28+
29+
operations = [
30+
migrations.AlterField(
31+
model_name='infraction',
32+
name='type',
33+
field=models.CharField(choices=[('note', 'Note'), ('warning', 'Warning'), ('watch', 'Watch'), ('mute', 'Mute'), ('kick', 'Kick'), ('ban', 'Ban'), ('superstar', 'Superstar'), ('voice_ban', 'Voice Ban'), ('voice_mute', 'Voice Mute')], help_text='The type of the infraction.', max_length=10),
34+
),
35+
migrations.RunPython(migrate_infractions, unmigrate_infractions)
36+
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Generated by Django 3.1.14 on 2022-01-25 20:22
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api', '0078_merge_20211213_0552'),
10+
('api', '0074_voice_mute'),
11+
]
12+
13+
operations = [
14+
]

pydis_site/apps/api/models/bot/infraction.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Infraction(ModelReprMixin, models.Model):
1717
("ban", "Ban"),
1818
("superstar", "Superstar"),
1919
("voice_ban", "Voice Ban"),
20+
("voice_mute", "Voice Mute"),
2021
)
2122
inserted_at = models.DateTimeField(
2223
default=timezone.now,
@@ -45,7 +46,7 @@ class Infraction(ModelReprMixin, models.Model):
4546
help_text="The user which applied the infraction."
4647
)
4748
type = models.CharField(
48-
max_length=9,
49+
max_length=10,
4950
choices=TYPE_CHOICES,
5051
help_text="The type of the infraction."
5152
)

pydis_site/apps/api/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def validate(self, attrs: dict) -> dict:
177177
raise ValidationError({'expires_at': [f'{infr_type} infractions cannot expire.']})
178178

179179
hidden = attrs.get('hidden')
180-
if hidden and infr_type in ('superstar', 'warning', 'voice_ban'):
180+
if hidden and infr_type in ('superstar', 'warning', 'voice_ban', 'voice_mute'):
181181
raise ValidationError({'hidden': [f'{infr_type} infractions cannot be hidden.']})
182182

183183
if not hidden and infr_type in ('note', ):

0 commit comments

Comments
 (0)