blob: 33f53c351134d5d155df0980efa93e4087ba850d [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001# Copyright 2016 The Chromium Authors. All rights reserved.
2# Use of this source code is governed 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"""Helper functions used in sitewide servlets."""
7from __future__ import print_function
8from __future__ import division
9from __future__ import absolute_import
10
11import logging
12
13from framework import permissions
14from proto import project_pb2
15
16
17def GetViewableStarredProjects(
18 cnxn, services, viewed_user_id, effective_ids, logged_in_user):
19 """Returns a list of viewable starred projects."""
20 starred_project_ids = services.project_star.LookupStarredItemIDs(
21 cnxn, viewed_user_id)
22 projects = list(
23 services.project.GetProjects(cnxn, starred_project_ids).values())
24 viewable_projects = FilterViewableProjects(
25 projects, logged_in_user, effective_ids)
26 return viewable_projects
27
28
29def FilterViewableProjects(project_list, logged_in_user, effective_ids):
30 """Return subset of LIVE project protobufs viewable by the given user."""
31 viewable_projects = []
32 for project in project_list:
33 if (project.state == project_pb2.ProjectState.LIVE and
34 permissions.UserCanViewProject(
35 logged_in_user, effective_ids, project)):
36 viewable_projects.append(project)
37
38 return viewable_projects