Ejemplo n.º 1
0
 def put(self, request, lib_key_str, group_name):
     """
     Add a group to this content library, with permissions specified in the
     request body.
     """
     key = LibraryLocatorV2.from_string(lib_key_str)
     api.require_permission_for_library_key(key, request.user, permissions.CAN_EDIT_THIS_CONTENT_LIBRARY_TEAM)
     serializer = ContentLibraryPermissionLevelSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     group = get_object_or_404(Group, name=group_name)
     api.set_library_group_permissions(key, group, access_level=serializer.validated_data["access_level"])
     return Response({})
Ejemplo n.º 2
0
 def put(self, request, lib_key_str, username):
     """
     Add a user to this content library, with permissions specified in the
     request body.
     """
     key = LibraryLocatorV2.from_string(lib_key_str)
     api.require_permission_for_library_key(key, request.user, permissions.CAN_EDIT_THIS_CONTENT_LIBRARY_TEAM)
     serializer = ContentLibraryPermissionLevelSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     user = get_object_or_404(User, username=username)
     try:
         api.set_library_user_permissions(key, user, access_level=serializer.validated_data["access_level"])
     except api.LibraryPermissionIntegrityError as err:
         raise ValidationError(detail=str(err))
     grant = api.get_library_user_permissions(key, user)
     return Response(ContentLibraryPermissionSerializer(grant).data)