blob: 330ab73677804ca0cf3a42f5cc15e11587e0dfb7 [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"""Page for showing a user's hotlists."""
7from __future__ import print_function
8from __future__ import division
9from __future__ import absolute_import
10
11import ezt
12
13from features import features_bizobj
14from features import hotlist_views
15from framework import framework_views
16from framework import servlet
17
18
19class UserHotlists(servlet.Servlet):
20 """Servlet to display all of a user's hotlists."""
21
22 _PAGE_TEMPLATE = 'features/user-hotlists.ezt'
23
24 def GatherPageData(self, mr):
25 viewed_users_hotlists = self.services.features.GetHotlistsByUserID(
26 mr.cnxn, mr.viewed_user_auth.user_id)
27
28 viewed_starred_hids = self.services.hotlist_star.LookupStarredItemIDs(
29 mr.cnxn, mr.viewed_user_auth.user_id)
30 viewed_users_starred_hotlists, _ = self.services.features.GetHotlistsByID(
31 mr.cnxn, viewed_starred_hids)
32
33 viewed_users_relevant_hotlists = viewed_users_hotlists + list(
34 set(viewed_users_starred_hotlists.values()) -
35 set(viewed_users_hotlists))
36
37 users_by_id = framework_views.MakeAllUserViews(
38 mr.cnxn, self.services.user,
39 features_bizobj.UsersInvolvedInHotlists(viewed_users_relevant_hotlists))
40
41 views = [hotlist_views.HotlistView(
42 hotlist_pb, mr.perms, mr.auth, mr.viewed_user_auth.user_id,
43 users_by_id, self.services.hotlist_star.IsItemStarredBy(
44 mr.cnxn, hotlist_pb.hotlist_id, mr.auth.user_id))
45 for hotlist_pb in viewed_users_relevant_hotlists]
46
47 # visible to viewer, not viewed_user
48 visible_hotlists = [view for view in views if view.visible]
49
50 owner_of_hotlists = [hotlist_view for hotlist_view in visible_hotlists
51 if hotlist_view.role_name == 'owner']
52 editor_of_hotlists = [hotlist_view for hotlist_view in visible_hotlists
53 if hotlist_view.role_name == 'editor']
54 follower_of_hotlists = [hotlist_view for hotlist_view in visible_hotlists
55 if hotlist_view.role_name == '']
56 starred_hotlists = [hotlist_view for hotlist_view in visible_hotlists
57 if hotlist_view.hotlist_id in viewed_starred_hids]
58
59 viewed_user_display_name = framework_views.GetViewedUserDisplayName(mr)
60
61 return {
62 'user_tab_mode': 'st6',
63 'viewed_user_display_name': viewed_user_display_name,
64 'owner_of_hotlists': owner_of_hotlists,
65 'editor_of_hotlists': editor_of_hotlists,
66 'follower_of_hotlists': follower_of_hotlists,
67 'starred_hotlists': starred_hotlists,
68 'viewing_user_page': ezt.boolean(True),
69 }
70
71 def GatherHelpData(self, mr, page_data):
72 """Return a dict of values to drive on-page user help.
73
74 Args:
75 mr: common information parsed from the HTTP request.
76 page_data: Dictionary of base and page template data.
77
78 Returns:
79 A dict of values to drive on-page user help, to be added to page_data.
80 """
81 help_data = super(UserHotlists, self).GatherHelpData(mr, page_data)
82 help_data['cue'] = 'explain_hotlist_starring'
83 return help_data