Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'])
# 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'])
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),
existing = map_principals_with_local_roles(context)
def with_roles(entry):
all_groups = entry[1][0]
return [g for g in all_groups if g.startswith('role:')]
existing = filter(with_roles, existing)
seen = set([entry[0].name for entry in existing])
entries = []
if 'search' in request.params:
query = request.params['query']
found = False
for p in principals.search(query):
found = True
if p.name not in seen:
entries.append((p, list_groups_ext(p.name, context)))
if not found:
flash(u'No users or groups found.', 'info')
entries = existing + entries
return {
'api': TemplateAPIEdit(context, request),
'entries': entries,
'available_roles': available_roles,
'principals_to_roles': map_principals_with_local_roles(context),
}
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:
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