aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorGravatar Johannes Christ <[email protected]>2018-11-18 21:13:47 +0100
committerGravatar Johannes Christ <[email protected]>2018-11-18 21:13:47 +0100
commit9ac6157ba2b9f86598eede69df7b67fa320f95b2 (patch)
tree0ce8f8ff3a372b65bbe29a72af61e51bd2731806 /api
parentAdd the abstract `Message` model. (diff)
Add the `MessageDeletionContext` model.
Diffstat (limited to 'api')
-rw-r--r--api/migrations/0018_messagedeletioncontext.py24
-rw-r--r--api/models.py19
-rw-r--r--api/tests/test_models.py19
3 files changed, 57 insertions, 5 deletions
diff --git a/api/migrations/0018_messagedeletioncontext.py b/api/migrations/0018_messagedeletioncontext.py
new file mode 100644
index 00000000..39a4fb87
--- /dev/null
+++ b/api/migrations/0018_messagedeletioncontext.py
@@ -0,0 +1,24 @@
+# Generated by Django 2.1.1 on 2018-11-18 20:12
+
+import api.models
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('api', '0017_auto_20181029_1921'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='MessageDeletionContext',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('creation', models.DateTimeField(help_text='When this deletion took place.')),
+ ('actor', models.ForeignKey(help_text='The original actor causing this deletion. Could be the author of a manual clean command invocation, the bot when executing automatic actions, or nothing to indicate that the bulk deletion was not issued by us.', null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Member')),
+ ],
+ bases=(api.models.ModelReprMixin, models.Model),
+ ),
+ ]
diff --git a/api/models.py b/api/models.py
index 3ba0ac5c..bb3489d0 100644
--- a/api/models.py
+++ b/api/models.py
@@ -241,6 +241,25 @@ class Message(ModelReprMixin, models.Model):
abstract = True
+class MessageDeletionContext(ModelReprMixin, models.Model):
+ actor = models.ForeignKey(
+ Member,
+ on_delete=models.CASCADE,
+ help_text=(
+ "The original actor causing this deletion. Could be the author "
+ "of a manual clean command invocation, the bot when executing "
+ "automatic actions, or nothing to indicate that the bulk "
+ "deletion was not issued by us."
+ ),
+ null=True
+ )
+ creation = models.DateTimeField(
+ # Consider whether we want to add a validator here that ensures
+ # the deletion context does not take place in the future.
+ help_text="When this deletion took place."
+ )
+
+
class Tag(ModelReprMixin, models.Model):
"""A tag providing (hopefully) useful information."""
diff --git a/api/tests/test_models.py b/api/tests/test_models.py
index 1e4af806..92a59f46 100644
--- a/api/tests/test_models.py
+++ b/api/tests/test_models.py
@@ -1,12 +1,14 @@
+from datetime import datetime
+
from django.test import SimpleTestCase
from ..models import (
DocumentationLink, Member,
- Message, ModelReprMixin,
- OffTopicChannelName, Role,
- SnakeFact, SnakeIdiom,
- SnakeName, SpecialSnake,
- Tag
+ Message, MessageDeletionContext,
+ ModelReprMixin, OffTopicChannelName,
+ Role, SnakeFact,
+ SnakeIdiom, SnakeName,
+ SpecialSnake, Tag
)
@@ -51,6 +53,13 @@ class StringDunderMethodTests(SimpleTestCase):
content="wooey",
embeds=[]
),
+ MessageDeletionContext(
+ actor=Member(
+ id=5555, name='shawn',
+ discriminator=555, avatar_hash=None
+ ),
+ creation=datetime.utcnow()
+ ),
Member(
id=5, name='bob',
discriminator=1, avatar_hash=None