|
37 | 37 | Reminder,
|
38 | 38 | Role,
|
39 | 39 | User,
|
40 |
| - UserAltRelationship |
| 40 | + UserAltRelationship, |
| 41 | + UserModSettings |
41 | 42 | )
|
42 | 43 |
|
43 | 44 | class FrozenFieldsMixin:
|
@@ -701,11 +702,23 @@ class UserSerializer(ModelSerializer):
|
701 | 702 | # ID field must be explicitly set as the default id field is read-only.
|
702 | 703 | id = IntegerField(min_value=0)
|
703 | 704 |
|
| 705 | + def to_representation(self, instance: User) -> dict: |
| 706 | + """Serialize the user to a dictionary, serializing the moderator settings.""" |
| 707 | + ret = super().to_representation(instance) |
| 708 | + |
| 709 | + if hasattr(instance, 'mod_settings') and instance.mod_settings is not None: |
| 710 | + ret['mod_settings'] = UserModSettingsSerializer(instance.mod_settings).data |
| 711 | + else: |
| 712 | + del ret['mod_settings'] |
| 713 | + |
| 714 | + return ret |
| 715 | + |
704 | 716 | class Meta:
|
705 | 717 | """Metadata defined for the Django REST Framework."""
|
706 | 718 |
|
707 | 719 | model = User
|
708 |
| - fields = ('id', 'name', 'display_name', 'discriminator', 'roles', 'in_guild') |
| 720 | + fields = ('id', 'name', 'display_name', 'discriminator', 'roles', |
| 721 | + 'in_guild', 'mod_settings') |
709 | 722 | depth = 1
|
710 | 723 | list_serializer_class = UserListSerializer
|
711 | 724 |
|
@@ -736,6 +749,14 @@ def get_alts(self, user: User) -> list[dict]:
|
736 | 749 | for alt in user.alts.through.objects.filter(source=user)
|
737 | 750 | ]
|
738 | 751 |
|
| 752 | +class UserModSettingsSerializer(ModelSerializer): |
| 753 | + """A class to serialize the moderator settings for a user.""" |
| 754 | + |
| 755 | + class Meta: |
| 756 | + """Meta settings for the user moderator settings serializer.""" |
| 757 | + |
| 758 | + model = UserModSettings |
| 759 | + fields = ('pings_disabled_until', 'pings_schedule_start', 'pings_schedule_end') |
739 | 760 |
|
740 | 761 | class NominationEntrySerializer(ModelSerializer):
|
741 | 762 | """A class providing (de-)serialization of `NominationEntry` instances."""
|
|
0 commit comments