Commit 8bd6e5c8 authored by Fernando Ribeiro's avatar Fernando Ribeiro
Browse files

Fix: update views to add users into ProfessorGlobalMessageViewSet

parent e12c4425
......@@ -95,18 +95,14 @@ class ProfessorMessageViewSet(viewsets.ModelViewSet):
permission_classes = (IsAssistantOrCoordinatorOrReadOnly,)
def perform_create(self, serializer):
recipients = serializer.context['request'].data.get('users', None)
groups = serializer.context['request'].data.get('groups', None)
classes = serializer.context['request'].data.get('classes', None)
recipients = serializer.context['request'].data.get('users', None)
users_to_be_added = []
User = get_user_model()
# If groups were specified, their users are the recipients
if groups:
users_to_be_added = User.objects.filter(groups__in=groups)
# Otherwise, user the recipients list
elif recipients:
if recipients:
for user_id in serializer.context['request'].data['users']:
users_to_be_added.append(User.objects.get(id=user_id))
elif classes:
......@@ -146,12 +142,22 @@ class ProfessorGlobalMessageViewSet(mixins.CreateModelMixin,
def perform_create(self, serializer):
User = get_user_model()
all_students = serializer.context['request'].data.get('all_students', None)
users_to_be_added = []
all_students = serializer.context['request'].data.get('all_students', None)
recipients = serializer.context['request'].data.get('users', None)
groups = serializer.context['request'].data.get('groups', None)
if all_students:
# If all_students was set to True by the client, this is a global message
users_to_be_added = User.objects.all()
# If groups were specified, their users are the recipients
elif groups:
users_to_be_added = User.objects.filter(groups__in=groups)
# Otherwise, user the recipients list
elif recipients:
for user_id in serializer.context['request'].data['users']:
users_to_be_added.append(User.objects.get(id=user_id))
obj = serializer.save(professor=self.request.user, users=users_to_be_added)
if obj:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment