diff --git a/forum/migrations/0007_forummessagemeta.py b/forum/migrations/0007_forummessagemeta.py
new file mode 100644
index 00000000..38e0ff25
--- /dev/null
+++ b/forum/migrations/0007_forummessagemeta.py
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.utils.timezone
+from django.conf import settings
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ('forum', '0006_auto_20170128_2243'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='ForumMessageMeta',
+ fields=[
+ ('id', models.AutoField(verbose_name='ID', serialize=False, primary_key=True, auto_created=True)),
+ ('date', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date')),
+ ('action', models.CharField(max_length=16, choices=[('EDIT', 'Edit'), ('DELETE', 'Delete'), ('UNDELETE', 'Undelete')], verbose_name='action')),
+ ('message', models.ForeignKey(related_name='metas', to='forum.ForumMessage')),
+ ('user', models.ForeignKey(related_name='forum_message_metas', to=settings.AUTH_USER_MODEL)),
+ ],
+ ),
+ ]
diff --git a/forum/models.py b/forum/models.py
index 4c2a15d9..0483fb40 100644
--- a/forum/models.py
+++ b/forum/models.py
@@ -156,12 +156,33 @@ class ForumMessage(models.Model):
def can_be_viewed_by(self, user):
return user.can_view(self.topic)
+ def can_be_moderated_by(self, user):
+ return user.is_in_group(settings.SITH_GROUP_FORUM_ADMIN_ID)
+
def get_absolute_url(self):
return self.topic.get_absolute_url() + "#first_unread"
def mark_as_read(self, user):
self.readers.add(user)
+ def is_deleted(self):
+ meta = self.metas.exclude(action="EDIT").order_by('-date').first()
+ if meta:
+ return meta.action == "DELETE"
+ return False
+
+MESSAGE_META_ACTIONS = [
+ ('EDIT', _("Message edited by")),
+ ('DELETE', _("Message deleted by")),
+ ('UNDELETE', _("Message undeleted by")),
+ ]
+
+class ForumMessageMeta(models.Model):
+ user = models.ForeignKey(User, related_name="forum_message_metas")
+ message = models.ForeignKey(ForumMessage, related_name="metas")
+ date = models.DateTimeField(_('date'), default=timezone.now)
+ action = models.CharField(_("action"), choices=MESSAGE_META_ACTIONS, max_length=16)
+
class ForumUserInfo(models.Model):
user = models.OneToOneField(User, related_name="_forum_infos")
last_read_date = models.DateTimeField(_('last read date'), default=datetime(year=settings.SITH_SCHOOL_START_YEAR,
diff --git a/forum/templates/forum/topic.jinja b/forum/templates/forum/topic.jinja
index 9915f7fe..41ceb1c4 100644
--- a/forum/templates/forum/topic.jinja
+++ b/forum/templates/forum/topic.jinja
@@ -67,6 +67,13 @@
{% if user.can_edit(m) %}
{% trans %}Edit{% endtrans %}
{% endif %}
+ {% if m.can_be_moderated_by(user) %}
+ {% if m.is_deleted() %}
+ {% trans %}Undelete{% endtrans %}
+ {% else %}
+ {% trans %}Delete{% endtrans %}
+ {% endif %}
+ {% endif %}
{{ m.date|date(DATETIME_FORMAT) }} {{ m.date|time(DATETIME_FORMAT) }}
@@ -74,6 +81,13 @@