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 display a message explaining that a project has moved. |
| 6 | |
| 7 | When a project moves, we just display a link to the new location. |
| 8 | """ |
| 9 | from __future__ import print_function |
| 10 | from __future__ import division |
| 11 | from __future__ import absolute_import |
| 12 | |
| 13 | import logging |
| 14 | |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 15 | from framework import exceptions |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 16 | from framework import framework_helpers |
| 17 | from framework import servlet |
| 18 | from framework import urls |
| 19 | from project import project_constants |
| 20 | |
| 21 | |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 22 | class ProjectMoved(servlet.Servlet): |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 23 | """The ProjectMoved page explains that the project has moved.""" |
| 24 | |
| 25 | _PAGE_TEMPLATE = 'sitewide/moved-page.ezt' |
| 26 | |
| 27 | def GatherPageData(self, mr): |
| 28 | """Build up a dictionary of data values to use when rendering the page.""" |
| 29 | |
| 30 | # We are not actually in /p/PROJECTNAME, so mr.project_name is None. |
| 31 | # Putting the ProjectMoved page inside a moved project would make |
| 32 | # the redirect logic much more complicated. |
| 33 | if not mr.specified_project: |
| 34 | raise exceptions.InputException('No project specified') |
| 35 | |
| 36 | project = self.services.project.GetProjectByName( |
| 37 | mr.cnxn, mr.specified_project) |
| 38 | if not project: |
| 39 | self.abort(404, 'project not found') |
| 40 | |
| 41 | if not project.moved_to: |
| 42 | # Only show this page for projects that are actually moved. |
| 43 | # Don't allow hackers to construct misleading links to this servlet. |
| 44 | logging.info('attempt to view ProjectMoved for non-moved project: %s', |
| 45 | mr.specified_project) |
| 46 | self.abort(400, 'This project has not been moved') |
| 47 | |
| 48 | if project_constants.RE_PROJECT_NAME.match(project.moved_to): |
| 49 | moved_to_url = framework_helpers.FormatAbsoluteURL( |
| 50 | mr, urls.SUMMARY, include_project=True, project_name=project.moved_to) |
| 51 | elif (project.moved_to.startswith('https://') or |
| 52 | project.moved_to.startswith('http://')): |
| 53 | moved_to_url = project.moved_to |
| 54 | else: |
| 55 | # Prevent users from using javascript: or any other tricky URL scheme. |
| 56 | moved_to_url = '#invalid-destination-url' |
| 57 | |
| 58 | return { |
| 59 | 'project_name': mr.specified_project, |
| 60 | 'moved_to_url': moved_to_url, |
| 61 | } |
Adrià Vilanova Martínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 62 | |
Adrià Vilanova Martínez | 9f9ade5 | 2022-10-10 23:20:11 +0200 | [diff] [blame] | 63 | def GetProjectMoved(self, **kwargs): |
| 64 | return self.handler(**kwargs) |