Exemplo n.º 1
0
def update_permissions(user, access, recursive, name):

    access_type_id = get_access_type_id(access)
    object_id = get_collection_id(name)
    users_dict = get_user_dict()
    user_id = list(users_dict.keys())[list(users_dict.values()).index(user)]

    with TuRODSSession() as session:
        sql = "update R_OBJT_ACCESS set access_type_id = {} where object_id = {} and user_id = {}" \
            .format(access_type_id, object_id, user_id)

        alias = 'update_permissions2'
        query = SpecificQuery(session, sql, alias)

        # register specific query in iCAT
        _ = query.register()

        exception = None
        try:
            query.execute()
        except CAT_NO_ROWS_FOUND:
            pass
        except Exception as e:
            exception = e

        _ = query.remove()

        if exception is not None:
            log_and_raise_exception('Error in changing the permissions access_type_id = {} object_id = {} and user_id = {}' \
                        .format(access_type_id, object_id, user_id), exception)
Exemplo n.º 2
0
def delete_permission(user_id, object_id):

    with TuRODSSession() as session:

        sql = "delete from R_OBJT_ACCESS WHERE object_id = {} and user_id = {}".format(
            object_id, 24746)
        alias = 'del_permissions'

        query = SpecificQuery(session, sql, alias)

        # register specific query in iCAT
        _ = query.register()

        exception = None

        try:
            query.execute()
            query.get_results()
        except Exception as e:
            exception = e

        # delete specific query
        _ = query.remove()

        if exception is not None:
            log_and_raise_exception('Error in delete_permission', exception)
Exemplo n.º 3
0
def testje(path, user_id):
    with TuRODSSession() as session:
        sql = "select object_id from R_OBJT_ACCESS where user_id = {} and object_id in" \
        "(select R_COLL_MAIN.coll_id from R_COLL_MAIN WHERE R_COLL_MAIN.coll_name like '{}%' )". \
        format(user_id, path)



        sql = "select R_COLL_MAIN.coll_id from R_COLL_MAIN JOIN R_OBJT_ACCESS ON R_COLL_MAIN.coll_id = R_OBJT_ACCESS.object_id " \
        "WHERE R_COLL_MAIN.coll_name like '{}% and R_OBJT_ACCESS.user_id = {}".format(path, user_id)


        sql = "select R_COLL_MAIN.coll_id from R_COLL_MAIN " \
                "JOIN R_OBJT_ACCESS OA ON OA.object_id = R_COLL_MAIN.coll_id " \
                "WHERE user_id = " + str(user_id)

        #sql = "select R_COLL_MAIN.coll_id from R_COLL_MAIN WHERE R_COLL_MAIN.coll_name like '{}%' ".format(path)
        print(sql)

        alias = 'blepper14'
        columns = [Collection.id]
        query = SpecificQuery(session, sql, alias, columns)

        # register specific query in iCAT
        _ = query.register()

        exception = None
        n = 0
        try:
            query.execute()
            for result in query.get_results():
                n = n + 1
                print(n, result[Collection.id])

                print(get_collection_name(result[Collection.id]))

        except CAT_NO_ROWS_FOUND:
            print('no exception')
        except Exception as e:
            exception = e

        _ = query.remove()

        if exception is not None:
            log_and_raise_exception('Error', exception)
Exemplo n.º 4
0
def show_groups(users_dict):
    with TuRODSSession() as session:

        query = session.query(UserGroup.id, UserGroup.name)
        for result in query.get_results():
            print(result[UserGroup.id], result[UserGroup.name])

        sql = "select group_user_id, user_id from R_user_group"

        alias = 'blepper15'
        columns = [CollectionAccess.user_id, CollectionAccess.access_id]
        query = SpecificQuery(session, sql, alias, columns)

        # register specific query in iCAT
        _ = query.register()

        exception = None
        n = 0
        try:
            query.execute()
            for result in query.get_results():
                n = n + 1
                user = users_dict[result[CollectionAccess.access_id]]
                #print(n,result[CollectionAccess.user_id], user)
                print(result[CollectionAccess.user_id],
                      result[CollectionAccess.access_id])

        except CAT_NO_ROWS_FOUND:
            print('no exception')
        except Exception as e:
            exception = e

        _ = query.remove()

        if exception is not None:
            log_and_raise_exception('Error', exception)