Commit 7c2b69ca authored by Bruno Martin's avatar Bruno Martin
Browse files

add field to check if current user can edit the

classroom
parent 337af319
...@@ -40,6 +40,7 @@ class ClassroomSerializer(serializers.ModelSerializer): ...@@ -40,6 +40,7 @@ class ClassroomSerializer(serializers.ModelSerializer):
events = EventSerializer(read_only=True, many=True) events = EventSerializer(read_only=True, many=True)
courses = BasicCourseSerializer(read_only=True, many=True) courses = BasicCourseSerializer(read_only=True, many=True)
forum = ForumSumarySerializer(read_only=True) forum = ForumSumarySerializer(read_only=True)
can_edit = serializers.SerializerMethodField()
class Meta: class Meta:
model = Classroom model = Classroom
...@@ -55,5 +56,13 @@ class ClassroomSerializer(serializers.ModelSerializer): ...@@ -55,5 +56,13 @@ class ClassroomSerializer(serializers.ModelSerializer):
'events', 'events',
'chat_url', 'chat_url',
'forum', 'forum',
'can_edit',
) )
depth = 1 depth = 1
def get_can_edit(self, obj):
request = self.context.get("request", None)
if request and hasattr(request, "user"):
return request.user in obj.assistants.all() \
or request.user in obj.coordinators.all() \
or request.user.is_superuser
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