Exemplo n.º 1
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
Exemplo n.º 3
0
def confirm_person_bibref_assignments(person_id, bibrefs, uid):
    '''
    Confirms a bibref-bibrec assignment to a person. That internally
    raises the flag of the entry to 2, which means 'user confirmed' and
    sets the user level to the highest level of the user provided as param

    @param person_id: the id of the person to confirm the assignment to
    @type person_id: int
    @param bibrefs: the bibref-bibrec pairs that unambiguously identify records
    @type bibrefs: list of strings
    @param uid: the id of the user that arranges the confirmation
    @type uid: int

    @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.confirm_papers_to_person((pid,), refs, get_user_level(uid))
    except OperationalError:
        return False

    return True