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

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 370d87a59b2358891a697e4fa2a96b1ac57879e7
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:person-has-current-commsub-distribution
Merge into: launchpad:master
Prerequisite: ~cjwatson/launchpad:reorganize-distribution-permissions
Diff against target: 71 lines (+22/-4)
2 files modified
lib/lp/registry/model/person.py (+8/-2)
lib/lp/registry/tests/test_person.py (+14/-2)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+415390@code.launchpad.net

Commit message

Handle distributions in Person.hasCurrentCommercialSubscription

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/registry/model/person.py b/lib/lp/registry/model/person.py
2index b544ae3..1d5f2be 100644
3--- a/lib/lp/registry/model/person.py
4+++ b/lib/lp/registry/model/person.py
5@@ -1158,6 +1158,7 @@ class Person(
6 from lp.registry.model.commercialsubscription import (
7 CommercialSubscription,
8 )
9+ from lp.registry.model.distribution import Distribution
10 from lp.registry.model.person import Person
11 from lp.registry.model.product import Product
12 from lp.registry.model.teammembership import TeamParticipation
13@@ -1166,11 +1167,16 @@ class Person(
14 Join(
15 TeamParticipation,
16 Person.id == TeamParticipation.personID),
17- Join(
18+ LeftJoin(
19 Product, TeamParticipation.teamID == Product._ownerID),
20+ LeftJoin(
21+ Distribution,
22+ TeamParticipation.teamID == Distribution.ownerID),
23 Join(
24 CommercialSubscription,
25- CommercialSubscription.product_id == Product.id)
26+ Or(
27+ CommercialSubscription.product_id == Product.id,
28+ CommercialSubscription.distribution_id == Distribution.id))
29 ).find(
30 Person,
31 CommercialSubscription.date_expires > datetime.now(
32diff --git a/lib/lp/registry/tests/test_person.py b/lib/lp/registry/tests/test_person.py
33index 10d8456..c601415 100644
34--- a/lib/lp/registry/tests/test_person.py
35+++ b/lib/lp/registry/tests/test_person.py
36@@ -831,14 +831,24 @@ class TestPerson(TestCaseWithFactory):
37 self.assertTrue(owner.isAnyPillarOwner())
38 self.assertFalse(person.isAnyPillarOwner())
39
40- def test_has_current_commercial_subscription(self):
41- # IPerson.hasCurrentCommercialSubscription() checks for one.
42+ def test_has_current_commercial_subscription_product(self):
43+ # IPerson.hasCurrentCommercialSubscription() checks for one on a
44+ # product.
45 team = self.factory.makeTeam(
46 membership_policy=TeamMembershipPolicy.MODERATED)
47 product = self.factory.makeProduct(owner=team)
48 self.factory.makeCommercialSubscription(product)
49 self.assertTrue(team.teamowner.hasCurrentCommercialSubscription())
50
51+ def test_has_current_commercial_subscription_distribution(self):
52+ # IPerson.hasCurrentCommercialSubscription() checks for one on a
53+ # distribution.
54+ team = self.factory.makeTeam(
55+ membership_policy=TeamMembershipPolicy.MODERATED)
56+ distro = self.factory.makeDistribution(owner=team)
57+ self.factory.makeCommercialSubscription(distro)
58+ self.assertTrue(team.teamowner.hasCurrentCommercialSubscription())
59+
60 def test_does_not_have_current_commercial_subscription(self):
61 # IPerson.hasCurrentCommercialSubscription() is false if it has
62 # expired.
63@@ -846,6 +856,8 @@ class TestPerson(TestCaseWithFactory):
64 membership_policy=TeamMembershipPolicy.MODERATED)
65 product = self.factory.makeProduct(owner=team)
66 self.factory.makeCommercialSubscription(product, expired=True)
67+ distro = self.factory.makeDistribution(owner=team)
68+ self.factory.makeCommercialSubscription(distro, expired=True)
69 self.assertFalse(team.teamowner.hasCurrentCommercialSubscription())
70
71 def test_does_not_have_commercial_subscription(self):

Subscribers

People subscribed via source and target branches

to status/vote changes: