Exemplo n.º 1
0
def get_new_ticket_RT_info(uid, recId):
    response = {}
    response["resultCode"] = 0
    if BIBCATALOG_SYSTEM is None:
        response["description"] = "<!--No ticket system configured-->"
    elif BIBCATALOG_SYSTEM and uid:
        bibcat_resp = BIBCATALOG_SYSTEM.check_system(uid)
        if bibcat_resp == "":
            # add available owners
            users = []
            users_list = list_registered_users()
            for user_tuple in users_list:
                try:
                    user = {"username": get_user_preferences(user_tuple[0])["bibcatalog_username"], "id": user_tuple[0]}
                except KeyError:
                    continue
                users.append(user)
            response["users"] = users
            # add available queues
            response["queues"] = BIBCATALOG_SYSTEM.get_queues(uid)
            # add user email
            response["email"] = get_email(uid)
            # TODO try catch
            response["ticketTemplates"] = load_ticket_templates(recId)
            response["resultCode"] = 1
        else:
            # put something in the tickets container, for debug
            response["description"] = "Error connecting to RT<!--" + bibcat_resp + "-->"
    return response
Exemplo n.º 2
0
def get_new_ticket_RT_info(uid, recId):
    response = {}
    response['resultCode'] = 0
    if BIBCATALOG_SYSTEM is None:
        response['description'] = "<!--No ticket system configured-->"
    elif BIBCATALOG_SYSTEM and uid:
        bibcat_resp = BIBCATALOG_SYSTEM.check_system(uid)
        if bibcat_resp == "":
            # add available owners
            users = []
            users_list = list_registered_users()
            for user_tuple in users_list:
                try:
                    user = {'username': get_user_preferences(user_tuple[0])['bibcatalog_username'],
                        'id': user_tuple[0]}
                except KeyError:
                    continue
                users.append(user)
            response['users'] = users
            # add available queues
            response['queues'] = BIBCATALOG_SYSTEM.get_queues(uid)
            # add user email
            response['email'] = get_email(uid)
            # TODO try catch
            response['ticketTemplates'] = load_ticket_templates(recId)
            response['resultCode'] = 1
        else:
            # put something in the tickets container, for debug
            response['description'] = "Error connecting to RT<!--" + bibcat_resp + "-->"
    return response
Exemplo n.º 3
0
    def tmpl_your_tickets(self, uid, ln=CFG_SITE_LANG, start=1):
        """ make a pretty html body of tickets that belong to the user given as param """
        ln = wash_language(ln)
        _ = gettext_set_language(ln)
        if BIBCATALOG_SYSTEM is None:
            return _("Error: No BibCatalog system configured.")
        #errors? tell what happened and get out
        bibcat_probs = BIBCATALOG_SYSTEM.check_system(uid)
        if bibcat_probs:
            return _("Error")+" "+bibcat_probs

        tickets = BIBCATALOG_SYSTEM.ticket_search(uid, owner=uid) # get ticket id's
        lines = "" # put result here
        i = 1

        lines += (_("You have %(x_num)i tickets.", x_num=len(tickets))) + "<br/>"

        #make a prev link if needed
        if (start > 1):
            newstart = start - self.SHOW_MAX_TICKETS
            if (newstart < 1):
                newstart = 1
            lines += '<a href="/yourtickets/display?start='+str(newstart)+'">'+_("Previous")+'</a>'
        lines += """<table border="1">"""
        lastshown = len(tickets) # what was the number of the last shown ticket?
        for ticket in tickets:
            #get info and show only for those that within the show range
            if (i >= start) and (i < start+self.SHOW_MAX_TICKETS):
                ticket_info = BIBCATALOG_SYSTEM.ticket_get_info(uid, ticket)
                subject = ticket_info['subject']
                status = ticket_info['status']
                text = ""
                if 'text' in ticket_info:
                    text = ticket_info['text']
                display = '<a href="'+ticket_info['url_display']+'">'+_("show")+'</a>'
                close = '<a href="'+ticket_info['url_close']+'">'+_("close")+'</a>'
                lines += "<tr><td>"+str(ticket)+"</td><td>"+subject+" "+text+"</td><td>"+status+"</td><td>"+display+"</td><td>"+close+"</td></tr>\n"
                lastshown = i
            i = i+1
        lines += "</table>"

        #make next link if needed
        if (len(tickets) > lastshown):
            newstart = lastshown+1
            lines += '<a href="/yourtickets/display?start='+str(newstart)+'">'+_("Next")+'</a>'
        return lines
