Merge ~cjwatson/launchpad:fix-legitimate-polls into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: d2e50e4953a6215d18c47bd0b4a16372163861c6
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:fix-legitimate-polls
Merge into: launchpad:master
Diff against target: 106 lines (+40/-10)
4 files modified
lib/lp/registry/browser/poll.py (+0/-6)
lib/lp/registry/browser/team.py (+4/-2)
lib/lp/registry/browser/tests/test_poll.py (+15/-2)
lib/lp/registry/browser/tests/test_team.py (+21/-0)
Reviewer Review Type Date Requested Status
Thiago F. Pappacena (community) Approve
Review via email: mp+400388@code.launchpad.net

Commit message

Fix test failures from restricting poll creation

To post a comment you must log in.
Revision history for this message
Thiago F. Pappacena (pappacena) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/registry/browser/poll.py b/lib/lp/registry/browser/poll.py
2index 066407c..8c5debe 100644
3--- a/lib/lp/registry/browser/poll.py
4+++ b/lib/lp/registry/browser/poll.py
5@@ -411,12 +411,6 @@ class PollAddView(LaunchpadFormView):
6
7 page_title = 'New poll'
8
9- def __init__(self, context, request):
10- if not check_permission("launchpad.AnyLegitimatePerson", context):
11- raise CannotCreatePoll(
12- "You do not have permission to create polls.")
13- super(PollAddView, self).__init__(context, request)
14-
15 @property
16 def cancel_url(self):
17 """See `LaunchpadFormView`."""
18diff --git a/lib/lp/registry/browser/team.py b/lib/lp/registry/browser/team.py
19index 41af691..93f121c 100644
20--- a/lib/lp/registry/browser/team.py
21+++ b/lib/lp/registry/browser/team.py
22@@ -1541,11 +1541,13 @@ class TeamMenuMixin(PPANavigationMenuMixIn, CommonMenuLinks):
23 text = 'Show polls'
24 return Link(target, text, icon='info')
25
26- @enabled_with_permission('launchpad.Edit')
27 def add_poll(self):
28 target = '+newpoll'
29 text = 'Create a poll'
30- return Link(target, text, icon='add')
31+ enabled = (
32+ check_permission('launchpad.Edit', self.context) and
33+ check_permission('launchpad.AnyLegitimatePerson', self.context))
34+ return Link(target, text, icon='add', enabled=enabled)
35
36 @enabled_with_permission('launchpad.Edit')
37 def editemail(self):
38diff --git a/lib/lp/registry/browser/tests/test_poll.py b/lib/lp/registry/browser/tests/test_poll.py
39index fa1674d..7da8c34 100644
40--- a/lib/lp/registry/browser/tests/test_poll.py
41+++ b/lib/lp/registry/browser/tests/test_poll.py
42@@ -13,6 +13,7 @@ from datetime import (
43 )
44 import os
45
46+from fixtures import FakeLogger
47 import pytz
48
49 from lp.registry.interfaces.poll import (
50@@ -64,11 +65,23 @@ class TestPollAddView(BrowserTestCase):
51
52 def test_new_user(self):
53 # A brand new user cannot create polls.
54+ self.useFixture(FakeLogger())
55 new_person = self.factory.makePerson()
56 team = self.factory.makeTeam(owner=new_person)
57+ now = datetime.now(pytz.UTC)
58+ browser = self.getViewBrowser(
59+ team, view_name="+newpoll", user=new_person)
60+ browser.getControl("The unique name of this poll").value = "colour"
61+ browser.getControl("The title of this poll").value = "Favourite Colour"
62+ browser.getControl("The date and time when this poll opens").value = (
63+ str(now + timedelta(days=1)))
64+ browser.getControl("The date and time when this poll closes").value = (
65+ str(now + timedelta(days=2)))
66+ browser.getControl(
67+ "The proposition that is going to be voted").value = (
68+ "What is your favourite colour?")
69 self.assertRaises(
70- CannotCreatePoll,
71- self.getViewBrowser, team, view_name="+newpoll", user=new_person)
72+ CannotCreatePoll, browser.getControl("Continue").click)
73
74 def test_legitimate_user(self):
75 # A user with some kind of track record can create polls.
76diff --git a/lib/lp/registry/browser/tests/test_team.py b/lib/lp/registry/browser/tests/test_team.py
77index 639d053..a26c701 100644
78--- a/lib/lp/registry/browser/tests/test_team.py
79+++ b/lib/lp/registry/browser/tests/test_team.py
80@@ -667,6 +667,27 @@ class TestTeamMenu(TestCaseWithFactory):
81 link = menu.configure_mailing_list()
82 self.assertEqual('Configure mailing list', link.text)
83
84+ def test_TeamOverviewMenu_new_user_without_add_poll(self):
85+ # A brand new user does not see the add_poll link.
86+ self.pushConfig(
87+ 'launchpad', min_legitimate_karma=5, min_legitimate_account_age=5)
88+ login_person(self.team.teamowner)
89+ menu = TeamOverviewMenu(self.team)
90+ self.assertNotIn(
91+ 'add_poll',
92+ [link.name for link in menu.iterlinks() if link.enabled])
93+
94+ def test_TeamOverviewMenu_legitimate_user_with_add_poll(self):
95+ # A user with some kind of track record sees the add_poll link.
96+ self.pushConfig(
97+ 'launchpad', min_legitimate_karma=5, min_legitimate_account_age=5)
98+ team = self.factory.makeTeam(owner=self.factory.makePerson(karma=10))
99+ login_person(team.teamowner)
100+ menu = TeamOverviewMenu(team)
101+ self.assertIn(
102+ 'add_poll',
103+ [link.name for link in menu.iterlinks() if link.enabled])
104+
105
106 class TestMailingListArchiveView(TestCaseWithFactory):
107

Subscribers

People subscribed via source and target branches

to status/vote changes: