def format_element(bfo, separator="<br />"):
    """Prints the list of collections the record belongs to.

    @param separator: a separator between each collection link.
    """
    def _include(collname):
        return not (collname.startswith('provisional-') or
                    collname == 'zenodo-public' or collname == 'user-zenodo')

    if isinstance(bfo.recID, six.string_types):
        bfo.recID = int(bfo.recID)

    coll_names = filter(_include, get_all_collections_of_a_record(bfo.recID))

    navtrails = [
        create_navtrail_links(coll_name, ln=bfo.lang)
        for coll_name in coll_names
    ]
    navtrails = [navtrail for navtrail in navtrails if navtrail]
    navtrails.sort(lambda x, y: cmp(len(y), len(x)))
    final_navtrails = []
    for navtrail in navtrails:
        for final_navtrail in final_navtrails:
            if navtrail in final_navtrail:
                break
        else:
            final_navtrails.append(navtrail)
    return separator.join(final_navtrails)
def format_element(bfo, separator="<br />"):
    """Prints the list of collections the record belongs to.

    @param separator: a separator between each collection link.
    """

    coll_names = get_all_collections_of_a_record(bfo.recID)
    navtrails = [create_navtrail_links(coll_name, ln=bfo.lang) for coll_name in coll_names]
    navtrails = [navtrail for navtrail in navtrails if navtrail]
    navtrails.sort(lambda x, y: cmp(len(y), len(x)))
    final_navtrails = []
    for navtrail in navtrails:
        for final_navtrail in final_navtrails:
            if navtrail in final_navtrail:
                break
        else:
            final_navtrails.append(navtrail)
    return separator.join(final_navtrails)
示例#3
0
def format_element(bfo, separator="<br />"):
    """Prints the list of collections the record belongs to.

    @param separator: a separator between each collection link.
    """

    coll_names = get_all_collections_of_a_record(bfo.recID)
    navtrails = [create_navtrail_links(coll_name, ln=bfo.lang) for coll_name in coll_names]
    navtrails = [navtrail for navtrail in navtrails if navtrail]
    navtrails.sort(lambda x, y: cmp(len(y), len(x)))
    final_navtrails = []
    for navtrail in navtrails:
        for final_navtrail in final_navtrails:
            if navtrail in final_navtrail:
                break
        else:
            final_navtrails.append(navtrail)
    return separator.join(final_navtrails)
示例#4
0
def user_can_edit_record_collection(req, recid):
    """ Check if user has authorization to modify a collection
    the recid belongs to
    """

    def remove_volatile(field_value):
        """ Remove volatile keyword from field value """
        if field_value.startswith(VOLATILE_PREFIX):
            field_value = field_value[len(VOLATILE_PREFIX) :]
        return field_value

    # Get the collections the record belongs to
    record_collections = get_all_collections_of_a_record(recid)

    user_info = collect_user_info(req)
    uid = user_info["uid"]
    # In case we are creating a new record
    if cache_exists(recid, uid):
        record = get_cache_contents(recid, uid)[2]
        values = record_get_field_values(record, "980", code="a")
        record_collections.extend([remove_volatile(v) for v in values])

    normalized_collections = []
    for collection in record_collections:
        # Get the normalized collection name present in the action table
        res = run_sql(
            """SELECT value FROM "accARGUMENT"
                         WHERE keyword='collection'
                         AND value=%s;""",
            (collection,),
        )
        if res:
            normalized_collections.append(res[0][0])
    if not normalized_collections:
        # Check if user has access to all collections
        auth_code, dummy_message = acc_authorize_action(req, "runbibedit", collection="")
        if auth_code == 0:
            return True
    else:
        for collection in normalized_collections:
            auth_code, dummy_message = acc_authorize_action(req, "runbibedit", collection=collection)
            if auth_code == 0:
                return True
    return False
示例#5
0
def user_can_edit_record_collection(req, recid):
    """ Check if user has authorization to modify a collection
    the recid belongs to
    """
    def remove_volatile(field_value):
        """ Remove volatile keyword from field value """
        if field_value.startswith(VOLATILE_PREFIX):
            field_value = field_value[len(VOLATILE_PREFIX):]
        return field_value

    # Get the collections the record belongs to
    record_collections = get_all_collections_of_a_record(recid)

    user_info = collect_user_info(req)
    uid = user_info["uid"]
    # In case we are creating a new record
    if cache_exists(recid, uid):
        record = get_cache_contents(recid, uid)[2]
        values = record_get_field_values(record, '980', code="a")
        record_collections.extend([remove_volatile(v) for v in values])

    normalized_collections = []
    for collection in record_collections:
        # Get the normalized collection name present in the action table
        res = run_sql(
            """SELECT value FROM "accARGUMENT"
                         WHERE keyword='collection'
                         AND value=%s;""", (collection, ))
        if res:
            normalized_collections.append(res[0][0])
    if not normalized_collections:
        # Check if user has access to all collections
        auth_code, dummy_message = acc_authorize_action(req,
                                                        'runbibedit',
                                                        collection='')
        if auth_code == 0:
            return True
    else:
        for collection in normalized_collections:
            auth_code, dummy_message = acc_authorize_action(
                req, 'runbibedit', collection=collection)
            if auth_code == 0:
                return True
    return False
示例#6
0
def move_drafts_articles_to_ready(journal_name, issue):
    """
    Move draft articles to their final "collection".

    To do so we rely on the convention that an admin-chosen keyword
    must be removed from the metadata
    """
    protected_datafields = ['100', '245', '246', '520', '590', '700']
    keyword_to_remove = get_journal_draft_keyword_to_remove(journal_name)
    collections_to_refresh = {}
    indexes_to_refresh = get_journal_index_to_refresh_on_release(journal_name)
    bibindex_indexes_params = []
    if indexes_to_refresh:
        bibindex_indexes_params = ['-w', ','.join(indexes_to_refresh)]

    categories = get_journal_categories(journal_name, issue)
    task_sequence_id = str(bibtask_allocate_sequenceid())
    for category in categories:
        articles = get_journal_articles(journal_name, issue, category)
        for order, recids in iteritems(articles):
            for recid in recids:
                record_xml = format_record(recid, of='xm')
                if not record_xml:
                    continue
                new_record_xml_path = os.path.join(CFG_TMPSHAREDDIR,
                                                   'webjournal_publish_' + \
                                                   str(recid) + '.xml')
                if os.path.exists(new_record_xml_path):
                    # Do not modify twice
                    continue
                record_struc = create_record(record_xml)
                record = record_struc[0]
                new_record = update_draft_record_metadata(record,
                                                          protected_datafields,
                                                          keyword_to_remove)
                new_record_xml = print_rec(new_record)
                if new_record_xml.find(keyword_to_remove) >= 0:
                    new_record_xml = new_record_xml.replace(keyword_to_remove, '')
                    # Write to file
                    new_record_xml_file = file(new_record_xml_path, 'w')
                    new_record_xml_file.write(new_record_xml)
                    new_record_xml_file.close()
                    # Submit
                    task_low_level_submission('bibupload',
                                              'WebJournal',
                                              '-c', new_record_xml_path,
                                              '-I', task_sequence_id)
                    task_low_level_submission('bibindex',
                                              'WebJournal',
                                              '-i', str(recid),
                                              '-I', task_sequence_id,
                                               *bibindex_indexes_params)
                    for collection in get_all_collections_of_a_record(recid):
                        collections_to_refresh[collection] = ''

    # Refresh collections
    collections_to_refresh.update([(c, '') for c in get_journal_collection_to_refresh_on_release(journal_name)])
    for collection in collections_to_refresh.keys():
        task_low_level_submission('webcoll',
                                  'WebJournal',
                                  '-f', '-P', '2', '-p', '1', '-c', collection,
                                  '-I', task_sequence_id)
示例#7
0
def move_drafts_articles_to_ready(journal_name, issue):
    """
    Move draft articles to their final "collection".

    To do so we rely on the convention that an admin-chosen keyword
    must be removed from the metadata
    """
    protected_datafields = ['100', '245', '246', '520', '590', '700']
    keyword_to_remove = get_journal_draft_keyword_to_remove(journal_name)
    collections_to_refresh = {}
    indexes_to_refresh = get_journal_index_to_refresh_on_release(journal_name)
    bibindex_indexes_params = []
    if indexes_to_refresh:
        bibindex_indexes_params = ['-w', ','.join(indexes_to_refresh)]

    categories = get_journal_categories(journal_name, issue)
    task_sequence_id = str(bibtask_allocate_sequenceid())
    for category in categories:
        articles = get_journal_articles(journal_name, issue, category)
        for order, recids in iteritems(articles):
            for recid in recids:
                record_xml = format_record(recid, of='xm')
                if not record_xml:
                    continue
                new_record_xml_path = os.path.join(CFG_TMPSHAREDDIR,
                                                   'webjournal_publish_' + \
                                                   str(recid) + '.xml')
                if os.path.exists(new_record_xml_path):
                    # Do not modify twice
                    continue
                record_struc = create_record(record_xml)
                record = record_struc[0]
                new_record = update_draft_record_metadata(record,
                                                          protected_datafields,
                                                          keyword_to_remove)
                new_record_xml = print_rec(new_record)
                if new_record_xml.find(keyword_to_remove) >= 0:
                    new_record_xml = new_record_xml.replace(keyword_to_remove, '')
                    # Write to file
                    new_record_xml_file = file(new_record_xml_path, 'w')
                    new_record_xml_file.write(new_record_xml)
                    new_record_xml_file.close()
                    # Submit
                    task_low_level_submission('bibupload',
                                              'WebJournal',
                                              '-c', new_record_xml_path,
                                              '-I', task_sequence_id)
                    task_low_level_submission('bibindex',
                                              'WebJournal',
                                              '-i', str(recid),
                                              '-I', task_sequence_id,
                                               *bibindex_indexes_params)
                    for collection in get_all_collections_of_a_record(recid):
                        collections_to_refresh[collection] = ''

    # Refresh collections
    collections_to_refresh.update([(c, '') for c in get_journal_collection_to_refresh_on_release(journal_name)])
    for collection in collections_to_refresh.keys():
        task_low_level_submission('webcoll',
                                  'WebJournal',
                                  '-f', '-P', '2', '-p', '1', '-c', collection,
                                  '-I', task_sequence_id)