launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #01809
[Merge] lp:~lifeless/launchpad/features into lp:launchpad/devel
Robert Collins has proposed merging lp:~lifeless/launchpad/features into lp:launchpad/devel.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
#666538 add team: feature scope selector
https://bugs.launchpad.net/bugs/666538
Not much to say. Team based scope. \o/. Drive by fix in inTeam to handle nonexistant teams more gracefully. (We could raise, but the existing handling for e.g. teams that are Persons is to return False, so I followed that style, for now).
--
https://code.launchpad.net/~lifeless/launchpad/features/+merge/40049
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~lifeless/launchpad/features into lp:launchpad/devel.
=== modified file 'lib/lp/registry/model/person.py'
--- lib/lp/registry/model/person.py 2010-11-03 20:25:27 +0000
+++ lib/lp/registry/model/person.py 2010-11-04 05:26:08 +0000
@@ -1191,6 +1191,9 @@
# Translate the team name to an ITeam if we were passed a team.
if isinstance(team, (str, unicode)):
team = PersonSet().getByName(team)
+ if team is None:
+ # No team, no membership.
+ return False
if self.id == team.id:
# A team is always a member of itself.
=== modified file 'lib/lp/services/features/tests/test_webapp.py'
--- lib/lp/services/features/tests/test_webapp.py 2010-09-13 00:55:15 +0000
+++ lib/lp/services/features/tests/test_webapp.py 2010-11-04 05:26:08 +0000
@@ -7,7 +7,11 @@
from canonical.testing import layers
from lp.services.features import webapp
-from lp.testing import TestCase
+from lp.testing import (
+ login_as,
+ TestCase,
+ TestCaseWithFactory,
+ )
from canonical.launchpad.webapp.servers import LaunchpadTestRequest
@@ -39,3 +43,22 @@
self.assertTrue(scopes.lookup('pageid:'))
self.assertFalse(scopes.lookup('pageid:foo'))
self.assertFalse(scopes.lookup('pageid:foo'))
+
+
+class TestDBScopes(TestCaseWithFactory):
+
+ layer = layers.LaunchpadFunctionalLayer
+
+ def test_team_scope_outside_team(self):
+ request = LaunchpadTestRequest()
+ scopes = webapp.ScopesFromRequest(request)
+ self.factory.loginAsAnyone()
+ self.assertFalse(scopes.lookup('team:nonexistent'))
+
+ def test_team_scope_in_team(self):
+ request = LaunchpadTestRequest()
+ scopes = webapp.ScopesFromRequest(request)
+ member = self.factory.makePerson()
+ team = self.factory.makeTeam(members=[member])
+ login_as(member)
+ self.assertTrue(scopes.lookup('team:%s' % team.name))
=== modified file 'lib/lp/services/features/webapp.py'
--- lib/lp/services/features/webapp.py 2010-10-25 17:29:07 +0000
+++ lib/lp/services/features/webapp.py 2010-11-04 05:26:08 +0000
@@ -7,7 +7,10 @@
__metaclass__ = type
+from zope.component import getUtility
+
import canonical.config
+from canonical.launchpad.webapp.interfaces import ILaunchBag
from lp.services.features import per_thread
from lp.services.features.flags import FeatureController
from lp.services.features.rulesource import StormFeatureRuleSource
@@ -39,6 +42,8 @@
return True
if scope_name.startswith('pageid:'):
return self._lookup_pageid(scope_name[len('pageid:'):])
+ if scope_name.startswith('team:'):
+ return self._lookup_team(scope_name[len('team:'):])
parts = scope_name.split('.')
if len(parts) == 2:
if parts[0] == 'server':
@@ -65,6 +70,23 @@
return False
return True
+ def _lookup_team(self, team_name):
+ """Lookup a team membership as a scope.
+
+ This will do a two queries, so we probably want to keep the number of
+ team based scopes in use to a small number. (Person.inTeam could be
+ fixed to reduce this to one query).
+
+ teamid scopes are written as 'team:' + the team name to match.
+
+ E.g. the scope 'team:launchpad-beta-users' will match members of
+ the team 'launchpad-beta-users'.
+ """
+ person = getUtility(ILaunchBag).user
+ if person is None:
+ return False
+ return person.inTeam(team_name)
+
def _pageid_to_namespace(self, pageid):
"""Return a list of namespace elements for pageid."""
# Normalise delimiters.