blob: e9afa709475baaf48de4b67d886b728a62489202 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# Copyright 2018 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"""Classes that implement a web components page.
6
7Summary of classes:
8 WebComponentsPage: Show one web components page.
9"""
10from __future__ import print_function
11from __future__ import division
12from __future__ import absolute_import
13
14
15import logging
16
17import settings
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010018from framework import exceptions
Copybara854996b2021-09-07 19:36:02 +000019from framework import permissions
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010020from framework import servlet
Copybara854996b2021-09-07 19:36:02 +000021
22
23class WebComponentsPage(servlet.Servlet):
24
25 _PAGE_TEMPLATE = 'tracker/web-components-page.ezt'
26
27 def AssertBasePermission(self, mr):
28 # type: (MonorailRequest) -> None
29 """Check that the user has permission to visit this page."""
30 super(WebComponentsPage, self).AssertBasePermission(mr)
31
32 def GatherPageData(self, mr):
33 # type: (MonorailRequest) -> Mapping[str, Any]
34 """Build up a dictionary of data values to use when rendering the page.
35
36 Args:
37 mr: commonly used info parsed from the request.
38
39 Returns:
40 Dict of values used by EZT for rendering the page.
41 """
42 # Create link to view in old UI for the list view pages.
43 old_ui_url = None
44 url = mr.request.url
45 if '/hotlists/' in url:
46 hotlist = self.services.features.GetHotlist(mr.cnxn, mr.hotlist_id)
47 if '/people' in url:
48 old_ui_url = '/u/%s/hotlists/%s/people' % (
49 hotlist.owner_ids[0], hotlist.name)
50 elif '/settings' in url:
51 old_ui_url = '/u/%s/hotlists/%s/details' % (
52 hotlist.owner_ids[0], hotlist.name)
53 else:
54 old_ui_url = '/u/%s/hotlists/%s' % (hotlist.owner_ids[0], hotlist.name)
55
56 return {
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010057 'local_id': mr.local_id,
58 'old_ui_url': old_ui_url,
59 }
Copybara854996b2021-09-07 19:36:02 +000060
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010061 def GetWebComponentsIssueDetail(self, **kwargs):
62 return self.handler(**kwargs)
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020063
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010064 def GetWebComponentsIssueList(self, **kwargs):
65 return self.handler(**kwargs)
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020066
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010067 def GetWebComponentsIssueWizard(self, **kwargs):
68 return self.handler(**kwargs)
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020069
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010070 def GetWebComponentsIssueNewEntry(self, **kwargs):
71 return self.handler(**kwargs)
72
73 def GetWebComponentsHotlist(self, **kwargs):
74 return self.handler(**kwargs)
75
76 def GetWebComponentsUser(self, **kwargs):
77 return self.handler(**kwargs)
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020078
Copybara854996b2021-09-07 19:36:02 +000079
80class ProjectListPage(WebComponentsPage):
81
82 def GatherPageData(self, mr):
83 # type: (MonorailRequest) -> Mapping[str, Any]
84 """Build up a dictionary of data values to use when rendering the page.
85
86 May redirect the user to a default project if one is configured for
87 the current domain.
88
89 Args:
90 mr: commonly used info parsed from the request.
91
92 Returns:
93 Dict of values used by EZT for rendering the page.
94 """
95 redirect_msg = self._MaybeRedirectToDomainDefaultProject(mr)
96 logging.info(redirect_msg)
97 return {
98 'local_id': None,
99 'old_ui_url': '/hosting_old/',
100 }
101
102 def _MaybeRedirectToDomainDefaultProject(self, mr):
103 # type: (MonorailRequest) -> str
104 """If there is a relevant default project, redirect to it.
105
106 This function is copied from: sitewide/hostinghome.py
107
108 Args:
109 mr: commonly used info parsed from the request.
110
111 Returns:
112 String with a message about what happened for logging purposes.
113 """
114 project_name = settings.domain_to_default_project.get(mr.request.host)
115 if not project_name:
116 return 'No configured default project redirect for this domain.'
117
118 project = None
119 try:
120 project = self.services.project.GetProjectByName(mr.cnxn, project_name)
121 except exceptions.NoSuchProjectException:
122 pass
123
124 if not project:
125 return 'Domain default project %s not found' % project_name
126
127 if not permissions.UserCanViewProject(mr.auth.user_pb,
128 mr.auth.effective_ids, project):
129 return 'User cannot view default project: %r' % project
130
131 project_url = '/p/%s' % project_name
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +0100132 raise exceptions.RedirectException(project_url)
133
134 def GetProjectListPage(self, **kwargs):
135 return self.handler(**kwargs)