(self, request, pk=None)
return Response(serializer.data)
Grants a given user to be part of certain given role name under the
        current book

        ---
        parameters:
            - name: role_name
              required: true
              type: string
            - name: user_id
              required: true
              type: int
Grants a given user to be part of certain given role name under the
        current book
Grants a given user to be part of certain given role name under the current book
def grant_user(self, request, pk=None):
        """
        Grants a given user to be part of certain given role name under the
        current book

        ---
        parameters:
            - name: role_name
              required: true
              type: string
            - name: user_id
              required: true
              type: int
        """
        book = self.get_object()

        try:
            user = User.objects.get(id=request.data['user_id'])
        except User.DoesNotExist:
            logger.warn('BookViewSet.grant_user: User not found.')
            return Response({'detail': 'User not found'}, status=status.HTTP_404_NOT_FOUND)

        try:
            role = Role.objects.get(name=request.data['role_name'])
        except Role.DoesNotExist:
            logger.warn('BookViewSet.grant_user: Role not found.')
            return Response({'detail': 'Role not found'}, status=status.HTTP_404_NOT_FOUND)

        book_role, _ = BookRole.objects.get_or_create(
            role=role, book=book)
        book_role.members.add(user)

        serializer = core_serializers.BookRoleSerializer(book_role, context={'request': request})
        return Response(serializer.data)
def grant_user ( self , request , pk = None ) : book = self . get_object ( ) try : user = User . objects . get ( id = request . data [ 'user_id' ] ) except User . DoesNotExist : logger . warn ( 'BookViewSet.grant_user: User not found.' ) return Response ( { 'detail' : 'User not found' } , status = status . HTTP_404_NOT_FOUND ) try : role = Role . objects . get ( name = request . data [ 'role_name' ] ) except Role . DoesNotExist : logger . warn ( 'BookViewSet.grant_user: Role not found.' ) return Response ( { 'detail' : 'Role not found' } , status = status . HTTP_404_NOT_FOUND ) book_role , _ = BookRole . objects . get_or_create ( role = role , book = book ) book_role . members . add ( user ) serializer = core_serializers . BookRoleSerializer ( book_role , context = { 'request' : request } ) return Response ( serializer . data )