~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/browser/structuralsubscription.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-05-26 22:20:34 UTC
  • mfrom: (13122.1.2 bug-787765)
  • Revision ID: launchpad@pqm.canonical.com-20110526222034-6xm2tvb7u4u99rxx
[r=allenap][bug=787765] Optimise expose_user_administered_teams_to_js.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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:
 
435
    # see bug 788510.
 
436
    objects = IJSONRequestCache(request).objects
 
437
    if 'administratedTeams' in objects:
 
438
        return
434
439
    info = []
435
440
    api_request = IWebServiceClientRequest(request)
436
441
    is_distro = IDistribution.providedBy(context)
 
442
    if is_distro:
 
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
 
446
    else:
 
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:
448
 
                    continue
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)):
454
462
                    continue
455
463
                info.append({
456
464
                    'link': absoluteURL(team, api_request),
457
465
                    'title': team.title,
458
466
                    'url': canonical_url(team),
459
467
                })
460
 
    IJSONRequestCache(request).objects['administratedTeams'] = info
 
468
    objects['administratedTeams'] = info
461
469
 
462
470
 
463
471
def expose_user_subscriptions_to_js(user, subscriptions, request,