blob: 7609a96de90f0d68844a22549528349acd33b357 [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"""Some constants used throughout Monorail."""
6from __future__ import print_function
7from __future__ import division
8from __future__ import absolute_import
9
10import os
11import re
12
13
14# Number of seconds in various periods.
15SECS_PER_MINUTE = 60
16SECS_PER_HOUR = SECS_PER_MINUTE * 60
17SECS_PER_DAY = SECS_PER_HOUR * 24
18SECS_PER_MONTH = SECS_PER_DAY * 30
19SECS_PER_YEAR = SECS_PER_DAY * 365
20
21# When we write to memcache, let the values expire so that we don't
22# get any unexpected super-old values as we make code changes over the
23# years. Also, searches can contain date terms like [opened<today-1]
24# that would become wrong if cached for a long time.
25CACHE_EXPIRATION = 6 * SECS_PER_HOUR
26
27# Fulltext indexing happens asynchronously and we get no notification
28# when the indexing operation has completed. So, when we cache searches
29# that use fulltext terms, the results might be stale. We still do
30# cache them and use the cached values, but we expire them so that the
31# results cannot be stale for a long period of time.
32FULLTEXT_MEMCACHE_EXPIRATION = 3 * SECS_PER_MINUTE
33
34# Size in bytes of the largest form submission that we will accept
35MAX_POST_BODY_SIZE = 10 * 1024 * 1024 # = 10 MB
36
37# Special issue ID to use when an issue is explicitly not specified.
38NO_ISSUE_SPECIFIED = 0
39
40# Special user ID and name to use when no user was specified.
41NO_USER_SPECIFIED = 0
42NO_SESSION_SPECIFIED = 0
43NO_USER_NAME = '----'
44DELETED_USER_NAME = 'a_deleted_user'
45DELETED_USER_ID = 1
46USER_NOT_FOUND_NAME = 'user_not_found'
47
48# Queues for deleting users tasks.
49QUEUE_SEND_WIPEOUT_USER_LISTS = 'wipeoutsendusers'
50QUEUE_FETCH_WIPEOUT_DELETED_USERS = 'wipeoutdeleteusers'
51QUEUE_DELETE_USERS = 'deleteusers'
52
53# We remember the time of each user's last page view, but to reduce the
54# number of database writes, we only update it if it is newer by an hour.
55VISIT_RESOLUTION = 1 * SECS_PER_HOUR
56
57# String to display when some field has no value.
58NO_VALUES = '----'
59
60# If the user enters one or more dashes, that means "no value". This is useful
61# in bulk edit, inbound email, and commit log command where a blank field
62# means "keep what was there" or is ignored.
63NO_VALUE_RE = re.compile(r'^-+$')
64
65# Used to loosely validate column spec. Mainly guards against malicious input.
66COLSPEC_RE = re.compile(r'^[-.\w\s/]*$', re.UNICODE)
67COLSPEC_COL_RE = re.compile(r'[-.\w/]+', re.UNICODE)
68MAX_COL_PARTS = 25
69MAX_COL_LEN = 50
70
71# Used to loosely validate sort spec. Mainly guards against malicious input.
72SORTSPEC_RE = re.compile(r'^[-.\w\s/]*$', re.UNICODE)
73MAX_SORT_PARTS = 6
74
75# For the artifact search box autosizing when the user types a long query.
76MIN_ARTIFACT_SEARCH_FIELD_SIZE = 38
77MAX_ARTIFACT_SEARCH_FIELD_SIZE = 75
78AUTOSIZE_STEP = 3
79
80# Regular expressions used in parsing label and status configuration text
81IDENTIFIER_REGEX = r'[-.\w]+'
82IDENTIFIER_RE = re.compile(IDENTIFIER_REGEX, re.UNICODE)
83# Labels and status values that are prefixed by a pound-sign are not displayed
84# in autocomplete menus.
85IDENTIFIER_DOCSTRING_RE = re.compile(
86 r'^(#?%s)[ \t]*=?[ \t]*(.*)$' % IDENTIFIER_REGEX,
87 re.MULTILINE | re.UNICODE)
88
89# Number of label text fields that we can display on a web form for issues.
90MAX_LABELS = 24
91
92# Default number of comments to display on an artifact detail page at one time.
93# Other comments will be paginated.
94DEFAULT_COMMENTS_PER_PAGE = 100
95
96# Content type to use when serving JSON.
97CONTENT_TYPE_JSON = 'application/json; charset=UTF-8'
98CONTENT_TYPE_JSON_OPTIONS = 'nosniff'
99
100# Maximum comments to index to keep the search index from choking. E.g., if an
101# artifact had 1200 comments, only 0..99 and 701..1200 would be indexed.
102# This mainly affects advocacy issues which are highly redundant anyway.
103INITIAL_COMMENTS_TO_INDEX = 100
104FINAL_COMMENTS_TO_INDEX = 500
105
106# This is the longest string that GAE search will accept in one field.
107# The entire search document is also limited to 1MB, so our limit is 200 * 1024
108# chars so that each can be 4 bytes and the comments leave room for metadata.
109# https://cloud.google.com/appengine/docs/standard/python/search/#documents
110MAX_FTS_FIELD_SIZE = 200 * 1024
111
112# Base path to EZT templates.
113this_dir = os.path.dirname(__file__)
114TEMPLATE_PATH = this_dir[:this_dir.rindex('/')] + '/templates/'
115
116# Defaults for dooming a project.
117DEFAULT_DOOM_REASON = 'No longer needed'
118DEFAULT_DOOM_PERIOD = SECS_PER_DAY * 90
119
120MAX_PROJECT_PEOPLE = 1000
121
122MAX_HOTLIST_NAME_LENGTH = 80
123
124# When logging potentially long debugging strings, only show this many chars.
125LOGGING_MAX_LENGTH = 2000
126
127# Maps languages supported by google-code-prettify
128# to the class name that should be added to code blocks in that language.
129# This list should be kept in sync with the handlers registered
130# in lang-*.js and prettify.js from the prettify project.
131PRETTIFY_CLASS_MAP = {
132 ext: 'lang-' + ext
133 for ext in [
134 # Supported in lang-*.js
135 'apollo', 'agc', 'aea', 'lisp', 'el', 'cl', 'scm',
136 'css', 'go', 'hs', 'lua', 'fs', 'ml', 'proto', 'scala', 'sql', 'vb',
137 'vbs', 'vhdl', 'vhd', 'wiki', 'yaml', 'yml', 'clj',
138 # Supported in prettify.js
139 'htm', 'html', 'mxml', 'xhtml', 'xml', 'xsl',
140 'c', 'cc', 'cpp', 'cxx', 'cyc', 'm',
141 'json', 'cs', 'java', 'bsh', 'csh', 'sh', 'cv', 'py', 'perl', 'pl',
142 'pm', 'rb', 'js', 'coffee',
143 ]}
144
145# Languages which are not specifically mentioned in prettify.js
146# but which render intelligibly with the default handler.
147PRETTIFY_CLASS_MAP.update(
148 (ext, '') for ext in [
149 'hpp', 'hxx', 'hh', 'h', 'inl', 'idl', 'swig', 'd',
150 'php', 'tcl', 'aspx', 'cfc', 'cfm',
151 'ent', 'mod', 'as',
152 'y', 'lex', 'awk', 'n', 'pde',
153 ])
154
155# Languages which are not specifically mentioned in prettify.js
156# but which should be rendered using a certain prettify module.
157PRETTIFY_CLASS_MAP.update({
158 'docbook': 'lang-xml',
159 'dtd': 'lang-xml',
160 'duby': 'lang-rb',
161 'mk': 'lang-sh',
162 'mak': 'lang-sh',
163 'make': 'lang-sh',
164 'mirah': 'lang-rb',
165 'ss': 'lang-lisp',
166 'vcproj': 'lang-xml',
167 'xsd': 'lang-xml',
168 'xslt': 'lang-xml',
169})
170
171PRETTIFY_FILENAME_CLASS_MAP = {
172 'makefile': 'lang-sh',
173 'makefile.in': 'lang-sh',
174 'doxyfile': 'lang-sh', # Key-value pairs with hash comments
175 '.checkstyle': 'lang-xml',
176 '.classpath': 'lang-xml',
177 '.project': 'lang-xml',
178}
179
180OAUTH_SCOPE = 'https://www.googleapis.com/auth/userinfo.email'
181MONORAIL_SCOPE = 'https://www.googleapis.com/auth/monorail'
182
183FILENAME_RE = re.compile('^[-_.a-zA-Z0-9 #+()]+$')