Merge lp:~sinzui/launchpad/ml-moderate-view-0 into lp:launchpad

Proposed by Curtis Hovey
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 11964
Proposed branch: lp:~sinzui/launchpad/ml-moderate-view-0
Merge into: lp:launchpad
Diff against target: 58 lines (+21/-3)
2 files modified
lib/lp/registry/browser/team.py (+4/-2)
lib/lp/registry/browser/tests/test_team.py (+17/-1)
To merge this branch: bzr merge lp:~sinzui/launchpad/ml-moderate-view-0
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+41548@code.launchpad.net

Description of the change

This is my branch to redirect users from the mailing list moderation view.

    lp:~sinzui/launchpad/ml-moderate-view-0
    Diff size: 60
    Launchpad bug: https://bugs.launchpad.net/bugs/680009
    Test command: ./bin/test -vv \
        -t TestModeration -t stories/mailinglists/moderation
    Pre-implementation: no one
    Target release: 10.12

Redirect users from the mailing list moderation view
-----------------------------------------------------

The user hacked the url to access the +mailinglist-moderate view. I think we
want to replace the assert in TeamMailingListModerationView with a redirect to
the team page and add a notification to explain the team does not have a
mailing list.

Rules
-----

    * Like the +contact-user page, the view should issue a redirect and
      notification to explain why the page is not available.

QA
--

    * Visit https://launchpad.net/~elementaryos/+mailinglist-moderate
    * Verify you are redirected to https://launchpad.net/~elementaryos
    * Verify there is a notification stating that ~elementaryos does not
      have a mailing list.

Lint
----

Linting changed files:
  lib/lp/registry/browser/team.py
  lib/lp/registry/browser/tests/test_team.py

Implementation
--------------

Replaced the assert with a guard. Issue a notification and a redirect when
there is no mailing list.
    lib/lp/registry/browser/team.py
    lib/lp/registry/browser/tests/test_team.py

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

JFDI

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/browser/team.py'
2--- lib/lp/registry/browser/team.py 2010-11-11 21:30:09 +0000
3+++ lib/lp/registry/browser/team.py 2010-11-23 04:57:01 +0000
4@@ -801,8 +801,10 @@
5 super(TeamMailingListModerationView, self).__init__(context, request)
6 list_set = getUtility(IMailingListSet)
7 self.mailing_list = list_set.get(self.context.name)
8- assert(self.mailing_list is not None), (
9- 'No mailing list: %s' % self.context.name)
10+ if self.mailing_list is None:
11+ self.request.response.addInfoNotification(
12+ '%s does not have a mailing list.' % self.context.displayname)
13+ return self.request.response.redirect(canonical_url(self.context))
14
15 @cachedproperty
16 def hold_count(self):
17
18=== modified file 'lib/lp/registry/browser/tests/test_team.py'
19--- lib/lp/registry/browser/tests/test_team.py 2010-11-11 22:43:01 +0000
20+++ lib/lp/registry/browser/tests/test_team.py 2010-11-23 04:57:01 +0000
21@@ -3,6 +3,7 @@
22
23 __metaclass__ = type
24
25+from canonical.launchpad.webapp.publisher import canonical_url
26 from canonical.testing.layers import DatabaseFunctionalLayer
27 from lp.registry.browser.person import TeamOverviewMenu
28 from lp.testing import (
29@@ -12,7 +13,10 @@
30 )
31 from lp.testing.matchers import IsConfiguredBatchNavigator
32 from lp.testing.menu import check_menu_links
33-from lp.testing.views import create_initialized_view
34+from lp.testing.views import (
35+ create_initialized_view,
36+ create_view,
37+ )
38
39
40 class TestTeamMenu(TestCaseWithFactory):
41@@ -55,6 +59,18 @@
42 view.held_messages,
43 IsConfiguredBatchNavigator('message', 'messages'))
44
45+ def test_no_mailing_list_redirect(self):
46+ team = self.factory.makeTeam()
47+ login_person(team.teamowner)
48+ view = create_view(team, name='+mailinglist-moderate')
49+ response = view.request.response
50+ self.assertEqual(302, response.getStatus())
51+ self.assertEqual(canonical_url(team), response.getHeader('location'))
52+ self.assertEqual(1, len(response.notifications))
53+ self.assertEqual(
54+ '%s does not have a mailing list.' % (team.displayname),
55+ response.notifications[0].message)
56+
57
58 class TestTeamMemberAddView(TestCaseWithFactory):
59