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