From 2c88104434ad1af68877959059ef04a69eae5c33 Mon Sep 17 00:00:00 2001 From: kosayoda Date: Thu, 16 Jul 2020 10:38:14 +0800 Subject: Add mentions field to Reminder model --- pydis_site/apps/api/models/bot/reminder.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'pydis_site') 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.""" -- cgit v1.2.3 From cdbda598fafccdd4ef0a324e7b18ce070aaf2d70 Mon Sep 17 00:00:00 2001 From: kosayoda Date: Thu, 16 Jul 2020 10:38:58 +0800 Subject: Return mentions from ReminderSerializer --- pydis_site/apps/api/serializers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'pydis_site') 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): -- cgit v1.2.3 From 1e72079691fb1acf61390edad496736d332362ca Mon Sep 17 00:00:00 2001 From: kosayoda Date: Thu, 16 Jul 2020 10:39:23 +0800 Subject: Document mentions in ReminderViewSet --- pydis_site/apps/api/viewsets/bot/reminder.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'pydis_site') diff --git a/pydis_site/apps/api/viewsets/bot/reminder.py b/pydis_site/apps/api/viewsets/bot/reminder.py index 147f6dbc..5a44b7d3 100644 --- a/pydis_site/apps/api/viewsets/bot/reminder.py +++ b/pydis_site/apps/api/viewsets/bot/reminder.py @@ -27,6 +27,11 @@ class ReminderViewSet( ... { ... 'active': True, ... 'author': 1020103901030, + ... 'mentions': [ + ... 336843820513755157, + ... 165023948638126080, + ... 267628507062992896 + ... ], ... 'content': "Make dinner", ... 'expiration': '5018-11-20T15:52:00Z', ... 'id': 11 -- cgit v1.2.3 From 02412121e8272d35a03c30a80a4a67e6aabdf0eb Mon Sep 17 00:00:00 2001 From: kosayoda Date: Thu, 16 Jul 2020 10:40:03 +0800 Subject: Add migration for the mentions field in the Reminder model --- .../apps/api/migrations/0055_reminder_mentions.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 pydis_site/apps/api/migrations/0055_reminder_mentions.py (limited to 'pydis_site') 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), + ), + ] -- cgit v1.2.3 From 4c288387097dcb65feadce360857c9fbe1b2593f Mon Sep 17 00:00:00 2001 From: kosayoda Date: Thu, 16 Jul 2020 10:46:56 +0800 Subject: Document POSTing mentions in ReminderViewSet --- pydis_site/apps/api/viewsets/bot/reminder.py | 1 + 1 file changed, 1 insertion(+) (limited to 'pydis_site') diff --git a/pydis_site/apps/api/viewsets/bot/reminder.py b/pydis_site/apps/api/viewsets/bot/reminder.py index 5a44b7d3..b31330a0 100644 --- a/pydis_site/apps/api/viewsets/bot/reminder.py +++ b/pydis_site/apps/api/viewsets/bot/reminder.py @@ -48,6 +48,7 @@ class ReminderViewSet( #### Request body >>> { ... 'author': int, + ... 'mentions': List[int], ... 'content': str, ... 'expiration': str # ISO-formatted datetime ... } -- cgit v1.2.3 From 5cc5f5e2c7d4a6fa5b74aa33a6dbc7ffcf4bcc99 Mon Sep 17 00:00:00 2001 From: kosayoda Date: Thu, 16 Jul 2020 10:52:21 +0800 Subject: Document PATCH for reminders --- pydis_site/apps/api/viewsets/bot/reminder.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'pydis_site') diff --git a/pydis_site/apps/api/viewsets/bot/reminder.py b/pydis_site/apps/api/viewsets/bot/reminder.py index b31330a0..940d19d4 100644 --- a/pydis_site/apps/api/viewsets/bot/reminder.py +++ b/pydis_site/apps/api/viewsets/bot/reminder.py @@ -58,6 +58,22 @@ class ReminderViewSet( - 400: if the body format is invalid - 404: if no user with the given ID could be found + ### PATCH /bot/reminders/ + 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/ Delete the reminder with the given `id`. -- cgit v1.2.3 From 806b27bb30ceb32603bd90d31e32ae30bf8f499e Mon Sep 17 00:00:00 2001 From: kosayoda Date: Thu, 16 Jul 2020 14:11:35 +0800 Subject: Document more undocumented stuff --- pydis_site/apps/api/viewsets/bot/reminder.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'pydis_site') diff --git a/pydis_site/apps/api/viewsets/bot/reminder.py b/pydis_site/apps/api/viewsets/bot/reminder.py index 940d19d4..f4921d44 100644 --- a/pydis_site/apps/api/viewsets/bot/reminder.py +++ b/pydis_site/apps/api/viewsets/bot/reminder.py @@ -34,7 +34,9 @@ class ReminderViewSet( ... ], ... 'content': "Make dinner", ... 'expiration': '5018-11-20T15:52:00Z', - ... 'id': 11 + ... 'id': 11, + ... 'channel_id': 634547009956872193, + ... 'jump_url': "https://discord.com/channels///" ... }, ... ... ... ] @@ -50,7 +52,9 @@ class ReminderViewSet( ... 'author': int, ... 'mentions': List[int], ... 'content': str, - ... 'expiration': str # ISO-formatted datetime + ... 'expiration': str, # ISO-formatted datetime + ... 'channel_id': int, + ... 'jump_url': Optional[str] ... } #### Status codes -- cgit v1.2.3 From 18f055f9f9922033a4ef4172c8fa1eaa9cb2f4cd Mon Sep 17 00:00:00 2001 From: kosayoda Date: Thu, 16 Jul 2020 15:08:28 +0800 Subject: Add mentions field to valid data test --- pydis_site/apps/api/tests/test_reminders.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'pydis_site') diff --git a/pydis_site/apps/api/tests/test_reminders.py b/pydis_site/apps/api/tests/test_reminders.py index c7fa07c9..5042ea90 100644 --- a/pydis_site/apps/api/tests/test_reminders.py +++ b/pydis_site/apps/api/tests/test_reminders.py @@ -4,7 +4,7 @@ from django.forms.models import model_to_dict from django_hosts.resolvers import reverse from .base import APISubdomainTestCase -from ..models import Reminder, User +from ..models import Reminder, Role, User class UnauthedReminderAPITests(APISubdomainTestCase): @@ -54,6 +54,18 @@ class ReminderCreationTests(APISubdomainTestCase): name='Mermaid Man', discriminator=1234, ) + cls.user = User.objects.create( + id=5678, + name='Fish Dude', + discriminator=5678, + ) + cls.role = Role.objects.create( + id=555, + name="Random role", + colour=2, + permissions=0b01010010101, + position=10, + ) def test_accepts_valid_data(self): data = { @@ -62,6 +74,7 @@ class ReminderCreationTests(APISubdomainTestCase): 'expiration': datetime.utcnow().isoformat(), 'jump_url': "https://www.google.com", 'channel_id': 123, + 'mentions': [self.user.id, self.role.id], } url = reverse('bot:reminder-list', host='api') response = self.client.post(url, data=data) -- cgit v1.2.3 From fbcf39f2bb05b9746ac911d25c2118ac9cf9dff3 Mon Sep 17 00:00:00 2001 From: kosayoda Date: Thu, 16 Jul 2020 15:52:02 +0800 Subject: Merge migrations --- pydis_site/apps/api/migrations/0057_merge_20200716_0751.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 pydis_site/apps/api/migrations/0057_merge_20200716_0751.py (limited to 'pydis_site') 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 = [ + ] -- cgit v1.2.3 From f6111a35e0b5385ccd02cea12d0afc4a86615ba0 Mon Sep 17 00:00:00 2001 From: kosayoda Date: Sun, 19 Jul 2020 12:49:04 +0800 Subject: Use literal integers for mentions ID in test Since the mentions field stores static IDs and not foreign keys, there is no need to create the objects for the test. --- pydis_site/apps/api/tests/test_reminders.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'pydis_site') diff --git a/pydis_site/apps/api/tests/test_reminders.py b/pydis_site/apps/api/tests/test_reminders.py index 5042ea90..a05d9296 100644 --- a/pydis_site/apps/api/tests/test_reminders.py +++ b/pydis_site/apps/api/tests/test_reminders.py @@ -4,7 +4,7 @@ from django.forms.models import model_to_dict from django_hosts.resolvers import reverse from .base import APISubdomainTestCase -from ..models import Reminder, Role, User +from ..models import Reminder, User class UnauthedReminderAPITests(APISubdomainTestCase): @@ -54,18 +54,6 @@ class ReminderCreationTests(APISubdomainTestCase): name='Mermaid Man', discriminator=1234, ) - cls.user = User.objects.create( - id=5678, - name='Fish Dude', - discriminator=5678, - ) - cls.role = Role.objects.create( - id=555, - name="Random role", - colour=2, - permissions=0b01010010101, - position=10, - ) def test_accepts_valid_data(self): data = { @@ -74,7 +62,7 @@ class ReminderCreationTests(APISubdomainTestCase): 'expiration': datetime.utcnow().isoformat(), 'jump_url': "https://www.google.com", 'channel_id': 123, - 'mentions': [self.user.id, self.role.id], + 'mentions': [8888, 9999], } url = reverse('bot:reminder-list', host='api') response = self.client.post(url, data=data) -- cgit v1.2.3 From 387b763af7dfe3675a476ab6a2b9815e2ac8e83a Mon Sep 17 00:00:00 2001 From: kosayoda Date: Sun, 19 Jul 2020 12:50:01 +0800 Subject: Fix misleading documentation --- pydis_site/apps/api/viewsets/bot/reminder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pydis_site') diff --git a/pydis_site/apps/api/viewsets/bot/reminder.py b/pydis_site/apps/api/viewsets/bot/reminder.py index f4921d44..6f8a28f2 100644 --- a/pydis_site/apps/api/viewsets/bot/reminder.py +++ b/pydis_site/apps/api/viewsets/bot/reminder.py @@ -54,7 +54,7 @@ class ReminderViewSet( ... 'content': str, ... 'expiration': str, # ISO-formatted datetime ... 'channel_id': int, - ... 'jump_url': Optional[str] + ... 'jump_url': str ... } #### Status codes -- cgit v1.2.3