def obj_create(self, bundle, **kwargs): biz_cc_id = bundle.data.pop('biz_cc_id', None) template_id = bundle.data.pop('template_id', None) try: template = CommonTemplate.objects.get(pk=template_id) except Exception: raise BadRequest('common template does not exist') business = get_business_for_user(bundle.request.user, ['view_business']) if not business.filter(cc_id=biz_cc_id).exists(): raise ImmediateHttpResponse( HttpResponseForbidden( 'you have no permission to make such operation')) bundle.data['name'] = name_handler(bundle.data['name'], TEMPLATE_NODE_NAME_MAX_LENGTH) kwargs['unique_id'] = '%s-%s-%s' % (biz_cc_id, template_id, bundle.data['name']) if TemplateScheme.objects.filter( unique_id=kwargs['unique_id']).exists(): raise BadRequest( 'common template scheme name has existed, please change the name' ) kwargs['template'] = template.pipeline_template return super(CommonTemplateSchemeResource, self).obj_create(bundle, **kwargs)
def obj_delete(self, bundle, **kwargs): try: scheme_id = kwargs['pk'] scheme = TemplateScheme.objects.get(pk=scheme_id) template = TaskTemplate.objects.get(pipeline_template=scheme.template) except Exception: raise BadRequest('scheme or template does not exist') business = get_business_for_user(bundle.request.user, ['manage_business']) if not business.filter(cc_id=template.business.cc_id).exists(): raise ImmediateHttpResponse(HttpResponseForbidden('you have no permission to make such operation')) return super(TemplateSchemeResource, self).obj_delete(bundle, **kwargs)
def obj_delete(self, bundle, **kwargs): try: appmaker_id = kwargs['pk'] appmaker = AppMaker.objects.get(pk=appmaker_id) except Exception: raise BadRequest('appmaker[id=%s] does not exist' % appmaker_id) biz_cc_id = appmaker.business.cc_id business = get_business_for_user(bundle.request.user, ['manage_business']) if not business.filter(cc_id=biz_cc_id).exists(): raise ImmediateHttpResponse(HttpResponseForbidden('you have no permissions to delete appmaker')) if settings.RUN_MODE in ['PRODUCT', 'STAGING']: fake = False else: fake = True result, data = AppMaker.objects.del_app_maker( biz_cc_id, appmaker_id, fake ) if not result: raise BadRequest(data)
def obj_delete(self, bundle, **kwargs): try: scheme_id = kwargs['pk'] scheme = TemplateScheme.objects.get(pk=scheme_id) CommonTemplate.objects.get(pipeline_template=scheme.template) except Exception: raise BadRequest('common scheme or template does not exist') try: biz_cc_id = int(scheme['unique_id'].split('-')[0]) except Exception: # maybe old unique id rule biz_cc_id = None business = get_business_for_user(bundle.request.user, ['manage_business']) if Business.objects.filter(cc_id=biz_cc_id) and not business.filter( cc_id=biz_cc_id).exists(): raise ImmediateHttpResponse( HttpResponseForbidden( 'you have no permission to make such operation')) return super(CommonTemplateSchemeResource, self).obj_delete(bundle, **kwargs)