OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is govered 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 display a message explaining that a project has moved. |
| 7 |
| 8 When a project moves, we just display a link to the new location. |
| 9 """ |
| 10 |
| 11 import logging |
| 12 |
| 13 from framework import framework_bizobj |
| 14 from framework import framework_helpers |
| 15 from framework import monorailrequest |
| 16 from framework import servlet |
| 17 |
| 18 |
| 19 class ProjectMoved(servlet.Servlet): |
| 20 """The ProjectMoved page explains that the project has moved.""" |
| 21 |
| 22 _PAGE_TEMPLATE = 'sitewide/moved-page.ezt' |
| 23 |
| 24 def GatherPageData(self, mr): |
| 25 """Build up a dictionary of data values to use when rendering the page.""" |
| 26 |
| 27 # We are not actually in /p/PROJECTNAME, so mr.project_name is None. |
| 28 # Putting the ProjectMoved page inside a moved project would make |
| 29 # the redirect logic much more complicated. |
| 30 if not mr.specified_project: |
| 31 raise monorailrequest.InputException('No project specified') |
| 32 |
| 33 project = self.services.project.GetProjectByName( |
| 34 mr.cnxn, mr.specified_project) |
| 35 if not project: |
| 36 self.abort(404, 'project not found') |
| 37 |
| 38 if not project.moved_to: |
| 39 # Only show this page for projects that are actually moved. |
| 40 # Don't allow hackers to construct misleading links to this servlet. |
| 41 logging.info('attempt to view ProjectMoved for non-moved project: %s', |
| 42 mr.specified_project) |
| 43 self.abort(400, 'This project has not been moved') |
| 44 |
| 45 if framework_bizobj.RE_PROJECT_NAME.match(project.moved_to): |
| 46 moved_to_url = framework_helpers.FormatMovedProjectURL( |
| 47 mr, project.moved_to) |
| 48 elif project.moved_to.startswith('http'): |
| 49 moved_to_url = project.moved_to |
| 50 else: |
| 51 # Prevent users from using javascript: or any other tricky URL scheme. |
| 52 moved_to_url = '#invalid-destination-url' |
| 53 |
| 54 return { |
| 55 'project_name': mr.specified_project, |
| 56 'moved_to_url': moved_to_url, |
| 57 } |
OLD | NEW |