Merge pull request #2516 from FinnStutzenstein/Issue2502
Remove chat history
This commit is contained in:
commit
676e783039
@ -22,6 +22,7 @@ Core:
|
|||||||
- Moved custom slides to own app "topics". Renamed it to "Topic".
|
- Moved custom slides to own app "topics". Renamed it to "Topic".
|
||||||
- Added support for multiple projectors.
|
- Added support for multiple projectors.
|
||||||
- Added an overlay for the current list of speakers.
|
- Added an overlay for the current list of speakers.
|
||||||
|
- Added button to clear the chatbox.
|
||||||
|
|
||||||
Motions:
|
Motions:
|
||||||
- Added origin field.
|
- Added origin field.
|
||||||
|
19
openslides/core/migrations/0007_manage_chat_permission.py
Normal file
19
openslides/core/migrations/0007_manage_chat_permission.py
Normal 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'))},
|
||||||
|
),
|
||||||
|
]
|
@ -287,7 +287,8 @@ class ChatMessage(RESTModelMixin, models.Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
default_permissions = ()
|
default_permissions = ()
|
||||||
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):
|
def __str__(self):
|
||||||
return 'Message {}'.format(self.timestamp)
|
return 'Message {}'.format(self.timestamp)
|
||||||
|
@ -1405,7 +1405,7 @@ img {
|
|||||||
border-color: #dddddd;
|
border-color: #dddddd;
|
||||||
border-width: 1px;
|
border-width: 1px;
|
||||||
box-shadow: -5px 5px 5px rgba(0, 0, 0, 0.2);
|
box-shadow: -5px 5px 5px rgba(0, 0, 0, 0.2);
|
||||||
height: 200px;
|
height: 234px;
|
||||||
padding: 0 10px 10px 10px;
|
padding: 0 10px 10px 10px;
|
||||||
z-index: 5;
|
z-index: 5;
|
||||||
}
|
}
|
||||||
|
@ -1338,6 +1338,10 @@ angular.module('OpenSlidesApp.core.site', [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$scope.clearChatHistory = function () {
|
||||||
|
$http.post('/rest/core/chatmessage/clear/');
|
||||||
|
};
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@ -63,6 +63,12 @@
|
|||||||
<button type="submit" class="btn btn-default" id="messageSendButton">
|
<button type="submit" class="btn btn-default" id="messageSendButton">
|
||||||
<i class="fa fa-comment"></i>
|
<i class="fa fa-comment"></i>
|
||||||
</button>
|
</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>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -15,25 +15,27 @@ from django.core.urlresolvers import get_resolver
|
|||||||
from django.db.models import F
|
from django.db.models import F
|
||||||
from django.http import Http404, HttpResponse
|
from django.http import Http404, HttpResponse
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from openslides import __version__ as version
|
from .. import __version__ as version
|
||||||
from openslides.utils import views as utils_views
|
from ..utils import views as utils_views
|
||||||
from openslides.utils.collection import Collection, CollectionElement
|
from ..utils.autoupdate import inform_deleted_data
|
||||||
from openslides.utils.plugins import (
|
from ..utils.collection import Collection, CollectionElement
|
||||||
|
from ..utils.plugins import (
|
||||||
get_plugin_description,
|
get_plugin_description,
|
||||||
get_plugin_verbose_name,
|
get_plugin_verbose_name,
|
||||||
get_plugin_version,
|
get_plugin_version,
|
||||||
)
|
)
|
||||||
from openslides.utils.rest_api import (
|
from ..utils.rest_api import (
|
||||||
ModelViewSet,
|
ModelViewSet,
|
||||||
Response,
|
Response,
|
||||||
SimpleMetadata,
|
SimpleMetadata,
|
||||||
ValidationError,
|
ValidationError,
|
||||||
ViewSet,
|
ViewSet,
|
||||||
detail_route,
|
detail_route,
|
||||||
|
list_route,
|
||||||
)
|
)
|
||||||
from openslides.utils.search import search
|
from ..utils.search import search
|
||||||
|
|
||||||
from .access_permissions import (
|
from .access_permissions import (
|
||||||
ChatMessageAccessPermissions,
|
ChatMessageAccessPermissions,
|
||||||
ConfigAccessPermissions,
|
ConfigAccessPermissions,
|
||||||
@ -667,13 +669,18 @@ class ChatMessageViewSet(ModelViewSet):
|
|||||||
"""
|
"""
|
||||||
if self.action in ('list', 'retrieve'):
|
if self.action in ('list', 'retrieve'):
|
||||||
result = self.get_access_permissions().check_permissions(self.request.user)
|
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
|
# We do not want anonymous users to use the chat even the anonymous
|
||||||
# group has the permission core.can_use_chat.
|
# group has the permission core.can_use_chat.
|
||||||
result = (
|
result = (
|
||||||
self.action in ('metadata', 'create') and
|
|
||||||
self.request.user.is_authenticated() and
|
self.request.user.is_authenticated() and
|
||||||
self.request.user.has_perm('core.can_use_chat'))
|
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
|
return result
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
def perform_create(self, serializer):
|
||||||
@ -683,6 +690,22 @@ class ChatMessageViewSet(ModelViewSet):
|
|||||||
"""
|
"""
|
||||||
serializer.save(user=self.request.user)
|
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
|
# Special API views
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ def create_builtin_groups_and_admin(**kwargs):
|
|||||||
'core.can_manage_config',
|
'core.can_manage_config',
|
||||||
'core.can_manage_projector',
|
'core.can_manage_projector',
|
||||||
'core.can_manage_tags',
|
'core.can_manage_tags',
|
||||||
|
'core.can_manage_chat',
|
||||||
'core.can_see_frontpage',
|
'core.can_see_frontpage',
|
||||||
'core.can_see_projector',
|
'core.can_see_projector',
|
||||||
'core.can_use_chat',
|
'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_projector'],
|
||||||
permission_dict['core.can_manage_tags'],
|
permission_dict['core.can_manage_tags'],
|
||||||
permission_dict['core.can_use_chat'],
|
permission_dict['core.can_use_chat'],
|
||||||
|
permission_dict['core.can_manage_chat'],
|
||||||
permission_dict['mediafiles.can_see'],
|
permission_dict['mediafiles.can_see'],
|
||||||
permission_dict['mediafiles.can_manage'],
|
permission_dict['mediafiles.can_manage'],
|
||||||
permission_dict['mediafiles.can_upload'],
|
permission_dict['mediafiles.can_upload'],
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
from rest_framework import status
|
||||||
from rest_framework.test import APIClient
|
from rest_framework.test import APIClient
|
||||||
|
|
||||||
from openslides.core.config import config
|
from openslides.core.config import config
|
||||||
@ -145,3 +146,18 @@ class TestConfigDBQueries(TestCase):
|
|||||||
"""
|
"""
|
||||||
with self.assertNumQueries(61):
|
with self.assertNumQueries(61):
|
||||||
self.client.get(reverse('config-list'))
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user