def submit_rt_ticket(obj, queue, subject, body, requestors, ticket_id_key): """Submit ticket to RT with the given parameters.""" from inspire.utils.tickets import get_instance # Trick to prepare ticket body body = "\n ".join([line.strip() for line in body.split("\n")]) rt_instance = get_instance() if cfg.get("PRODUCTION_MODE") else None rt_queue = cfg.get("CFG_BIBCATALOG_QUEUES") or queue recid = obj.extra_data.get("recid", "") if not recid: recid = obj.data.get("recid", "") if not rt_instance: obj.log.error("No RT instance available. Skipping!") obj.log.info("Ticket submission ignored.") else: ticket_id = rt_instance.create_ticket( Queue=rt_queue, Subject=subject, Text=body, Requestors=requestors, CF_RecordID=recid ) obj.extra_data[ticket_id_key] = ticket_id obj.log.info("Ticket {0} created:\n{1}".format( ticket_id, body.encode("utf-8", "ignore") )) return True
def _reply_ticket(obj, eng): from invenio_accounts.models import User from invenio_workflows.errors import WorkflowError from inspire.utils.tickets import get_instance ticket_id = obj.extra_data.get("ticket_id", "") if not ticket_id: obj.log.error("No ticket ID found!") return if template: # Body rendered by template. deposition = Deposition(obj) user = User.query.get(obj.id_user) context = { "object": obj, "user": user, "title": deposition.title, "reason": obj.extra_data.get("reason", ""), "record_url": obj.extra_data.get("url", ""), } body = render_template( template, **context ) else: # Body already rendered in reason. body = obj.extra_data.get("reason").strip() if not body: raise WorkflowError("No body for ticket reply", eng.uuid, obj.id) # Trick to prepare ticket body body = "\n ".join([line.strip() for line in body.strip().split("\n")]) rt = get_instance() if not rt: obj.log.error("No RT instance available. Skipping!") else: rt.reply( ticket_id=ticket_id, text=body, ) obj.log.info("Reply created:\n{0}".format( body.encode("utf-8", "ignore") )) if keep_new: # We keep the state as new rt.edit_ticket( ticket_id=ticket_id, Status="new" )
def _close_ticket(obj, eng): from inspire.utils.tickets import get_instance ticket_id = obj.extra_data.get(ticket_id_key, "") if not ticket_id: obj.log.error("No ticket ID found!") return rt = get_instance() if not rt: obj.log.error("No RT instance available. Skipping!") else: try: rt.edit_ticket( ticket_id=ticket_id, Status="resolved" ) except IndexError: # Probably already resolved, lets check ticket = rt.get_ticket(ticket_id) if ticket["Status"] != "resolved": raise obj.log.warning("Ticket is already resolved.")