Exemplo n.º 4
0
    def exists(self):
        """
        Does the ticket already exist in the RT system?

        @return results: Evaluates to True if it exists, False if not.
        """
        results = BIBCATALOG_SYSTEM.ticket_search(None,
                                                  recordid=self.recid,
                                                  queue=self.queue,
                                                  subject=self.subject)
        return results
Exemplo n.º 5
0
    def exists(self):
        """
        Does the ticket already exist in the RT system?

        @return results: Evaluates to True if it exists, False if not.
        """
        results = BIBCATALOG_SYSTEM.ticket_search(None,
                                                  recordid=self.recid,
                                                  queue=self.queue,
                                                  subject=self.subject)
        return results
Exemplo n.º 6
0
def submit_ticket(record, record_id):
    """ Submit the errors to bibcatalog """

    if task_get_option("no_tickets", False):
        return

    msg = """
Bibcheck found some problems with the record with id %s:

Errors:
%s

Amendments:
%s

Warnings:
%s

Edit this record: %s
"""
    msg = msg % (
        record_id,
        "\n".join(record.errors),
        "\n".join(record.amendments),
        "\n".join(record.warnings),
        "%s/record/%s/edit" % (CFG_SITE_URL, record_id),
    )
    if isinstance(msg, unicode):
        msg = msg.encode("utf-8")

    subject = "Bibcheck rule failed in record %s" % record_id

    ticket_id = BIBCATALOG_SYSTEM.ticket_submit(
        subject=subject,
        recordid=record_id,
        text=subject,
        queue=task_get_option("queue", "Bibcheck")
    )
    write_message("Bibcatalog returned %s" % ticket_id)
    if ticket_id:
        BIBCATALOG_SYSTEM.ticket_comment(None, ticket_id, msg)
Exemplo n.º 7
0
    def submit(self):
        """
        Submits the ticket using BibCatalog API.

        @raise Exception: if ticket creation is not successful.
        @return bool: True if created, False if not.
        """
        if not self.exists():
            self.ticketid = BIBCATALOG_SYSTEM.ticket_submit(
                                                  subject=self.subject,
                                                  queue=self.queue,
                                                  text=self.body,
                                                  recordid=self.recid)
            return True
        return False
Exemplo n.º 8
0
    def submit(self):
        """
        Submits the ticket using BibCatalog API.

        @raise Exception: if ticket creation is not successful.
        @return bool: True if created, False if not.
        """
        if not self.exists():
            self.ticketid = BIBCATALOG_SYSTEM.ticket_submit(
                                                  subject=self.subject,
                                                  queue=self.queue,
                                                  text=self.body,
                                                  recordid=self.recid)
            return True
        return False
Exemplo n.º 9
0
def task_check_options():
    """ Reimplement this method for having the possibility to check options
    before submitting the task, in order for example to provide default
    values. It must return False if there are errors in the options.
    """
    if not task_get_option('new') \
            and not task_get_option('modified') \
            and not task_get_option('recids') \
            and not task_get_option('collections')\
            and not task_get_option('reportnumbers'):
        print >>sys.stderr, 'Error: No records specified, you need' \
            ' to specify which records to run on'
        return False

    ticket_plugins = {}
    all_plugins, error_messages = load_ticket_plugins()

    if error_messages:
        # We got broken plugins. We alert only for now.
        print >>sys.stderr, "\n".join(error_messages)

    if task_get_option('tickets'):
        # Tickets specified
        for ticket in task_get_option('tickets'):
            if ticket not in all_plugins.get_enabled_plugins():
                print ticket
                print >>sys.stderr, 'Error: plugin %s is broken or does not exist'
                return False
            ticket_plugins[ticket] = all_plugins[ticket]
    elif task_get_option('all-tickets'):
        ticket_plugins = all_plugins.get_enabled_plugins()
    else:
        print >>sys.stderr, 'Error: No tickets specified, you need' \
            ' to specify at least one ticket type to create'
        return False

    task_set_option('tickets', ticket_plugins)

    if not BIBCATALOG_SYSTEM:
        print >>sys.stderr, 'Error: no cataloging system defined'
        return False

    res = BIBCATALOG_SYSTEM.check_system()
    if res:
        print >>sys.stderr, 'Error while checking cataloging system: %s' % \
            (res,)
    return True
