def update(self, id, **kw): # XXX Thus function is awkward and needs to be cleaned up. try: job = Job.by_id(id) except InvalidRequestError: raise cherrypy.HTTPError(status=400, message='Invalid job id %s' % id) if not job.can_change_product(identity.current.user) or not \ job.can_change_retention_tag(identity.current.user): raise cherrypy.HTTPError(status=403, message="You don't have permission to update job id %s" % id) returns = {'success' : True, 'vars':{}} if 'retentiontag' in kw or 'product' in kw: #convert them to int and correct Job attribute name if 'retentiontag' in kw: kw['retention_tag_id'] = int(kw['retentiontag']) del kw['retentiontag'] if 'product' in kw: kw['product_id'] = int(kw['product']) del kw['product'] retention_tag_id = kw.get('retention_tag_id') product_id = kw.get('product_id') #update_task_product should also ensure that our id's are valid returns.update(Utility.update_task_product(job,retention_tag_id,product_id)) if returns['success'] is False: return returns #kw should be santised and correct by the time it gets here for attr in kw: try: setattr(job, attr, kw[attr]) except AttributeError, e: return {'success' : False }
def set_retention_product(self, job_t_id, retention_tag_name, product_name): job = TaskBase.get_by_t_id(job_t_id) if job.can_change_product(identity.current.user) and \ job.can_change_retention_tag(identity.current.user): if retention_tag_name: try: retention_tag = RetentionTag.by_name(retention_tag_name) except NoResultFound: raise ValueError('%s is not a valid tag' % retention_tag_name) else: retention_tag = None if product_name: try: product = Product.by_name(product_name) product_id = product.id except NoResultFound: raise ValueError('%s is not a valid product' % product_name) elif product_name == "": product = ProductWidget.product_deselected product_id = product else: product = None product_id = product retentiontag_id = getattr(retention_tag, 'id', None) result = Utility.update_task_product(job, retentiontag_id=retentiontag_id, product_id=product_id) if not result['success'] is True: raise BeakerException('Job %s not updated: %s' % (job.id, result.get('msg', 'Unknown reason'))) if product == ProductWidget.product_deselected and \ job.product != None: job.product = None elif product is not None and product != job.product: job.product = product if retention_tag is not None and retention_tag != job.retention_tag: job.retention_tag = retention_tag else: raise BeakerException('No permission to modify %s' % job)