def search_principals(request, context=None, ignore=None, extra=()): flash = request.session.flash principals = get_principals() if ignore is None: ignore = set() entries = [] for principal_name in extra: if principal_name not in ignore: p = principals[principal_name] entries.append((p, list_groups_ext(principal_name, context))) ignore.add(principal_name) postdata = request.POST if request.method == "POST" and request.is_xhr: postdata = request.json if "search" in postdata: if request.is_xhr: query = "*{}*".format(postdata["query"]) else: query = "*{}*".format(request.params["query"]) found = False for p in principals.search(name=query, title=query, email=query): found = True if p.name not in ignore: entries.append((p, list_groups_ext(p.name, context))) if not found: flash(_("No users or groups were found."), "info") return entries
def search_principals(request, context=None, ignore=None, extra=()): flash = request.session.flash principals = get_principals() if ignore is None: ignore = set() entries = [] for principal_name in extra: if principal_name not in ignore: p = principals[principal_name] entries.append((p, list_groups_ext(principal_name, context))) ignore.add(principal_name) if 'search' in request.POST: query = '*%s*' % request.params['query'] found = False for p in principals.search(name=query, title=query, email=query): found = True if p.name not in ignore: entries.append((p, list_groups_ext(p.name, context))) if not found: flash(_(u'No users or groups were found.'), 'info') return entries
def search_principals(request, context=None, ignore=None, extra=()): flash = request.session.flash principals = get_principals() if ignore is None: ignore = set() entries = [] for principal_name in extra: if principal_name not in ignore: p = principals[principal_name] entries.append((p, list_groups_ext(principal_name, context))) ignore.add(principal_name) postdata = request.POST if request.method == 'POST' and request.is_xhr: postdata = request.json if 'search' in postdata: if request.is_xhr: query = '*{0}*'.format(postdata['query']) else: query = '*{0}*'.format(request.params['query']) found = False for p in principals.search(name=query, title=query, email=query): found = True if p.name not in ignore: entries.append((p, list_groups_ext(p.name, context))) if not found: flash(_('No users or groups were found.'), 'info') return entries
def search_principals(request, context=None, ignore=None, extra=()): flash = request.session.flash principals = get_principals() if ignore is None: ignore = set() entries = [] for principal_name in extra: if principal_name not in ignore: p = principals[principal_name] entries.append((p, list_groups_ext(principal_name, context))) ignore.add(principal_name) if 'search' in request.POST: query = '*%s*' % request.params['query'] found = False for p in principals.search(name=query, title=query, email=query): found = True if p.name not in ignore: entries.append((p, list_groups_ext(p.name, context))) if not found: flash(_(u'No users or groups found.'), 'info') return entries
def search_principals(request, context=None, ignore=None, extra=()): flash = request.session.flash principals = get_principals() if ignore is None: ignore = set() entries = [] for principal_name in extra: if principal_name not in ignore: p = principals[principal_name] entries.append((p, list_groups_ext(principal_name, context))) ignore.add(principal_name) if "search" in request.POST: query = "*%s*" % request.params["query"] found = False for p in principals.search(name=query, title=query, email=query): found = True if p.name not in ignore: entries.append((p, list_groups_ext(p.name, context))) if not found: flash(u"No users or groups found.", "notice") return entries
def test_nested_groups(self): from kotti.resources import get_root from kotti.security import list_groups from kotti.security import list_groups_ext self.add_some_groups() root = get_root() child = root[u'child'] grandchild = child[u'grandchild'] # Check bob's groups on every level: self.assertEqual(list_groups('bob', root), ['group:bobsgroup']) self.assertEqual( set(list_groups('bob', child)), set(['group:bobsgroup', 'group:franksgroup', 'role:editor'])) self.assertEqual( set(list_groups('bob', grandchild)), set([ 'group:bobsgroup', 'group:franksgroup', 'role:editor', 'role:owner' ])) # Check group:franksgroup groups on every level: self.assertEqual(set(list_groups('frank', root)), set(['group:franksgroup', 'role:editor'])) self.assertEqual(set(list_groups('frank', child)), set(['group:franksgroup', 'role:editor'])) self.assertEqual( set(list_groups('frank', grandchild)), set([ 'group:franksgroup', 'role:editor', 'role:owner', 'group:bobsgroup' ])) # Sometimes it's useful to know which of the groups were # inherited, that's what 'list_groups_ext' is for: groups, inherited = list_groups_ext('bob', root) self.assertEqual(groups, ['group:bobsgroup']) self.assertEqual(inherited, []) groups, inherited = list_groups_ext('bob', child) self.assertEqual( set(groups), set(['group:bobsgroup', 'group:franksgroup', 'role:editor'])) self.assertEqual( set(inherited), set(['group:bobsgroup', 'group:franksgroup', 'role:editor'])) groups, inherited = list_groups_ext('group:bobsgroup', child) self.assertEqual(set(groups), set(['group:franksgroup', 'role:editor'])) self.assertEqual(inherited, ['role:editor']) groups, inherited = list_groups_ext('group:franksgroup', grandchild) self.assertEqual(set(groups), set(['group:bobsgroup', 'role:owner', 'role:editor'])) self.assertEqual(inherited, ['role:editor'])
def test_nested_groups(self, db_session, root): from kotti.security import list_groups from kotti.security import list_groups_ext self.add_some_groups(db_session, root) child = root["child"] grandchild = child["grandchild"] # Check bob's groups on every level: assert list_groups("bob", root) == ["group:bobsgroup"] assert set(list_groups("bob", child)) == { "group:bobsgroup", "group:franksgroup", "role:editor", } assert set(list_groups("bob", grandchild)) == { "group:bobsgroup", "group:franksgroup", "role:editor", "role:owner", } # Check group:franksgroup groups on every level: assert set(list_groups("frank", root)) == {"group:franksgroup", "role:editor"} assert set(list_groups("frank", child)) == {"group:franksgroup", "role:editor"} assert set(list_groups("frank", grandchild)) == { "group:franksgroup", "role:editor", "role:owner", "group:bobsgroup", } # Sometimes it's useful to know which of the groups were # inherited, that's what 'list_groups_ext' is for: groups, inherited = list_groups_ext("bob", root) assert groups == ["group:bobsgroup"] assert inherited == [] groups, inherited = list_groups_ext("bob", child) assert set(groups) == { "group:bobsgroup", "group:franksgroup", "role:editor" } assert set(inherited) == { "group:bobsgroup", "group:franksgroup", "role:editor" } groups, inherited = list_groups_ext("group:bobsgroup", child) assert set(groups) == {"group:franksgroup", "role:editor"} assert inherited == ["role:editor"] groups, inherited = list_groups_ext("group:franksgroup", grandchild) assert set(groups) == {"group:bobsgroup", "role:owner", "role:editor"} assert inherited == ["role:editor"]
def test_nested_groups(self): self.add_some_groups() root = get_root() child = root[u'child'] grandchild = child[u'grandchild'] # Check bob's groups on every level: self.assertEqual(list_groups('bob', root), ['group:bobsgroup']) self.assertEqual( set(list_groups('bob', child)), set(['group:bobsgroup', 'group:franksgroup', 'role:editor'])) self.assertEqual( set(list_groups('bob', grandchild)), set([ 'group:bobsgroup', 'group:franksgroup', 'role:editor', 'role:owner' ])) # Check group:franksgroup groups on every level: self.assertEqual( set(list_groups('frank', root)), set(['group:franksgroup', 'role:editor'])) self.assertEqual( set(list_groups('frank', child)), set(['group:franksgroup', 'role:editor'])) self.assertEqual( set(list_groups('frank', grandchild)), set([ 'group:franksgroup', 'role:editor', 'role:owner', 'group:bobsgroup' ])) # Sometimes it's useful to know which of the groups were # inherited, that's what 'list_groups_ext' is for: groups, inherited = list_groups_ext('bob', root) self.assertEqual(groups, ['group:bobsgroup']) self.assertEqual(inherited, []) groups, inherited = list_groups_ext('bob', child) self.assertEqual( set(groups), set(['group:bobsgroup', 'group:franksgroup', 'role:editor'])) self.assertEqual( set(inherited), set(['group:bobsgroup', 'group:franksgroup', 'role:editor'])) groups, inherited = list_groups_ext('group:bobsgroup', child) self.assertEqual( set(groups), set(['group:franksgroup', 'role:editor'])) self.assertEqual(inherited, ['role:editor']) groups, inherited = list_groups_ext('group:franksgroup', grandchild) self.assertEqual( set(groups), set(['group:bobsgroup', 'role:owner', 'role:editor'])) self.assertEqual(inherited, ['role:editor'])
def test_nested_groups(self, db_session, root): from kotti.security import list_groups from kotti.security import list_groups_ext self.add_some_groups(db_session, root) child = root[u'child'] grandchild = child[u'grandchild'] # Check bob's groups on every level: assert list_groups('bob', root) == ['group:bobsgroup'] assert (set(list_groups('bob', child)) == { 'group:bobsgroup', 'group:franksgroup', 'role:editor' }) assert (set(list_groups('bob', grandchild)) == { 'group:bobsgroup', 'group:franksgroup', 'role:editor', 'role:owner' }) # Check group:franksgroup groups on every level: assert (set(list_groups('frank', root)) == {'group:franksgroup', 'role:editor'}) assert (set(list_groups( 'frank', child)) == {'group:franksgroup', 'role:editor'}) assert (set(list_groups('frank', grandchild)) == { 'group:franksgroup', 'role:editor', 'role:owner', 'group:bobsgroup' }) # Sometimes it's useful to know which of the groups were # inherited, that's what 'list_groups_ext' is for: groups, inherited = list_groups_ext('bob', root) assert groups == ['group:bobsgroup'] assert inherited == [] groups, inherited = list_groups_ext('bob', child) assert (set(groups) == { 'group:bobsgroup', 'group:franksgroup', 'role:editor' }) assert (set(inherited) == { 'group:bobsgroup', 'group:franksgroup', 'role:editor' }) groups, inherited = list_groups_ext('group:bobsgroup', child) assert set(groups) == {'group:franksgroup', 'role:editor'} assert inherited == ['role:editor'] groups, inherited = list_groups_ext('group:franksgroup', grandchild) assert (set(groups) == { 'group:bobsgroup', 'role:owner', 'role:editor' }) assert inherited == ['role:editor']
def test_nested_groups(self, db_session): from kotti.resources import get_root from kotti.security import list_groups from kotti.security import list_groups_ext self.add_some_groups() root = get_root() child = root[u'child'] grandchild = child[u'grandchild'] # Check bob's groups on every level: assert list_groups('bob', root) == ['group:bobsgroup'] assert (set(list_groups('bob', child)) == set(['group:bobsgroup', 'group:franksgroup', 'role:editor'])) assert (set(list_groups('bob', grandchild)) == set(['group:bobsgroup', 'group:franksgroup', 'role:editor', 'role:owner'])) # Check group:franksgroup groups on every level: assert (set(list_groups('frank', root)) == set(['group:franksgroup', 'role:editor'])) assert (set(list_groups('frank', child)) == set(['group:franksgroup', 'role:editor'])) assert (set(list_groups('frank', grandchild)) == set(['group:franksgroup', 'role:editor', 'role:owner', 'group:bobsgroup'])) # Sometimes it's useful to know which of the groups were # inherited, that's what 'list_groups_ext' is for: groups, inherited = list_groups_ext('bob', root) assert groups == ['group:bobsgroup'] assert inherited == [] groups, inherited = list_groups_ext('bob', child) assert (set(groups) == set(['group:bobsgroup', 'group:franksgroup', 'role:editor'])) assert (set(inherited) == set(['group:bobsgroup', 'group:franksgroup', 'role:editor'])) groups, inherited = list_groups_ext('group:bobsgroup', child) assert set(groups) == set(['group:franksgroup', 'role:editor']) assert inherited == ['role:editor'] groups, inherited = list_groups_ext('group:franksgroup', grandchild) assert (set(groups) == set(['group:bobsgroup', 'role:owner', 'role:editor'])) assert inherited == ['role:editor']