

def collections(action):
    if (not hasattr(request, 'auth_collections')):
        request.auth_collections = {
            READ: set(),
            WRITE: set(),
        }
        if is_admin():
            q = Collection.all_ids().filter((Collection.deleted_at == None))
            for (col_id,) in q:
                request.auth_collections[READ].add(col_id)
                request.auth_collections[WRITE].add(col_id)
        else:
            q = Permission.all()
            q = q.filter(Permission.role_id.in_(request.auth_roles))
            q = q.filter((Permission.resource_type == Permission.COLLECTION))
            for perm in q:
                if perm.read:
                    request.auth_collections[READ].add(perm.resource_id)
                if (perm.write and request.logged_in):
                    request.auth_collections[WRITE].add(perm.resource_id)
    return list(request.auth_collections.get(action, []))

dataset/ETHPy150Open pudo/aleph/aleph/authz.py collections/original