def lookup_all(context_path=None, parent_path=None, **kwargs): logger.debug("context_path: %s, parent_path: %s, kwargs: %s" % (context_path, parent_path, kwargs)) from ztree.query.traverse import lookup_search nodes_found = [] nodes_found = lookup_search(context_path=context_path, parent_path=parent_path, **kwargs) return (nodes_found, None)
def lookup(context_path=None, parent_path=None, **kwargs): logger.debug("context_path: %s, parent_path: %s, kwargs: %s" % (context_path, parent_path, kwargs)) from ztree.query.traverse import lookup_search for node in lookup_search(context_path=context_path, parent_path=parent_path, **kwargs): logger.debug("found node - " + node.absolute_path) # return first found return (node, None) logger.warning("node not found") return (None, None)
def get_user_context_permissions(context_path, authenticated_user): from ztree.query.traverse import lookup_search logger.debug('context_path: %s, user: "******"' % (context_path, authenticated_user.username)) if not authenticated_user: return [] cache_key = 'user_context_permissions:%s:%s' % ( authenticated_user.username, context_path) cached_permissions = cache.get(cache_key) if cached_permissions: logger.debug('Retrieving "%s" from cache' % cache_key) return cached_permissions content_filter = {'user__username': authenticated_user.username} permissions = [] #XXX could maybe simplify removing filter_children below by passing in parent_path # lookup_search(None, parent_path=context_path ...) # should do filter_children on parent_path and lookup_search # first get children LocalUser-s with the username #for n in filter_children(context_path, ct='ztreeauth.localuser', **content_filter): # local_user_obj = n.content_object # for grp in local_user_obj.groups.all(): # for perm in grp.permissions.all(): # if not perm in permissions: # permissions.append(perm) # lookup the ancestors and their siblings for LocalUser-s with the username #for n in lookup_search(context_path=context_path, parent_path=parent_path, ct='ztreeauth.localuser', **content_filter): # passing in parent_path indicates to lookup_search to first search children # of the context node, and then search up the ancestors tree for n in lookup_search(parent_path=context_path, ct='ztreeauth.localuser', **content_filter): local_user_obj = n.content_object for grp in local_user_obj.groups.all(): for perm in grp.permissions.all(): if not perm in permissions: permissions.append(perm) logger.debug('user "%s" permissions at %s: %s' % (authenticated_user.username, context_path, permissions)) cache.set(cache_key, permissions, 600) return permissions
def get_user_context_permissions(context_path, authenticated_user): from ztree.query.traverse import lookup_search logger.debug('context_path: %s, user: "******"' % (context_path, authenticated_user.username)) if not authenticated_user: return [] cache_key = 'user_context_permissions:%s:%s' % (authenticated_user.username, context_path) cached_permissions = cache.get(cache_key) if cached_permissions: logger.debug('Retrieving "%s" from cache' % cache_key) return cached_permissions content_filter = {'user__username': authenticated_user.username} permissions = [] #XXX could maybe simplify removing filter_children below by passing in parent_path # lookup_search(None, parent_path=context_path ...) # should do filter_children on parent_path and lookup_search # first get children LocalUser-s with the username #for n in filter_children(context_path, ct='ztreeauth.localuser', **content_filter): # local_user_obj = n.content_object # for grp in local_user_obj.groups.all(): # for perm in grp.permissions.all(): # if not perm in permissions: # permissions.append(perm) # lookup the ancestors and their siblings for LocalUser-s with the username #for n in lookup_search(context_path=context_path, parent_path=parent_path, ct='ztreeauth.localuser', **content_filter): # passing in parent_path indicates to lookup_search to first search children # of the context node, and then search up the ancestors tree for n in lookup_search(parent_path=context_path, ct='ztreeauth.localuser', **content_filter): local_user_obj = n.content_object for grp in local_user_obj.groups.all(): for perm in grp.permissions.all(): if not perm in permissions: permissions.append(perm) logger.debug('user "%s" permissions at %s: %s' % (authenticated_user.username, context_path, permissions)) cache.set(cache_key, permissions, 600) return permissions