From a8a0322c871ef04920167ded706cfdc8a425d958 Mon Sep 17 00:00:00 2001 From: bast Date: Fri, 18 Jun 2021 13:46:06 -0700 Subject: Adjust Message model to support new nitro messages with over 4000 chars --- .../apps/api/migrations/0070_auto_20210618_2010.py | 18 ++++++++++ pydis_site/apps/api/models/bot/message.py | 2 +- pydis_site/apps/api/tests/test_models.py | 40 +++++++++++++++++++++- 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 pydis_site/apps/api/migrations/0070_auto_20210618_2010.py (limited to 'pydis_site/apps') diff --git a/pydis_site/apps/api/migrations/0070_auto_20210618_2010.py b/pydis_site/apps/api/migrations/0070_auto_20210618_2010.py new file mode 100644 index 00000000..b0c79b32 --- /dev/null +++ b/pydis_site/apps/api/migrations/0070_auto_20210618_2010.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.14 on 2021-06-18 20:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0069_documentationlink_validators'), + ] + + operations = [ + migrations.AlterField( + model_name='deletedmessage', + name='content', + field=models.CharField(blank=True, help_text='The content of this message, taken from Discord.', max_length=4000), + ), + ] diff --git a/pydis_site/apps/api/models/bot/message.py b/pydis_site/apps/api/models/bot/message.py index ff06de21..60e2a553 100644 --- a/pydis_site/apps/api/models/bot/message.py +++ b/pydis_site/apps/api/models/bot/message.py @@ -43,7 +43,7 @@ class Message(ModelReprMixin, models.Model): verbose_name="Channel ID" ) content = models.CharField( - max_length=2_000, + max_length=4_000, help_text="The content of this message, taken from Discord.", blank=True ) diff --git a/pydis_site/apps/api/tests/test_models.py b/pydis_site/apps/api/tests/test_models.py index 66052e01..1303639e 100644 --- a/pydis_site/apps/api/tests/test_models.py +++ b/pydis_site/apps/api/tests/test_models.py @@ -1,6 +1,7 @@ from datetime import datetime as dt -from django.test import SimpleTestCase +from django.core.exceptions import ValidationError +from django.test import SimpleTestCase, TestCase from django.utils import timezone from pydis_site.apps.api.models import ( @@ -34,6 +35,43 @@ class ReprMixinTests(SimpleTestCase): self.assertEqual(repr(self.klass), expected) +class NitroMessageLengthTest(TestCase): + def setUp(self): + self.user = User.objects.create(id=50, name='bill', discriminator=5) + self.context = MessageDeletionContext.objects.create( + id=50, + actor=self.user, + creation=dt.utcnow() + ) + + def test_create(self): + message = DeletedMessage( + id=46, + author=self.user, + channel_id=666, + content="w"*4000, + deletion_context=self.context, + embeds=[] + ) + + try: + message.clean_fields() + except Exception as e: + self.fail(f"Creation of message of length 3950 failed with: {e}") + + def test_create_failure(self): + message = DeletedMessage( + id=47, + author=self.user, + channel_id=666, + content="w"*4001, + deletion_context=self.context, + embeds=[] + ) + + self.assertRaisesRegex(ValidationError, "content':", message.clean_fields) + + class StringDunderMethodTests(SimpleTestCase): def setUp(self): self.nomination = Nomination( -- cgit v1.2.3 From c40ed8c159f5101d1bc677a66406cef7c99843aa Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 18 Jun 2021 22:16:53 +0100 Subject: Use BigInt for permissions field and remove max value validator BigInt is needed as Discord's permissions number now exceeds that which can be stored in a normal int. I have removed the max value validator, as this just adds maintanence burden for us each time Discord adds new permissions. --- .../apps/api/migrations/0070_auto_20210618_2114.py | 19 +++++++++++++++++++ pydis_site/apps/api/models/bot/role.py | 8 ++------ 2 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 pydis_site/apps/api/migrations/0070_auto_20210618_2114.py (limited to 'pydis_site/apps') diff --git a/pydis_site/apps/api/migrations/0070_auto_20210618_2114.py b/pydis_site/apps/api/migrations/0070_auto_20210618_2114.py new file mode 100644 index 00000000..1d25e421 --- /dev/null +++ b/pydis_site/apps/api/migrations/0070_auto_20210618_2114.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.14 on 2021-06-18 21:14 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0069_documentationlink_validators'), + ] + + operations = [ + migrations.AlterField( + model_name='role', + name='permissions', + field=models.BigIntegerField(help_text='The integer value of the permission bitset of this role from Discord.', validators=[django.core.validators.MinValueValidator(limit_value=0, message='Role permissions cannot be negative.')]), + ), + ] diff --git a/pydis_site/apps/api/models/bot/role.py b/pydis_site/apps/api/models/bot/role.py index cfadfec4..733a8e08 100644 --- a/pydis_site/apps/api/models/bot/role.py +++ b/pydis_site/apps/api/models/bot/role.py @@ -1,6 +1,6 @@ from __future__ import annotations -from django.core.validators import MaxValueValidator, MinValueValidator +from django.core.validators import MinValueValidator from django.db import models from pydis_site.apps.api.models.mixins import ModelReprMixin @@ -38,16 +38,12 @@ class Role(ModelReprMixin, models.Model): ), help_text="The integer value of the colour of this role from Discord." ) - permissions = models.IntegerField( + permissions = models.BigIntegerField( validators=( MinValueValidator( limit_value=0, message="Role permissions cannot be negative." ), - MaxValueValidator( - limit_value=2 << 32, - message="Role permission bitset exceeds value of having all permissions" - ) ), help_text="The integer value of the permission bitset of this role from Discord." ) -- cgit v1.2.3 From 115220eee2e977e00b720a97e3dde0cf4a7497d2 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Mon, 21 Jun 2021 16:58:36 +0100 Subject: Remove RLBot from Communities list --- pydis_site/apps/resources/resources/communities/rlbot.yaml | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 pydis_site/apps/resources/resources/communities/rlbot.yaml (limited to 'pydis_site/apps') diff --git a/pydis_site/apps/resources/resources/communities/rlbot.yaml b/pydis_site/apps/resources/resources/communities/rlbot.yaml deleted file mode 100644 index d12c1dec..00000000 --- a/pydis_site/apps/resources/resources/communities/rlbot.yaml +++ /dev/null @@ -1,13 +0,0 @@ -description: RLBot is a community of programmers making awesome Rocket League bots. - They've created a framework that you can use to write bots in a number of languages (including Python), - and they host regular tournaments where botmakers can pit their creations against each other. -title_image: https://i.imgur.com/S8L1muZ.png -title_url: https://discord.gg/4JJdJKb -position: 7 -urls: - - icon: branding/discord - url: https://discord.gg/4JJdJKb - color: blurple - - icon: regular/link - url: https://www.rlbot.org/ - color: teal -- cgit v1.2.3 From 05730b3c55811ec2b9c7c0ff8484714a3ee498b2 Mon Sep 17 00:00:00 2001 From: bast Date: Thu, 24 Jun 2021 07:34:59 -0700 Subject: Add pragma: no cover to mark failure condition of test as known ok --- pydis_site/apps/api/tests/test_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pydis_site/apps') diff --git a/pydis_site/apps/api/tests/test_models.py b/pydis_site/apps/api/tests/test_models.py index 1303639e..5c9ddea4 100644 --- a/pydis_site/apps/api/tests/test_models.py +++ b/pydis_site/apps/api/tests/test_models.py @@ -56,7 +56,7 @@ class NitroMessageLengthTest(TestCase): try: message.clean_fields() - except Exception as e: + except Exception as e: # pragma: no cover self.fail(f"Creation of message of length 3950 failed with: {e}") def test_create_failure(self): -- cgit v1.2.3 From 6c9c7f078d2d677f4e377264e2741fd02a228cab Mon Sep 17 00:00:00 2001 From: bast Date: Thu, 24 Jun 2021 07:46:14 -0700 Subject: Recreate nitro message length migration and name it --- .../apps/api/migrations/0070_auto_20210618_2010.py | 18 ------------------ .../migrations/0071_increase_message_content_4000.py | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 pydis_site/apps/api/migrations/0070_auto_20210618_2010.py create mode 100644 pydis_site/apps/api/migrations/0071_increase_message_content_4000.py (limited to 'pydis_site/apps') diff --git a/pydis_site/apps/api/migrations/0070_auto_20210618_2010.py b/pydis_site/apps/api/migrations/0070_auto_20210618_2010.py deleted file mode 100644 index b0c79b32..00000000 --- a/pydis_site/apps/api/migrations/0070_auto_20210618_2010.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.0.14 on 2021-06-18 20:10 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0069_documentationlink_validators'), - ] - - operations = [ - migrations.AlterField( - model_name='deletedmessage', - name='content', - field=models.CharField(blank=True, help_text='The content of this message, taken from Discord.', max_length=4000), - ), - ] diff --git a/pydis_site/apps/api/migrations/0071_increase_message_content_4000.py b/pydis_site/apps/api/migrations/0071_increase_message_content_4000.py new file mode 100644 index 00000000..6ca5d21a --- /dev/null +++ b/pydis_site/apps/api/migrations/0071_increase_message_content_4000.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.14 on 2021-06-24 14:45 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0070_auto_20210618_2114'), + ] + + operations = [ + migrations.AlterField( + model_name='deletedmessage', + name='content', + field=models.CharField(blank=True, help_text='The content of this message, taken from Discord.', max_length=4000), + ), + ] -- cgit v1.2.3