def submit_rt_ticket(obj, queue, subject, body, requestors, ticket_id_key): """Submit ticket to RT with the given parameters.""" from inspirehep.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 _close_ticket(obj, eng): from inspirehep.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!") obj.log.info( "Was going to close ticket {ticket_id}".format( ticket_id=ticket_id, ) ) return 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.")
def _reply_ticket(obj, eng): from inspirehep.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 user = User.query.get(obj.id_user) if not user: obj.log.error( "No user found for object {0}, skipping ticket creation".format( obj.id)) return if template: context = {} if context_factory: context = context_factory(user, obj) body = render_template( template, **context ) else: # Body already rendered in reason. body = obj.extra_data.get("reason").strip() if not body: obj.log.error("No body for ticket reply. Skipping reply.") return # 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!") obj.log.info( "Was going to reply to {ticket_id}\n\n{body}\n\n".format( ticket_id=ticket_id, body=body, ) ) return rt.reply( ticket_id=ticket_id, text=body, ) if keep_new: # We keep the state as new rt.edit_ticket( ticket_id=ticket_id, Status="new" )
def _reply_ticket(obj, eng): from invenio_accounts.models import User from invenio_workflows.errors import WorkflowError from inspirehep.utils.tickets import get_instance from flask import render_template 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. user = User.query.get(obj.id_user) context = { "object": obj, "user": user, "author_name": obj.data.get("name").get("preferred_name"), "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") # 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 _reply_ticket(obj, eng): from inspirehep.utils.tickets import get_instance from flask import render_template 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. user = User.query.get(obj.id_user) context = { "object": obj, "user": user, "author_name": obj.data.get("name").get("preferred_name"), "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") # 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 _reply_ticket(obj, eng): from inspirehep.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 user = User.query.get(obj.id_user) if not user: obj.log.error( "No user found for object {0}, skipping ticket creation". format(obj.id)) return if template: context = {} if context_factory: context = context_factory(user, obj) body = render_template(template, **context) else: # Body already rendered in reason. body = obj.extra_data.get("reason").strip() if not body: obj.log.error("No body for ticket reply. Skipping reply.") return # 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!") obj.log.info( "Was going to reply to {ticket_id}\n\n{body}\n\n".format( ticket_id=ticket_id, body=body, )) return rt.reply( ticket_id=ticket_id, text=body, ) if keep_new: # We keep the state as new rt.edit_ticket(ticket_id=ticket_id, Status="new")
def submit_rt_ticket(obj, queue, subject, body, requestors, ticket_id_key): """Submit ticket to RT with the given parameters.""" rt_instance = get_instance() if current_app.config.get( "PRODUCTION_MODE") else None if not rt_instance: obj.log.error("No RT instance available. Skipping!") obj.log.info( "Was going to submit: {subject}\n\n{body}\n\n" "To: {requestors} Queue: {queue}".format( queue=queue, subject=subject, requestors=requestors, body=body ) ) return # Trick to prepare ticket body body = "\n ".join([line.strip() for line in body.split("\n")]) rt_queue = current_app.config.get("BIBCATALOG_QUEUES") or queue payload = dict( Queue=rt_queue, Subject=subject, Text=body, ) recid = obj.extra_data.get("recid") or obj.data.get("control_number") \ or obj.data.get("recid") if recid: payload['CF_RecordID'] = recid # Check if requests is set and also ignore admin due to RT mail loop if requestors and "*****@*****.**" not in requestors: payload['requestors'] = requestors ticket_id = rt_instance.create_ticket(**payload) 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 submit_rt_ticket(obj, queue, subject, body, requestors, ticket_id_key): """Submit ticket to RT with the given parameters.""" rt_instance = get_instance() if current_app.config.get( "PRODUCTION_MODE") else None if not rt_instance: obj.log.error("No RT instance available. Skipping!") obj.log.info("Was going to submit: {subject}\n\n{body}\n\n" "To: {requestors} Queue: {queue}".format( queue=queue, subject=subject, requestors=requestors, body=body)) return # Trick to prepare ticket body body = "\n ".join([line.strip() for line in body.split("\n")]) rt_queue = current_app.config.get("BIBCATALOG_QUEUES") or queue payload = dict( Queue=rt_queue, Subject=subject, Text=body, ) recid = obj.extra_data.get("recid") or obj.data.get("control_number") \ or obj.data.get("recid") if recid: payload['CF_RecordID'] = recid # Check if requests is set and also ignore admin due to RT mail loop if requestors and "*****@*****.**" not in requestors: payload['requestors'] = requestors ticket_id = rt_instance.create_ticket(**payload) 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 _close_ticket(obj, eng): from inspirehep.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!") obj.log.info("Was going to close ticket {ticket_id}".format( ticket_id=ticket_id, )) return 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.")