~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/code/browser/codereviewvote.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, navigation and actions for CodeReviewVotes."""
 
5
 
 
6
__metaclass__ = type
 
7
 
 
8
 
 
9
from zope.interface import Interface
 
10
 
 
11
from canonical.launchpad import _
 
12
from canonical.launchpad.webapp import canonical_url
 
13
from lp.app.browser.launchpadform import (
 
14
    action,
 
15
    LaunchpadFormView,
 
16
    )
 
17
from lp.code.errors import (
 
18
    ReviewNotPending,
 
19
    UserHasExistingReview,
 
20
    )
 
21
from lp.services.fields import PublicPersonChoice
 
22
 
 
23
 
 
24
class ReassignSchema(Interface):
 
25
    """Schema to use when reassigning the reviewer for a requested review."""
 
26
 
 
27
    reviewer = PublicPersonChoice(title=_('Reviewer'), required=True,
 
28
            description=_('A person who you want to review this.'),
 
29
            vocabulary='ValidPersonOrTeam')
 
30
 
 
31
 
 
32
class CodeReviewVoteReassign(LaunchpadFormView):
 
33
    """View for reassinging the reviewer for a requested review."""
 
34
 
 
35
    schema = ReassignSchema
 
36
 
 
37
    page_title = label = 'Reassign review request'
 
38
 
 
39
    @property
 
40
    def next_url(self):
 
41
        return canonical_url(self.context.branch_merge_proposal)
 
42
 
 
43
    cancel_url = next_url
 
44
 
 
45
    @action('Reassign', name='reassign')
 
46
    def reassign_action(self, action, data):
 
47
        """Use the form data to change the review request reviewer."""
 
48
        self.context.reassignReview(data['reviewer'])
 
49
 
 
50
    def validate(self, data):
 
51
        """Make sure that the reassignment can happen."""
 
52
        reviewer = data.get('reviewer')
 
53
        if reviewer is not None:
 
54
            try:
 
55
                self.context.validateReasignReview(reviewer)
 
56
            except (ReviewNotPending, UserHasExistingReview), e:
 
57
                self.addError(str(e))