<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def apply( self, query: BaseQuery, func: Callable) -> BaseQuery: """ Filter queries to only those owned by current user if can_only_access_owned_queries permission is set. :returns: query """

        if security_manager.can_only_access_owned_queries():
            query = (
                query
                .filter(Query.user_id == g.user.get_user_id())
            )
        return query