blob: 8c8b8183ef7cfb38b3c4fe62811bf73e21db3142 [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
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020016from six.moves import http_client
Copybara854996b2021-09-07 19:36:02 +000017
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020018from framework import flaskservlet
Copybara854996b2021-09-07 19:36:02 +000019from framework import framework_helpers
20from framework import servlet
21from framework import urls
22
23
24class WikiRedirect(servlet.Servlet):
25 """Redirect to the wiki documentation, if provided."""
26
27 def get(self, **kwargs):
28 """Construct a 302 pointing at project.docs_url, or at adminIntro."""
29 if not self.mr.project:
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020030 # TODO(crbug.com/monorail/10936): status in Flask is status_code
31 # self.response.status_code = http_client.NOT_FOUND
32 self.response.status = http_client.NOT_FOUND
Copybara854996b2021-09-07 19:36:02 +000033 return
34 docs_url = self.mr.project.docs_url
35 if not docs_url:
36 docs_url = framework_helpers.FormatAbsoluteURL(
37 self.mr, urls.ADMIN_INTRO, include_project=True)
38 self.response.location = docs_url
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020039 # TODO(crbug.com/monorail/10936): status in Flask is status_code
40 # self.response.status_code = http_client.MOVED_PERMANENTLY
41 self.response.status = http_client.MOVED_PERMANENTLY
42
43 # def GetWikiListRedirect(self, **kwargs):
44 # return self.handler(**kwargs)
45
46 # def GetWikiRedirect(self, **kwargs):
47 # return self.handler(**kwargs)
Copybara854996b2021-09-07 19:36:02 +000048
49
50class SourceRedirect(servlet.Servlet):
51 """Redirect to the source browser, if provided."""
52
53 def get(self, **kwargs):
54 """Construct a 302 pointing at project.source_url, or at adminIntro."""
55 if not self.mr.project:
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020056 # TODO(crbug.com/monorail/10936): status in Flask is status_code
57 # self.response.status_code = http_client.NOT_FOUND
58 self.response.status = http_client.NOT_FOUND
Copybara854996b2021-09-07 19:36:02 +000059 return
60 source_url = self.mr.project.source_url
61 if not source_url:
62 source_url = framework_helpers.FormatAbsoluteURL(
63 self.mr, urls.ADMIN_INTRO, include_project=True)
64 self.response.location = source_url
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020065 # TODO(crbug.com/monorail/10936): status in Flask is status_code
66 # self.response.status_code = http_client.MOVED_PERMANENTLY
67 self.response.status = http_client.MOVED_PERMANENTLY
68
69 # def GetSourceRedirect(self, **kwargs):
70 # return self.handler(**kwargs)