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