launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #26762
[Merge] ~cjwatson/launchpad:fix-legitimate-polls into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:fix-legitimate-polls into launchpad:master.
Commit message:
Fix test failures from restricting poll creation
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/400388
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:fix-legitimate-polls into launchpad:master.
diff --git a/lib/lp/registry/browser/poll.py b/lib/lp/registry/browser/poll.py
index 066407c..8c5debe 100644
--- a/lib/lp/registry/browser/poll.py
+++ b/lib/lp/registry/browser/poll.py
@@ -411,12 +411,6 @@ class PollAddView(LaunchpadFormView):
page_title = 'New poll'
- def __init__(self, context, request):
- if not check_permission("launchpad.AnyLegitimatePerson", context):
- raise CannotCreatePoll(
- "You do not have permission to create polls.")
- super(PollAddView, self).__init__(context, request)
-
@property
def cancel_url(self):
"""See `LaunchpadFormView`."""
diff --git a/lib/lp/registry/browser/team.py b/lib/lp/registry/browser/team.py
index 41af691..93f121c 100644
--- a/lib/lp/registry/browser/team.py
+++ b/lib/lp/registry/browser/team.py
@@ -1541,11 +1541,13 @@ class TeamMenuMixin(PPANavigationMenuMixIn, CommonMenuLinks):
text = 'Show polls'
return Link(target, text, icon='info')
- @enabled_with_permission('launchpad.Edit')
def add_poll(self):
target = '+newpoll'
text = 'Create a poll'
- return Link(target, text, icon='add')
+ enabled = (
+ check_permission('launchpad.Edit', self.context) and
+ check_permission('launchpad.AnyLegitimatePerson', self.context))
+ return Link(target, text, icon='add', enabled=enabled)
@enabled_with_permission('launchpad.Edit')
def editemail(self):
diff --git a/lib/lp/registry/browser/tests/test_poll.py b/lib/lp/registry/browser/tests/test_poll.py
index fa1674d..7da8c34 100644
--- a/lib/lp/registry/browser/tests/test_poll.py
+++ b/lib/lp/registry/browser/tests/test_poll.py
@@ -13,6 +13,7 @@ from datetime import (
)
import os
+from fixtures import FakeLogger
import pytz
from lp.registry.interfaces.poll import (
@@ -64,11 +65,23 @@ class TestPollAddView(BrowserTestCase):
def test_new_user(self):
# A brand new user cannot create polls.
+ self.useFixture(FakeLogger())
new_person = self.factory.makePerson()
team = self.factory.makeTeam(owner=new_person)
+ now = datetime.now(pytz.UTC)
+ browser = self.getViewBrowser(
+ team, view_name="+newpoll", user=new_person)
+ browser.getControl("The unique name of this poll").value = "colour"
+ browser.getControl("The title of this poll").value = "Favourite Colour"
+ browser.getControl("The date and time when this poll opens").value = (
+ str(now + timedelta(days=1)))
+ browser.getControl("The date and time when this poll closes").value = (
+ str(now + timedelta(days=2)))
+ browser.getControl(
+ "The proposition that is going to be voted").value = (
+ "What is your favourite colour?")
self.assertRaises(
- CannotCreatePoll,
- self.getViewBrowser, team, view_name="+newpoll", user=new_person)
+ CannotCreatePoll, browser.getControl("Continue").click)
def test_legitimate_user(self):
# A user with some kind of track record can create polls.
diff --git a/lib/lp/registry/browser/tests/test_team.py b/lib/lp/registry/browser/tests/test_team.py
index 639d053..a26c701 100644
--- a/lib/lp/registry/browser/tests/test_team.py
+++ b/lib/lp/registry/browser/tests/test_team.py
@@ -667,6 +667,27 @@ class TestTeamMenu(TestCaseWithFactory):
link = menu.configure_mailing_list()
self.assertEqual('Configure mailing list', link.text)
+ def test_TeamOverviewMenu_new_user_without_add_poll(self):
+ # A brand new user does not see the add_poll link.
+ self.pushConfig(
+ 'launchpad', min_legitimate_karma=5, min_legitimate_account_age=5)
+ login_person(self.team.teamowner)
+ menu = TeamOverviewMenu(self.team)
+ self.assertNotIn(
+ 'add_poll',
+ [link.name for link in menu.iterlinks() if link.enabled])
+
+ def test_TeamOverviewMenu_legitimate_user_with_add_poll(self):
+ # A user with some kind of track record sees the add_poll link.
+ self.pushConfig(
+ 'launchpad', min_legitimate_karma=5, min_legitimate_account_age=5)
+ team = self.factory.makeTeam(owner=self.factory.makePerson(karma=10))
+ login_person(team.teamowner)
+ menu = TeamOverviewMenu(team)
+ self.assertIn(
+ 'add_poll',
+ [link.name for link in menu.iterlinks() if link.enabled])
+
class TestMailingListArchiveView(TestCaseWithFactory):