Skip to content

Commit

Permalink
Add UserModSettings model
Browse files Browse the repository at this point in the history
Update imports in API models to include UserModSettings

Add migration for UserModSettings model
  • Loading branch information
jb3 committed May 24, 2024
1 parent ba6aec1 commit 086e941
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
29 changes: 29 additions & 0 deletions pydis_site/apps/api/migrations/0097_user_mod_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 5.0.6 on 2024-05-19 19:15

import django.db.models.deletion
import pydis_site.apps.api.models.mixins
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0096_merge_0093_user_alts_0095_user_display_name'),
]

operations = [
migrations.CreateModel(
name='UserModSettings',
fields=[
('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')),
('pings_disabled_until', models.DateTimeField(help_text='Date and time that moderation pings are disabled until', null=True)),
('pings_schedule_start', models.TimeField(help_text='UTC time that the moderator wishes to receive pings from', null=True)),
('pings_schedule_end', models.DurationField(help_text='Duration after the schedule start time the moderator wishes to receive pings', null=True)),
],
bases=(pydis_site.apps.api.models.mixins.ModelReprMixin, models.Model),
),
migrations.AddConstraint(
model_name='usermodsettings',
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'),
),
]
3 changes: 2 additions & 1 deletion pydis_site/apps/api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
Reminder,
Role,
User,
UserAltRelationship
UserAltRelationship,
UserModSettings
)
2 changes: 1 addition & 1 deletion pydis_site/apps/api/models/bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
from .offensive_message import OffensiveMessage
from .reminder import Reminder
from .role import Role
from .user import User, UserAltRelationship
from .user import User, UserAltRelationship, UserModSettings
38 changes: 37 additions & 1 deletion pydis_site/apps/api/models/bot/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def username(self) -> str:
"""
return str(self)


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

Expand Down Expand Up @@ -140,3 +139,40 @@ class Meta:
check=~models.Q(source=models.F("target")),
),
]

class UserModSettings(ModelReprMixin, models.Model):
"""Moderation settings for a Moderator member of staff."""

moderator = models.OneToOneField(
User,
primary_key=True,
on_delete=models.CASCADE,
related_name="mod_settings",
help_text="The moderator for whom these settings belong to"
)

pings_disabled_until = models.DateTimeField(
null=True,
help_text="Date and time that moderation pings are disabled until"
)

pings_schedule_start = models.TimeField(
null=True,
help_text="UTC time that the moderator wishes to receive pings from"
)

pings_schedule_end = models.DurationField(
null=True,
help_text="Duration after the schedule start time the moderator wishes to receive pings"
)

class Meta:
"""Meta options on the moderator preferences."""

constraints = [
models.CheckConstraint(
check=models.Q(pings_schedule_start__isnull=True, pings_schedule_end__isnull=True)
| models.Q(pings_schedule_start__isnull=False, pings_schedule_end__isnull=False),
name="complete_pings_schedule"
)
]

0 comments on commit 086e941

Please sign in to comment.