Colin Watson has proposed merging
lp:~cjwatson/launchpad/refactor-launchpad-container into lp:launchpad.
Commit message:
Refactor LaunchpadContainer to work with scope URLs and to automatically follow
the canonical URL chain.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/refactor-launchpad-container/+merge/287412
Refactor LaunchpadContainer to work with scope URLs and to automatically follow
the canonical URL chain. This is in preparation for introducing caveats, where
we'll definitely want to work with URL paths rather than objects.
LaunchpadPrincipal.scope_url will change again, but this is a relatively
non-painful way to allow the LaunchpadContainer changes to land in isolation.
--
Your team Launchpad code reviewers is requested to review the proposed merge of
lp:~cjwatson/launchpad/refactor-launchpad-container into lp:launchpad.
=== modified file 'lib/lp/bugs/publisher.py'
--- lib/lp/bugs/publisher.py 2015-07-08 16:05:11 +
+++ lib/lp/bugs/publisher.py 2016-02-28 19:25:32 +
@@ -1,4 +1,4 @@
-# Copyright 2010-2011 Canonical Ltd. This software is licensed under the
+# Copyright 2010-2016 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Bugs' custom publication."""
@@ -55,12 +55,8 @@
class LaunchpadBugContainer(LaunchpadContainer):
-def isWithin(self, scope):
-"""Is this bug within the given scope?
-
-A bug is in the scope of any of its bugtasks' targets.
-"""
+def getParentContainers(self):
+"""See `ILaunchpadContainer`."""
+# A bug is within any of its bugtasks' targets.
for bugtask in self.context.bugtasks:
-if ILaunchpadContainer(bugtask.target).isWithin(scope):
-return True
-return False
+yield ILaunchpadContainer(bugtask.target)
=== modified file 'lib/lp/code/publisher.py'
--- lib/lp/code/publisher.py 2015-07-08 16:05:11 +
+++ lib/lp/code/publisher.py 2016-02-28 19:25:32 +
@@ -1,4 +1,4 @@
-# Copyright 2010-2011 Canonical Ltd. This software is licensed under the
+# Copyright 2010-2016 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Code's custom publication."""
@@ -13,6 +13,7 @@
]
+from zope.component import queryAdapter
from zope.interface import implementer
from zope.publisher.interfaces.browser import (
IBrowserRequest,
@@ -56,12 +57,10 @@
class LaunchpadBranchContainer(LaunchpadContainer):
-def isWithin(self, scope):
-"""Is this branch within the given scope?
-
-If a branch has a product, it is always in the scope that product or
-its project. Otherwise it's not in any scope.
-"""
-if self.context.product is None:
-return False
-return ILaunchpadContainer(self.context.product).isWithin(scope)
+def getParentContainers(self):
+"""See `ILaunchpadContainer`."""
+# A branch is within its target.
+adapter = queryAdapter(
+self.context.target.context, ILaunchpadContainer)
+if adapter is not None:
+yield adapter
=== modified file 'lib/lp/registry/configure.zcml'
--- lib/lp/registry/configure.zcml 2016-02-05 20:28:29 +
+++ lib/lp/registry/configure.zcml 2016-02-28 19:25:32 +
@@ -613,7 +613,7 @@
+factory="lp.services.webapp.publisher.LaunchpadContainer"/>
>> ubuntu = getUtility(IDistributionSet)['ubuntu']
>>> evolution = ubuntu.getSourcePackage('evolution')
-The ILaunchpadContainer defines only the isWithin(context) method, which
-returns True if this context is the given one or is within it.
+The ILaunchpadContainer defines only the isWithin(scope_url) method, which
+returns True if this context is at the given URL or is within it.
A product is within itself or its project group.
->>> ILaunchpadContainer(firefox).isWithin(firefox)
-True
->>> ILaunchpadContainer(firefox).isWithin(mozilla)
-True
->>> ILaunchpadContainer(firefox).isWithin(ubuntu)
+>>> ILaunchpadContainer(firefox).isWithin('/firefox')
+True
+>>> ILaunchpadContainer(firefox).isWithin('/mozilla')
+True
+>>> ILaunchpadContainer(firefox).isWithin('/ubuntu')
False
>>> verifyObject(ILaunchpadContainer, ILaunchpadContainer(firefox))
True
A project group is only within itself.
->>> ILaunchpadContainer(mozilla).isWithin(mozilla)
+>>> ILaunchpadContainer(mozilla).isWithin('/mozilla')
True
->>> ILaunchpadContainer(mozilla).isWithin(firefox)
+>>> ILaunchpadContainer(mozilla).isWithin('/firefox')
False
->>> ILaunchpadContainer(mozilla).isWithin(ubuntu)
+>>> ILaunchpadContainer(mozilla).isWithin('/ubuntu')
False
>>> verifyObject(ILaunchpadContainer, ILaunchpadContainer(mozilla))