Beispiel #1
0
 def obj_create(self, bundle, **kwargs):
     model = bundle.obj.__class__
     try:
         pipeline_template_kwargs = {
             'name': bundle.data.pop('name'),
             'creator': bundle.request.user.username,
             'pipeline_tree': json.loads(bundle.data.pop('pipeline_tree')),
             'description': bundle.data.pop('description', ''),
         }
     except (KeyError, ValueError) as e:
         raise BadRequest(e.message)
     # XSS handle
     self.handle_template_name_attr(pipeline_template_kwargs)
     # validate pipeline tree
     try:
         validate_web_pipeline_tree(
             pipeline_template_kwargs['pipeline_tree'])
     except PipelineException as e:
         raise BadRequest(e.message)
     # Note: tastypie won't use model's create method
     try:
         pipeline_template = model.objects.__class__.create_pipeline_template(
             **pipeline_template_kwargs)
     except PipelineException as e:
         raise BadRequest(e.message)
     except TaskTemplate.DoesNotExist:
         raise BadRequest('Template referred by SubProcess does not exist')
     kwargs['pipeline_template_id'] = pipeline_template.id
     return super(TaskTemplateResource, self).obj_create(bundle, **kwargs)
Beispiel #2
0
 def obj_create(self, bundle, **kwargs):
     model = bundle.obj.__class__
     try:
         template_id = bundle.data['template_id']
         creator = bundle.request.user.username
         pipeline_instance_kwargs = {
             'name': bundle.data.pop('name'),
             'creator': creator,
             'pipeline_tree': json.loads(bundle.data.pop('pipeline_tree')),
         }
         if 'description' in bundle.data:
             pipeline_instance_kwargs['description'] = bundle.data.pop(
                 'description')
     except (KeyError, ValueError) as e:
         raise BadRequest(e.message)
     # XSS handle
     self.handle_task_name_attr(pipeline_instance_kwargs)
     # validate pipeline tree
     try:
         validate_web_pipeline_tree(
             pipeline_instance_kwargs['pipeline_tree'])
     except PipelineException as e:
         raise BadRequest(e.message)
     try:
         template = TaskTemplate.objects.get(id=template_id)
     except TaskTemplate.DoesNotExist:
         raise BadRequest('template[id=%s] does not exist' % template_id)
     if bundle.data['create_method'] == 'app_maker':
         try:
             app_maker = AppMaker.objects.get(id=bundle.data['create_info'])
         except AppMaker.DoesNotExist:
             raise BadRequest(
                 'Mini-APP[id=%s] does not exist, that is the value of create_info'
                 % bundle.data['create_info'])
         if app_maker.task_template.id != int(template_id):
             raise BadRequest(
                 'Template[id=%s] does not match the template[id=%s] used to creating '
                 'Mini-APP[id=%s]' %
                 (template_id, app_maker.task_template.id,
                  bundle.data['create_info']))
     if not bundle.request.user.has_perm('fill_params', template):
         raise ImmediateHttpResponse(
             HttpResponseForbidden(
                 'You have no permissions to create task'))
     try:
         pipeline_instance = model.objects.__class__.create_pipeline_instance(
             template, **pipeline_instance_kwargs)
     except PipelineException as e:
         raise BadRequest(e.message)
     kwargs['category'] = template.category
     if bundle.data['flow_type'] == 'common_func':
         kwargs['current_flow'] = 'func_claim'
     else:
         kwargs['current_flow'] = 'execute_task'
     kwargs['pipeline_instance_id'] = pipeline_instance.id
     super(TaskFlowInstanceResource, self).obj_create(bundle, **kwargs)
     return bundle
Beispiel #3
0
 def obj_create(self, bundle, **kwargs):
     model = bundle.obj.__class__
     try:
         template_id = bundle.data['template_id']
         creator = bundle.request.user.username
         pipeline_instance_kwargs = {
             'name': bundle.data.pop('name'),
             'creator': creator,
             'pipeline_tree': json.loads(bundle.data.pop('pipeline_tree')),
         }
         if 'description' in bundle.data:
             pipeline_instance_kwargs['description'] = bundle.data.pop(
                 'description')
     except (KeyError, ValueError) as e:
         raise BadRequest(e.message)
     # XSS handle
     self.handle_task_name_attr(pipeline_instance_kwargs)
     # validate pipeline tree
     try:
         validate_web_pipeline_tree(
             pipeline_instance_kwargs['pipeline_tree'])
     except PipelineException as e:
         raise BadRequest(e.message)
     try:
         template = TaskTemplate.objects.get(id=template_id)
     except TaskTemplate.DoesNotExist:
         raise BadRequest('template[id=%s] does not exist' % template_id)
     if not bundle.request.user.has_perm(CREATE_TASK_PERM_NAME, template):
         raise ImmediateHttpResponse(
             HttpResponseForbidden(
                 'You have no permissions to create task'))
     try:
         pipeline_instance = model.objects.__class__.create_pipeline_instance(
             template, **pipeline_instance_kwargs)
     except PipelineException as e:
         raise BadRequest(e.message)
     kwargs['category'] = template.category
     if bundle.data['flow_type'] == 'common_func':
         kwargs['current_flow'] = 'func_claim'
     else:
         kwargs['current_flow'] = 'execute_task'
     kwargs['pipeline_instance_id'] = pipeline_instance.id
     super(TaskFlowInstanceResource, self).obj_create(bundle, **kwargs)
     return bundle
Beispiel #4
0
    def __init__(self, web_pipeline_tree):

        validate_web_pipeline_tree(web_pipeline_tree)
        pipeline_tree = format_web_data_to_pipeline(web_pipeline_tree)
        super(WebPipelineAdapter, self).__init__(pipeline_tree)