blob: 333d8430efc589a6389fa4e057c7317b815c5744 [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"""Page for showing a user's hotlists."""
6from __future__ import print_function
7from __future__ import division
8from __future__ import absolute_import
9
10import ezt
11
12from features import features_bizobj
13from features import hotlist_views
14from framework import framework_views
15from framework import servlet
16
17
18class UserHotlists(servlet.Servlet):
19 """Servlet to display all of a user's hotlists."""
20
21 _PAGE_TEMPLATE = 'features/user-hotlists.ezt'
22
23 def GatherPageData(self, mr):
24 viewed_users_hotlists = self.services.features.GetHotlistsByUserID(
25 mr.cnxn, mr.viewed_user_auth.user_id)
26
27 viewed_starred_hids = self.services.hotlist_star.LookupStarredItemIDs(
28 mr.cnxn, mr.viewed_user_auth.user_id)
29 viewed_users_starred_hotlists, _ = self.services.features.GetHotlistsByID(
30 mr.cnxn, viewed_starred_hids)
31
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010032 viewed_users_relevant_hotlists = viewed_users_hotlists + [
33 hotlist for hotlist in viewed_users_starred_hotlists.values()
34 if hotlist not in viewed_users_hotlists
35 ]
Copybara854996b2021-09-07 19:36:02 +000036
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
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020084
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010085 def GetUserHotlistsPage(self, **kwargs):
86 return self.handler(**kwargs)
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020087
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010088 def PostUserHotlistsPage(self, **kwargs):
89 return self.handler(**kwargs)