431
431
def expose_user_administered_teams_to_js(request, user, context,
432
432
absoluteURL=absoluteURL):
433
433
"""Make the list of teams the user administers available to JavaScript."""
434
# XXX: Robert Collins workaround multiple calls making this cause timeouts:
436
objects = IJSONRequestCache(request).objects
437
if 'administratedTeams' in objects:
435
440
api_request = IWebServiceClientRequest(request)
436
441
is_distro = IDistribution.providedBy(context)
443
# If the context is a distro AND a bug supervisor is set then we only
444
# allow subscriptions from members of the bug supervisor team.
445
bug_supervisor = context.bug_supervisor
447
bug_supervisor = None
437
448
if user is not None:
438
administrated_teams = user.administrated_teams
449
administrated_teams = set(user.administrated_teams)
439
450
if administrated_teams:
440
451
# Get this only if we need to.
441
membership = list(user.teams_participated_in)
442
for team in administrated_teams:
443
# If the user is not a member of the team itself, then
444
# skip it, because structural subscriptions and their
445
# filters can only be edited by the subscriber.
446
# This can happen if the user is an owner but not a member.
447
if not team in membership:
449
# If the context is a distro AND a bug supervisor is set
450
# AND the admininistered team is not a member of the bug
451
# supervisor team THEN skip it.
452
if (is_distro and context.bug_supervisor is not None and
453
not team.inTeam(context.bug_supervisor)):
452
membership = set(user.teams_participated_in)
453
# Only consider teams the user is both in and administers:
454
# If the user is not a member of the team itself, then
455
# skip it, because structural subscriptions and their
456
# filters can only be edited by the subscriber.
457
# This can happen if the user is an owner but not a member.
458
administers_and_in = membership.intersection(administrated_teams)
459
for team in administers_and_in:
460
if (bug_supervisor is not None and
461
not team.inTeam(bug_supervisor)):
456
464
'link': absoluteURL(team, api_request),
457
465
'title': team.title,
458
466
'url': canonical_url(team),
460
IJSONRequestCache(request).objects['administratedTeams'] = info
468
objects['administratedTeams'] = info
463
471
def expose_user_subscriptions_to_js(user, subscriptions, request,