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 """Classes for the user projects feed.""" |
| 7 |
| 8 from framework import jsonfeed |
| 9 from sitewide import sitewide_helpers |
| 10 |
| 11 |
| 12 class ProjectsJsonFeed(jsonfeed.JsonFeed): |
| 13 """Servlet to get all of a user's projects in JSON format.""" |
| 14 |
| 15 def HandleRequest(self, mr): |
| 16 """Retrieve list of a user's projects for the "My projects" menu. |
| 17 |
| 18 Args: |
| 19 mr: common information parsed from the HTTP request. |
| 20 |
| 21 Returns: |
| 22 Results dictionary in JSON format |
| 23 """ |
| 24 if not mr.auth.user_id: |
| 25 return {'error': 'User is not logged in.'} |
| 26 |
| 27 json_data = {} |
| 28 |
| 29 with self.profiler.Phase('page processing'): |
| 30 json_data.update(self._GatherProjects(mr)) |
| 31 |
| 32 return json_data |
| 33 |
| 34 def _GatherProjects(self, mr): |
| 35 """Return a dict of project names the current user is involved in.""" |
| 36 with self.profiler.Phase('GetUserProjects'): |
| 37 project_lists = sitewide_helpers.GetUserProjects( |
| 38 mr.cnxn, self.services, mr.auth.user_pb, mr.auth.effective_ids, |
| 39 mr.auth.effective_ids) |
| 40 (visible_ownership, _visible_deleted, visible_membership, |
| 41 visible_contrib) = project_lists |
| 42 |
| 43 with self.profiler.Phase('GetStarredProjects'): |
| 44 starred_projects = sitewide_helpers.GetViewableStarredProjects( |
| 45 mr.cnxn, self.services, mr.auth.user_id, |
| 46 mr.auth.effective_ids, mr.auth.user_pb) |
| 47 |
| 48 projects_dict = { |
| 49 'memberof': [p.project_name for p in visible_membership], |
| 50 'ownerof': [p.project_name for p in visible_ownership], |
| 51 'contributorto': [p.project_name for p in visible_contrib], |
| 52 'starred_projects': [p.project_name for p in starred_projects], |
| 53 } |
| 54 |
| 55 return projects_dict |
OLD | NEW |