mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 18:06:44 +00:00
signups: Use internal_send_stream_message().
We prefer this to internal_send_message(). We are trying to deprecate `internal_send_message`, which has extra moving parts related to `extract_recipients` and `Addressee.legacy_build`. There are two chunks of code that I touch here that look pretty similar, but I'm not quite sure they're worth de-duplicating, since they use different topics and different message content.
This commit is contained in:
@@ -390,7 +390,7 @@ python_rules = RuleList(
|
|||||||
# This one in check_message is kinda terrible, since it's
|
# This one in check_message is kinda terrible, since it's
|
||||||
# how most instances are written, but better to exclude something than nothing
|
# how most instances are written, but better to exclude something than nothing
|
||||||
('zerver/lib/actions.py', 'stream = get_stream(stream_name, realm)'),
|
('zerver/lib/actions.py', 'stream = get_stream(stream_name, realm)'),
|
||||||
('zerver/lib/actions.py', 'get_stream("signups", admin_realm)'),
|
('zerver/lib/actions.py', 'return get_stream("signups", realm)'),
|
||||||
]),
|
]),
|
||||||
'description': 'Please use access_stream_by_*() to fetch Stream objects',
|
'description': 'Please use access_stream_by_*() to fetch Stream objects',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -254,6 +254,10 @@ def realm_user_count_by_role(realm: Realm) -> Dict[str, Any]:
|
|||||||
RealmAuditLog.ROLE_COUNT_BOTS: bot_count,
|
RealmAuditLog.ROLE_COUNT_BOTS: bot_count,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def get_signups_stream(realm: Realm) -> Stream:
|
||||||
|
# This one-liner helps us work around a lint rule.
|
||||||
|
return get_stream("signups", realm)
|
||||||
|
|
||||||
def notify_new_user(user_profile: UserProfile) -> None:
|
def notify_new_user(user_profile: UserProfile) -> None:
|
||||||
sender_email = settings.NOTIFICATION_BOT
|
sender_email = settings.NOTIFICATION_BOT
|
||||||
sender = get_system_bot(sender_email)
|
sender = get_system_bot(sender_email)
|
||||||
@@ -263,11 +267,10 @@ def notify_new_user(user_profile: UserProfile) -> None:
|
|||||||
# Send notification to realm signup notifications stream if it exists
|
# Send notification to realm signup notifications stream if it exists
|
||||||
# Don't send notification for the first user in a realm
|
# Don't send notification for the first user in a realm
|
||||||
if signup_notifications_stream is not None and user_count > 1:
|
if signup_notifications_stream is not None and user_count > 1:
|
||||||
internal_send_message(
|
internal_send_stream_message(
|
||||||
user_profile.realm,
|
user_profile.realm,
|
||||||
sender_email,
|
sender,
|
||||||
"stream",
|
signup_notifications_stream,
|
||||||
signup_notifications_stream.name,
|
|
||||||
"signups",
|
"signups",
|
||||||
"@_**%s|%s** just signed up for Zulip. (total: %i)" % (
|
"@_**%s|%s** just signed up for Zulip. (total: %i)" % (
|
||||||
user_profile.full_name, user_profile.id, user_count
|
user_profile.full_name, user_profile.id, user_count
|
||||||
@@ -278,17 +281,11 @@ def notify_new_user(user_profile: UserProfile) -> None:
|
|||||||
admin_realm = sender.realm
|
admin_realm = sender.realm
|
||||||
try:
|
try:
|
||||||
# Check whether the stream exists
|
# Check whether the stream exists
|
||||||
get_stream("signups", admin_realm)
|
signups_stream = get_signups_stream(admin_realm)
|
||||||
except Stream.DoesNotExist:
|
internal_send_stream_message(
|
||||||
# If the signups stream hasn't been created in the admin
|
|
||||||
# realm, don't auto-create it to send to it; just do nothing.
|
|
||||||
return
|
|
||||||
|
|
||||||
internal_send_message(
|
|
||||||
admin_realm,
|
admin_realm,
|
||||||
sender_email,
|
sender,
|
||||||
"stream",
|
signups_stream,
|
||||||
"signups",
|
|
||||||
user_profile.realm.display_subdomain,
|
user_profile.realm.display_subdomain,
|
||||||
"%s <`%s`> just signed up for Zulip! (total: **%i**)" % (
|
"%s <`%s`> just signed up for Zulip! (total: **%i**)" % (
|
||||||
user_profile.full_name,
|
user_profile.full_name,
|
||||||
@@ -297,6 +294,11 @@ def notify_new_user(user_profile: UserProfile) -> None:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
except Stream.DoesNotExist:
|
||||||
|
# If the signups stream hasn't been created in the admin
|
||||||
|
# realm, don't auto-create it to send to it; just do nothing.
|
||||||
|
pass
|
||||||
|
|
||||||
def notify_invites_changed(user_profile: UserProfile) -> None:
|
def notify_invites_changed(user_profile: UserProfile) -> None:
|
||||||
event = dict(type="invites_changed")
|
event = dict(type="invites_changed")
|
||||||
admin_ids = [user.id for user in
|
admin_ids = [user.id for user in
|
||||||
@@ -3788,9 +3790,24 @@ def do_create_realm(string_id: str, name: str,
|
|||||||
|
|
||||||
# Send a notification to the admin realm
|
# Send a notification to the admin realm
|
||||||
signup_message = "Signups enabled"
|
signup_message = "Signups enabled"
|
||||||
admin_realm = get_system_bot(settings.NOTIFICATION_BOT).realm
|
sender = get_system_bot(settings.NOTIFICATION_BOT)
|
||||||
internal_send_message(admin_realm, settings.NOTIFICATION_BOT, "stream",
|
admin_realm = sender.realm
|
||||||
"signups", realm.display_subdomain, signup_message)
|
|
||||||
|
try:
|
||||||
|
signups_stream = get_signups_stream(admin_realm)
|
||||||
|
topic = realm.display_subdomain
|
||||||
|
|
||||||
|
internal_send_stream_message(
|
||||||
|
admin_realm,
|
||||||
|
sender,
|
||||||
|
signups_stream,
|
||||||
|
topic,
|
||||||
|
signup_message
|
||||||
|
)
|
||||||
|
except Stream.DoesNotExist: # nocoverage
|
||||||
|
# If the signups stream hasn't been created in the admin
|
||||||
|
# realm, don't auto-create it to send to it; just do nothing.
|
||||||
|
pass
|
||||||
return realm
|
return realm
|
||||||
|
|
||||||
def do_change_notification_settings(user_profile: UserProfile, name: str,
|
def do_change_notification_settings(user_profile: UserProfile, name: str,
|
||||||
|
|||||||
Reference in New Issue
Block a user