Merge lp:~adeuring/launchpad/bug-1067736 into lp:launchpad

Proposed by Abel Deuring on 2012-10-26
Status: Merged
Approved by: Abel Deuring on 2012-10-26
Approved revision: no longer in the source branch.
Merged at revision: 16203
Proposed branch: lp:~adeuring/launchpad/bug-1067736
Merge into: lp:launchpad
Diff against target: 88 lines (+20/-24)
3 files modified
lib/lp/app/browser/tests/test_launchpad.py (+0/-3)
lib/lp/registry/model/product.py (+10/-18)
lib/lp/registry/tests/test_product.py (+10/-3)
To merge this branch: bzr merge lp:~adeuring/launchpad/bug-1067736
Reviewer Review Type Date Requested Status
Deryck Hodge (community) 2012-10-26 Approve on 2012-10-26
Review via email: mp+131527@code.launchpad.net

Commit Message

Product.userCanView(): don't give registry experts the permission lp.View for all private products; check for team grants for regular users

Description of the Change

This branch changes Product.userCanView() so that members of the registry experts team do not get accss to al rpivate products.

Additionally, the method now calls SharingService.checkPillarAccess() to check the permission for ordinary users. This method looks also for team grants, so I added a related assertion to test_access_launchpad_View_proprietary_product().

test:

./bin/test -vvt lp.registry.tests.test_product.TestProduct.test_access_launchpad_View_proprietary_product

no lint

To post a comment you must log in.
Deryck Hodge (deryck) wrote :

Looks good. Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/app/browser/tests/test_launchpad.py'
2--- lib/lp/app/browser/tests/test_launchpad.py 2012-10-12 16:20:51 +0000
3+++ lib/lp/app/browser/tests/test_launchpad.py 2012-10-26 10:06:25 +0000
4@@ -565,9 +565,6 @@
5 # products.
6 with celebrity_logged_in('admin'):
7 self.check_admin_access()
8- # Registry experts can access to all products.
9- with celebrity_logged_in('registry_experts'):
10- self.check_admin_access()
11 # Commercial admins have access to all products.
12 with celebrity_logged_in('commercial_admin'):
13 self.check_admin_access()
14
15=== modified file 'lib/lp/registry/model/product.py'
16--- lib/lp/registry/model/product.py 2012-10-24 14:54:46 +0000
17+++ lib/lp/registry/model/product.py 2012-10-26 10:06:25 +0000
18@@ -90,6 +90,7 @@
19 ILaunchpadUsage,
20 IServiceUsage,
21 )
22+from lp.app.interfaces.services import IService
23 from lp.app.model.launchpad import InformationTypeMixin
24 from lp.blueprints.enums import (
25 SpecificationFilter,
26@@ -1522,25 +1523,16 @@
27 return False
28 if user.id in self._known_viewers:
29 return True
30- # We need the plain Storm Person object for the SQL query below
31- # but an IPersonRoles object for the team membership checks.
32- if IPersonRoles.providedBy(user):
33- plain_user = user.person
34- else:
35- plain_user = user
36+ if not IPersonRoles.providedBy(user):
37 user = IPersonRoles(user)
38- if (user.in_commercial_admin or user.in_admin or
39- user.in_registry_experts):
40- self._known_viewers.add(user.id)
41- return True
42- policy = getUtility(IAccessPolicySource).find(
43- [(self, self.information_type)]).one()
44- grants_for_user = getUtility(IAccessPolicyGrantSource).find(
45- [(policy, plain_user)])
46- if grants_for_user.is_empty():
47- return False
48- self._known_viewers.add(user.id)
49- return True
50+ if user.in_commercial_admin or user.in_admin:
51+ self._known_viewers.add(user.id)
52+ return True
53+ if getUtility(IService, 'sharing').checkPillarAccess(
54+ [self], self.information_type, user):
55+ self._known_viewers.add(user.id)
56+ return True
57+ return False
58
59
60 def get_precached_products(products, need_licences=False, need_projects=False,
61
62=== modified file 'lib/lp/registry/tests/test_product.py'
63--- lib/lp/registry/tests/test_product.py 2012-10-24 14:54:46 +0000
64+++ lib/lp/registry/tests/test_product.py 2012-10-26 10:06:25 +0000
65@@ -735,13 +735,20 @@
66 with person_logged_in(ordinary_user):
67 for attribute_name in names:
68 getattr(product, attribute_name)
69+ # Access can be granted to a team too.
70+ other_user = self.factory.makePerson()
71+ team = self.factory.makeTeam(members=[other_user])
72+ with person_logged_in(owner):
73+ getUtility(IService, 'sharing').sharePillarInformation(
74+ product, team, owner,
75+ {InformationType.PROPRIETARY: SharingPermission.ALL})
76+ with person_logged_in(other_user):
77+ for attribute_name in names:
78+ getattr(product, attribute_name)
79 # Admins can access proprietary products.
80 with celebrity_logged_in('admin'):
81 for attribute_name in names:
82 getattr(product, attribute_name)
83- with celebrity_logged_in('registry_experts'):
84- for attribute_name in names:
85- getattr(product, attribute_name)
86 # Commercial admins have access to all products.
87 with celebrity_logged_in('commercial_admin'):
88 for attribute_name in names: