invenio_migrator/legacy/access.py
def get_connected_roles(action_id):
    """Get roles connected to an action."""
    try:
        from invenio.access_control_admin import compile_role_definition
    except ImportError:
        from invenio.modules.access.firerole import compile_role_definition

    run_sql = _get_run_sql()

    roles = {}
    res = run_sql(
        'select r.id, r.name, r.description, r.firerole_def_src, '
        'a.keyword, a.value, email from accROLE as r '
        'join accROLE_accACTION_accARGUMENT on r.id=id_accROLE '
        'join accARGUMENT as a on  a.id=id_accARGUMENT '
        'join user_accROLE as u on r.id=u.id_accROLE '
        'join user on user.id=u.id_user '
        'where id_accACTION=%s', (action_id, )
    )

    for r in res:
        role = roles.setdefault(
            r[0], {
                'id': r[0],
                'name': r[1],
                'description': r[2],
                'firerole_def': r[3],
                'compiled_firerole_def': compile_role_definition(r[3]),
                'users': set(),
                'parameters': {}
            }
        )
        param = role['parameters'].setdefault(r[4], set())
        param.add(r[5])
        role['users'].add(r[6])

    return six.itervalues(roles)
def get_connected_roles(action_id):
    """Get roles connected to an action."""
    try:
        from invenio.access_control_admin import compile_role_definition
    except ImportError:
        from invenio.modules.access.firerole import compile_role_definition

    run_sql = _get_run_sql()

    roles = {}
    res = run_sql(
        'select r.id, r.name, r.description, r.firerole_def_src, '
        'a.keyword, a.value, email from accROLE as r '
        'join accROLE_accACTION_accARGUMENT on r.id=id_accROLE '
        'join accARGUMENT as a on  a.id=id_accARGUMENT '
        'join user_accROLE as u on r.id=u.id_accROLE '
        'join user on user.id=u.id_user '
        'where id_accACTION=%s', (action_id, )
    )

    for r in res:
        role = roles.setdefault(
            r[0], {
                'id': r[0],
                'name': r[1],
                'description': r[2],
                'firerole_def': r[3],
                'compiled_firerole_def': compile_role_definition(r[3]),
                'users': set(),
                'parameters': {}
            }
        )
        param = role['parameters'].setdefault(r[4], set())
        param.add(r[5])
        role['users'].add(r[6])

    return six.itervalues(roles)
Get roles connected to an action.