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