Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | # 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. |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 4 | |
| 5 | """A class to forward requests to configured urls. |
| 6 | |
| 7 | This page handles the /wiki and /source urls which are forwarded from Codesite. |
| 8 | If a project has defined appropriate urls, then the users are forwarded there. |
| 9 | If not, they are redirected to adminIntro. |
| 10 | """ |
| 11 | from __future__ import print_function |
| 12 | from __future__ import division |
| 13 | from __future__ import absolute_import |
| 14 | |
Adrià Vilanova Martínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 15 | from six.moves import http_client |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 16 | |
| 17 | from framework import framework_helpers |
| 18 | from framework import servlet |
| 19 | from framework import urls |
| 20 | |
| 21 | |
| 22 | class WikiRedirect(servlet.Servlet): |
| 23 | """Redirect to the wiki documentation, if provided.""" |
| 24 | |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 25 | def get(self): |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 26 | """Construct a 302 pointing at project.docs_url, or at adminIntro.""" |
| 27 | if not self.mr.project: |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 28 | self.response.status_code = http_client.NOT_FOUND |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 29 | 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ínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 35 | self.response.status_code = http_client.MOVED_PERMANENTLY |
Adrià Vilanova Martínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 36 | |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 37 | def GetWikiListRedirect(self, **kwargs): |
| 38 | return self.handler(**kwargs) |
Adrià Vilanova Martínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 39 | |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 40 | def GetWikiRedirect(self, **kwargs): |
| 41 | return self.handler(**kwargs) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 42 | |
| 43 | |
| 44 | class SourceRedirect(servlet.Servlet): |
| 45 | """Redirect to the source browser, if provided.""" |
| 46 | |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 47 | def get(self): |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 48 | """Construct a 302 pointing at project.source_url, or at adminIntro.""" |
| 49 | if not self.mr.project: |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 50 | self.response.status_code = http_client.NOT_FOUND |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 51 | 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ínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 57 | self.response.status_code = http_client.MOVED_PERMANENTLY |
Adrià Vilanova Martínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 58 | |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 59 | def GetSourceRedirect(self, **kwargs): |
| 60 | return self.handler(**kwargs) |