From ee3f4f937c99ef3db92afc2fcba746003ec694f0 Mon Sep 17 00:00:00 2001 From: Akarys42 Date: Mon, 28 Oct 2019 18:20:07 +0100 Subject: Add a attachments field to the message model --- pydis_site/apps/api/models/bot/message.py | 6 ++++++ pydis_site/apps/api/serializers.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pydis_site/apps/api/models/bot/message.py b/pydis_site/apps/api/models/bot/message.py index 31316a01..72b0b61a 100644 --- a/pydis_site/apps/api/models/bot/message.py +++ b/pydis_site/apps/api/models/bot/message.py @@ -51,6 +51,12 @@ class Message(ModelReprMixin, models.Model): ), help_text="Embeds attached to this message." ) + attachments = pgfields.ArrayField( + models.URLField( + max_length=512 + ), + help_text="Attachments attached to this message." + ) @property def timestamp(self) -> datetime: diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py index 8a605612..e091ff4f 100644 --- a/pydis_site/apps/api/serializers.py +++ b/pydis_site/apps/api/serializers.py @@ -49,7 +49,8 @@ class DeletedMessageSerializer(ModelSerializer): fields = ( 'id', 'author', 'channel_id', 'content', - 'embeds', 'deletion_context' + 'embeds', 'deletion_context', + 'attachments' ) -- cgit v1.2.3 From 541850858cb1fe7da61fa94ed4f8d3e0f787e3a7 Mon Sep 17 00:00:00 2001 From: Akarys42 Date: Mon, 28 Oct 2019 18:22:00 +0100 Subject: Add migration for message.attachments --- .../migrations/0047_deletedmessage_attachments.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 pydis_site/apps/api/migrations/0047_deletedmessage_attachments.py diff --git a/pydis_site/apps/api/migrations/0047_deletedmessage_attachments.py b/pydis_site/apps/api/migrations/0047_deletedmessage_attachments.py new file mode 100644 index 00000000..a738faff --- /dev/null +++ b/pydis_site/apps/api/migrations/0047_deletedmessage_attachments.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.6 on 2019-10-28 17:12 + +import django.contrib.postgres.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0046_reminder_jump_url'), + ] + + operations = [ + migrations.AddField( + model_name='deletedmessage', + name='attachments', + field=django.contrib.postgres.fields.ArrayField(base_field=models.URLField(max_length=512), default=[], help_text='Attachments attached to this message.', size=None), + preserve_default=False, + ), + ] -- cgit v1.2.3 From 803331562bcc8bf5b09b2a7e9fcfbe00e8796ea9 Mon Sep 17 00:00:00 2001 From: Akarys42 Date: Mon, 28 Oct 2019 18:23:47 +0100 Subject: Show attachments in staff logs --- pydis_site/templates/staff/logs.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pydis_site/templates/staff/logs.html b/pydis_site/templates/staff/logs.html index 9c8ed7d3..a0bfa2a7 100644 --- a/pydis_site/templates/staff/logs.html +++ b/pydis_site/templates/staff/logs.html @@ -24,6 +24,11 @@
{{ message.content|linebreaks }}
+
+ {% for attachment in message.attachments %} + Attachment + {% endfor %} +
{% for embed in message.embeds %}
-- cgit v1.2.3 From 14cde62b4d8358032f1b1f706250efaaf9c646ea Mon Sep 17 00:00:00 2001 From: Akarys42 Date: Mon, 28 Oct 2019 18:50:23 +0100 Subject: Write tests for message.attachments --- pydis_site/apps/api/tests/test_deleted_messages.py | 9 ++++++--- pydis_site/apps/staff/tests/test_logs_view.py | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pydis_site/apps/api/tests/test_deleted_messages.py b/pydis_site/apps/api/tests/test_deleted_messages.py index d1e9f2f5..b3a8197b 100644 --- a/pydis_site/apps/api/tests/test_deleted_messages.py +++ b/pydis_site/apps/api/tests/test_deleted_messages.py @@ -25,14 +25,16 @@ class DeletedMessagesWithoutActorTests(APISubdomainTestCase): 'id': 55, 'channel_id': 5555, 'content': "Terror Billy is a meanie", - 'embeds': [] + 'embeds': [], + 'attachments': [] }, { 'author': cls.author.id, 'id': 56, 'channel_id': 5555, 'content': "If you purge this, you're evil", - 'embeds': [] + 'embeds': [], + 'attachments': [] } ] } @@ -64,7 +66,8 @@ class DeletedMessagesWithActorTests(APISubdomainTestCase): 'id': 12903, 'channel_id': 1824, 'content': "I hate trailing commas", - 'embeds': [] + 'embeds': [], + 'attachments': [] }, ] } diff --git a/pydis_site/apps/staff/tests/test_logs_view.py b/pydis_site/apps/staff/tests/test_logs_view.py index 32cb6bbf..b01e3f3e 100644 --- a/pydis_site/apps/staff/tests/test_logs_view.py +++ b/pydis_site/apps/staff/tests/test_logs_view.py @@ -37,6 +37,7 @@ class TestLogsView(TestCase): channel_id=1984, content='I think my tape has run out...', embeds=[], + attachments=[], deletion_context=cls.deletion_context, ) @@ -101,6 +102,7 @@ class TestLogsView(TestCase): channel_id=1984, content='Does that mean this thing will halt?', embeds=[cls.embed_one, cls.embed_two], + attachments=['https://http.cat/100', 'https://http.cat/402'], deletion_context=cls.deletion_context, ) -- cgit v1.2.3 From 904edb20f694c40435ba27f5a96f759dbf87f3e3 Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Thu, 31 Oct 2019 13:16:15 +0100 Subject: Allow empty attachment field --- .../api/migrations/0048_alter_deletedmessage_api.py | 19 +++++++++++++++++++ pydis_site/apps/api/models/bot/message.py | 1 + 2 files changed, 20 insertions(+) create mode 100644 pydis_site/apps/api/migrations/0048_alter_deletedmessage_api.py diff --git a/pydis_site/apps/api/migrations/0048_alter_deletedmessage_api.py b/pydis_site/apps/api/migrations/0048_alter_deletedmessage_api.py new file mode 100644 index 00000000..364f57b1 --- /dev/null +++ b/pydis_site/apps/api/migrations/0048_alter_deletedmessage_api.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.6 on 2019-10-31 12:14 + +import django.contrib.postgres.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0047_deletedmessage_attachments'), + ] + + operations = [ + migrations.AlterField( + model_name='deletedmessage', + name='attachments', + field=django.contrib.postgres.fields.ArrayField(base_field=models.URLField(max_length=512), blank=True, help_text='Attachments attached to this message.', size=None), + ), + ] diff --git a/pydis_site/apps/api/models/bot/message.py b/pydis_site/apps/api/models/bot/message.py index 72b0b61a..8b18fc9f 100644 --- a/pydis_site/apps/api/models/bot/message.py +++ b/pydis_site/apps/api/models/bot/message.py @@ -55,6 +55,7 @@ class Message(ModelReprMixin, models.Model): models.URLField( max_length=512 ), + blank=True, help_text="Attachments attached to this message." ) -- cgit v1.2.3 From 80c5799cb3538dcfff48b2f9f017097abb65ab72 Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Fri, 15 Nov 2019 10:04:29 +0100 Subject: Allow blank attachment field --- pydis_site/apps/api/migrations/0047_deletedmessage_attachments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydis_site/apps/api/migrations/0047_deletedmessage_attachments.py b/pydis_site/apps/api/migrations/0047_deletedmessage_attachments.py index a738faff..f335e003 100644 --- a/pydis_site/apps/api/migrations/0047_deletedmessage_attachments.py +++ b/pydis_site/apps/api/migrations/0047_deletedmessage_attachments.py @@ -14,7 +14,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='deletedmessage', name='attachments', - field=django.contrib.postgres.fields.ArrayField(base_field=models.URLField(max_length=512), default=[], help_text='Attachments attached to this message.', size=None), + field=django.contrib.postgres.fields.ArrayField(base_field=models.URLField(max_length=512), default=[], blank=True, help_text='Attachments attached to this message.', size=None), preserve_default=False, ), ] -- cgit v1.2.3 From 912ecffab9797fa86ed90590438de3bd1211f2c8 Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Fri, 15 Nov 2019 10:05:02 +0100 Subject: Delete useless migration file --- .../api/migrations/0048_alter_deletedmessage_api.py | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 pydis_site/apps/api/migrations/0048_alter_deletedmessage_api.py diff --git a/pydis_site/apps/api/migrations/0048_alter_deletedmessage_api.py b/pydis_site/apps/api/migrations/0048_alter_deletedmessage_api.py deleted file mode 100644 index 364f57b1..00000000 --- a/pydis_site/apps/api/migrations/0048_alter_deletedmessage_api.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 2.2.6 on 2019-10-31 12:14 - -import django.contrib.postgres.fields -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0047_deletedmessage_attachments'), - ] - - operations = [ - migrations.AlterField( - model_name='deletedmessage', - name='attachments', - field=django.contrib.postgres.fields.ArrayField(base_field=models.URLField(max_length=512), blank=True, help_text='Attachments attached to this message.', size=None), - ), - ] -- cgit v1.2.3 From 4b58cf53a7931ab0b3091266afa6e15dd0b985a0 Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Fri, 15 Nov 2019 10:16:49 +0100 Subject: Update migration history --- .../migrations/0047_deletedmessage_attachments.py | 20 -------------------- .../migrations/0049_deletedmessage_attachments.py | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 20 deletions(-) delete mode 100644 pydis_site/apps/api/migrations/0047_deletedmessage_attachments.py create mode 100644 pydis_site/apps/api/migrations/0049_deletedmessage_attachments.py diff --git a/pydis_site/apps/api/migrations/0047_deletedmessage_attachments.py b/pydis_site/apps/api/migrations/0047_deletedmessage_attachments.py deleted file mode 100644 index f335e003..00000000 --- a/pydis_site/apps/api/migrations/0047_deletedmessage_attachments.py +++ /dev/null @@ -1,20 +0,0 @@ -# Generated by Django 2.2.6 on 2019-10-28 17:12 - -import django.contrib.postgres.fields -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0046_reminder_jump_url'), - ] - - operations = [ - migrations.AddField( - model_name='deletedmessage', - name='attachments', - field=django.contrib.postgres.fields.ArrayField(base_field=models.URLField(max_length=512), default=[], blank=True, help_text='Attachments attached to this message.', size=None), - preserve_default=False, - ), - ] diff --git a/pydis_site/apps/api/migrations/0049_deletedmessage_attachments.py b/pydis_site/apps/api/migrations/0049_deletedmessage_attachments.py new file mode 100644 index 00000000..9cbde96d --- /dev/null +++ b/pydis_site/apps/api/migrations/0049_deletedmessage_attachments.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.6 on 2019-10-28 17:12 + +import django.contrib.postgres.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0048_add_infractions_unique_constraints_active'), + ] + + operations = [ + migrations.AddField( + model_name='deletedmessage', + name='attachments', + field=django.contrib.postgres.fields.ArrayField(base_field=models.URLField(max_length=512), default=[], blank=True, help_text='Attachments attached to this message.', size=None), + preserve_default=False, + ), + ] -- cgit v1.2.3 From 8e4ed686ebe06e8e15604d204969042efb434b30 Mon Sep 17 00:00:00 2001 From: Akarys42 Date: Wed, 20 Nov 2019 18:21:16 +0100 Subject: Test for the attachment image to be in the staff log --- pydis_site/apps/staff/tests/test_logs_view.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pydis_site/apps/staff/tests/test_logs_view.py b/pydis_site/apps/staff/tests/test_logs_view.py index b01e3f3e..1415c558 100644 --- a/pydis_site/apps/staff/tests/test_logs_view.py +++ b/pydis_site/apps/staff/tests/test_logs_view.py @@ -151,6 +151,21 @@ class TestLogsView(TestCase): self.assertInHTML(embed_colour_needle.format(colour=embed_one_colour), html_response) self.assertInHTML(embed_colour_needle.format(colour=embed_two_colour), html_response) + def test_if_both_attachments_are_included_html_response(self): + url = reverse('logs', host="staff", args=(self.deletion_context.id,)) + response = self.client.get(url) + + html_response = response.content.decode() + attachment_needle = 'Attachment' + self.assertInHTML( + attachment_needle.format(url=self.deleted_message_two.attachments[0]), + html_response + ) + self.assertInHTML( + attachment_needle.format(url=self.deleted_message_two.attachments[1]), + html_response + ) + def test_if_html_in_content_is_properly_escaped(self): url = reverse('logs', host="staff", args=(self.deletion_context.id,)) response = self.client.get(url) -- cgit v1.2.3 From 8c23efacc061bd0018075aed689d0123fc8d8d84 Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Mon, 13 Jan 2020 13:08:29 +0100 Subject: Update migration dependency to the latest merged --- pydis_site/apps/api/migrations/0049_deletedmessage_attachments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydis_site/apps/api/migrations/0049_deletedmessage_attachments.py b/pydis_site/apps/api/migrations/0049_deletedmessage_attachments.py index 9cbde96d..31ac239a 100644 --- a/pydis_site/apps/api/migrations/0049_deletedmessage_attachments.py +++ b/pydis_site/apps/api/migrations/0049_deletedmessage_attachments.py @@ -7,7 +7,7 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('api', '0048_add_infractions_unique_constraints_active'), + ('api', '0049_offensivemessage'), ] operations = [ -- cgit v1.2.3