Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 1 | # 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. |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 4 | |
| 5 | """Helper functions used in sitewide servlets.""" |
| 6 | from __future__ import print_function |
| 7 | from __future__ import division |
| 8 | from __future__ import absolute_import |
| 9 | |
| 10 | import logging |
| 11 | |
| 12 | from framework import permissions |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 13 | from mrproto import project_pb2 |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 14 | |
| 15 | |
| 16 | def GetViewableStarredProjects( |
| 17 | cnxn, services, viewed_user_id, effective_ids, logged_in_user): |
| 18 | """Returns a list of viewable starred projects.""" |
| 19 | starred_project_ids = services.project_star.LookupStarredItemIDs( |
| 20 | cnxn, viewed_user_id) |
| 21 | projects = list( |
| 22 | services.project.GetProjects(cnxn, starred_project_ids).values()) |
| 23 | viewable_projects = FilterViewableProjects( |
| 24 | projects, logged_in_user, effective_ids) |
| 25 | return viewable_projects |
| 26 | |
| 27 | |
| 28 | def FilterViewableProjects(project_list, logged_in_user, effective_ids): |
| 29 | """Return subset of LIVE project protobufs viewable by the given user.""" |
| 30 | viewable_projects = [] |
| 31 | for project in project_list: |
| 32 | if (project.state == project_pb2.ProjectState.LIVE and |
| 33 | permissions.UserCanViewProject( |
| 34 | logged_in_user, effective_ids, project)): |
| 35 | viewable_projects.append(project) |
| 36 | |
| 37 | return viewable_projects |