예제 #1
0
def delete_person_external_ids(person_id, existing_ext_ids, userinfo=''):
    '''
    Deletes external ids of the person
    @param person_id: person id
    @type person_id: int
    @param existing_ext_ids: external ids to delete
    @type existing_ext_ids: list
    '''
    if userinfo.count('||'):
        uid = userinfo.split('||')[0]
    else:
        uid = ''

    deleted_ids = []
    for el in existing_ext_ids:
        if el.count('||'):
            ext_sys = el.split('||')[0]
            ext_id = el.split('||')[1]
        else:
            continue
        tag = 'extid:%s' % ext_sys
        dbapi.del_person_data(tag, person_id, ext_id)
        deleted_ids.append((person_id, tag, ext_id))

    dbapi.insert_user_log(userinfo, person_id, 'data_deletion', 'CMPUI_deleteextid', '', 'External ids manually deleted: ' + str(deleted_ids), userid=uid)
예제 #2
0
def add_person_external_id(person_id, ext_sys, ext_id, userinfo=''):
    '''
    Adds an external id for the person
    @param person_id: person id
    @type person_id: int
    @param ext_sys: external system
    @type ext_sys: str
    @param ext_id: external id
    @type ext_id: str
    '''
    if userinfo.count('||'):
        uid = userinfo.split('||')[0]
    else:
        uid = ''

    tag = 'extid:%s' % ext_sys
    dbapi.set_person_data(person_id, tag, ext_id)

    log_value = '%s %s %s' % (person_id, tag, ext_id)
    dbapi.insert_user_log(userinfo,
                          person_id,
                          'data_insertion',
                          'CMPUI_addexternalid',
                          log_value,
                          'External id manually added.',
                          userid=uid)
예제 #3
0
def update_person_canonical_name(person_id, canonical_name, userinfo=''):
    '''
    Updates a person's canonical name
    @param person_id: person id
    @param canonical_name: string
    '''
    dbapi.update_personID_canonical_names((person_id,), overwrite=True, suggested=canonical_name)
    dbapi.insert_user_log(userinfo, person_id, 'data_update', 'CMPUI_changecanonicalname', '', 'Canonical name manually updated.')
예제 #4
0
def update_person_canonical_name(person_id, canonical_name, userinfo=''):
    '''
    Updates a person's canonical name
    @param person_id: person id
    @param canonical_name: string
    '''
    if userinfo.count('||'):
        uid = userinfo.split('||')[0]
    else:
        uid = ''
    dbapi.update_personID_canonical_names([person_id], overwrite=True, suggested=canonical_name)
    dbapi.insert_user_log(userinfo, person_id, 'data_update', 'CMPUI_changecanonicalname', '', 'Canonical name manually updated.', userid=uid)
예제 #5
0
def update_person_canonical_name(person_id, canonical_name, userinfo=''):
    '''
    Updates a person's canonical name
    @param person_id: person id
    @param canonical_name: string
    '''
    if userinfo.count('||'):
        uid = userinfo.split('||')[0]
    else:
        uid = ''
    dbapi.update_personID_canonical_names([person_id], overwrite=True, suggested=canonical_name)
    dbapi.insert_user_log(userinfo, person_id, 'data_update', 'CMPUI_changecanonicalname', '', 'Canonical name manually updated.', userid=uid)
예제 #6
0
def update_person_canonical_name(person_id, canonical_name, userinfo=''):
    '''
    Updates a person's canonical name
    @param person_id: person id
    @param canonical_name: string
    '''
    dbapi.update_personID_canonical_names(persons_list=[[person_id]],
                                          overwrite=True,
                                          suggested=canonical_name)
    dbapi.insert_user_log(userinfo, person_id, 'data_update',
                          'CMPUI_changecanonicalname', '',
                          'Canonical name manually updated.')
예제 #7
0
def add_person_external_id(person_id, ext_sys, ext_id, userinfo=''):
    '''
    Adds an external id for the person
    @param person_id: person id
    @type person_id: int
    @param ext_sys: external system
    @type ext_sys: str
    @param ext_id: external id
    @type ext_id: str
    '''
    if userinfo.count('||'):
        uid = userinfo.split('||')[0]
    else:
        uid = ''

    tag = 'extid:%s' % ext_sys
    dbapi.set_person_data(person_id, tag, ext_id)

    log_value = '%s %s %s' % (person_id, tag, ext_id)
    dbapi.insert_user_log(userinfo, person_id, 'data_insertion', 'CMPUI_addexternalid', log_value, 'External id manually added.', userid=uid)
