~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Stuart Bishop
  • Date: 2011-09-28 12:49:24 UTC
  • mfrom: (9893.10.1 trivial)
  • mto: This revision was merged to the branch mainline in revision 14178.
  • Revision ID: stuart.bishop@canonical.com-20110928124924-m5a22fymqghw6c5i
Merged trivial into distinct-db-users.

Show diffs side-by-side

added added

removed removed

Lines of Context:
110
110
from lp.bugs.interfaces.bugwatch import IBugWatchSet
111
111
from lp.bugs.interfaces.cve import ICveSet
112
112
from lp.bugs.mail.bugnotificationbuilder import format_rfc2822_date
 
113
from lp.bugs.model.personsubscriptioninfo import PersonSubscriptions
113
114
from lp.bugs.model.structuralsubscription import (
114
115
    get_structural_subscriptions_for_bug,
115
116
    )
116
 
from lp.bugs.model.personsubscriptioninfo import PersonSubscriptions
117
117
from lp.services.fields import DuplicateBug
118
118
from lp.services.propertycache import cachedproperty
119
119
 
664
664
        LaunchpadView.initialize(self)
665
665
        cache = IJSONRequestCache(self.request).objects
666
666
        self.extractBugSubscriptionDetails(self.user, self.context, cache)
 
667
        cache['bug_is_private'] = self.context.private
667
668
        if self.user:
668
669
            cache['notifications_text'] = self.notifications_text
669
670
 
849
850
        data = dict(data)
850
851
 
851
852
        # We handle privacy changes by hand instead of leaving it to
852
 
        # the usual machinery because we must use bug.setPrivate() to
853
 
        # ensure auditing information is recorded.
 
853
        # the usual machinery because we must use
 
854
        # bug.setPrivacyAndSecurityRelated() to ensure auditing information is
 
855
        # recorded.
854
856
        bug = self.context.bug
855
 
        bug_before_modification = Snapshot(
856
 
            bug, providing=providedBy(bug))
857
857
        private = data.pop('private')
858
858
        user_will_be_subscribed = (
859
859
            private and bug.getSubscribersForPerson(self.user).is_empty())
860
860
        security_related = data.pop('security_related')
861
 
        private_changed = bug.setPrivate(
862
 
            private, getUtility(ILaunchBag).user)
863
 
        security_related_changed = bug.setSecurityRelated(security_related)
864
 
        if private_changed or security_related_changed:
865
 
            changed_fields = []
866
 
            if private_changed:
867
 
                changed_fields.append('private')
868
 
                self._handlePrivacyChanged(user_will_be_subscribed)
869
 
            if security_related_changed:
870
 
                changed_fields.append('security_related')
871
 
            notify(ObjectModifiedEvent(
872
 
                    bug, bug_before_modification, changed_fields))
 
861
        user = getUtility(ILaunchBag).user
 
862
        (private_changed, security_related_changed) = (
 
863
            bug.setPrivacyAndSecurityRelated(private, security_related, user))
 
864
        if private_changed:
 
865
            self._handlePrivacyChanged(user_will_be_subscribed)
873
866
        if self.request.is_ajax:
874
867
            if private_changed or security_related_changed:
875
868
                return self._getSubscriptionDetails()
889
882
            bug = self.context
890
883
        subscribers_portlet = BugPortletSubscribersWithDetails(
891
884
            bug, self.request)
892
 
        subscription_data = subscribers_portlet()
893
 
        cache_data = dumps(
894
 
            cache, cls=ResourceJSONEncoder,
 
885
        subscription_data = subscribers_portlet.subscriber_data
 
886
        result_data = dict(
 
887
            cache_data=cache,
 
888
            subscription_data=subscription_data)
 
889
        self.request.response.setHeader('content-type', 'application/json')
 
890
        return dumps(
 
891
            result_data, cls=ResourceJSONEncoder,
895
892
            media_type=EntryResource.JSON_TYPE)
896
893
 
897
 
        return """{
898
 
            "cache_data": %s,
899
 
            "subscription_data": %s}
900
 
            """ % (cache_data, subscription_data)
901
 
 
902
894
    def _handlePrivacyChanged(self, user_will_be_subscribed):
903
895
        """Handle the case where the privacy of the bug has been changed.
904
896