Merge pull request #2516 from FinnStutzenstein/Issue2502

Remove chat history
This commit is contained in:
Norman Jäckel 2016-10-17 21:48:34 +02:00 committed by GitHub
commit 676e783039
9 changed files with 83 additions and 11 deletions

View File

@ -22,6 +22,7 @@ Core:
- Moved custom slides to own app "topics". Renamed it to "Topic".
- Added support for multiple projectors.
- Added an overlay for the current list of speakers.
- Added button to clear the chatbox.
Motions:
- Added origin field.

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.1 on 2016-10-17 09:50
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('core', '0006_multiprojector'),
]
operations = [
migrations.AlterModelOptions(
name='chatmessage',
options={'default_permissions': (), 'permissions': (('can_use_chat', 'Can use the chat'), ('can_manage_chat', 'Can manage the chat'))},
),
]

View File

@ -287,7 +287,8 @@ class ChatMessage(RESTModelMixin, models.Model):
class Meta:
default_permissions = ()
permissions = (
('can_use_chat', 'Can use the chat'),)
('can_use_chat', 'Can use the chat'),
('can_manage_chat', 'Can manage the chat'),)
def __str__(self):
return 'Message {}'.format(self.timestamp)

View File

@ -1405,7 +1405,7 @@ img {
border-color: #dddddd;
border-width: 1px;
box-shadow: -5px 5px 5px rgba(0, 0, 0, 0.2);
height: 200px;
height: 234px;
padding: 0 10px 10px 10px;
z-index: 5;
}

View File

@ -1338,6 +1338,10 @@ angular.module('OpenSlidesApp.core.site', [
}
}
});
$scope.clearChatHistory = function () {
$http.post('/rest/core/chatmessage/clear/');
};
}
])

View File

@ -63,6 +63,12 @@
<button type="submit" class="btn btn-default" id="messageSendButton">
<i class="fa fa-comment"></i>
</button>
<button os-perms="core.can_manage_chat" type="button"
class="btn btn-default btn-danger" id="clearchatHistory"
ng-bootbox-confirm="{{ 'Are you sure to delete the chat history?' | translate }}"
ng-bootbox-confirm-action="clearChatHistory()">
<i class="fa fa-trash"></i>
</button>
</span>
</div>
</form>

View File

@ -15,25 +15,27 @@ from django.core.urlresolvers import get_resolver
from django.db.models import F
from django.http import Http404, HttpResponse
from django.utils.timezone import now
from django.utils.translation import ugettext as _
from openslides import __version__ as version
from openslides.utils import views as utils_views
from openslides.utils.collection import Collection, CollectionElement
from openslides.utils.plugins import (
from .. import __version__ as version
from ..utils import views as utils_views
from ..utils.autoupdate import inform_deleted_data
from ..utils.collection import Collection, CollectionElement
from ..utils.plugins import (
get_plugin_description,
get_plugin_verbose_name,
get_plugin_version,
)
from openslides.utils.rest_api import (
from ..utils.rest_api import (
ModelViewSet,
Response,
SimpleMetadata,
ValidationError,
ViewSet,
detail_route,
list_route,
)
from openslides.utils.search import search
from ..utils.search import search
from .access_permissions import (
ChatMessageAccessPermissions,
ConfigAccessPermissions,
@ -667,13 +669,18 @@ class ChatMessageViewSet(ModelViewSet):
"""
if self.action in ('list', 'retrieve'):
result = self.get_access_permissions().check_permissions(self.request.user)
else:
elif self.action in ('metadata', 'create'):
# We do not want anonymous users to use the chat even the anonymous
# group has the permission core.can_use_chat.
result = (
self.action in ('metadata', 'create') and
self.request.user.is_authenticated() and
self.request.user.has_perm('core.can_use_chat'))
elif self.action == 'clear':
result = (
self.request.user.has_perm('core.can_use_chat') and
self.request.user.has_perm('core.can_manage_chat'))
else:
result = False
return result
def perform_create(self, serializer):
@ -683,6 +690,22 @@ class ChatMessageViewSet(ModelViewSet):
"""
serializer.save(user=self.request.user)
@list_route(methods=['post'])
def clear(self, request):
"""
Deletes all chat messages.
"""
# Collect all chat messages with their collection_string and id
chatmessages = ChatMessage.objects.all()
args = []
for chatmessage in chatmessages:
args.append(chatmessage.get_collection_string())
args.append(chatmessage.pk)
chatmessages.delete()
# Trigger autoupdate and setup response.
inform_deleted_data(*args)
return Response({'detail': _('All chat messages deleted successfully.')})
# Special API views

View File

@ -27,6 +27,7 @@ def create_builtin_groups_and_admin(**kwargs):
'core.can_manage_config',
'core.can_manage_projector',
'core.can_manage_tags',
'core.can_manage_chat',
'core.can_see_frontpage',
'core.can_see_projector',
'core.can_use_chat',
@ -102,6 +103,7 @@ def create_builtin_groups_and_admin(**kwargs):
permission_dict['core.can_manage_projector'],
permission_dict['core.can_manage_tags'],
permission_dict['core.can_use_chat'],
permission_dict['core.can_manage_chat'],
permission_dict['mediafiles.can_see'],
permission_dict['mediafiles.can_manage'],
permission_dict['mediafiles.can_upload'],

View File

@ -1,4 +1,5 @@
from django.core.urlresolvers import reverse
from rest_framework import status
from rest_framework.test import APIClient
from openslides.core.config import config
@ -145,3 +146,18 @@ class TestConfigDBQueries(TestCase):
"""
with self.assertNumQueries(61):
self.client.get(reverse('config-list'))
class ChatMessageViewSet(TestCase):
"""
Tests requests to deal with chat messages.
"""
def setUp(self):
admin = User.objects.get(pk=1)
self.client.force_login(admin)
ChatMessage.objects.create(message='test_message_peechiel8IeZoohaem9e', user=admin)
def test_clear_chat(self):
response = self.client.post(reverse('chatmessage-clear'))
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(ChatMessage.objects.all().count(), 0)