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 | |
| 16 | import httplib |
| 17 | |
| 18 | from framework import framework_helpers |
| 19 | from framework import servlet |
| 20 | from framework import urls |
| 21 | |
| 22 | |
| 23 | class 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 | |
| 39 | class 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 |