Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | # 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 | |
| 8 | This page handles the /wiki and /source urls which are forwarded from Codesite. |
| 9 | If a project has defined appropriate urls, then the users are forwarded there. |
| 10 | If not, they are redirected to adminIntro. |
| 11 | """ |
| 12 | from __future__ import print_function |
| 13 | from __future__ import division |
| 14 | from __future__ import absolute_import |
| 15 | |
Adrià Vilanova Martínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 16 | from six.moves import http_client |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 17 | |
Adrià Vilanova Martínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 18 | from framework import flaskservlet |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 19 | from framework import framework_helpers |
| 20 | from framework import servlet |
| 21 | from framework import urls |
| 22 | |
| 23 | |
| 24 | class 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ínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 30 | # 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 |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 33 | 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ínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 39 | # 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) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 48 | |
| 49 | |
| 50 | class 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ínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 56 | # 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 |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 59 | 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ínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 65 | # 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) |