Exemplo n.º 10
0
def task_check_options():
    """ Reimplement this method for having the possibility to check options
    before submitting the task, in order for example to provide default
    values. It must return False if there are errors in the options.
    """
    if not task_get_option('new') \
            and not task_get_option('modified') \
            and not task_get_option('recids') \
            and not task_get_option('collections')\
            and not task_get_option('reportnumbers'):
        print >>sys.stderr, 'Error: No records specified, you need' \
            ' to specify which records to run on'
        return False

    ticket_plugins = {}
    all_plugins, error_messages = load_ticket_plugins()

    if error_messages:
        # We got broken plugins. We alert only for now.
        print >>sys.stderr, "\n".join(error_messages)

    if task_get_option('tickets'):
        # Tickets specified
        for ticket in task_get_option('tickets'):
            if ticket not in all_plugins.get_enabled_plugins():
                print ticket
                print >>sys.stderr, 'Error: plugin %s is broken or does not exist'
                return False
            ticket_plugins[ticket] = all_plugins[ticket]
    elif task_get_option('all-tickets'):
        ticket_plugins = all_plugins.get_enabled_plugins()
    else:
        print >>sys.stderr, 'Error: No tickets specified, you need' \
            ' to specify at least one ticket type to create'
        return False

    task_set_option('tickets', ticket_plugins)

    if not BIBCATALOG_SYSTEM:
        print >>sys.stderr, 'Error: no cataloging system defined'
        return False

    res = BIBCATALOG_SYSTEM.check_system()
    if res:
        print >>sys.stderr, 'Error while checking cataloging system: %s' % \
            (res,)
    return True
