Merge ~cjwatson/launchpad:archiveauthtoken-multiple-subscriptions into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 77e5133ee6f5e4d7dfe3f46fd1dfd84ee2155146
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:archiveauthtoken-multiple-subscriptions
Merge into: launchpad:master
Diff against target: 55 lines (+17/-2)
2 files modified
lib/lp/soyuz/doc/archiveauthtoken.txt (+16/-1)
lib/lp/soyuz/model/archiveauthtoken.py (+1/-1)
Reviewer Review Type Date Requested Status
Cristian Gonzalez (community) Approve
Review via email: mp+400549@code.launchpad.net

Commit message

Fix ArchiveAuthToken lookup with multiple subscriptions

Description of the change

When querying for tokens with current subscriptions, `ArchiveAuthTokenSet.getByArchive` could return multiple rows even though there was only a single token due to the additional joins. Add `DISTINCT` to avoid this.

To post a comment you must log in.
Revision history for this message
Cristian Gonzalez (cristiangsp) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/soyuz/doc/archiveauthtoken.txt b/lib/lp/soyuz/doc/archiveauthtoken.txt
2index c6c3fa3..c02db56 100644
3--- a/lib/lp/soyuz/doc/archiveauthtoken.txt
4+++ b/lib/lp/soyuz/doc/archiveauthtoken.txt
5@@ -21,7 +21,7 @@ New tokens are created using IArchive.newAuthToken() but this is only
6 possible if there is already a valid subscription for the user for
7 that archive.
8
9-Create Brad, and his team:
10+Create Brad, and his teams:
11
12 >>> login("admin@canonical.com")
13 >>> bradsmith = factory.makePerson(
14@@ -29,6 +29,8 @@ Create Brad, and his team:
15 ... email="brad@example.com")
16 >>> teambrad = factory.makeTeam(
17 ... owner=bradsmith, displayname="Team Brad", name='teambrad')
18+ >>> teambrad2 = factory.makeTeam(
19+ ... owner=bradsmith, displayname="Team Brad 2", name='teambrad2')
20
21 Create a subscription for Team Brad to joe's archive:
22
23@@ -169,6 +171,19 @@ Tokens are only returned if they match a current subscription:
24 >>> removeSecurityProxy(subscription_to_joe_private_ppa).status = (
25 ... ArchiveSubscriberStatus.CURRENT)
26
27+Retrieving tokens works even if the user is subscribed to the archive via
28+multiple paths:
29+
30+ >>> _ = login_person(joe)
31+ >>> _ = joe_private_ppa.newSubscription(teambrad2, joe)
32+ >>> login("brad@example.com")
33+ >>> print(token_set.getActiveTokenForArchiveAndPerson(
34+ ... new_token.archive, new_token.person).token)
35+ testtoken
36+ >>> print(token_set.getActiveTokenForArchiveAndPersonName(
37+ ... new_token.archive, "bradsmith").token)
38+ testtoken
39+
40
41 == Amending Tokens ==
42
43diff --git a/lib/lp/soyuz/model/archiveauthtoken.py b/lib/lp/soyuz/model/archiveauthtoken.py
44index 2dfe646..3d39143 100644
45--- a/lib/lp/soyuz/model/archiveauthtoken.py
46+++ b/lib/lp/soyuz/model/archiveauthtoken.py
47@@ -103,7 +103,7 @@ class ArchiveAuthTokenSet:
48 ArchiveSubscriber.subscriber_id == TeamParticipation.teamID,
49 TeamParticipation.personID == ArchiveAuthToken.person_id,
50 ])
51- return store.find(ArchiveAuthToken, *clauses)
52+ return store.find(ArchiveAuthToken, *clauses).config(distinct=True)
53
54 def getActiveTokenForArchiveAndPerson(self, archive, person):
55 """See `IArchiveAuthTokenSet`."""

Subscribers

People subscribed via source and target branches

to status/vote changes: