Merge lp:~stevenk/launchpad/shift-ap-creation into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Steve Kowalik
Approved revision: no longer in the source branch.
Merged at revision: 15890
Proposed branch: lp:~stevenk/launchpad/shift-ap-creation
Merge into: lp:launchpad
Diff against target: 140 lines (+30/-30)
3 files modified
lib/lp/registry/model/product.py (+18/-20)
lib/lp/registry/tests/test_product.py (+9/-10)
lib/lp/testing/factory.py (+3/-0)
To merge this branch: bzr merge lp:~stevenk/launchpad/shift-ap-creation
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+121985@code.launchpad.net

Commit message

No longer create AccessPolicies in IProductSet.createProduct(), do it in IProduct.setB{ranch,ug}SharingPolicy().

Description of the change

Currently, when a new product is created, createProduct() will create PRIVATESECURITY and USERDATA AccessPolicies. This does not make sense if the product has its branch and bug sharing policies set to PROPRIETARY since the two that were created will just be cleaned up by a garbo job.

As such, stop creating them in createProduct(), and ensure they exist in setB{ranch,ug}SharingPolicy(). I have also refactored those two methods so that all of the heavy lifting is done by a generic method.

I have deleted a test that no longer makes sense, since creating a product itself won't create APs.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) wrote :

+ def _check_and_set_sharing_policy(self, var, enum, kind, allowed_types):

It doesn't actually set the sharing policy. It just prepares for it.

27 + if var != enum.PUBLIC:
28 + if not self.has_current_commercial_subscription:

This can be a single if statement now.

208 + return self.makeProduct(skip_sharing_policy=True, **kwargs)

