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