~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/coop/answersbugs/browser.py

[r=sinzui][bug=855670] Add additional checks to the private team
        launchpad.LimitedView security adaptor so more users in defined
        roles can see the team.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Views for linking bugs and questions."""
 
5
 
 
6
__metaclass__ = type
 
7
__all__ = []
 
8
 
 
9
 
 
10
from lazr.lifecycle.event import ObjectModifiedEvent
 
11
from lazr.lifecycle.snapshot import Snapshot
 
12
from zope.event import notify
 
13
from zope.interface import providedBy
 
14
 
 
15
from canonical.launchpad import _
 
16
from canonical.launchpad.webapp.publisher import canonical_url
 
17
from lp.app.browser.launchpadform import (
 
18
    action,
 
19
    LaunchpadFormView,
 
20
    )
 
21
from lp.bugs.interfaces.bug import (
 
22
    CreateBugParams,
 
23
    IBug,
 
24
    )
 
25
 
 
26
 
 
27
class QuestionMakeBugView(LaunchpadFormView):
 
28
    """Browser class for adding a bug from a question."""
 
29
 
 
30
    schema = IBug
 
31
 
 
32
    field_names = ['title', 'description']
 
33
 
 
34
    def initialize(self):
 
35
        """Initialize the view when a Bug may be reported for the Question."""
 
36
        question = self.context
 
37
        if question.bugs:
 
38
            # we can't make a bug when we have linked bugs
 
39
            self.request.response.addErrorNotification(
 
40
                _('You cannot create a bug report from a question'
 
41
                  'that already has bugs linked to it.'))
 
42
            self.request.response.redirect(canonical_url(question))
 
43
            return
 
44
        LaunchpadFormView.initialize(self)
 
45
 
 
46
    @property
 
47
    def page_title(self):
 
48
        return 'Create bug report based on question #%s' % self.context.id
 
49
 
 
50
    @property
 
51
    def label(self):
 
52
        return 'Create a bug based on a question'
 
53
 
 
54
    @property
 
55
    def initial_values(self):
 
56
        """Return the initial form values."""
 
57
        question = self.context
 
58
        return {'title': '',
 
59
                'description': question.description}
 
60
 
 
61
    @action(_('Create Bug Report'), name='create')
 
62
    def create_action(self, action, data):
 
63
        """Create a Bug from a Question."""
 
64
        question = self.context
 
65
 
 
66
        unmodifed_question = Snapshot(
 
67
            question, providing=providedBy(question))
 
68
        params = CreateBugParams(
 
69
            owner=self.user, title=data['title'], comment=data['description'])
 
70
        bug = question.target.createBug(params)
 
71
        question.linkBug(bug)
 
72
        bug.subscribe(question.owner, self.user)
 
73
        bug_added_event = ObjectModifiedEvent(
 
74
            question, unmodifed_question, ['bugs'])
 
75
        notify(bug_added_event)
 
76
        self.request.response.addNotification(
 
77
            _('Thank you! Bug #$bugid created.', mapping={'bugid': bug.id}))
 
78
        self.next_url = canonical_url(bug)
 
79
 
 
80
 
 
81