def reset_person_bibref_decisions(person_id, bibrefs):
    '''
    Resets a bibref-bibrec assignment of a person. That internally
    sets the flag of the entry to 0, which means 'no user interaction' and
    sets the user level to 0 to give the record free for claiming/curation

    @param person_id: the id of the person to reset the assignment from
    @type person_id: int
    @param bibrefs: the bibref-bibrec pairs that unambiguously identify records
    @type bibrefs: list of strings

    @return: True if the process ran smoothly, False if there was an error
    @rtype: boolean
    '''
    pid = wash_integer_id(person_id)
    refs = []

    if pid < 0:
        return False

    if not isinstance(bibrefs, list) or not len(bibrefs):
        return False
    else:
        for bibref in bibrefs:
            if is_valid_bibref(bibref):
                refs.append((bibref,))
            else:
                return False

    try:
        tu.reset_papers_flag((person_id,), refs)
    except OperationalError:
        return False

    return True
Example #2
0
def execute_action(action, pid, bibref, uid, userinfo='', comment=''):
    '''
    Executes the action, setting the last user right according to uid

    @param action: the action to perform
    @type action: string
    @param pid: the Person ID to perform the action on
    @type pid: int
    @param bibref: the bibref pair to perform the action for
    @type bibref: string
    @param uid: the internal user ID of the currently logged in user
    @type uid: int

    @return: success of the process
    @rtype: boolean
    '''
    pid = wash_integer_id(pid)

    if not action in ['confirm', 'assign', 'repeal', 'reset']:
        return False
    elif pid < 0:
        return False
    elif pid == -3:
        pid = tu.create_new_person(uid, uid_is_owner=False)
    elif not is_valid_bibref(bibref):
        return False

    user_level = _resolve_maximum_acces_rights(uid)[1]

    if action in ['confirm', 'assign']:
        tu.insert_user_log(userinfo, pid, 'assign', 'CMPUI_ticketcommit',
                           bibref, comment)
        tu.confirm_papers_to_person([pid], [[bibref]], user_level)
    elif action in ['repeal']:
        tu.insert_user_log(userinfo, pid, 'repeal', 'CMPUI_ticketcommit',
                           bibref, comment)
        tu.reject_papers_from_person([pid], [[bibref]], user_level)
    elif action in ['reset']:
        tu.insert_user_log(userinfo, pid, 'reset', 'CMPUI_ticketcommit',
                           bibref, comment)
        tu.reset_papers_flag([pid], [[bibref]])
    else:
        return False
    return True
def execute_action(action, pid, bibref, uid, userinfo='', comment=''):
    '''
    Executes the action, setting the last user right according to uid

    @param action: the action to perform
    @type action: string
    @param pid: the Person ID to perform the action on
    @type pid: int
    @param bibref: the bibref pair to perform the action for
    @type bibref: string
    @param uid: the internal user ID of the currently logged in user
    @type uid: int

    @return: success of the process
    @rtype: boolean
    '''
    pid = wash_integer_id(pid)

    if not action in ['confirm', 'assign', 'repeal', 'reset']:
        return False
    elif pid < 0:
        return False
    elif pid == -3:
        pid = tu.create_new_person(uid, uid_is_owner=False)
    elif not is_valid_bibref(bibref):
        return False

    user_level = _resolve_maximum_acces_rights(uid)[1]

    if action in ['confirm', 'assign']:
        tu.insert_user_log(userinfo, pid, 'assign', 'CMPUI_ticketcommit', bibref, comment)
        tu.confirm_papers_to_person([pid], [[bibref]], user_level)
    elif action in ['repeal']:
        tu.insert_user_log(userinfo, pid, 'repeal', 'CMPUI_ticketcommit', bibref, comment)
        tu.reject_papers_from_person([pid], [[bibref]], user_level)
    elif action in ['reset']:
        tu.insert_user_log(userinfo, pid, 'reset', 'CMPUI_ticketcommit', bibref, comment)
        tu.reset_papers_flag([pid], [[bibref]])
    else:
        return False
    return True