~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
= Renewing your own memberships =

Depending on a team's renewal policy, a team member may be allowed to
renew his own membership. That is allowed for teams which have ONDEMAND
as the renewal policy and for active memberships which are about to
expire. Also note that this can only be done by the members themselves or
by an administrator of a member team.

We'll use Karl's membership on the Mirror Administrators team to
demonstrate that. That team's renewal policy is not ONDEMAND and the
membership is not about to expire, so it can't be renewed unless we make
some changes.

    >>> from lp.testing import ANONYMOUS, login, logout
    >>> login(ANONYMOUS)
    >>> from zope.component import getUtility
    >>> from lp.registry.interfaces.person import (
    ...     IPersonSet,
    ...     TeamMembershipRenewalPolicy,
    ...     )
    >>> from lp.registry.interfaces.teammembership import ITeamMembershipSet
    >>> personset = getUtility(IPersonSet)
    >>> membership = getUtility(ITeamMembershipSet).getByPersonAndTeam(
    ...     personset.getByName('karl'),
    ...     personset.getByName('ubuntu-mirror-admins'))
    >>> print membership.dateexpires
    None
    >>> membership.team.renewal_policy != TeamMembershipRenewalPolicy.ONDEMAND
    True
    >>> logout()

Even though there won't be a link to the page in which it would
otherwise be possible to renew that membership, the user could manually
craft the URL to get to it, so in this case the page will simply say the
membership can't be renewed and explain why.

    >>> browser = setupBrowser(auth='Basic karl@canonical.com:test')
    >>> browser.open('http://launchpad.dev/~karl/+expiringmembership/'
    ...              'ubuntu-mirror-admins')
    >>> browser.getControl('Renew')
    Traceback (most recent call last):
    ...
    LookupError: label 'Renew'
    >>> print extract_text(find_tag_by_id(browser.contents, 'maincontent'))
    Renew membership of Karl Tilbury in Mirror Administrators
    ...
    This membership cannot be renewed because Mirror Administrators
    (ubuntu-mirror-admins) is not a team that allows its members to renew
    their own memberships.

Other users (apart from Karl) can't see that page.

    >>> user_browser.open('http://launchpad.dev/~karl/+expiringmembership/'
    ...                   'ubuntu-mirror-admins')
    Traceback (most recent call last):
    ...
    Unauthorized: ...

If we change the team's renewal policy it still won't be possible for
the user to renew that membership because it's not about to expire.

    >>> team_admin_browser = setupBrowser(auth='Basic mark@example.com:test')
    >>> team_admin_browser.open(
    ...     'http://launchpad.dev/~ubuntu-mirror-admins/+edit')
    >>> team_admin_browser.getControl(
    ...     'invite them to renew their own membership').selected = True
    >>> team_admin_browser.getControl('Renewal period').value = '30'
    >>> team_admin_browser.getControl('Save').click()

    >>> browser.open('http://launchpad.dev/~karl/+expiringmembership/'
    ...              'ubuntu-mirror-admins')
    >>> browser.getControl('Renew')
    Traceback (most recent call last):
    ...
    LookupError: label 'Renew'
    >>> print extract_text(find_tag_by_id(browser.contents, 'maincontent'))
    Renew membership of Karl Tilbury in Mirror Administrators
    ...
    This membership cannot be renewed because it is not set to expire in
    7 days or less. You or one of the team administrators has already
    renewed it.

If we now change Karl's membership to expire in a couple days, he'll be
able to renew it himself.

See pagetests/foaf/40-team-membership.txt for an explanation of the
mech_control TestBrowser voodoo.

    >>> from datetime import datetime, timedelta
    >>> import pytz
    >>> now = datetime.now(pytz.timezone('UTC'))
    >>> day_after_tomorrow = now + timedelta(days=2)

    >>> team_admin_browser.open(
    ...     'http://launchpad.dev/~ubuntu-mirror-admins/+member/karl')
    >>> team_admin_browser.getControl(name='expires').value = ['date']
    >>> expiry = team_admin_browser.getControl(
    ...     name='membership.expirationdate')
    >>> expiry.mech_control.disabled = False # control may be disabled in JS
    >>> expiry.value = day_after_tomorrow.date().strftime('%Y-%m-%d')
    >>> team_admin_browser.getControl(name='change').click()

    >>> team_admin_browser.url
    'http://launchpad.dev/~ubuntu-mirror-admins/+members'

    >>> browser.open('http://launchpad.dev/~karl/+expiringmembership/'
    ...              'ubuntu-mirror-admins')
    >>> print extract_text(find_tag_by_id(browser.contents, 'maincontent'))
    Renew membership of Karl Tilbury in Mirror Administrators
    ...
    This membership is going to expire in ... from now; if you want to
    remain a member of Mirror Administrators, you must renew it.
    or Cancel

