← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:person-has-current-commsub-distribution into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:person-has-current-commsub-distribution into launchpad:master with ~cjwatson/launchpad:reorganize-distribution-permissions as a prerequisite.

Commit message:
Handle distributions in Person.hasCurrentCommercialSubscription

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/415390
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:person-has-current-commsub-distribution into launchpad:master.
diff --git a/lib/lp/registry/model/person.py b/lib/lp/registry/model/person.py
index b544ae3..1d5f2be 100644
--- a/lib/lp/registry/model/person.py
+++ b/lib/lp/registry/model/person.py
@@ -1158,6 +1158,7 @@ class Person(
         from lp.registry.model.commercialsubscription import (
             CommercialSubscription,
             )
+        from lp.registry.model.distribution import Distribution
         from lp.registry.model.person import Person
         from lp.registry.model.product import Product
         from lp.registry.model.teammembership import TeamParticipation
@@ -1166,11 +1167,16 @@ class Person(
             Join(
                 TeamParticipation,
                 Person.id == TeamParticipation.personID),
-            Join(
+            LeftJoin(
                 Product, TeamParticipation.teamID == Product._ownerID),
+            LeftJoin(
+                Distribution,
+                TeamParticipation.teamID == Distribution.ownerID),
             Join(
                 CommercialSubscription,
-                CommercialSubscription.product_id == Product.id)
+                Or(
+                    CommercialSubscription.product_id == Product.id,
+                    CommercialSubscription.distribution_id == Distribution.id))
             ).find(
                 Person,
                 CommercialSubscription.date_expires > datetime.now(
diff --git a/lib/lp/registry/tests/test_person.py b/lib/lp/registry/tests/test_person.py
index 10d8456..c601415 100644
--- a/lib/lp/registry/tests/test_person.py
+++ b/lib/lp/registry/tests/test_person.py
@@ -831,14 +831,24 @@ class TestPerson(TestCaseWithFactory):
         self.assertTrue(owner.isAnyPillarOwner())
         self.assertFalse(person.isAnyPillarOwner())
 
-    def test_has_current_commercial_subscription(self):
-        # IPerson.hasCurrentCommercialSubscription() checks for one.
+    def test_has_current_commercial_subscription_product(self):
+        # IPerson.hasCurrentCommercialSubscription() checks for one on a
+        # product.
         team = self.factory.makeTeam(
             membership_policy=TeamMembershipPolicy.MODERATED)
         product = self.factory.makeProduct(owner=team)
         self.factory.makeCommercialSubscription(product)
         self.assertTrue(team.teamowner.hasCurrentCommercialSubscription())
 
+    def test_has_current_commercial_subscription_distribution(self):
+        # IPerson.hasCurrentCommercialSubscription() checks for one on a
+        # distribution.
+        team = self.factory.makeTeam(
+            membership_policy=TeamMembershipPolicy.MODERATED)
+        distro = self.factory.makeDistribution(owner=team)
+        self.factory.makeCommercialSubscription(distro)
+        self.assertTrue(team.teamowner.hasCurrentCommercialSubscription())
+
     def test_does_not_have_current_commercial_subscription(self):
         # IPerson.hasCurrentCommercialSubscription() is false if it has
         # expired.
@@ -846,6 +856,8 @@ class TestPerson(TestCaseWithFactory):
             membership_policy=TeamMembershipPolicy.MODERATED)
         product = self.factory.makeProduct(owner=team)
         self.factory.makeCommercialSubscription(product, expired=True)
+        distro = self.factory.makeDistribution(owner=team)
+        self.factory.makeCommercialSubscription(distro, expired=True)
         self.assertFalse(team.teamowner.hasCurrentCommercialSubscription())
 
     def test_does_not_have_commercial_subscription(self):