OLD | NEW |
(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 """A class to display a paginated list of project members. |
| 7 |
| 8 This page lists owners, members, and contribtors. For each |
| 9 member, we display their username, permission system role + extra |
| 10 perms, and notes on their involvement in the project. |
| 11 """ |
| 12 |
| 13 import logging |
| 14 import time |
| 15 |
| 16 from third_party import ezt |
| 17 |
| 18 from framework import framework_bizobj |
| 19 from framework import framework_constants |
| 20 from framework import framework_helpers |
| 21 from framework import framework_views |
| 22 from framework import paginate |
| 23 from framework import permissions |
| 24 from framework import servlet |
| 25 from framework import urls |
| 26 from project import project_helpers |
| 27 from project import project_views |
| 28 |
| 29 MEMBERS_PER_PAGE = 50 |
| 30 |
| 31 |
| 32 class PeopleList(servlet.Servlet): |
| 33 """People list page shows a paginatied list of project members.""" |
| 34 |
| 35 _PAGE_TEMPLATE = 'project/people-list-page.ezt' |
| 36 _MAIN_TAB_MODE = servlet.Servlet.MAIN_TAB_PEOPLE |
| 37 |
| 38 def AssertBasePermission(self, mr): |
| 39 super(PeopleList, self).AssertBasePermission(mr) |
| 40 # For now, contributors who cannot view other contributors are further |
| 41 # restricted from viewing any part of the member list or detail pages. |
| 42 if not permissions.CanViewContributorList(mr): |
| 43 raise permissions.PermissionException( |
| 44 'User is not allowed to view the project people list') |
| 45 |
| 46 def GatherPageData(self, mr): |
| 47 """Build up a dictionary of data values to use when rendering the page.""" |
| 48 all_members = (mr.project.owner_ids + |
| 49 mr.project.committer_ids + |
| 50 mr.project.contributor_ids) |
| 51 |
| 52 with self.profiler.Phase('gathering members on this page'): |
| 53 users_by_id = framework_views.MakeAllUserViews( |
| 54 mr.cnxn, self.services.user, all_members) |
| 55 framework_views.RevealAllEmailsToMembers(mr, users_by_id) |
| 56 |
| 57 # TODO(jrobbins): re-implement FindUntrustedGroups() |
| 58 untrusted_user_group_proxies = [] |
| 59 |
| 60 with self.profiler.Phase('gathering commitments (notes)'): |
| 61 project_commitments = self.services.project.GetProjectCommitments( |
| 62 mr.cnxn, mr.project_id) |
| 63 |
| 64 with self.profiler.Phase('making member views'): |
| 65 owner_views = self._MakeMemberViews( |
| 66 mr.auth.user_id, users_by_id, mr.project.owner_ids, mr.project, |
| 67 project_commitments) |
| 68 committer_views = self._MakeMemberViews( |
| 69 mr.auth.user_id, users_by_id, mr.project.committer_ids, mr.project, |
| 70 project_commitments) |
| 71 contributor_views = self._MakeMemberViews( |
| 72 mr.auth.user_id, users_by_id, mr.project.contributor_ids, mr.project, |
| 73 project_commitments) |
| 74 all_member_views = owner_views + committer_views + contributor_views |
| 75 |
| 76 pagination = paginate.ArtifactPagination( |
| 77 mr, all_member_views, MEMBERS_PER_PAGE, urls.PEOPLE_LIST) |
| 78 |
| 79 offer_membership_editing = mr.perms.HasPerm( |
| 80 permissions.EDIT_PROJECT, mr.auth.user_id, mr.project) |
| 81 |
| 82 check_abandonment = permissions.ShouldCheckForAbandonment(mr) |
| 83 |
| 84 return { |
| 85 'pagination': pagination, |
| 86 'subtab_mode': None, |
| 87 'offer_membership_editing': ezt.boolean(offer_membership_editing), |
| 88 'initial_add_members': '', |
| 89 'initially_expand_form': ezt.boolean(False), |
| 90 'untrusted_user_groups': untrusted_user_group_proxies, |
| 91 'check_abandonment': ezt.boolean(check_abandonment), |
| 92 'total_num_owners': len(mr.project.owner_ids), |
| 93 } |
| 94 |
| 95 def GatherHelpData(self, mr, _page_data): |
| 96 """Return a dict of values to drive on-page user help. |
| 97 |
| 98 Args: |
| 99 mr: common information parsed from the HTTP request. |
| 100 _page_data: Dictionary of base and page template data. |
| 101 |
| 102 Returns: |
| 103 A dict of values to drive on-page user help, to be added to page_data. |
| 104 """ |
| 105 cue = None |
| 106 if (mr.auth.user_id and |
| 107 not framework_bizobj.UserIsInProject( |
| 108 mr.project, mr.auth.effective_ids) and |
| 109 'how_to_join_project' not in mr.auth.user_pb.dismissed_cues): |
| 110 cue = 'how_to_join_project' |
| 111 |
| 112 return {'cue': cue} |
| 113 |
| 114 def _MakeMemberViews( |
| 115 self, logged_in_user_id, users_by_id, member_ids, project, |
| 116 project_commitments): |
| 117 """Return a sorted list of MemberViews for display by EZT.""" |
| 118 member_views = [ |
| 119 project_views.MemberView( |
| 120 logged_in_user_id, member_id, users_by_id[member_id], project, |
| 121 project_commitments) |
| 122 for member_id in member_ids] |
| 123 member_views.sort(key=lambda mv: mv.user.email) |
| 124 return member_views |
| 125 |
| 126 def ProcessFormData(self, mr, post_data): |
| 127 """Process the posted form.""" |
| 128 permit_edit = mr.perms.HasPerm( |
| 129 permissions.EDIT_PROJECT, mr.auth.user_id, mr.project) |
| 130 if not permit_edit: |
| 131 raise permissions.PermissionException( |
| 132 'User is not permitted to edit project membership') |
| 133 |
| 134 if 'addbtn' in post_data: |
| 135 return self.ProcessAddMembers(mr, post_data) |
| 136 elif 'removebtn' in post_data: |
| 137 return self.ProcessRemoveMembers(mr, post_data) |
| 138 |
| 139 def ProcessAddMembers(self, mr, post_data): |
| 140 """Process the user's request to add members. |
| 141 |
| 142 Args: |
| 143 mr: common information parsed from the HTTP request. |
| 144 post_data: dictionary of form data. |
| 145 |
| 146 Returns: |
| 147 String URL to redirect the user to after processing. |
| 148 """ |
| 149 # 1. Parse and validate user input. |
| 150 new_member_ids = project_helpers.ParseUsernames( |
| 151 mr.cnxn, self.services.user, post_data.get('addmembers')) |
| 152 role = post_data['role'] |
| 153 |
| 154 owner_ids, committer_ids, contributor_ids = project_helpers.MembersWith( |
| 155 mr.project, new_member_ids, role) |
| 156 |
| 157 total_people = len(owner_ids) + len(committer_ids) + len(contributor_ids) |
| 158 if total_people > framework_constants.MAX_PROJECT_PEOPLE: |
| 159 mr.errors.addmembers = ( |
| 160 'Too many project members. The combined limit is %d.' % |
| 161 framework_constants.MAX_PROJECT_PEOPLE) |
| 162 |
| 163 # 2. Call services layer to save changes. |
| 164 if not mr.errors.AnyErrors(): |
| 165 self.services.project.UpdateProjectRoles( |
| 166 mr.cnxn, mr.project.project_id, |
| 167 owner_ids, committer_ids, contributor_ids) |
| 168 |
| 169 # 3. Determine the next page in the UI flow. |
| 170 if mr.errors.AnyErrors(): |
| 171 add_members_str = post_data.get('addmembers', '') |
| 172 self.PleaseCorrect( |
| 173 mr, initial_add_members=add_members_str, initially_expand_form=True) |
| 174 else: |
| 175 return framework_helpers.FormatAbsoluteURL( |
| 176 mr, urls.PEOPLE_LIST, saved=1, ts=int(time.time())) |
| 177 |
| 178 def ProcessRemoveMembers(self, mr, post_data): |
| 179 """Process the user's request to remove members. |
| 180 |
| 181 Args: |
| 182 mr: common information parsed from the HTTP request. |
| 183 post_data: dictionary of form data. |
| 184 |
| 185 Returns: |
| 186 String URL to redirect the user to after processing. |
| 187 """ |
| 188 # 1. Parse and validate user input. |
| 189 remove_strs = post_data.getall('remove') |
| 190 logging.info('remove_strs = %r', remove_strs) |
| 191 remove_ids = set( |
| 192 self.services.user.LookupUserIDs(mr.cnxn, remove_strs).values()) |
| 193 owner_ids, committer_ids, contributor_ids = project_helpers.MembersWithout( |
| 194 mr.project, remove_ids) |
| 195 |
| 196 # 2. Call services layer to save changes. |
| 197 self.services.project.UpdateProjectRoles( |
| 198 mr.cnxn, mr.project.project_id, owner_ids, committer_ids, |
| 199 contributor_ids) |
| 200 |
| 201 # 3. Determine the next page in the UI flow. |
| 202 return framework_helpers.FormatAbsoluteURL( |
| 203 mr, urls.PEOPLE_LIST, saved=1, ts=int(time.time())) |
OLD | NEW |