blob: 0be5c37136c246580c250a3671c8f71353ef5a78 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# 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.
Copybara854996b2021-09-07 19:36:02 +00004
5"""A class to display a message explaining that a project has moved.
6
7When a project moves, we just display a link to the new location.
8"""
9from __future__ import print_function
10from __future__ import division
11from __future__ import absolute_import
12
13import logging
14
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010015from framework import exceptions
Copybara854996b2021-09-07 19:36:02 +000016from framework import framework_helpers
17from framework import servlet
18from framework import urls
19from project import project_constants
20
21
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010022class ProjectMoved(servlet.Servlet):
Copybara854996b2021-09-07 19:36:02 +000023 """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ínezde942802022-07-15 14:06:55 +020062
Adrià Vilanova Martínez9f9ade52022-10-10 23:20:11 +020063 def GetProjectMoved(self, **kwargs):
64 return self.handler(**kwargs)