def set_retention_product(self, job_t_id, retention_tag_name, product_name): """ XML-RPC method to update a job's retention tag, product, or both. There is an important distinction between product_name of None, which means do not change the existing value, vs. empty string, which means clear the existing product. """ 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 and product_name: retention_tag = RetentionTag.by_name(retention_tag_name) product = Product.by_name(product_name) result = Utility.update_retention_tag_and_product(job, retention_tag, product) elif retention_tag_name and product_name == '': retention_tag = RetentionTag.by_name(retention_tag_name) result = Utility.update_retention_tag_and_product(job, retention_tag, None) elif retention_tag_name: retention_tag = RetentionTag.by_name(retention_tag_name) result = Utility.update_retention_tag(job, retention_tag) elif product_name: product = Product.by_name(product_name) result = Utility.update_product(job, product) elif product_name == '': result = Utility.update_product(job, None) else: result = {'success': False, 'msg': 'Nothing to do'} if not result['success'] is True: raise BeakerException('Job %s not updated: %s' % (job.id, result.get('msg', 'Unknown reason'))) else: raise BeakerException('No permission to modify %s' % job)
def set_retention_product(self, job_t_id, retention_tag_name, product_name): """ XML-RPC method to update a job's retention tag, product, or both. There is an important distinction between product_name of None, which means do not change the existing value, vs. empty string, which means clear the existing product. """ 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 and product_name: retention_tag = RetentionTag.by_name(retention_tag_name) product = Product.by_name(product_name) old_tag = job.retention_tag if job.retention_tag else None result = Utility.update_retention_tag_and_product( job, retention_tag, product) job.record_activity(user=identity.current.user, service=u'XMLRPC', field=u'Retention Tag', action='Changed', old=old_tag.tag, new=retention_tag.tag) elif retention_tag_name and product_name == '': retention_tag = RetentionTag.by_name(retention_tag_name) old_tag = job.retention_tag if job.retention_tag else None result = Utility.update_retention_tag_and_product( job, retention_tag, None) job.record_activity(user=identity.current.user, service=u'XMLRPC', field=u'Retention Tag', action='Changed', old=old_tag.tag, new=retention_tag.tag) elif retention_tag_name: retention_tag = RetentionTag.by_name(retention_tag_name) old_tag = job.retention_tag if job.retention_tag else None result = Utility.update_retention_tag(job, retention_tag) job.record_activity(user=identity.current.user, service=u'XMLRPC', field=u'Retention Tag', action='Changed', old=old_tag.tag, new=retention_tag.tag) elif product_name: product = Product.by_name(product_name) result = Utility.update_product(job, product) elif product_name == '': result = Utility.update_product(job, None) else: result = {'success': False, 'msg': 'Nothing to do'} if not result['success'] is True: raise BeakerException( 'Job %s not updated: %s' % (job.id, result.get('msg', 'Unknown reason'))) else: raise BeakerException('No permission to modify %s' % job)
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 and 'product' in kw: retention_tag = RetentionTag.by_id(kw['retentiontag']) if int(kw['product']) == ProductWidget.product_deselected: product = None else: product = Product.by_id(kw['product']) returns.update(Utility.update_retention_tag_and_product(job, retention_tag, product)) elif 'retentiontag' in kw: retention_tag = RetentionTag.by_id(kw['retentiontag']) returns.update(Utility.update_retention_tag(job, retention_tag)) elif 'product' in kw: if int(kw['product']) == ProductWidget.product_deselected: product = None else: product = Product.by_id(kw['product']) returns.update(Utility.update_product(job, product)) if 'whiteboard' in kw: job.whiteboard = kw['whiteboard'] return returns
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 and 'product' in kw: retention_tag = RetentionTag.by_id(kw['retentiontag']) if int(kw['product']) == ProductWidget.product_deselected: product = None else: product = Product.by_id(kw['product']) old_tag = job.retention_tag if job.retention_tag else None returns.update( Utility.update_retention_tag_and_product( job, retention_tag, product)) job.record_activity(user=identity.current.user, service=u'WEBUI', field=u'Retention Tag', action='Changed', old=old_tag.tag, new=retention_tag.tag) elif 'retentiontag' in kw: retention_tag = RetentionTag.by_id(kw['retentiontag']) old_tag = job.retention_tag if job.retention_tag else None returns.update(Utility.update_retention_tag(job, retention_tag)) job.record_activity(user=identity.current.user, service=u'WEBUI', field=u'Retention Tag', action='Changed', old=old_tag.tag, new=retention_tag.tag) elif 'product' in kw: if int(kw['product']) == ProductWidget.product_deselected: product = None else: product = Product.by_id(kw['product']) returns.update(Utility.update_product(job, product)) if 'whiteboard' in kw: job.whiteboard = kw['whiteboard'] return returns