Coverage for app/backend/src/couchers/constants.py: 100%

51 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-21 21:52 +0000

1from datetime import UTC, datetime, timedelta 

2 

3# terms of service version 

4TOS_VERSION = 2 

5 

6# community guidelines version 

7GUIDELINES_VERSION = 1 

8 

9# When updating this, also update the "activeness_probe" notification strings in 

10# src/couchers/email/locales/en.json 

11LATEST_RELEASE_BLOG_URL = "https://couchers.org/blog/2026/05/25/couchers-spring-release" 

12 

13EMAIL_REGEX = r"^[0-9a-z]([0-9a-z\-\_\+]|(\.[0-9a-z\-\_\+]))*@([0-9a-z\-]+\.)*[0-9a-z\-]+\.[a-z]{2,}$" 

14 

15# Must match the frontend values in app/web/utils/validation.ts 

16VALID_NAME_MIN_LENGTH = 2 

17VALID_NAME_MAX_LENGTH = 100 

18 

19# Letters, diacritics, internal spaces, quotes, dashes, commas, dots, and's for two names. See tests! 

20VALID_NAME_REGEX = r"""^(?!\p{Zs})[\p{L}\p{M}\p{Zs}\p{Pi}\p{Pf}\p{Pd},.'"·・&/|]+(?<!\p{Zs})$""" 

21 

22BANNED_USERNAME_PHRASES = [ 

23 "admin", 

24 "bot", 

25 "safety", 

26 "security", 

27 "secure", 

28 "trust", 

29 "couchers", 

30 "help", 

31 "moderation", 

32 "moderator", 

33 "noreply", 

34 "official", 

35 "security", 

36 "staff", 

37 "support", 

38 "system", 

39 "team", 

40 "verify", 

41] 

42 

43# expiry time for a verified phone number 

44PHONE_VERIFICATION_LIFETIME = timedelta(days=2 * 365) 

45 

46# shortest period between phone verification code requests 

47PHONE_REVERIFICATION_INTERVAL = timedelta(days=2) 

48 

49# expiry time for an sms code 

50SMS_CODE_LIFETIME = timedelta(hours=24) 

51 

52# max attempts to enter the sms code 

53SMS_CODE_ATTEMPTS = 3 

54 

55# Postal verification constants 

56POSTAL_VERIFICATION_CODE_LENGTH = 6 

57# Reduced alphabet to avoid confusion (no I, O, 0, 1) 

58POSTAL_VERIFICATION_CODE_ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789" 

59# Code valid for 90 days after postcard sent 

60POSTAL_VERIFICATION_CODE_LIFETIME = timedelta(days=90) 

61# Max wrong code attempts before lockout 

62POSTAL_VERIFICATION_MAX_ATTEMPTS = 5 

63# Can only initiate once per 30 days 

64POSTAL_VERIFICATION_RATE_LIMIT = timedelta(days=30) 

65 

66SIGNUP_EMAIL_TOKEN_VALIDITY = timedelta(hours=48) 

67 

68DATETIME_MINUS_INFINITY = datetime(1, 1, 1, tzinfo=UTC) 

69DATETIME_INFINITY = datetime(9876, 12, 31, hour=23, minute=59, second=59, tzinfo=UTC) 

70 

71# the api workers listen on API_BASE_PORT .. API_BASE_PORT + API_WORKER_COUNT - 1; must stay in sync with 

72# proxy/envoy.yaml and docker-compose.prod.yml 

73API_WORKER_COUNT = 4 

74API_BASE_PORT = 1761 

75MEDIA_PORT = 1753 

76 

77# per API worker process; kept small since we parallelize across processes (API_WORKER_COUNT), not threads 

78SERVER_THREADS = 8 

79 

80# on SIGTERM, how long to let in-flight RPCs drain before the server is forced down; kept under the 

81# container's stop_grace_period (docker-compose stop_grace_period: 30s) so workers drain, not SIGKILLed 

82GRACEFUL_SHUTDOWN_TIMEOUT = 5 

83 

84# how long the user has to undelete their account 

85UNDELETE_DAYS = 7 

86 

87# expiry time for preferred language cookie 

88PREFERRED_LANGUAGE_COOKIE_EXPIRY = timedelta(days=3650) 

89 

90 

91# activeness probe settings 

92# wait about 11 months before sending one out 

93ACTIVENESS_PROBE_INACTIVITY_PERIOD = timedelta(days=333) 

94# times at which to send notifications after inactivity (cumulative since start of probe) 

95ACTIVENESS_PROBE_TIME_REMINDERS = [timedelta(days=0), timedelta(days=2, hours=8)] 

96# total time from initiation after which to expire the probe 

97ACTIVENESS_PROBE_EXPIRY_TIME = timedelta(days=4) 

98 

99HOST_REQUEST_MAX_REMINDERS = 1 

100HOST_REQUEST_REMINDER_INTERVAL = timedelta(days=2) 

101 

102# Note: Javascript's string.length is in utf16 code units, Python's len(str) is in utf8 code units. 

103HOST_REQUEST_MIN_LENGTH_UTF16 = 250 # Must match frontend 

104PUBLIC_TRIP_DESCRIPTION_MIN_LENGTH_UTF16 = 150 # Must match frontend 

105 

106ANTIBOT_FREQ = timedelta(hours=48) 

107 

108EVENT_REMINDER_TIMEDELTA = timedelta(hours=24) 

109 

110COMMUNITIES_SEARCH_FUZZY_SIMILARITY_THRESHOLD = 0.35 

111 

112UNKNOWN_ERROR_MESSAGE = "An unknown backend error occurred. Please consider filing a bug!" 

113 

114# NOTE: these codes are on purpose not translatable 

115NONEXISTENT_API_CALL_ERROR_MESSAGE = "API call does not exist. Please refresh and try again." 

116MISSING_AUTH_LEVEL_ERROR_MESSAGE = "Internal authentication error." 

117COOKIES_AND_AUTH_HEADER_ERROR_MESSAGE = 'Both "cookie" and "authorization" in request' 

118CALL_CANCELLED_ERROR_MESSAGE = "Call cancelled." 

119 

120# NOTE: the frontend uses these (and error codes) to distinguish between jailed and logged out 

121UNAUTHORIZED_ERROR_MESSAGE = "Unauthorized" 

122PERMISSION_DENIED_ERROR_MESSAGE = "Permission denied" 

123 

124GHOST_USERNAME = "ghost" 

125 

126# Photo gallery limits 

127GALLERY_MAX_PHOTOS_NOT_VERIFIED = 2 

128GALLERY_MAX_PHOTOS_VERIFIED = 5 

129 

130COMPLETED_PROFILE_MINIMUM_CHAR_LENGTH = 150 

131 

132# How long a container must run uninterrupted before /status reports stable=true 

133STABLE_THRESHOLD_SECONDS = 5 * 60 

134 

135MODERATION_AUTO_APPROVE_FLAG_PRIORITY = 1000