예제 #1
0
파일: step.py 프로젝트: karbon62/atmosphere
    def put(self, request, provider_uuid, identity_uuid, step_id):
        """
        Update a specific step.

        NOTE: This may not affect an active step.
        """
        user = request.user
        serialized_data = []
        data = request.DATA.copy()
        try:
            step = fetch_step(identity_uuid, step_id)
        except CoreStep.DoesNotExist:
            return step_not_found(step_id)
        if not step:
            return step_not_found(step_id)
        if not user.is_staff and user != step.created_by:
            return failure_response(
                status.HTTP_400_BAD_REQUEST,
                "Only the step creator can update %s step." % step_id)
        required_fields(data, step)
        serializer = StepSerializer(step, data=data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_200_OK)
        return failure_response(
            status.HTTP_400_BAD_REQUEST,
            serializer.errors)
예제 #2
0
    def put(self, request, provider_id, identity_id, step_id):
        """
        Update a specific step.

        NOTE: This may not affect an active step.
        """
        user = request.user
        serialized_data = []
        data = request.DATA.copy()
        try:
            step = fetch_step(identity_id, step_id)
        except CoreStep.DoesNotExist:
            return step_not_found(step_id)
        if not step:
            return step_not_found(step_id)
        if not user.is_staff and user != step.created_by:
            return failure_response(
                status.HTTP_400_BAD_REQUEST,
                "Only the step creator can update %s step." % step_id)
        required_fields(data, step)
        serializer = StepSerializer(step, data=data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_200_OK)
        return failure_response(status.HTTP_400_BAD_REQUEST, serializer.errors)
예제 #3
0
파일: step.py 프로젝트: karbon62/atmosphere
    def post(self, request, provider_uuid, identity_uuid):
        """
        Create a new step.
        """
        data = request.DATA.copy()
        valid, messages = validate_post(data)
        if not valid:
            return failure_response(
                status.HTTP_400_BAD_REQUEST,
                messages)
        if data.get("instance_alias"):
            instance = CoreInstance.objects.get(
                provider_alias=data["instance_alias"])
        else:
            instance = None
        if data.get("flow_alias"):
            flow = CoreFlow.objects.get(alias=data["flow_alias"])
        else:
            flow = None
        identity = CoreIdentity.objects.get(uuid=identity_uuid)
        step = CoreStep(alias=uuid1(),
                        name=data["name"],
                        script=data["script"],
                        instance=instance,
                        flow=flow,
                        created_by=request.user,
                        created_by_identity=identity)

        serializer = StepSerializer(step, data=data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return failure_response(
            status.HTTP_400_BAD_REQUEST,
            serializer.errors)
예제 #4
0
    def post(self, request, provider_id, identity_id):
        """
        Create a new step.
        """
        data = request.DATA.copy()
        valid, messages = validate_post(data)
        if not valid:
            return failure_response(status.HTTP_400_BAD_REQUEST, messages)
        if data.get("instance_alias"):
            instance = CoreInstance.objects.get(
                provider_alias=data["instance_alias"])
        else:
            instance = None
        if data.get("flow_alias"):
            flow = CoreFlow.objects.get(alias=data["flow_alias"])
        else:
            flow = None
        identity = CoreIdentity.objects.get(id=identity_id)
        step = CoreStep(alias=uuid1(),
                        name=data["name"],
                        script=data["script"],
                        instance=instance,
                        flow=flow,
                        created_by=request.user,
                        created_by_identity=identity)

        serializer = StepSerializer(step, data=data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return failure_response(status.HTTP_400_BAD_REQUEST, serializer.errors)