blob: b49182a2b5ec2cc5462ff33c1a53b97e50e58a51 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# Copyright 2016 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
Copybara854996b2021-09-07 19:36:02 +00004
5"""A class to forward requests to configured urls.
6
7This page handles the /wiki and /source urls which are forwarded from Codesite.
8If a project has defined appropriate urls, then the users are forwarded there.
9If not, they are redirected to adminIntro.
10"""
11from __future__ import print_function
12from __future__ import division
13from __future__ import absolute_import
14
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020015from six.moves import http_client
Copybara854996b2021-09-07 19:36:02 +000016
17from framework import framework_helpers
18from framework import servlet
19from framework import urls
20
21
22class WikiRedirect(servlet.Servlet):
23 """Redirect to the wiki documentation, if provided."""
24
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010025 def get(self):
Copybara854996b2021-09-07 19:36:02 +000026 """Construct a 302 pointing at project.docs_url, or at adminIntro."""
27 if not self.mr.project:
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010028 self.response.status_code = http_client.NOT_FOUND
Copybara854996b2021-09-07 19:36:02 +000029 return
30 docs_url = self.mr.project.docs_url
31 if not docs_url:
32 docs_url = framework_helpers.FormatAbsoluteURL(
33 self.mr, urls.ADMIN_INTRO, include_project=True)
34 self.response.location = docs_url
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010035 self.response.status_code = http_client.MOVED_PERMANENTLY
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020036
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010037 def GetWikiListRedirect(self, **kwargs):
38 return self.handler(**kwargs)
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020039
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010040 def GetWikiRedirect(self, **kwargs):
41 return self.handler(**kwargs)
Copybara854996b2021-09-07 19:36:02 +000042
43
44class SourceRedirect(servlet.Servlet):
45 """Redirect to the source browser, if provided."""
46
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010047 def get(self):
Copybara854996b2021-09-07 19:36:02 +000048 """Construct a 302 pointing at project.source_url, or at adminIntro."""
49 if not self.mr.project:
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010050 self.response.status_code = http_client.NOT_FOUND
Copybara854996b2021-09-07 19:36:02 +000051 return
52 source_url = self.mr.project.source_url
53 if not source_url:
54 source_url = framework_helpers.FormatAbsoluteURL(
55 self.mr, urls.ADMIN_INTRO, include_project=True)
56 self.response.location = source_url
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010057 self.response.status_code = http_client.MOVED_PERMANENTLY
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020058
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010059 def GetSourceRedirect(self, **kwargs):
60 return self.handler(**kwargs)