Skip to content

Commit 086e941

Browse files
committed
Add UserModSettings model
Update imports in API models to include UserModSettings Add migration for UserModSettings model
1 parent ba6aec1 commit 086e941

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 5.0.6 on 2024-05-19 19:15
2+
3+
import django.db.models.deletion
4+
import pydis_site.apps.api.models.mixins
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('api', '0096_merge_0093_user_alts_0095_user_display_name'),
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='UserModSettings',
17+
fields=[
18+
('moderator', models.OneToOneField(help_text='The moderator for whom these settings belong to', on_delete=django.db.models.deletion.CASCADE, primary_key=True, related_name='mod_settings', serialize=False, to='api.user')),
19+
('pings_disabled_until', models.DateTimeField(help_text='Date and time that moderation pings are disabled until', null=True)),
20+
('pings_schedule_start', models.TimeField(help_text='UTC time that the moderator wishes to receive pings from', null=True)),
21+
('pings_schedule_end', models.DurationField(help_text='Duration after the schedule start time the moderator wishes to receive pings', null=True)),
22+
],
23+
bases=(pydis_site.apps.api.models.mixins.ModelReprMixin, models.Model),
24+
),
25+
migrations.AddConstraint(
26+
model_name='usermodsettings',
27+
constraint=models.CheckConstraint(check=models.Q(models.Q(('pings_schedule_end__isnull', True), ('pings_schedule_start__isnull', True)), models.Q(('pings_schedule_end__isnull', False), ('pings_schedule_start__isnull', False)), _connector='OR'), name='complete_pings_schedule'),
28+
),
29+
]

pydis_site/apps/api/models/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
Reminder,
2121
Role,
2222
User,
23-
UserAltRelationship
23+
UserAltRelationship,
24+
UserModSettings
2425
)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
from .offensive_message import OffensiveMessage
1717
from .reminder import Reminder
1818
from .role import Role
19-
from .user import User, UserAltRelationship
19+
from .user import User, UserAltRelationship, UserModSettings

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

+37-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ def username(self) -> str:
9999
"""
100100
return str(self)
101101

102-
103102
class UserAltRelationship(ModelReprMixin, ModelTimestampMixin, models.Model):
104103
"""A relationship between a Discord user and its alts."""
105104

@@ -140,3 +139,40 @@ class Meta:
140139
check=~models.Q(source=models.F("target")),
141140
),
142141
]
142+
143+
class UserModSettings(ModelReprMixin, models.Model):
144+
"""Moderation settings for a Moderator member of staff."""
145+
146+
moderator = models.OneToOneField(
147+
User,
148+
primary_key=True,
149+
on_delete=models.CASCADE,
150+
related_name="mod_settings",
151+
help_text="The moderator for whom these settings belong to"
152+
)
153+
154+
pings_disabled_until = models.DateTimeField(
155+
null=True,
156+
help_text="Date and time that moderation pings are disabled until"
157+
)
158+
159+
pings_schedule_start = models.TimeField(
160+
null=True,
161+
help_text="UTC time that the moderator wishes to receive pings from"
162+
)
163+
164+
pings_schedule_end = models.DurationField(
165+
null=True,
166+
help_text="Duration after the schedule start time the moderator wishes to receive pings"
167+
)
168+
169+
class Meta:
170+
"""Meta options on the moderator preferences."""
171+
172+
constraints = [
173+
models.CheckConstraint(
174+
check=models.Q(pings_schedule_start__isnull=True, pings_schedule_end__isnull=True)
175+
| models.Q(pings_schedule_start__isnull=False, pings_schedule_end__isnull=False),
176+
name="complete_pings_schedule"
177+
)
178+
]

0 commit comments

Comments
 (0)