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)
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)
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)
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)
def complete(self, request, pk=None): step = self.get_object() step.completed = not step.completed step.save() step.task.set_item_attr(APP_TODO, step.task.get_info()) serializer = StepSerializer(instance=step, context={'request': request}) return Response(serializer.data)
def rename(self, request, pk=None): if 'value' not in self.request.query_params: return Response({'Error': "Expected parameter 'value'"}, status=status.HTTP_400_BAD_REQUEST) step = self.get_object() step.name = self.request.query_params['value'] step.save() serializer = StepSerializer(instance=step, context={'request': request}) return Response(serializer.data)
def get(self, request, provider_id, identity_id): """ Using provider and identity, getlist of machines TODO: Cache this request """ step_list = [ s for s in CoreStep.objects.filter( created_by_identity__id=identity_id) ] serialized_data = StepSerializer(step_list, many=True).data return Response(serialized_data)
def get(self, request, provider_id, identity_id, step_id): """ Get details of a specific step. """ serialized_data = [] 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) serialized_data = StepSerializer(step).data return Response(serialized_data)