add "delete all speakers" button (fixes #2210)
This commit is contained in:
parent
2627724c55
commit
589137ece7
@ -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.
|
||||||
|
@ -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 = [];
|
||||||
|
@ -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>
|
||||||
|
@ -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,18 +141,23 @@ 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)
|
||||||
try:
|
if type(speaker_ids) is int:
|
||||||
speaker = Speaker.objects.get(pk=int(speaker_id))
|
speaker_ids = [speaker_ids]
|
||||||
except (ValueError, Speaker.DoesNotExist):
|
for speaker_id in speaker_ids:
|
||||||
raise ValidationError({'detail': _('Speaker does not exist.')})
|
try:
|
||||||
|
speaker = Speaker.objects.get(pk=int(speaker_id))
|
||||||
# Delete the speaker.
|
except (ValueError, Speaker.DoesNotExist):
|
||||||
speaker.delete()
|
raise ValidationError({'detail': _('Speaker does not exist.')})
|
||||||
message = _('Speaker %s was successfully removed from the list of speakers.') % speaker
|
# Delete the speaker.
|
||||||
|
speaker.delete()
|
||||||
|
message = _('Speaker %s was successfully removed from the list of speakers.') % speaker
|
||||||
|
|
||||||
# Initiate response.
|
# Initiate response.
|
||||||
return Response({'detail': message})
|
return Response({'detail': message})
|
||||||
|
Loading…
Reference in New Issue
Block a user