diff options
| author | 2020-07-20 13:56:10 -0400 | |
|---|---|---|
| committer | 2020-07-20 13:56:10 -0400 | |
| commit | d720d56e8d99bcc5df1679cfe83593c39fc0cb0e (patch) | |
| tree | 04aba87e98d75d5052371139cca202c25311dba2 /pydis_site/apps | |
| parent | Bump jQuery version (diff) | |
| parent | Fix misleading documentation (diff) | |
Merge pull request #370 from python-discord/role-reminders
Add mentions field to Reminders model
Diffstat (limited to 'pydis_site/apps')
| -rw-r--r-- | pydis_site/apps/api/migrations/0055_reminder_mentions.py | 20 | ||||
| -rw-r--r-- | pydis_site/apps/api/migrations/0057_merge_20200716_0751.py | 14 | ||||
| -rw-r--r-- | pydis_site/apps/api/models/bot/reminder.py | 14 | ||||
| -rw-r--r-- | pydis_site/apps/api/serializers.py | 4 | ||||
| -rw-r--r-- | pydis_site/apps/api/tests/test_reminders.py | 1 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/reminder.py | 30 | 
6 files changed, 80 insertions, 3 deletions
| diff --git a/pydis_site/apps/api/migrations/0055_reminder_mentions.py b/pydis_site/apps/api/migrations/0055_reminder_mentions.py new file mode 100644 index 00000000..d73b450d --- /dev/null +++ b/pydis_site/apps/api/migrations/0055_reminder_mentions.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.14 on 2020-07-15 07:37 + +import django.contrib.postgres.fields +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('api', '0054_user_invalidate_unknown_role'), +    ] + +    operations = [ +        migrations.AddField( +            model_name='reminder', +            name='mentions', +            field=django.contrib.postgres.fields.ArrayField(base_field=models.BigIntegerField(validators=[django.core.validators.MinValueValidator(limit_value=0, message='Mention IDs cannot be negative.')]), blank=True, default=list, help_text='IDs of roles or users to ping with the reminder.', size=None), +        ), +    ] diff --git a/pydis_site/apps/api/migrations/0057_merge_20200716_0751.py b/pydis_site/apps/api/migrations/0057_merge_20200716_0751.py new file mode 100644 index 00000000..47a6d2d4 --- /dev/null +++ b/pydis_site/apps/api/migrations/0057_merge_20200716_0751.py @@ -0,0 +1,14 @@ +# Generated by Django 2.2.14 on 2020-07-16 07:51 + +from django.db import migrations + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('api', '0055_reminder_mentions'), +        ('api', '0056_allow_blank_user_roles'), +    ] + +    operations = [ +    ] diff --git a/pydis_site/apps/api/models/bot/reminder.py b/pydis_site/apps/api/models/bot/reminder.py index d53fedb5..4b5d15ca 100644 --- a/pydis_site/apps/api/models/bot/reminder.py +++ b/pydis_site/apps/api/models/bot/reminder.py @@ -1,3 +1,4 @@ +from django.contrib.postgres.fields import ArrayField  from django.core.validators import MinValueValidator  from django.db import models @@ -45,6 +46,19 @@ class Reminder(ModelReprMixin, models.Model):      expiration = models.DateTimeField(          help_text="When this reminder should be sent."      ) +    mentions = ArrayField( +        models.BigIntegerField( +            validators=( +                MinValueValidator( +                    limit_value=0, +                    message="Mention IDs cannot be negative." +                ), +            ) +        ), +        default=list, +        blank=True, +        help_text="IDs of roles or users to ping with the reminder." +    )      def __str__(self):          """Returns some info on the current reminder, for display purposes.""" diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py index f2d5144c..80e552a6 100644 --- a/pydis_site/apps/api/serializers.py +++ b/pydis_site/apps/api/serializers.py @@ -203,7 +203,9 @@ class ReminderSerializer(ModelSerializer):          """Metadata defined for the Django REST Framework."""          model = Reminder -        fields = ('active', 'author', 'jump_url', 'channel_id', 'content', 'expiration', 'id') +        fields = ( +            'active', 'author', 'jump_url', 'channel_id', 'content', 'expiration', 'id', 'mentions' +        )  class RoleSerializer(ModelSerializer): diff --git a/pydis_site/apps/api/tests/test_reminders.py b/pydis_site/apps/api/tests/test_reminders.py index c7fa07c9..a05d9296 100644 --- a/pydis_site/apps/api/tests/test_reminders.py +++ b/pydis_site/apps/api/tests/test_reminders.py @@ -62,6 +62,7 @@ class ReminderCreationTests(APISubdomainTestCase):              'expiration': datetime.utcnow().isoformat(),              'jump_url': "https://www.google.com",              'channel_id': 123, +            'mentions': [8888, 9999],          }          url = reverse('bot:reminder-list', host='api')          response = self.client.post(url, data=data) diff --git a/pydis_site/apps/api/viewsets/bot/reminder.py b/pydis_site/apps/api/viewsets/bot/reminder.py index 147f6dbc..6f8a28f2 100644 --- a/pydis_site/apps/api/viewsets/bot/reminder.py +++ b/pydis_site/apps/api/viewsets/bot/reminder.py @@ -27,9 +27,16 @@ class ReminderViewSet(      ...     {      ...         'active': True,      ...         'author': 1020103901030, +    ...         'mentions': [ +    ...             336843820513755157, +    ...             165023948638126080, +    ...             267628507062992896 +    ...         ],      ...         'content': "Make dinner",      ...         'expiration': '5018-11-20T15:52:00Z', -    ...         'id': 11 +    ...         'id': 11, +    ...         'channel_id': 634547009956872193, +    ...         'jump_url': "https://discord.com/channels/<guild_id>/<channel_id>/<message_id>"      ...     },      ...     ...      ... ] @@ -43,8 +50,11 @@ class ReminderViewSet(      #### Request body      >>> {      ...     'author': int, +    ...     'mentions': List[int],      ...     'content': str, -    ...     'expiration': str  # ISO-formatted datetime +    ...     'expiration': str,  # ISO-formatted datetime +    ...     'channel_id': int, +    ...     'jump_url': str      ... }      #### Status codes @@ -52,6 +62,22 @@ class ReminderViewSet(      - 400: if the body format is invalid      - 404: if no user with the given ID could be found +    ### PATCH /bot/reminders/<id:int> +    Update the user with the given `id`. +    All fields in the request body are optional. + +    #### Request body +    >>> { +    ...     'mentions': List[int], +    ...     'content': str, +    ...     'expiration': str  # ISO-formatted datetime +    ... } + +    #### Status codes +    - 200: returned on success +    - 400: if the body format is invalid +    - 404: if no user with the given ID could be found +      ### DELETE /bot/reminders/<id:int>      Delete the reminder with the given `id`. | 