Karl then renews his membership.

    >>> browser.getControl('Renew').click()
    >>> browser.url
    'http://launchpad.dev/~karl'
    >>> for tag in find_tags_by_class(
    ...         browser.contents, 'informational message'):
    ...     print tag.renderContents()
    Membership renewed until ...

Karl can't renew it again, since it's now not set to expire soon.

    >>> browser.open('http://launchpad.dev/~karl/+expiringmembership/'
    ...              'ubuntu-mirror-admins')
    >>> browser.getControl('Renew')
    Traceback (most recent call last):
    ...
    LookupError: label 'Renew'
    >>> print extract_text(find_tag_by_id(browser.contents, 'maincontent'))
    Renew membership of Karl Tilbury in Mirror Administrators
    ...
    This membership cannot be renewed because it is not set to expire in
    7 days or less. You or one of the team administrators has already
    renewed it.

In the case of subteams whose membership is about to expire, any admin of the
member team can renew the soon-to-expire membership, as long as the parent
team's renewal policy is ONDEMAND.

    >>> login('mark@example.com')
    >>> mirror_admins = personset.getByName('ubuntu-mirror-admins')
    >>> landscape_devs = personset.getByName('landscape-developers')
    >>> ignored = mirror_admins.addMember(
    ...     landscape_devs, mirror_admins.teamowner, force_team_add=True)
    >>> membership = getUtility(ITeamMembershipSet).getByPersonAndTeam(
    ...     landscape_devs, mirror_admins)
    >>> membership.setExpirationDate(
    ...     now + timedelta(days=1), mirror_admins.teamowner)
    >>> from lp.services.database.sqlbase import flush_database_updates
    >>> flush_database_updates()
    >>> logout()

Logged in as Sample Person (one of landscape developers' admins), we'll
now renew the membership.

    >>> browser = setupBrowser(auth='Basic test@canonical.com:test')
    >>> browser.open('http://launchpad.dev/~landscape-developers'
    ...              '/+expiringmembership/ubuntu-mirror-admins')
    >>> print extract_text(find_tag_by_id(browser.contents, 'maincontent'))
    Renew membership of Landscape Developers in Mirror Administrators
    ...
    This membership is going to expire in ... from now; if you want this team
    to remain a member of Mirror Administrators, you must renew it.
    or Cancel

    >>> browser.getControl('Renew').click()
    >>> browser.url
    'http://launchpad.dev/~landscape-developers'
    >>> for tag in find_tags_by_class(
    ...         browser.contents, 'informational message'):
    ...     print tag.renderContents()
    Membership renewed until ...

If the user double clicks or goes back to a cached version of the page
and tries to resubmit the form, it will skip the actual renewal process,
and it will display the same message. This prevents the user from being
confused, which would be the case if a double click on the submit button
provided no information as to whether the membership was renewed.

    >>> browser.goBack()
    >>> browser.getControl('Renew').click()
    >>> browser.url
    'http://launchpad.dev/~landscape-developers'
    >>> for tag in find_tags_by_class(
    ...         browser.contents, 'informational message'):
    ...     print tag.renderContents()
    Membership renewed until ...

When the page is loaded again, there is no form since the membership
will no longer be expiring soon.

    >>> browser.open('http://launchpad.dev/~landscape-developers'
    ...              '/+expiringmembership/ubuntu-mirror-admins')
    >>> print extract_text(find_tag_by_id(browser.contents, 'maincontent'))
    Renew membership of Landscape Developers in Mirror Administrators
    ...
    This membership cannot be renewed because it is not set to expire in
    7 days or less. Somebody else has already renewed it.

Any user who's not an admin of landscape-developers can't even see that page.

    >>> user_browser.open('http://launchpad.dev/~landscape-developers'
    ...                   '/+expiringmembership/ubuntu-mirror-admins')
    Traceback (most recent call last):
    ...
    Unauthorized: ...