Merge lp:~rharding/launchpad/translatables into lp:launchpad

Proposed by Richard Harding
Status: Work in progress
Proposed branch: lp:~rharding/launchpad/translatables
Merge into: lp:launchpad
Diff against target: 86 lines (+44/-1)
2 files modified
lib/lp/registry/model/projectgroup.py (+2/-0)
lib/lp/registry/tests/test_projectgroup.py (+42/-1)
To merge this branch: bzr merge lp:~rharding/launchpad/translatables
Reviewer Review Type Date Requested Status
Launchpad code reviewers Pending
Review via email: mp+135492@code.launchpad.net

Commit message

Update projectgroup.translatables to take information type into account to prevent access.

Description of the change

= Summary =

The .translations property and then getTranslatable methods it calls do not
take the privacy filter into account when querying.

== Pre Implementation ==

Talked with Deryck. getTranslatable is a method on both product and
projectgroup. In order to keep the api consistant we use the launchbag here as
was done in the product version of the method.

== Implementation Notes ==

Simple case of get the user and add the privacy filter to the query.

has_translatables() is based off the count of .translatables so this fixes
both points noted in the card.

== Tests ==

lib/lp/registry/model/projectgroup.py

To post a comment you must log in.

Unmerged revisions

16298. By Richard Harding

lint

16297. By Richard Harding

Update the translatables to take information type into account

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/model/projectgroup.py'
2--- lib/lp/registry/model/projectgroup.py 2012-11-20 20:52:40 +0000
3+++ lib/lp/registry/model/projectgroup.py 2012-11-21 18:16:21 +0000
4@@ -204,6 +204,7 @@
5 Only products with IProduct.translations_usage set to
6 ServiceUsage.LAUNCHPAD are considered translatable.
7 """
8+ user = getUtility(ILaunchBag).user
9 store = Store.of(self)
10 origin = [
11 Product,
12@@ -214,6 +215,7 @@
13 Product,
14 Product.project == self.id,
15 Product.translations_usage == ServiceUsage.LAUNCHPAD,
16+ ProductSet.getProductPrivacyFilter(user),
17 ).config(distinct=True)
18
19 @cachedproperty
20
21=== modified file 'lib/lp/registry/tests/test_projectgroup.py'
22--- lib/lp/registry/tests/test_projectgroup.py 2012-10-19 14:22:36 +0000
23+++ lib/lp/registry/tests/test_projectgroup.py 2012-11-21 18:16:21 +0000
24@@ -8,7 +8,10 @@
25 from zope.security.interfaces import Unauthorized
26 from zope.security.proxy import removeSecurityProxy
27
28-from lp.app.enums import InformationType
29+from lp.app.enums import (
30+ InformationType,
31+ ServiceUsage,
32+ )
33 from lp.registry.enums import (
34 EXCLUSIVE_TEAM_POLICY,
35 INCLUSIVE_TEAM_POLICY,
36@@ -33,6 +36,27 @@
37
38 layer = DatabaseFunctionalLayer
39
40+ def _create_translatable_products(self):
41+ """Generate a public and private product for translatables testing."""
42+ owner = self.factory.makePerson()
43+ project_group = self.factory.makeProject()
44+
45+ private_product = removeSecurityProxy(self.factory.makeProduct(
46+ project=project_group, owner=owner,
47+ information_type=InformationType.PROPRIETARY))
48+ private_product.translations_usage = ServiceUsage.LAUNCHPAD
49+ private_series = removeSecurityProxy(self.factory.makeProductSeries(
50+ product=private_product))
51+ self.factory.makePOTemplate(productseries=private_series)
52+
53+ public_product = removeSecurityProxy(self.factory.makeProduct(
54+ project=project_group, information_type=InformationType.PUBLIC))
55+ public_product.translations_usage = ServiceUsage.LAUNCHPAD
56+ public_series = self.factory.makeProductSeries(product=public_product)
57+ self.factory.makePOTemplate(productseries=public_series)
58+
59+ return private_product, public_product, project_group
60+
61 def test_pillar_category(self):
62 # The pillar category is correct.
63 pg = self.factory.makeProject()
64@@ -65,6 +89,23 @@
65 self.assertNotIn(product, project_group.getProducts(outsider))
66 self.assertIn(product, project_group.getProducts(owner))
67
68+ def test_translatables(self):
69+ """Verify that the translatables for public case is correct."""
70+ private, public, group = self._create_translatable_products()
71+
72+ public_user = self.factory.makePerson()
73+ with person_logged_in(public_user):
74+ self.assertIn(public, group.translatables)
75+ self.assertNotIn(private, group.translatables)
76+
77+ def test_translatables_with_proprietary(self):
78+ """Block users from seeing products they can't access."""
79+ private, public, group = self._create_translatable_products()
80+
81+ with person_logged_in(private.owner):
82+ self.assertIn(public, group.translatables)
83+ self.assertIn(private, group.translatables)
84+
85
86 class ProjectGroupSearchTestCase(TestCaseWithFactory):
87