Merge lp:~lifeless/launchpad/edge into lp:launchpad

Proposed by Robert Collins
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 11824
Proposed branch: lp:~lifeless/launchpad/edge
Merge into: lp:launchpad
Diff against target: 158 lines (+9/-91)
3 files modified
lib/canonical/config/schema-lazr.conf (+0/-7)
lib/canonical/launchpad/browser/launchpad.py (+8/-42)
lib/canonical/launchpad/pagetests/webservice/xx-service.txt (+1/-42)
To merge this branch: bzr merge lp:~lifeless/launchpad/edge
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+39594@code.launchpad.net

Commit message

Get rid of stale 'beta redirection' code.

Description of the change

Get rid of stale 'beta redirection' code.

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Given we aren't replacing parts of the url any more, we can simplify the following:

   uri = URI(canonical_url(bug.default_bugtask))
   # Empty the traversal stack, since we're redirecting.
   self.request.setTraversalStack([])
   # And perform a temporary redirect.
   return RedirectionView(str(uri), self.request, status=303)

to just be

   # Empty the traversal stack, since we're redirecting.
   self.request.setTraversalStack([])
   # And perform a temporary redirect.
   return RedirectionView(canonical_url(bug.default_bugtask), self.request, status=303)

But on the whole, it looks fine.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/canonical/config/schema-lazr.conf'
--- lib/canonical/config/schema-lazr.conf 2010-10-25 13:16:10 +0000
+++ lib/canonical/config/schema-lazr.conf 2010-10-29 14:12:12 +0000
@@ -1056,11 +1056,6 @@
1056# datatype: string1056# datatype: string
1057non_restricted_hostname: launchpad.net1057non_restricted_hostname: launchpad.net
10581058
1059# If set, the host name to redirect beta testers to.
1060# e.g. beta.launchpad.net
1061# datatype: string
1062beta_testers_redirection_host: none
1063
1064# Domain where incoming email related to specifications are sent to.1059# Domain where incoming email related to specifications are sent to.
1065# datatype: string1060# datatype: string
1066specs_domain: specs.launchpad.net1061specs_domain: specs.launchpad.net
@@ -2008,8 +2003,6 @@
2008openid_delegate_profile: False2003openid_delegate_profile: False
20092004
2010[vhost.api]2005[vhost.api]
2011# This key should be removed once the production configs have been updated.
2012beta_test_team: disabled
2013enable_server_side_representation_cache: False2006enable_server_side_representation_cache: False
2014# By default, cache representations for 4 hours.2007# By default, cache representations for 4 hours.
2015representation_cache_expiration_time: 144002008representation_cache_expiration_time: 14400
20162009
=== modified file 'lib/canonical/launchpad/browser/launchpad.py'
--- lib/canonical/launchpad/browser/launchpad.py 2010-10-27 08:51:05 +0000
+++ lib/canonical/launchpad/browser/launchpad.py 2010-10-29 14:12:12 +0000
@@ -688,29 +688,12 @@
688 if WebServiceLayer.providedBy(self.request):688 if WebServiceLayer.providedBy(self.request):
689 return None689 return None
690690
691 mainsite_host = config.vhost.mainsite.hostname
692
693 # If the hostname for our URL isn't under the main site691 # If the hostname for our URL isn't under the main site
694 # (e.g. shipit.ubuntu.com), don't redirect.692 # (e.g. shipit.ubuntu.com), don't redirect.
695 uri = URI(self.request.getURL())693 uri = URI(self.request.getURL())
696 if not uri.host.endswith(mainsite_host):694 if not uri.host.endswith(config.vhost.mainsite.hostname):
697 return None695 return None
698696
699 beta_host = config.launchpad.beta_testers_redirection_host
700 user = getUtility(ILaunchBag).user
701 # Test to see if the user is None before attempting to get the
702 # launchpad_beta_testers celebrity. In the odd test where the
703 # database is empty the series of tests will work.
704 if user is None:
705 user_is_beta_tester = False
706 else:
707 beta_testers = (
708 getUtility(ILaunchpadCelebrities).launchpad_beta_testers)
709 if user.inTeam(beta_testers):
710 user_is_beta_tester = True
711 else:
712 user_is_beta_tester = False
713
714 # If the request is for a bug then redirect straight to that bug.697 # If the request is for a bug then redirect straight to that bug.
715 bug_match = re.match("/bugs/(\d+)$", self.request['PATH_INFO'])698 bug_match = re.match("/bugs/(\d+)$", self.request['PATH_INFO'])
716 if bug_match:699 if bug_match:
@@ -722,30 +705,13 @@
722 raise NotFound(self.context, bug_number)705 raise NotFound(self.context, bug_number)
723 if not check_permission("launchpad.View", bug):706 if not check_permission("launchpad.View", bug):
724 raise Unauthorized("Bug %s is private" % bug_number)707 raise Unauthorized("Bug %s is private" % bug_number)
725 uri = URI(canonical_url(bug.default_bugtask))708 # Empty the traversal stack, since we're redirecting.
726 if beta_host is not None and user_is_beta_tester:709 self.request.setTraversalStack([])
727 # Alter the host name to point at the beta target.710 # And perform a temporary redirect.
728 new_host = uri.host[:-len(mainsite_host)] + beta_host711 return RedirectionView(canonical_url(bug.default_bugtask),
729 uri = uri.replace(host=new_host)712 self.request, status=303)
730 else:713 # Explicit catchall - do not redirect.
731 # If no redirection host is set or the user is not a beta tester,714 return None
732 # don't redirect.
733 if beta_host is None or not user_is_beta_tester:
734 return None
735 # Alter the host name to point at the beta target.
736 new_host = uri.host[:-len(mainsite_host)] + beta_host
737 uri = uri.replace(host=new_host)
738 # Complete the URL from the environment.
739 uri = uri.replace(path=self.request['PATH_INFO'])
740 query_string = self.request.get('QUERY_STRING')
741 if query_string:
742 uri = uri.replace(query=query_string)
743
744 # Empty the traversal stack, since we're redirecting.
745 self.request.setTraversalStack([])
746
747 # And perform a temporary redirect.
748 return RedirectionView(str(uri), self.request, status=303)
749715
750 def publishTraverse(self, request, name):716 def publishTraverse(self, request, name):
751 beta_redirection_view = self._getBetaRedirectionView()717 beta_redirection_view = self._getBetaRedirectionView()
752718
=== modified file 'lib/canonical/launchpad/pagetests/webservice/xx-service.txt'
--- lib/canonical/launchpad/pagetests/webservice/xx-service.txt 2010-10-18 22:24:59 +0000
+++ lib/canonical/launchpad/pagetests/webservice/xx-service.txt 2010-10-29 14:12:12 +0000
@@ -30,48 +30,6 @@
30 HTTP/1.1 404 Not Found30 HTTP/1.1 404 Not Found
31 ...31 ...
3232
33No beta team redirection
34========================
35
36Members of the beta team aren't redirected to the beta site on API call.
37
38(Enable beta redirection for demonstration purpose)
39
40 >>> from canonical.config import config
41 >>> beta_data = """
42 ... [launchpad]
43 ... beta_testers_redirection_host = beta.launchpad.dev
44 ... """
45 >>> config.push('beta_data', beta_data)
46
47 >>> from lp.testing import ANONYMOUS, login, logout
48 >>> from zope.component import getUtility
49 >>> from canonical.launchpad.testing.pages import webservice_for_person
50 >>> from lp.registry.interfaces.person import IPersonSet
51 >>> login(ANONYMOUS)
52 >>> beta_admin = getUtility(IPersonSet).getByEmail(
53 ... 'beta-admin@launchpad.net')
54 >>> beta_user = webservice_for_person(beta_admin)
55 >>> logout()
56
57A request to the web site is redirected:
58
59 >>> print http('GET /~launchpad-beta-owner HTTP/1.1\n'
60 ... 'Host: launchpad.dev\n'
61 ... 'Authorization: Basic %s\n' %
62 ... "beta-admin@launchpad.net:test".encode('base64'))
63 HTTP/1.1 303 See Other
64 ...
65 Location: http://beta.launchpad.dev/~launchpad-beta-owner
66 ...
67
68But not a request to the web service:
69
70 >>> print beta_user.get("/~launchpad-beta-owner")
71 HTTP/1.1 200 Ok
72 ...
73
74 >>> ignored = config.pop('beta_data')
7533
76Resources not exposed on the web service34Resources not exposed on the web service
77========================================35========================================
@@ -118,6 +76,7 @@
118doesn't recognize the client.76doesn't recognize the client.
11977
120 >>> login(ANONYMOUS)78 >>> login(ANONYMOUS)
79 >>> from zope.component import getUtility
121 >>> consumer_set = getUtility(IOAuthConsumerSet)80 >>> consumer_set = getUtility(IOAuthConsumerSet)
122 >>> print consumer_set.getByKey('another-new-consumer')81 >>> print consumer_set.getByKey('another-new-consumer')
123 None82 None