예제 #8
0
def insert_log(userinfo,
               personid,
               action,
               tag,
               value,
               comment='',
               transactionid=0):
    '''
    Log an action performed by a user

    Examples (in the DB):
    1 2010-09-30 19:30  admin||10.0.0.1  1  assign  paper  1133:4442 'from 23'
    1 2010-09-30 19:30  admin||10.0.0.1  1  assign  paper  8147:4442
    2 2010-09-30 19:35  admin||10.0.0.1  1  reject  paper  72:4442

    @param userinfo: information about the user [UID|IP]
    @type userinfo: string
    @param personid: ID of the person this action is targeting
    @type personid: int
    @param action: intended action
    @type action: string
    @param tag: A tag to describe the data entered
    @type tag: string
    @param value: The value of the action described by the tag
    @type value: string
    @param comment: Optional comment to describe the transaction
    @type comment: string
    @param transactionid: May group bulk operations together
    @type transactionid: int

    @return: Returns the current transactionid
    @rtype: int
    '''
    userinfo = escape(str(userinfo))
    action = escape(str(action))
    tag = escape(str(tag))
    value = escape(str(value))
    comment = escape(str(comment))

    if not isinstance(personid, int):
        try:
            personid = int(personid)
        except (ValueError, TypeError):
            return -1

    if not isinstance(transactionid, int):
        try:
            transactionid = int(transactionid)
        except (ValueError, TypeError):
            return -1

    return dbapi.insert_user_log(userinfo, personid, action, tag, value,
                                 comment, transactionid)
예제 #9
0
def insert_log(userinfo, personid, action, tag, value, comment='', transactionid=0):
    '''
    Log an action performed by a user

    Examples (in the DB):
    1 2010-09-30 19:30  admin||10.0.0.1  1  assign  paper  1133:4442 'from 23'
    1 2010-09-30 19:30  admin||10.0.0.1  1  assign  paper  8147:4442
    2 2010-09-30 19:35  admin||10.0.0.1  1  reject  paper  72:4442

    @param userinfo: information about the user [UID|IP]
    @type userinfo: string
    @param personid: ID of the person this action is targeting
    @type personid: int
    @param action: intended action
    @type action: string
    @param tag: A tag to describe the data entered
    @type tag: string
    @param value: The value of the action described by the tag
    @type value: string
    @param comment: Optional comment to describe the transaction
    @type comment: string
    @param transactionid: May group bulk operations together
    @type transactionid: int

    @return: Returns the current transactionid
    @rtype: int
    '''
    userinfo = escape(str(userinfo))
    action = escape(str(action))
    tag = escape(str(tag))
    value = escape(str(value))
    comment = escape(str(comment))

    if not isinstance(personid, int):
        try:
            personid = int(personid)
        except (ValueError, TypeError):
            return -1

    if not isinstance(transactionid, int):
        try:
            transactionid = int(transactionid)
        except (ValueError, TypeError):
            return -1

    if userinfo.count('||'):
        uid = userinfo.split('||')[0]
    else:
        uid = ''

    return dbapi.insert_user_log(userinfo, personid, action, tag,
                       value, comment, transactionid, userid=uid)
예제 #10
0
def execute_action(action,
                   pid,
                   bibref,
                   uid,
                   gather_list,
                   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 = dbapi.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']:
        dbapi.insert_user_log(userinfo, pid, 'assign', 'CMPUI_ticketcommit',
                              bibref, comment)
        dbapi.confirm_papers_to_person((str(pid), ), [[bibref]], gather_list,
                                       user_level)
    elif action in ['repeal']:
        dbapi.insert_user_log(userinfo, pid, 'repeal', 'CMPUI_ticketcommit',
                              bibref, comment)
        dbapi.reject_papers_from_person((str(pid), ), [[bibref]], gather_list,
                                        user_level)
    elif action in ['reset']:
        dbapi.insert_user_log(userinfo, pid, 'reset', 'CMPUI_ticketcommit',
                              bibref, comment)
        dbapi.reset_papers_flag((str(pid), ), [[bibref]], gather_list)
    else:
        return False

    #This is the only point which modifies a person, so this can trigger the
    #deletion of a cached page
    dbapi.delete_cached_author_page(pid)

    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 = dbapi.create_new_person(uid, uid_is_owner=False)
    elif not is_valid_bibref(bibref):
        return False

    if userinfo.count('||'):
        uid = userinfo.split('||')[0]
    else:
        uid = ''

    user_level = _resolve_maximum_acces_rights(uid)[1]

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

    #This is the only point which modifies a person, so this can trigger the
    #deletion of a cached page
    webauthorapi.expire_all_cache_for_personid(pid)

    return True
예제 #12
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: list of a tuple: [(status, message), ] or None if something went wrong
    @rtype: [(bool, str), ]
    '''
    pid = wash_integer_id(pid)

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

    if userinfo.count('||'):
        uid = userinfo.split('||')[0]
    else:
        uid = ''

    user_level = _resolve_maximum_acces_rights(uid)[1]

    res = None
    if action in ['confirm', 'assign']:
        dbapi.insert_user_log(userinfo, pid, 'assign', 'CMPUI_ticketcommit', bibref, comment, userid=uid)
        res = dbapi.confirm_papers_to_person(pid, [bibref], user_level)
    elif action in ['repeal']:
        dbapi.insert_user_log(userinfo, pid, 'repeal', 'CMPUI_ticketcommit', bibref, comment, userid=uid)
        res = dbapi.reject_papers_from_person(pid, [bibref], user_level)
    elif action in ['reset']:
        dbapi.insert_user_log(userinfo, pid, 'reset', 'CMPUI_ticketcommit', bibref, comment, userid=uid)
        res = dbapi.reset_papers_flag(pid, [bibref])

    #This is the only point which modifies a person, so this can trigger the
    #deletion of a cached page
    webauthorapi.expire_all_cache_for_personid(pid)

    return res