Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: appengine/monorail/sitewide/userprofile.py

Issue 1868553004: Open Source Monorail (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is govered 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 the user profile page ("my page")."""
7
8 import logging
9 import time
10
11 from third_party import ezt
12
13 from framework import framework_helpers
14 from framework import framework_views
15 from framework import permissions
16 from framework import servlet
17 from project import project_views
18 from sitewide import sitewide_helpers
19
20
21 class AbstractUserPage(servlet.Servlet):
22 """Base class for UserProfile and UserUpdates pages."""
23
24 _PAGE_TEMPLATE = None
25
26 def GatherPageData(self, mr):
27 """Build up a dictionary of data values to use when rendering the page."""
28 raise NotImplementedError()
29
30
31 class UserProfile(AbstractUserPage):
32 """Shows a page of information about a user."""
33
34 _PAGE_TEMPLATE = 'sitewide/user-profile-page.ezt'
35
36 def GatherPageData(self, mr):
37 """Build up a dictionary of data values to use when rendering the page."""
38 viewing_self = mr.viewed_user_auth.user_id == mr.auth.user_id
39
40 if self.services.usergroup.GetGroupSettings(
41 mr.cnxn, mr.viewed_user_auth.user_id):
42 url = framework_helpers.FormatAbsoluteURL(
43 mr, '/g/%s/' % mr.viewed_user_auth.user_pb.email,
44 include_project=False)
45 self.redirect(url, abort=True) # Show group page instead.
46
47 with self.profiler.Phase('GetUserProjects'):
48 project_lists = sitewide_helpers.GetUserProjects(
49 mr.cnxn, self.services, mr.auth.user_pb, mr.auth.effective_ids,
50 mr.viewed_user_auth.effective_ids)
51
52 (visible_ownership, visible_archived, visible_membership,
53 visible_contrib) = project_lists
54
55 # Do not obscure email if current user is a site admin. Do not obscure
56 # email if current user is viewing his/her own profile. For all other
57 # cases do whatever obscure_email setting for the user is.
58 email_obscured = (not(mr.auth.user_pb.is_site_admin or viewing_self)
59 and mr.viewed_user_auth.user_view.obscure_email)
60 if email_obscured:
61 _, domain, obscured_username = framework_views.ParseAndObscureAddress(
62 mr.viewed_user_auth.email)
63 viewed_user_display_name = '%s...@%s' % (obscured_username, domain)
64 else:
65 viewed_user_display_name = mr.viewed_user_auth.email
66
67 with self.profiler.Phase('GetStarredProjects'):
68 starred_projects = sitewide_helpers.GetViewableStarredProjects(
69 mr.cnxn, self.services, mr.viewed_user_auth.user_id,
70 mr.auth.effective_ids, mr.auth.user_pb)
71
72 logged_in_starred_pids = []
73 if mr.auth.user_id:
74 logged_in_starred_pids = self.services.project_star.LookupStarredItemIDs(
75 mr.cnxn, mr.auth.user_id)
76
77 starred_user_ids = self.services.user_star.LookupStarredItemIDs(
78 mr.cnxn, mr.viewed_user_auth.user_id)
79 starred_user_dict = framework_views.MakeAllUserViews(
80 mr.cnxn, self.services.user, starred_user_ids)
81 starred_users = starred_user_dict.values()
82
83 is_user_starred = self._IsUserStarred(
84 mr.cnxn, mr.auth.user_id, mr.viewed_user_auth.user_id)
85
86 page_data = {
87 'user_tab_mode': 'st2',
88 'viewed_user_display_name': viewed_user_display_name,
89 'viewed_user_is_banned': ezt.boolean(
90 mr.viewed_user_auth.user_pb.banned),
91 'viewed_user_ignore_action_limits': (
92 ezt.boolean(mr.viewed_user_auth.user_pb.ignore_action_limits)),
93 'owner_of_projects': [
94 project_views.ProjectView(
95 p, starred=p.project_id in logged_in_starred_pids)
96 for p in visible_ownership],
97 'committer_of_projects': [
98 project_views.ProjectView(
99 p, starred=p.project_id in logged_in_starred_pids)
100 for p in visible_membership],
101 'contributor_to_projects': [
102 project_views.ProjectView(
103 p, starred=p.project_id in logged_in_starred_pids)
104 for p in visible_contrib],
105 'owner_of_archived_projects': [
106 project_views.ProjectView(p) for p in visible_archived],
107 'starred_projects': [
108 project_views.ProjectView(
109 p, starred=p.project_id in logged_in_starred_pids)
110 for p in starred_projects],
111 'starred_users': starred_users,
112 'is_user_starred': ezt.boolean(is_user_starred),
113 'viewing_user_page': ezt.boolean(True),
114 }
115
116 settings = framework_helpers.UserSettings.GatherUnifiedSettingsPageData(
117 mr.auth.user_id, mr.viewed_user_auth.user_view,
118 mr.viewed_user_auth.user_pb)
119 page_data.update(settings)
120
121 return page_data
122
123 def _IsUserStarred(self, cnxn, logged_in_user_id, viewed_user_id):
124 """Return whether the logged in user starred the viewed user."""
125 if logged_in_user_id:
126 return self.services.user_star.IsItemStarredBy(
127 cnxn, viewed_user_id, logged_in_user_id)
128 return False
129
130 def ProcessFormData(self, mr, post_data):
131 """Process the posted form."""
132 has_admin_perm = mr.perms.HasPerm(permissions.ADMINISTER_SITE, None, None)
133 framework_helpers.UserSettings.ProcessSettingsForm(
134 mr.cnxn, self.services.user, post_data, mr.viewed_user_auth.user_id,
135 mr.viewed_user_auth.user_pb, admin=has_admin_perm)
136
137 # TODO(jrobbins): Check all calls to FormatAbsoluteURL for include_project.
138 return framework_helpers.FormatAbsoluteURL(
139 mr, mr.viewed_user_auth.user_view.profile_url, include_project=False,
140 saved=1, ts=int(time.time()))
OLDNEW
« no previous file with comments | « appengine/monorail/sitewide/test/userupdates_test.py ('k') | appengine/monorail/sitewide/userprojects.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698