blob: b6ef76fd2f8473c8afc5bba395edca70a9319069 [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"""Protocol buffers for Monorail usergroups."""
7
8from __future__ import print_function
9from __future__ import division
10from __future__ import absolute_import
11
12from protorpc import messages
13
14
15class MemberVisibility(messages.Enum):
16 """Enum controlling who can see the members of a user group."""
17 OWNERS = 0
18 MEMBERS = 1
19 ANYONE = 2
20
21
22class GroupType(messages.Enum):
23 """Type of external group to import."""
24 CHROME_INFRA_AUTH = 0
25 MDB = 1
26 BAGGINS = 3
27 COMPUTED = 4
28
29
30class UserGroupSettings(messages.Message):
31 """In-memory busines object for representing user group settings."""
32 who_can_view_members = messages.EnumField(
33 MemberVisibility, 1, default=MemberVisibility.MEMBERS)
34 ext_group_type = messages.EnumField(GroupType, 2)
35 last_sync_time = messages.IntegerField(
36 3, default=0, variant=messages.Variant.INT32)
37 friend_projects = messages.IntegerField(
38 4, repeated=True, variant=messages.Variant.INT32)
39 notify_members = messages.BooleanField(5, default=True)
40 notify_group = messages.BooleanField(6, default=False)
41# TODO(jrobbins): add settings to control who can join, etc.
42
43
44def MakeSettings(who_can_view_members_str, ext_group_type_str=None,
45 last_sync_time=0, friend_projects=None, notify_members=True,
46 notify_group=False):
47 """Create and return a new user record in RAM."""
48 settings = UserGroupSettings(
49 who_can_view_members=MemberVisibility(who_can_view_members_str.upper()),
50 notify_members=notify_members, notify_group=notify_group)
51 if ext_group_type_str:
52 settings.ext_group_type = GroupType(ext_group_type_str.upper())
53 settings.last_sync_time = last_sync_time
54 settings.friend_projects = friend_projects or []
55 return settings