1
# Copyright 2009 Canonical Ltd. This software is licensed under the
1
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
4
"""Database class for table ArchiveSubscriber."""
31
31
from canonical.database.constants import UTC_NOW
32
32
from canonical.database.enumcol import DBEnum
33
from canonical.launchpad.database.emailaddress import EmailAddress
34
from canonical.launchpad.interfaces.emailaddress import EmailAddressStatus
33
35
from lp.registry.interfaces.person import validate_person
34
36
from lp.registry.model.teammembership import TeamParticipation
35
37
from lp.soyuz.interfaces.archiveauthtoken import IArchiveAuthTokenSet
96
98
store = Store.of(self)
97
99
if self.subscriber.is_team:
101
# We get all the people who already have active tokens for
102
# this archive (for example, through separate subscriptions).
103
auth_token = LeftJoin(
105
And(ArchiveAuthToken.person_id == Person.id,
106
ArchiveAuthToken.archive_id == self.archive_id,
107
ArchiveAuthToken.date_deactivated == None))
109
team_participation = Join(
111
TeamParticipation.personID == Person.id)
113
# Only return people with preferred email address set.
114
preferred_email = Join(
115
EmailAddress, EmailAddress.personID == Person.id)
99
117
# We want to get all participants who are themselves
100
118
# individuals, not teams:
101
all_subscribers = store.find(
119
non_active_subscribers = store.using(
120
Person, team_participation, preferred_email, auth_token).find(
121
(Person, EmailAddress),
122
EmailAddress.status == EmailAddressStatus.PREFERRED,
103
123
TeamParticipation.teamID == self.subscriber_id,
104
TeamParticipation.personID == Person.id,
105
Person.teamowner == None)
107
# Then we get all the people who already have active
108
# tokens for this archive (for example, through separate
110
active_subscribers = store.find(
112
Person.id == ArchiveAuthToken.person_id,
113
ArchiveAuthToken.archive_id == self.archive_id,
114
ArchiveAuthToken.date_deactivated == None)
116
# And return just the non active subscribers:
117
non_active_subscribers = all_subscribers.difference(
124
Person.teamowner == None,
125
# There is no existing archive auth token.
126
ArchiveAuthToken.person_id == None)
119
127
non_active_subscribers.order_by(Person.name)
120
128
return non_active_subscribers
128
136
return EmptyResultSet()
130
138
# Otherwise return a result set containing only the
132
return store.find(Person, Person.id == self.subscriber_id)
139
# subscriber and their preferred email address.
141
(Person, EmailAddress),
142
Person.id == self.subscriber_id,
143
EmailAddress.personID == Person.id,
144
EmailAddress.status == EmailAddressStatus.PREFERRED)
135
147
class ArchiveSubscriberSet: