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') 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 get_record_collections(recid): """Get all collections the record belong to.""" try: from invenio.search_engine import get_all_collections_of_a_record except ImportError: from invenio.legacy.search_engine import \ get_all_collections_of_a_record return get_all_collections_of_a_record( recid, recreate_cache_if_needed=False)
def get_record_collections(recid): """Get all collections the record belong to.""" try: from invenio.search_engine import get_all_collections_of_a_record except ImportError: from invenio.legacy.search_engine import \ get_all_collections_of_a_record return get_all_collections_of_a_record(recid, recreate_cache_if_needed=False)
def user_can_edit_record_collection(req, recid): """ Check if user has authorization to modify a collection the recid belongs to """ record_collections = get_all_collections_of_a_record(recid) for collection in record_collections: auth_code, auth_message = acc_authorize_action(req, 'runbibedit', collection=collection) if auth_code == 0: return True return False
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 = {} categories = get_journal_categories(journal_name, issue) for category in categories: articles = get_journal_articles(journal_name, issue, category) for order, recids in articles.iteritems(): for recid in recids: record_xml = format_record(recid, of='xm') if not record_xml: continue new_record_xml_path = os.path.join(CFG_TMPDIR, '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) task_low_level_submission('bibindex', 'WebJournal', '-i', str(recid)) 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','-c', collection)
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 = {} categories = get_journal_categories(journal_name, issue) for category in categories: articles = get_journal_articles(journal_name, issue, category) for order, recids in articles.iteritems(): for recid in recids: record_xml = format_record(recid, of='xm') if not record_xml: continue new_record_xml_path = os.path.join(CFG_TMPDIR, '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) task_low_level_submission('bibindex', 'WebJournal', '-i', str(recid)) 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', '-c', collection)
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)
def user_can_perform_action_on_collection(req, recid, action=""): """ Check if user has authorization to modify a collection the recid belongs to """ record_collections = get_all_collections_of_a_record(recid) if not record_collections: # Check if user has access to all collections auth_code, auth_message = acc_authorize_action(req, action, collection='') if auth_code == 0: return True else: for collection in record_collections: auth_code, auth_message = acc_authorize_action(req, action, collection=collection) if auth_code == 0: return True return False
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) uid = getUid(req) # In case we are creating a new record if cache_exists(recid, uid): dummy1, dummy2, record, dummy3, dummy4, dummy5, dummy6 = get_cache_file_contents( recid, uid) 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, auth_message = acc_authorize_action(req, 'runbibedit', collection='') if auth_code == 0: return True else: for collection in normalized_collections: auth_code, auth_message = acc_authorize_action( req, 'runbibedit', collection=collection) if auth_code == 0: return True return False
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
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 = {} categories = get_journal_categories(journal_name, issue) for category in categories: articles = get_journal_articles(journal_name, issue, category) for order, recids in articles.iteritems(): for recid in recids: record_xml = format_record(recid, of="xm") if not record_xml: continue new_record_xml_path = os.path.join(CFG_TMPDIR, "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) task_low_level_submission("bibindex", "WebJournal", "-i", str(recid)) 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", "-c", collection)
def user_can_perform_action_on_collection(req, recid, action=""): """ Check if user has authorization to modify a collection the recid belongs to """ record_collections = get_all_collections_of_a_record(recid) if not record_collections: # Check if user has access to all collections auth_code, auth_message = acc_authorize_action(req, action, collection='') if auth_code == 0: return True else: for collection in record_collections: auth_code, auth_message = acc_authorize_action( req, action, collection=collection) if auth_code == 0: return True return False
def get_record_collections(recid): """Get all collections the record belong to.""" try: from invenio.search_engine import ( get_all_collections_of_a_record, get_restricted_collections_for_recid) except ImportError: from invenio.legacy.search_engine import ( get_all_collections_of_a_record, get_restricted_collections_for_recid) collections = { 'all': get_all_collections_of_a_record(recid, recreate_cache_if_needed=False), } collections['restricted'] = dict( (coll, _get_collection_restrictions(coll)) for coll in get_restricted_collections_for_recid( recid, recreate_cache_if_needed=False)) return collections
def get_record_collections(recid): """Get all collections the record belong to.""" try: from invenio.search_engine import (get_all_collections_of_a_record, get_restricted_collections_for_recid ) except ImportError: from invenio.legacy.search_engine import ( get_all_collections_of_a_record, get_restricted_collections_for_recid) collections = { 'all': get_all_collections_of_a_record(recid, recreate_cache_if_needed=False), } collections['restricted'] = dict( (coll, _get_collection_restrictions(coll)) for coll in get_restricted_collections_for_recid( recid, recreate_cache_if_needed=False)) return collections
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') 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)