1
# Copyright 2011 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
6
'userIsActiveTeamMember',
9
from zope.component import getUtility
11
from canonical.launchpad.webapp.authorization import check_permission
12
from canonical.launchpad.webapp.interfaces import ILaunchBag
15
def userIsActiveTeamMember(team):
16
"""Return True if the user is an active member of this team."""
17
user = getUtility(ILaunchBag).user
20
if not check_permission('launchpad.View', team):
22
return user in team.activemembers
26
"""Mixin class for views related to joining teams."""
29
def user_can_subscribe_to_list(self):
30
"""Can the prospective member subscribe to this team's mailing list?
32
A user can subscribe to the list if the team has an active
33
mailing list, and if they do not already have a subscription.
35
if self.team_has_mailing_list:
36
# If we are already subscribed, then we can not subscribe again.
37
return not self.user_is_subscribed_to_list
42
def user_is_subscribed_to_list(self):
43
"""Is the user subscribed to the team's mailing list?
45
Subscriptions hang around even if the list is deactivated, etc.
47
It is an error to ask if the user is subscribed to a mailing list
53
mailing_list = self.context.mailing_list
54
assert mailing_list is not None, "This team has no mailing list."
55
has_subscription = bool(mailing_list.getSubscription(self.user))
56
return has_subscription
59
def team_has_mailing_list(self):
60
"""Is the team mailing list available for subscription?"""
61
mailing_list = self.context.mailing_list
62
return mailing_list is not None and mailing_list.is_usable
65
def user_is_active_member(self):
66
"""Return True if the user is an active member of this team."""
67
return userIsActiveTeamMember(self.context)
70
def user_is_proposed_member(self):
71
"""Return True if the user is a proposed member of this team."""
74
return self.user in self.context.proposedmembers
77
def user_can_request_to_leave(self):
78
"""Return true if the user can request to leave this team.
80
A given user can leave a team only if he's an active member.
82
return self.user_is_active_member