Privacy relies on the APs existing, so you can't set skip_sharing_policy unconditionally here. I think it'd be better to have the one or two tests that need it remove the APs themselves, rather than preventing them from being created in the first place.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/registry/model/product.py'
--- lib/lp/registry/model/product.py 2012-08-29 03:19:38 +0000
+++ lib/lp/registry/model/product.py 2012-08-30 23:47:20 +0000
@@ -107,6 +107,9 @@
107 )107 )
108from lp.code.enums import BranchType108from lp.code.enums import BranchType
109from lp.code.interfaces.branch import DEFAULT_BRANCH_STATUS_IN_LISTING109from lp.code.interfaces.branch import DEFAULT_BRANCH_STATUS_IN_LISTING
110from lp.code.model.branchnamespace import (
111 POLICY_ALLOWED_TYPES as BRANCH_POLICY_ALLOWED_TYPES,
112 )
110from lp.code.model.branchvisibilitypolicy import BranchVisibilityPolicyMixin113from lp.code.model.branchvisibilitypolicy import BranchVisibilityPolicyMixin
111from lp.code.model.hasbranches import (114from lp.code.model.hasbranches import (
112 HasBranchesMixin,115 HasBranchesMixin,
@@ -119,6 +122,7 @@
119 BranchSharingPolicy,122 BranchSharingPolicy,
120 BugSharingPolicy,123 BugSharingPolicy,
121 InformationType,124 InformationType,
125 PRIVATE_INFORMATION_TYPES,
122 )126 )
123from lp.registry.errors import CommercialSubscribersOnly127from lp.registry.errors import CommercialSubscribersOnly
124from lp.registry.interfaces.accesspolicy import (128from lp.registry.interfaces.accesspolicy import (
@@ -560,28 +564,26 @@
560 self.checkPrivateBugsTransitionAllowed(private_bugs, user)564 self.checkPrivateBugsTransitionAllowed(private_bugs, user)
561 self.private_bugs = private_bugs565 self.private_bugs = private_bugs
562566
567 def _prepare_to_set_sharing_policy(self, var, enum, kind, allowed_types):
568 if var != enum.PUBLIC and not self.has_current_commercial_subscription:
569 raise CommercialSubscribersOnly(
570 "A current commercial subscription is required to use "
571 "proprietary %s." % kind)
572 required_policies = set(allowed_types[var]).intersection(
573 set(PRIVATE_INFORMATION_TYPES))
574 self._ensurePolicies(required_policies)
575
563 def setBranchSharingPolicy(self, branch_sharing_policy):576 def setBranchSharingPolicy(self, branch_sharing_policy):
564 """See `IProductEditRestricted`."""577 """See `IProductEditRestricted`."""
565 if branch_sharing_policy != BranchSharingPolicy.PUBLIC:578 self._prepare_to_set_sharing_policy(
566 if not self.has_current_commercial_subscription:579 branch_sharing_policy, BranchSharingPolicy, 'branches',
567 raise CommercialSubscribersOnly(580 BRANCH_POLICY_ALLOWED_TYPES)
568 "A current commercial subscription is required to use "
569 "proprietary branches.")
570 required_policies = [InformationType.PROPRIETARY]
571 if (branch_sharing_policy ==
572 BranchSharingPolicy.EMBARGOED_OR_PROPRIETARY):
573 required_policies.append(InformationType.EMBARGOED)
574 self._ensurePolicies(required_policies)
575 self.branch_sharing_policy = branch_sharing_policy581 self.branch_sharing_policy = branch_sharing_policy
576582
577 def setBugSharingPolicy(self, bug_sharing_policy):583 def setBugSharingPolicy(self, bug_sharing_policy):
578 """See `IProductEditRestricted`."""584 """See `IProductEditRestricted`."""
579 if bug_sharing_policy != BugSharingPolicy.PUBLIC:585 self._prepare_to_set_sharing_policy(
580 if not self.has_current_commercial_subscription:586 bug_sharing_policy, BugSharingPolicy, 'bugs', POLICY_ALLOWED_TYPES)
581 raise CommercialSubscribersOnly(
582 "A current commercial subscription is required to use "
583 "proprietary bugs.")
584 self._ensurePolicies([InformationType.PROPRIETARY])
585 self.bug_sharing_policy = bug_sharing_policy587 self.bug_sharing_policy = bug_sharing_policy
586588
587 def getAllowedBugInformationTypes(self):589 def getAllowedBugInformationTypes(self):
@@ -1574,10 +1576,6 @@
1574 'rather than a stable release branch. This is sometimes also '1576 'rather than a stable release branch. This is sometimes also '
1575 'called MAIN or HEAD.'))1577 'called MAIN or HEAD.'))
1576 product.development_focus = trunk1578 product.development_focus = trunk
1577
1578 # Add default AccessPolicies.
1579 product._ensurePolicies((InformationType.USERDATA,
1580 InformationType.PRIVATESECURITY))
1581 return product1579 return product
15821580
1583 def forReview(self, search_text=None, active=None,1581 def forReview(self, search_text=None, active=None,
15841582
=== modified file 'lib/lp/registry/tests/test_product.py'
--- lib/lp/registry/tests/test_product.py 2012-08-29 03:19:38 +0000
+++ lib/lp/registry/tests/test_product.py 2012-08-30 23:47:20 +0000
@@ -342,14 +342,6 @@
342 product.setPrivateBugs(True, bug_supervisor)342 product.setPrivateBugs(True, bug_supervisor)
343 self.assertTrue(product.private_bugs)343 self.assertTrue(product.private_bugs)
344344
345 def test_product_creation_creates_accesspolicies(self):
346 # Creating a new product also creates AccessPolicies for it.
347 product = self.factory.makeProduct()
348 ap = getUtility(IAccessPolicySource).findByPillar((product,))
349 expected = [
350 InformationType.USERDATA, InformationType.PRIVATESECURITY]
351 self.assertContentEqual(expected, [policy.type for policy in ap])
352
353 def test_product_creation_grants_maintainer_access(self):345 def test_product_creation_grants_maintainer_access(self):
354 # Creating a new product creates an access grant for the maintainer346 # Creating a new product creates an access grant for the maintainer
355 # for all default policies.347 # for all default policies.
@@ -364,8 +356,8 @@
364 self.assertEqual(expected_grantess, grantees)356 self.assertEqual(expected_grantess, grantees)
365357
366 def test_open_product_creation_sharing_policies(self):358 def test_open_product_creation_sharing_policies(self):
367 # Creating a new open (non-proprietary) product sets the bug and branch359 # Creating a new open (non-proprietary) product sets the bug and
368 # sharing polices to public.360 # branch sharing polices to public, and creates policies if required.
369 owner = self.factory.makePerson()361 owner = self.factory.makePerson()
370 with person_logged_in(owner):362 with person_logged_in(owner):
371 product = getUtility(IProductSet).createProduct(363 product = getUtility(IProductSet).createProduct(
@@ -374,6 +366,10 @@
374 self.assertEqual(BugSharingPolicy.PUBLIC, product.bug_sharing_policy)366 self.assertEqual(BugSharingPolicy.PUBLIC, product.bug_sharing_policy)
375 self.assertEqual(367 self.assertEqual(
376 BranchSharingPolicy.PUBLIC, product.branch_sharing_policy)368 BranchSharingPolicy.PUBLIC, product.branch_sharing_policy)
369 aps = getUtility(IAccessPolicySource).findByPillar([product])
370 expected = [
371 InformationType.USERDATA, InformationType.PRIVATESECURITY]
372 self.assertContentEqual(expected, [policy.type for policy in aps])
377373
378 def test_proprietary_product_creation_sharing_policies(self):374 def test_proprietary_product_creation_sharing_policies(self):
379 # Creating a new proprietary product sets the bug and branch sharing375 # Creating a new proprietary product sets the bug and branch sharing
@@ -387,6 +383,9 @@
387 BugSharingPolicy.PROPRIETARY, product.bug_sharing_policy)383 BugSharingPolicy.PROPRIETARY, product.bug_sharing_policy)
388 self.assertEqual(384 self.assertEqual(
389 BranchSharingPolicy.PROPRIETARY, product.branch_sharing_policy)385 BranchSharingPolicy.PROPRIETARY, product.branch_sharing_policy)
386 aps = getUtility(IAccessPolicySource).findByPillar([product])
387 expected = [InformationType.PROPRIETARY]
388 self.assertContentEqual(expected, [policy.type for policy in aps])
390389
391390
392class TestProductBugInformationTypes(TestCaseWithFactory):391class TestProductBugInformationTypes(TestCaseWithFactory):
393392
=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py 2012-08-30 11:48:26 +0000
+++ lib/lp/testing/factory.py 2012-08-30 23:47:20 +0000
@@ -1017,6 +1017,9 @@
1017 # migrated.1017 # migrated.
1018 # XXX This method can be removed when branch visibility policy dies.1018 # XXX This method can be removed when branch visibility policy dies.
1019 product = self.makeProduct(**kwargs)1019 product = self.makeProduct(**kwargs)
1020 # Since createProduct() doesn't create PRIVATESECURITY/USERDATA.
1021 removeSecurityProxy(product)._ensurePolicies([
1022 InformationType.PRIVATESECURITY, InformationType.USERDATA])
1020 removeSecurityProxy(product).bug_sharing_policy = None1023 removeSecurityProxy(product).bug_sharing_policy = None
1021 removeSecurityProxy(product).branch_sharing_policy = None1024 removeSecurityProxy(product).branch_sharing_policy = None
1022 return product1025 return product