Merge lp:~edwin-grubbs/launchpad/bug-576388-proposing-team-info-message into lp:launchpad

Proposed by Edwin Grubbs
Status: Merged
Approved by: Edwin Grubbs
Approved revision: no longer in the source branch.
Merged at revision: 11103
Proposed branch: lp:~edwin-grubbs/launchpad/bug-576388-proposing-team-info-message
Merge into: lp:launchpad
Diff against target: 86 lines (+35/-13)
2 files modified
lib/lp/registry/browser/person.py (+33/-11)
lib/lp/registry/stories/team/xx-team-add-my-teams.txt (+2/-2)
To merge this branch: bzr merge lp:~edwin-grubbs/launchpad/bug-576388-proposing-team-info-message
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Review via email: mp+29026@code.launchpad.net

Description of the change

Improved informational message so that it will not say a team was proposed when it was really added due to having an existing invite.

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

The branch looks good Edwin.

Personally I think:

team_string = team_names[0]

is more readable than:

[team_string] = team_names

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/browser/person.py'
2--- lib/lp/registry/browser/person.py 2010-06-30 01:39:11 +0000
3+++ lib/lp/registry/browser/person.py 2010-07-08 15:12:48 +0000
4@@ -4201,6 +4201,10 @@
5 context = self.context
6 is_admin = check_permission('launchpad.Admin', context)
7 membership_set = getUtility(ITeamMembershipSet)
8+ proposed_team_names = []
9+ added_team_names = []
10+ accepted_invite_team_names = []
11+ membership_set = getUtility(ITeamMembershipSet)
12 for team in data['teams']:
13 membership = membership_set.getByPersonAndTeam(team, context)
14 if (membership is not None
15@@ -4209,21 +4213,39 @@
16 context,
17 'Accepted an already pending invitation while trying to '
18 'propose the team for membership.')
19+ accepted_invite_team_names.append(team.displayname)
20 elif is_admin:
21 context.addMember(team, reviewer=self.user)
22+ added_team_names.append(team.displayname)
23 else:
24 team.join(context, requester=self.user)
25- if (context.subscriptionpolicy == TeamSubscriptionPolicy.MODERATED
26- and not is_admin):
27- msg = 'proposed to this team.'
28- else:
29- msg = 'added to this team.'
30- if len(data['teams']) > 1:
31- msg = "have been %s" % msg
32- else:
33- msg = "has been %s" % msg
34- team_names = ', '.join(team.displayname for team in data['teams'])
35- self.request.response.addInfoNotification("%s %s" % (team_names, msg))
36+ membership = membership_set.getByPersonAndTeam(team, context)
37+ if membership.status == TeamMembershipStatus.PROPOSED:
38+ proposed_team_names.append(team.displayname)
39+ elif membership.status == TeamMembershipStatus.APPROVED:
40+ added_team_names.append(team.displayname)
41+ else:
42+ raise AssertionError(
43+ 'Unexpected membership status (%s) for %s.'
44+ % (membership.status.name, team.name))
45+ full_message = ''
46+ for team_names, message in (
47+ (proposed_team_names, 'proposed to this team.'),
48+ (added_team_names, 'added to this team.'),
49+ (accepted_invite_team_names,
50+ 'added to this team because of an existing invite.'),
51+ ):
52+ if len(team_names) == 0:
53+ continue
54+ elif len(team_names) == 1:
55+ verb = 'has been'
56+ team_string = team_names[0]
57+ elif len(team_names) > 1:
58+ verb = 'have been'
59+ team_string= (
60+ ', '.join(team_names[:-1]) + ' and ' + team_names[-1])
61+ full_message += '%s %s %s ' % (team_string, verb, message)
62+ self.request.response.addInfoNotification(full_message)
63
64
65 class TeamLeaveView(LaunchpadFormView, TeamJoinMixin):
66
67=== modified file 'lib/lp/registry/stories/team/xx-team-add-my-teams.txt'
68--- lib/lp/registry/stories/team/xx-team-add-my-teams.txt 2010-06-29 18:13:00 +0000
69+++ lib/lp/registry/stories/team/xx-team-add-my-teams.txt 2010-07-08 15:12:48 +0000
70@@ -62,7 +62,7 @@
71 >>> print user_browser.title
72 Super Team in Launchpad
73 >>> print get_feedback_messages(user_browser.contents)
74- [u'Sub Team has been added to this team.']
75+ [u'Sub Team has been added to this team because of an existing invite.']
76 >>> print extract_text(
77 ... find_tag_by_id(user_browser.contents, 'recently-approved'))
78 Latest members
79@@ -146,7 +146,7 @@
80 ... 'guadamen', 'ubuntu-security']
81 >>> browser.getControl('Continue').click()
82 >>> print "\n".join(get_feedback_messages(browser.contents))
83- GuadaMen, Ubuntu Security Team have been added to this team.
84+ GuadaMen and Ubuntu Security Team have been added to this team.
85
86 And when no teams can be added, a message is displayed:
87