blob: d7a74c9c66663ff136688fb18ecfbc613a931e50 [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"""Classes for user updates pages.
6
7 AbstractUserUpdatesPage: Base class for all user updates pages
8 UserUpdatesProjects: Handles displaying starred projects
9 UserUpdatesDevelopers: Handles displaying starred developers
10 UserUpdatesIndividual: Handles displaying activities by the viewed user
11"""
12from __future__ import print_function
13from __future__ import division
14from __future__ import absolute_import
15
16
17import logging
18
19import ezt
20
21from businesslogic import work_env
22from features import activities
23from framework import servlet
24from framework import urls
Copybara854996b2021-09-07 19:36:02 +000025
26
27class AbstractUserUpdatesPage(servlet.Servlet):
28 """Base class for user updates pages."""
29
30 _PAGE_TEMPLATE = 'sitewide/user-updates-page.ezt'
31
32 # Subclasses should override these constants.
33 _UPDATES_PAGE_URL = None
34 # What to highlight in the middle column on user updates pages - 'project',
35 # 'user', or None
36 _HIGHLIGHT = None
37 # What the ending phrase for activity titles should be - 'by_user',
38 # 'in_project', or None
39 _ENDING = None
40 _TAB_MODE = None
41
42 def GatherPageData(self, mr):
43 """Build up a dictionary of data values to use when rendering the page."""
44 # TODO(jrobbins): re-implement
45 # if self.CheckRevelationCaptcha(mr, mr.errors):
46 # mr.viewed_user_auth.user_view.RevealEmail()
47
48 page_data = {
49 'user_tab_mode': 'st5',
50 'viewing_user_page': ezt.boolean(True),
51 'user_updates_tab_mode': self._TAB_MODE,
52 }
53
54 user_ids = self._GetUserIDsForUpdates(mr)
55 project_ids = self._GetProjectIDsForUpdates(mr)
56 page_data.update(activities.GatherUpdatesData(
57 self.services, mr, user_ids=user_ids,
58 project_ids=project_ids, ending=self._ENDING,
59 updates_page_url=self._UPDATES_PAGE_URL, highlight=self._HIGHLIGHT))
60
61 return page_data
62
63 def _GetUserIDsForUpdates(self, _mr):
64 """Returns a list of user IDs to retrieve activities from."""
65 return None # Means any.
66
67 def _GetProjectIDsForUpdates(self, _mr):
68 """Returns a list of project IDs to retrieve activities from."""
69 return None # Means any.
70
71
72class UserUpdatesProjects(AbstractUserUpdatesPage):
73 """Shows a page of updates from projects starred by a user."""
74
75 _UPDATES_FEED_URL = urls.USER_UPDATES_PROJECTS
76 _UPDATES_PAGE_URL = urls.USER_UPDATES_PROJECTS
77 _HIGHLIGHT = 'project'
78 _ENDING = 'by_user'
79 _TAB_MODE = 'st2'
80
81 def _GetProjectIDsForUpdates(self, mr):
82 """Returns a list of project IDs whom to retrieve activities from."""
83 with work_env.WorkEnv(mr, self.services) as we:
84 starred_projects = we.ListStarredProjects(
85 viewed_user_id=mr.viewed_user_auth.user_id)
86 return [project.project_id for project in starred_projects]
87
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010088 def GetUserUpdatesProjectsPage(self, **kwargs):
89 return self.handler(**kwargs)
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020090
Copybara854996b2021-09-07 19:36:02 +000091
92class UserUpdatesDevelopers(AbstractUserUpdatesPage):
93 """Shows a page of updates from developers starred by a user."""
94
95 _UPDATES_FEED_URL = urls.USER_UPDATES_DEVELOPERS
96 _UPDATES_PAGE_URL = urls.USER_UPDATES_DEVELOPERS
97 _HIGHLIGHT = 'user'
98 _ENDING = 'in_project'
99 _TAB_MODE = 'st3'
100
101 def _GetUserIDsForUpdates(self, mr):
102 """Returns a list of user IDs whom to retrieve activities from."""
103 user_ids = self.services.user_star.LookupStarredItemIDs(
104 mr.cnxn, mr.viewed_user_auth.user_id)
105 logging.debug('StarredUsers: %r', user_ids)
106 return user_ids
107
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +0100108 def GetUserUpdatesDevelopersPage(self, **kwargs):
109 return self.handler(**kwargs)
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +0200110
Copybara854996b2021-09-07 19:36:02 +0000111
112class UserUpdatesIndividual(AbstractUserUpdatesPage):
113 """Shows a page of updates initiated by a user."""
114
115 _UPDATES_FEED_URL = urls.USER_UPDATES_MINE + '/user'
116 _UPDATES_PAGE_URL = urls.USER_UPDATES_MINE
117 _HIGHLIGHT = 'project'
118 _TAB_MODE = 'st1'
119
120 def _GetUserIDsForUpdates(self, mr):
121 """Returns a list of user IDs whom to retrieve activities from."""
122 return [mr.viewed_user_auth.user_id]
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +0200123
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +0100124 def GetUserUpdatesPage(self, **kwargs):
125 return self.handler(**kwargs)