~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Abel Deuring
  • Date: 2011-07-27 16:22:36 UTC
  • mfrom: (13539 devel)
  • mto: This revision was merged to the branch mainline in revision 13587.
  • Revision ID: abel.deuring@canonical.com-20110727162236-m5e4e45257ehq65r
devel merged

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
from lp.bugs.enum import BugNotificationLevel
50
50
from lp.bugs.interfaces.bug import IBug
51
51
from lp.bugs.interfaces.bugsubscription import IBugSubscription
52
 
from lp.bugs.interfaces.bugtask import IBugTask
53
52
from lp.bugs.model.personsubscriptioninfo import PersonSubscriptions
54
53
from lp.bugs.model.structuralsubscription import (
55
54
    get_structural_subscriptions_for_bug,
529
528
class BugPortletSubscribersWithDetails(LaunchpadView):
530
529
    """A view that returns a JSON dump of the subscriber details for a bug."""
531
530
 
532
 
    @property
533
 
    def subscriber_data_js(self):
534
 
        """Return subscriber_ids in a form suitable for JavaScript use."""
 
531
    @cachedproperty
 
532
    def api_request(self):
 
533
        return IWebServiceClientRequest(self.request)
 
534
 
 
535
    def direct_subscriber_data(self, bug):
 
536
        """Get the direct subscriber data.
 
537
 
 
538
        This method is isolated from the subscriber_data_js so that query
 
539
        count testing can be done accurately and robustly.
 
540
        """
535
541
        data = []
536
 
        if IBug.providedBy(self.context):
537
 
            bug = self.context
538
 
        elif IBugTask.providedBy(self.context):
539
 
            bug = self.context.bug
540
542
        details = list(bug.getDirectSubscribersWithDetails())
541
 
        api_request = IWebServiceClientRequest(self.request)
542
 
        for person, subscription in details:
 
543
        for person, subscribed_by, subscription in details:
543
544
            can_edit = subscription.canBeUnsubscribedByUser(self.user)
544
545
            if person == self.user or (person.private and not can_edit):
545
546
                # Skip the current user viewing the page,
550
551
                'name': person.name,
551
552
                'display_name': person.displayname,
552
553
                'web_link': canonical_url(person, rootsite='mainsite'),
553
 
                'self_link': absoluteURL(person, api_request),
 
554
                'self_link': absoluteURL(person, self.api_request),
554
555
                'is_team': person.is_team,
555
556
                'can_edit': can_edit,
 
557
                'display_subscribed_by': subscription.display_subscribed_by,
556
558
                }
557
559
            record = {
558
560
                'subscriber': subscriber,
560
562
                    removeSecurityProxy(subscription.bug_notification_level)),
561
563
                }
562
564
            data.append(record)
 
565
        return data
 
566
 
 
567
    @property
 
568
    def subscriber_data_js(self):
 
569
        """Return subscriber_ids in a form suitable for JavaScript use."""
 
570
        bug = IBug(self.context)
 
571
        data = self.direct_subscriber_data(bug)
563
572
 
564
573
        others = list(bug.getIndirectSubscribers())
565
574
        for person in others:
570
579
                'name': person.name,
571
580
                'display_name': person.displayname,
572
581
                'web_link': canonical_url(person, rootsite='mainsite'),
573
 
                'self_link': absoluteURL(person, api_request),
 
582
                'self_link': absoluteURL(person, self.api_request),
574
583
                'is_team': person.is_team,
575
584
                'can_edit': False,
576
585
                }