Exemplo n.º 11
0
def index():
    """Editor index page."""
    from invenio.legacy.bibedit.utils import get_record_templates
    from invenio.legacy.bibedit.engine import (get_available_kbs,
                                               get_available_fields_templates)

    # Add script data.
    record_templates = get_record_templates()
    record_templates.sort()
    tag_names = get_name_tags_all()
    protected_fields = ['001']
    protected_fields.extend(cfg['CFG_BIBEDIT_PROTECTED_FIELDS'].split(','))
    cern_site = 'false'
    if CFG_CERN_SITE:
        cern_site = 'true'

    data = {
        'gRECORD_TEMPLATES': record_templates,
        'gTAG_NAMES': tag_names,
        'gPROTECTED_FIELDS': protected_fields,
        'gINTERNAL_DOI_PROTECTION_LEVEL':
            CFG_BIBEDIT_INTERNAL_DOI_PROTECTION_LEVEL,
        'gSITE_URL': CFG_SITE_URL,
        'gSITE_RECORD': CFG_SITE_RECORD,
        'gCERN_SITE': cern_site,
        'gINSPIRE_SITE': CFG_INSPIRE_SITE,
        'gHASH_CHECK_INTERVAL': cfg['CFG_BIBEDIT_JS_HASH_CHECK_INTERVAL'],
        'gCHECK_SCROLL_INTERVAL': cfg['CFG_BIBEDIT_JS_CHECK_SCROLL_INTERVAL'],
        'gSTATUS_ERROR_TIME': cfg['CFG_BIBEDIT_JS_STATUS_ERROR_TIME'],
        'gSTATUS_INFO_TIME': cfg['CFG_BIBEDIT_JS_STATUS_INFO_TIME'],
        'gCLONED_RECORD_COLOR':
            '"' + cfg['CFG_BIBEDIT_JS_CLONED_RECORD_COLOR'] + '"',
        'gCLONED_RECORD_COLOR_FADE_DURATION':
            cfg['CFG_BIBEDIT_JS_CLONED_RECORD_COLOR_FADE_DURATION'],
        'gNEW_ADD_FIELD_FORM_COLOR':
            '"' + cfg['CFG_BIBEDIT_JS_NEW_ADD_FIELD_FORM_COLOR'] + '"',
        'gNEW_ADD_FIELD_FORM_COLOR_FADE_DURATION':
            cfg['CFG_BIBEDIT_JS_NEW_ADD_FIELD_FORM_COLOR_FADE_DURATION'],
        'gNEW_CONTENT_COLOR': '"' +
            cfg['CFG_BIBEDIT_JS_NEW_CONTENT_COLOR'] + '"',
        'gNEW_CONTENT_COLOR_FADE_DURATION':
            cfg['CFG_BIBEDIT_JS_NEW_CONTENT_COLOR_FADE_DURATION'],
        'gNEW_CONTENT_HIGHLIGHT_DELAY':
            cfg['CFG_BIBEDIT_JS_NEW_CONTENT_HIGHLIGHT_DELAY'],
        'gTICKET_REFRESH_DELAY': cfg['CFG_BIBEDIT_JS_TICKET_REFRESH_DELAY'],
        'gRESULT_CODES': cfg['CFG_BIBEDIT_AJAX_RESULT_CODES'],
        'gAUTOSUGGEST_TAGS': cfg['CFG_BIBEDIT_AUTOSUGGEST_TAGS'],
        'gAUTOCOMPLETE_TAGS': cfg['CFG_BIBEDIT_AUTOCOMPLETE_TAGS_KBS'].keys(),
        'gKEYWORD_TAG': '"' + cfg['CFG_BIBEDIT_KEYWORD_TAG'] + '"',
        'gREQUESTS_UNTIL_SAVE': cfg['CFG_BIBEDIT_REQUESTS_UNTIL_SAVE'],
        'gAVAILABLE_KBS': get_available_kbs(),
        'gDOILookupField': '"' + cfg['CFG_BIBEDIT_DOI_LOOKUP_FIELD'] + '"',
        'gDisplayReferenceTags': cfg['CFG_BIBEDIT_DISPLAY_REFERENCE_TAGS'],
        'gDisplayAuthorTags': cfg['CFG_BIBEDIT_DISPLAY_AUTHOR_TAGS'],
        'gExcludeCuratorTags': cfg['CFG_BIBEDIT_EXCLUDE_CURATOR_TAGS'],
        'gSHOW_HP_REMOVED_FIELDS': CFG_BIBEDIT_SHOW_HOLDING_PEN_REMOVED_FIELDS,
        'gBIBCATALOG_SYSTEM_RT_URL': repr(CFG_BIBCATALOG_SYSTEM_RT_URL),
        'gAutoComplete': json.dumps(CFG_BIBEDIT_AUTOCOMPLETE)
    }

    fieldTemplates = get_available_fields_templates()

    def convert(data):
        """Return JS friendly strings."""
        if isinstance(data, unicode):
            return str(data)
        else:
            return json.dumps(data)

    for key in data:
        data[key] = convert(data[key])

    try:
        BIBCATALOG_SYSTEM.ticket_search(0)
        can_search_for_ticket = True
    except NotImplementedError:
        can_search_for_ticket = False

    ctx = {
        "data": data,
        "fieldTemplates": json.dumps(fieldTemplates),
        "can_search_for_ticket": can_search_for_ticket
    }

    return render_template('editor/index.html', **ctx)
