blob: b4490027a596857e209d046b2bbd2bc552c15f27 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# 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.
Copybara854996b2021-09-07 19:36:02 +00004
5"""Helper functions used in sitewide servlets."""
6from __future__ import print_function
7from __future__ import division
8from __future__ import absolute_import
9
10import logging
11
12from framework import permissions
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010013from mrproto import project_pb2
Copybara854996b2021-09-07 19:36:02 +000014
15
16def 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
28def 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