add "delete all speakers" button (fixes #2210)

This commit is contained in:
Maximilian Krambach 2016-07-07 13:33:18 +02:00
parent 2627724c55
commit 589137ece7
4 changed files with 47 additions and 13 deletions

View File

@ -8,6 +8,9 @@ Version 2.1 (unreleased)
======================== ========================
[https://github.com/OpenSlides/OpenSlides/milestones/2.1] [https://github.com/OpenSlides/OpenSlides/milestones/2.1]
Agenda:
- Added button to remove all speakers from a list of speakers.
Core: Core:
- Used Django Channels instead of Tornado. - Used Django Channels instead of Tornado.
- Added support for big assemblies with lots of users. - Added support for big assemblies with lots of users.

View File

@ -290,6 +290,26 @@ angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda'])
$scope.speakers = item.speakers; $scope.speakers = item.speakers;
}; };
//delete all speakers from list of speakers
$scope.removeAllSpeakers = function () {
var speakersOnList = [];
angular.forEach(item.speakers, function (speaker) {
speakersOnList.push(speaker.id);
});
$http.delete(
'/rest/agenda/item/' + item.id + '/manage_speaker/',
{headers: {'Content-Type': 'application/json'},
data: JSON.stringify({speaker: speakersOnList})}
)
.success(function(data){
$scope.speakers = item.speakers;
})
.error(function(data){
$scope.alert = { type: 'danger', msg: data.detail, show: true };
});
$scope.speakers = item.speakers;
};
// check if user is allowed to see 'add me' / 'remove me' button // check if user is allowed to see 'add me' / 'remove me' button
$scope.isAllowed = function (action) { $scope.isAllowed = function (action) {
var nextUsers = []; var nextUsers = [];

View File

@ -37,6 +37,12 @@
<div ng-if="item" class="details listOfSpeakers"> <div ng-if="item" class="details listOfSpeakers">
<div class="pull-right"> <div class="pull-right">
<span os-perms="agenda.can_manage"> <span os-perms="agenda.can_manage">
<button class="btn btn-danger"
ng-bootbox-confirm="{{ 'Are you sure you want to remove all speakers from this list?'| translate }}"
ng-bootbox-confirm-action="removeAllSpeakers()">
<i class="fa fa-trash fa-lg"></i>
<translate>Remove all speakers</translate>
</button>
<button ng-if="item.speaker_list_closed" ng-click="closeList(false)" <button ng-if="item.speaker_list_closed" ng-click="closeList(false)"
class="btn btn-sm btn-default"> class="btn btn-sm btn-default">
<i class="fa fa-toggle-off"></i> <i class="fa fa-toggle-off"></i>

View File

@ -81,8 +81,9 @@ class ItemViewSet(ListModelMixin, RetrieveModelMixin, UpdateModelMixin, GenericV
""" """
Special view endpoint to add users to the list of speakers or remove Special view endpoint to add users to the list of speakers or remove
them. Send POST {'user': <user_id>} to add a new speaker. Omit them. Send POST {'user': <user_id>} to add a new speaker. Omit
data to add yourself. Send DELETE {'speaker': <speaker_id>} to remove data to add yourself. Send DELETE {'speaker': <speaker_id>} or
someone from the list of speakers. Omit data to remove yourself. DELETE {'speaker': [<speaker_id>, <speaker_id>, ...]} to remove one or
more speakers from the list of speakers. Omit data to remove yourself.
Checks also whether the requesting user can do this. He needs at Checks also whether the requesting user can do this. He needs at
least the permissions 'agenda.can_see' (see least the permissions 'agenda.can_see' (see
@ -126,11 +127,10 @@ class ItemViewSet(ListModelMixin, RetrieveModelMixin, UpdateModelMixin, GenericV
else: else:
# request.method == 'DELETE' # request.method == 'DELETE'
# Retrieve speaker_id speaker_ids = request.data.get('speaker')
speaker_id = request.data.get('speaker')
# Check permissions and other conditions. Get speaker instance. # Check permissions and other conditions. Get speaker instance.
if speaker_id is None: if speaker_ids is None:
# Remove oneself # Remove oneself
queryset = Speaker.objects.filter( queryset = Speaker.objects.filter(
item=item, user=self.request.user).exclude(weight=None) item=item, user=self.request.user).exclude(weight=None)
@ -141,15 +141,20 @@ class ItemViewSet(ListModelMixin, RetrieveModelMixin, UpdateModelMixin, GenericV
speaker = queryset.get() speaker = queryset.get()
except Speaker.DoesNotExist: except Speaker.DoesNotExist:
raise ValidationError({'detail': _('You are not on the list of speakers.')}) raise ValidationError({'detail': _('You are not on the list of speakers.')})
else:
speaker.delete()
message = _('You are successfully removed from the list of speakers.')
else: else:
# Remove someone else. # Remove someone else.
if not self.request.user.has_perm('agenda.can_manage'): if not self.request.user.has_perm('agenda.can_manage'):
self.permission_denied(request) self.permission_denied(request)
if type(speaker_ids) is int:
speaker_ids = [speaker_ids]
for speaker_id in speaker_ids:
try: try:
speaker = Speaker.objects.get(pk=int(speaker_id)) speaker = Speaker.objects.get(pk=int(speaker_id))
except (ValueError, Speaker.DoesNotExist): except (ValueError, Speaker.DoesNotExist):
raise ValidationError({'detail': _('Speaker does not exist.')}) raise ValidationError({'detail': _('Speaker does not exist.')})
# Delete the speaker. # Delete the speaker.
speaker.delete() speaker.delete()
message = _('Speaker %s was successfully removed from the list of speakers.') % speaker message = _('Speaker %s was successfully removed from the list of speakers.') % speaker