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