Refactor mutations
This commit is contained in:
parent
c3274b4a65
commit
a3fe315df3
|
|
@ -39,7 +39,7 @@ class AddRoom(MutateRoom):
|
||||||
@classmethod
|
@classmethod
|
||||||
def mutate_and_get_payload(cls, root, info, **kwargs):
|
def mutate_and_get_payload(cls, root, info, **kwargs):
|
||||||
user = info.context.user
|
user = info.context.user
|
||||||
if not user.has_perm('users.can_manage_school_class_content'):
|
if not user.is_teacher():
|
||||||
return cls(room=None, errors=['not allowed'])
|
return cls(room=None, errors=['not allowed'])
|
||||||
|
|
||||||
room_data = kwargs.get('room')
|
room_data = kwargs.get('room')
|
||||||
|
|
@ -92,9 +92,9 @@ class MutateRoomEntry(relay.ClientIDMutation):
|
||||||
room_entry_data['room'] = room.id
|
room_entry_data['room'] = room.id
|
||||||
|
|
||||||
if room_entry_data.get('id') is not None:
|
if room_entry_data.get('id') is not None:
|
||||||
serializer = cls.update_path(info, room_entry_data)
|
serializer = cls.update_room_entry(info, room_entry_data)
|
||||||
else:
|
else:
|
||||||
serializer = cls.add_path(info, room_entry_data, room)
|
serializer = cls.add_room_entry(info, room_entry_data, room)
|
||||||
|
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
serializer.save()
|
serializer.save()
|
||||||
|
|
@ -104,7 +104,7 @@ class MutateRoomEntry(relay.ClientIDMutation):
|
||||||
return cls(room_entry=None, errors=['{}: {}'.format(key, value) for key, value in serializer.errors.items()])
|
return cls(room_entry=None, errors=['{}: {}'.format(key, value) for key, value in serializer.errors.items()])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def update_path(cls, info, room_entry_data):
|
def update_room_entry(cls, info, room_entry_data):
|
||||||
instance = get_object(RoomEntry, room_entry_data.get('id'))
|
instance = get_object(RoomEntry, room_entry_data.get('id'))
|
||||||
|
|
||||||
if not instance.room.school_class.is_user_in_schoolclass(info.context.user):
|
if not instance.room.school_class.is_user_in_schoolclass(info.context.user):
|
||||||
|
|
@ -116,7 +116,7 @@ class MutateRoomEntry(relay.ClientIDMutation):
|
||||||
return RoomEntrySerializer(instance, data=room_entry_data, partial=True)
|
return RoomEntrySerializer(instance, data=room_entry_data, partial=True)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_path(cls, info, room_entry_data, room):
|
def add_room_entry(cls, info, room_entry_data, room):
|
||||||
|
|
||||||
if not room or not room.school_class.is_user_in_schoolclass(info.context.user):
|
if not room or not room.school_class.is_user_in_schoolclass(info.context.user):
|
||||||
raise PermissionDenied('You are in the wrong class')
|
raise PermissionDenied('You are in the wrong class')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue