def _update_application(self, request, app, **kwargs): data = request.DATA user = request.user data = request.DATA app_owner = app.created_by app_members = app.get_members() if user != app_owner and not Group.check_membership(user, app_members): return failure_response(status.HTTP_403_FORBIDDEN, "You are not the Application owner. " "This incident will be reported") #Or it wont.. Up to operations.. partial_update = True if request.method == 'PATCH' else False serializer = ApplicationSerializer(app, data=data, context={'request': request}, partial=partial_update) if serializer.is_valid(): logger.info('metadata = %s' % data) #TODO: Update application metadata on each machine? #update_machine_metadata(esh_driver, esh_machine, data) serializer.save() if 'created_by_identity' in data: identity = serializer.object.created_by_identity update_application_owner(serializer.object, identity) if 'boot_scripts' in data: _save_scripts_to_application(serializer.object, data.get('boot_scripts',[])) return Response(serializer.data) return failure_response( status.HTTP_400_BAD_REQUEST, serializer.errors)
def _update_application(self, request, app, **kwargs): data = request.DATA user = request.user data = request.DATA app_owner = app.created_by app_members = app.get_members() if user != app_owner and not Group.check_membership(user, app_members): return failure_response( status.HTTP_403_FORBIDDEN, "You are not the Application owner. " "This incident will be reported") #Or it wont.. Up to operations.. partial_update = True if request.method == 'PATCH' else False serializer = ApplicationSerializer(app, data=data, context={'request': request}, partial=partial_update) if serializer.is_valid(): logger.info('metadata = %s' % data) #TODO: Update application metadata on each machine? #update_machine_metadata(esh_driver, esh_machine, data) serializer.save() if 'created_by_identity' in data: identity = serializer.object.created_by_identity update_application_owner(serializer.object, identity) if 'boot_scripts' in data: _save_scripts_to_application(serializer.object, data.get('boot_scripts', [])) return Response(serializer.data) return failure_response(status.HTTP_400_BAD_REQUEST, serializer.errors)
def _update_threshold(self, request, app, **kwargs): user = request.user data = request.DATA app_owner = app.created_by app_members = app.get_members() if user != app_owner and not Group.check_membership(user, app_members): return failure_response(status.HTTP_403_FORBIDDEN, "You are not the Application owner. " "This incident will be reported") #Or it wont.. Up to operations.. if kwargs.get('delete'): threshold = app.get_threshold() if threshold: threshold.delete() serializer = ApplicationThresholdSerializer( app.get_threshold()) return Response(serializer.data) partial_update = True if request.method == 'PATCH' else False serializer = ApplicationThresholdSerializer( app.threshold, data=data, context={'request': request}, partial=partial_update) if serializer.is_valid(): serializer.save() logger.info(serializer.data) return Response(serializer.data) return failure_response( status.HTTP_400_BAD_REQUEST, serializer.errors)
def _update_threshold(self, request, app, **kwargs): user = request.user data = request.DATA app_owner = app.created_by app_members = app.get_members() if user != app_owner and not Group.check_membership(user, app_members): return failure_response( status.HTTP_403_FORBIDDEN, "You are not the Application owner. " "This incident will be reported") #Or it wont.. Up to operations.. if kwargs.get('delete'): threshold = app.get_threshold() if threshold: threshold.delete() serializer = ApplicationThresholdSerializer(app.get_threshold()) return Response(serializer.data) partial_update = True if request.method == 'PATCH' else False serializer = ApplicationThresholdSerializer( app.threshold, data=data, context={'request': request}, partial=partial_update) if serializer.is_valid(): serializer.save() logger.info(serializer.data) return Response(serializer.data) return failure_response(status.HTTP_400_BAD_REQUEST, serializer.errors)