blob: de1aa6ee7a96916b47415a9995d7b836a81c2a9b [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 users."""
6
7from __future__ import print_function
8from __future__ import division
9from __future__ import absolute_import
10
11from protorpc import messages
12
13
14class IssueUpdateNav(messages.Enum):
15 """Pref for where a project member goes after an issue update."""
16 UP_TO_LIST = 0 # Back to issue list or grid view.
17 STAY_SAME_ISSUE = 1 # Show the same issue with the update.
18 NEXT_IN_LIST = 2 # Triage mode: go to next issue, if any.
19
20
21class User(messages.Message):
22 """In-memory busines object for representing users."""
23 user_id = messages.IntegerField(1) # TODO(jrobbins): make it required.
24
25 # Is this user a site administer?
26 is_site_admin = messages.BooleanField(4, required=True, default=False)
27
28 # User notification preferences. These preferences describe when
29 # a user is sent a email notification after an issue has changed.
30 # The user is notified if either of the following is true:
31 # 1. notify_issue_change is True and the user is named in the
32 # issue's Owner or CC field.
33 # 2. notify_starred_issue_change is True and the user has starred
34 # the issue.
35 notify_issue_change = messages.BooleanField(5, default=True)
36 notify_starred_issue_change = messages.BooleanField(6, default=True)
37 # Opt-in to email subject lines like "proj:123: issue summary".
38 email_compact_subject = messages.BooleanField(14, default=False)
39 # Opt-out of "View Issue" button in Gmail inbox.
40 email_view_widget = messages.BooleanField(15, default=True)
41 # Opt-in to ping emails from issues that the user starred.
42 notify_starred_ping = messages.BooleanField(16, default=False)
43
44 # This user has been banned, and this string describes why. All access
45 # to Monorail pages should be disabled.
46 banned = messages.StringField(7, default='')
47
48 # Fields 8-13 are no longer used: they were User action counts and limits.
49
50 after_issue_update = messages.EnumField(
51 IssueUpdateNav, 29, default=IssueUpdateNav.STAY_SAME_ISSUE)
52
53 # Should we obfuscate the user's email address and require solving a captcha
54 # to reveal it entirely? The default value corresponds to requiring users to
55 # opt into publishing their identities, but our code ensures that the
56 # opposite takes place for Gmail accounts.
57 obscure_email = messages.BooleanField(26, default=True)
58
59 # The email address chosen by the user to reveal on the site.
60 email = messages.StringField(27)
61
62 # Sticky state for show/hide widget on people details page.
63 keep_people_perms_open = messages.BooleanField(33, default=False)
64
65 deleted = messages.BooleanField(39, default=False)
66 deleted_timestamp = messages.IntegerField(40, default=0)
67
68 preview_on_hover = messages.BooleanField(42, default=True)
69
70 last_visit_timestamp = messages.IntegerField(45, default=0)
71 email_bounce_timestamp = messages.IntegerField(46, default=0)
72 vacation_message = messages.StringField(47)
73
74 linked_parent_id = messages.IntegerField(48)
75 linked_child_ids = messages.IntegerField(49, repeated=True)
76
77
78class UserPrefValue(messages.Message):
79 """Holds a single non-default user pref."""
80 name = messages.StringField(1, required=True)
81 value = messages.StringField(2)
82
83
84class UserPrefs(messages.Message):
85 """In-memory business object for representing user preferences."""
86 user_id = messages.IntegerField(1, required=True)
87 prefs = messages.MessageField(UserPrefValue, 2, repeated=True)
88
89
90
91def MakeUser(user_id, email=None, obscure_email=False):
92 """Create and return a new user record in RAM."""
93 user = User(user_id=user_id, obscure_email=bool(obscure_email))
94 if email:
95 user.email = email
96 return user