blob: 7813a565eb1f5069b3a39a1c349a78bd4a13aaad [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001# Copyright 2016 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style
3# license that can be found in the LICENSE file or at
4# https://developers.google.com/open-source/licenses/bsd
5
6"""A class to forward requests to configured urls.
7
8This page handles the /wiki and /source urls which are forwarded from Codesite.
9If a project has defined appropriate urls, then the users are forwarded there.
10If not, they are redirected to adminIntro.
11"""
12from __future__ import print_function
13from __future__ import division
14from __future__ import absolute_import
15
16import httplib
17
18from framework import framework_helpers
19from framework import servlet
20from framework import urls
21
22
23class WikiRedirect(servlet.Servlet):
24 """Redirect to the wiki documentation, if provided."""
25
26 def get(self, **kwargs):
27 """Construct a 302 pointing at project.docs_url, or at adminIntro."""
28 if not self.mr.project:
29 self.response.status = httplib.NOT_FOUND
30 return
31 docs_url = self.mr.project.docs_url
32 if not docs_url:
33 docs_url = framework_helpers.FormatAbsoluteURL(
34 self.mr, urls.ADMIN_INTRO, include_project=True)
35 self.response.location = docs_url
36 self.response.status = httplib.MOVED_PERMANENTLY
37
38
39class SourceRedirect(servlet.Servlet):
40 """Redirect to the source browser, if provided."""
41
42 def get(self, **kwargs):
43 """Construct a 302 pointing at project.source_url, or at adminIntro."""
44 if not self.mr.project:
45 self.response.status = httplib.NOT_FOUND
46 return
47 source_url = self.mr.project.source_url
48 if not source_url:
49 source_url = framework_helpers.FormatAbsoluteURL(
50 self.mr, urls.ADMIN_INTRO, include_project=True)
51 self.response.location = source_url
52 self.response.status = httplib.MOVED_PERMANENTLY