Exemplo n.º 12
0
def index():
    """Editor index page."""
    from invenio.legacy.bibedit.utils import get_record_templates
    from invenio.legacy.bibedit.engine import (get_available_kbs,
                                               get_available_fields_templates)

    # Add script data.
    record_templates = get_record_templates()
    record_templates.sort()
    tag_names = get_name_tags_all()
    protected_fields = ['001']
    protected_fields.extend(cfg['CFG_BIBEDIT_PROTECTED_FIELDS'].split(','))
    cern_site = 'false'
    if CFG_CERN_SITE:
        cern_site = 'true'

    data = {
        'gRECORD_TEMPLATES':
        record_templates,
        'gTAG_NAMES':
        tag_names,
        'gPROTECTED_FIELDS':
        protected_fields,
        'gINTERNAL_DOI_PROTECTION_LEVEL':
        CFG_BIBEDIT_INTERNAL_DOI_PROTECTION_LEVEL,
        'gSITE_URL':
        CFG_SITE_URL,
        'gSITE_RECORD':
        CFG_SITE_RECORD,
        'gCERN_SITE':
        cern_site,
        'gINSPIRE_SITE':
        CFG_INSPIRE_SITE,
        'gHASH_CHECK_INTERVAL':
        cfg['CFG_BIBEDIT_JS_HASH_CHECK_INTERVAL'],
        'gCHECK_SCROLL_INTERVAL':
        cfg['CFG_BIBEDIT_JS_CHECK_SCROLL_INTERVAL'],
        'gSTATUS_ERROR_TIME':
        cfg['CFG_BIBEDIT_JS_STATUS_ERROR_TIME'],
        'gSTATUS_INFO_TIME':
        cfg['CFG_BIBEDIT_JS_STATUS_INFO_TIME'],
        'gCLONED_RECORD_COLOR':
        '"' + cfg['CFG_BIBEDIT_JS_CLONED_RECORD_COLOR'] + '"',
        'gCLONED_RECORD_COLOR_FADE_DURATION':
        cfg['CFG_BIBEDIT_JS_CLONED_RECORD_COLOR_FADE_DURATION'],
        'gNEW_ADD_FIELD_FORM_COLOR':
        '"' + cfg['CFG_BIBEDIT_JS_NEW_ADD_FIELD_FORM_COLOR'] + '"',
        'gNEW_ADD_FIELD_FORM_COLOR_FADE_DURATION':
        cfg['CFG_BIBEDIT_JS_NEW_ADD_FIELD_FORM_COLOR_FADE_DURATION'],
        'gNEW_CONTENT_COLOR':
        '"' + cfg['CFG_BIBEDIT_JS_NEW_CONTENT_COLOR'] + '"',
        'gNEW_CONTENT_COLOR_FADE_DURATION':
        cfg['CFG_BIBEDIT_JS_NEW_CONTENT_COLOR_FADE_DURATION'],
        'gNEW_CONTENT_HIGHLIGHT_DELAY':
        cfg['CFG_BIBEDIT_JS_NEW_CONTENT_HIGHLIGHT_DELAY'],
        'gTICKET_REFRESH_DELAY':
        cfg['CFG_BIBEDIT_JS_TICKET_REFRESH_DELAY'],
        'gRESULT_CODES':
        cfg['CFG_BIBEDIT_AJAX_RESULT_CODES'],
        'gAUTOSUGGEST_TAGS':
        cfg['CFG_BIBEDIT_AUTOSUGGEST_TAGS'],
        'gAUTOCOMPLETE_TAGS':
        cfg['CFG_BIBEDIT_AUTOCOMPLETE_TAGS_KBS'].keys(),
        'gKEYWORD_TAG':
        '"' + cfg['CFG_BIBEDIT_KEYWORD_TAG'] + '"',
        'gREQUESTS_UNTIL_SAVE':
        cfg['CFG_BIBEDIT_REQUESTS_UNTIL_SAVE'],
        'gAVAILABLE_KBS':
        get_available_kbs(),
        'gDOILookupField':
        '"' + cfg['CFG_BIBEDIT_DOI_LOOKUP_FIELD'] + '"',
        'gDisplayReferenceTags':
        cfg['CFG_BIBEDIT_DISPLAY_REFERENCE_TAGS'],
        'gDisplayAuthorTags':
        cfg['CFG_BIBEDIT_DISPLAY_AUTHOR_TAGS'],
        'gExcludeCuratorTags':
        cfg['CFG_BIBEDIT_EXCLUDE_CURATOR_TAGS'],
        'gSHOW_HP_REMOVED_FIELDS':
        CFG_BIBEDIT_SHOW_HOLDING_PEN_REMOVED_FIELDS,
        'gBIBCATALOG_SYSTEM_RT_URL':
        repr(CFG_BIBCATALOG_SYSTEM_RT_URL),
        'gAutoComplete':
        json.dumps(CFG_BIBEDIT_AUTOCOMPLETE)
    }

    fieldTemplates = get_available_fields_templates()

    def convert(data):
        """Return JS friendly strings."""
        if isinstance(data, unicode):
            return str(data)
        else:
            return json.dumps(data)

    for key in data:
        data[key] = convert(data[key])

    try:
        BIBCATALOG_SYSTEM.ticket_search(0)
        can_search_for_ticket = True
    except NotImplementedError:
        can_search_for_ticket = False

    ctx = {
        "data": data,
        "fieldTemplates": json.dumps(fieldTemplates),
        "can_search_for_ticket": can_search_for_ticket
    }

    return render_template('editor/index.html', **ctx)