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 | """Protocol buffers for Monorail usergroups.""" |
| 6 | |
| 7 | from __future__ import print_function |
| 8 | from __future__ import division |
| 9 | from __future__ import absolute_import |
| 10 | |
| 11 | from protorpc import messages |
| 12 | |
| 13 | |
| 14 | class 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 | |
| 21 | class 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 | |
| 29 | class 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 | |
| 43 | def 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 |