mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
org settings: Add realm level setting for missed message content in email.
This adds a setting under "Notification" section of "Organization settings" tab, which enables Organization administrator to control whether the missed message emails include the message content or not. Fixes: #11123.
This commit is contained in:
committed by
Tim Abbott
parent
bec875a9af
commit
1e811b42ec
@@ -683,6 +683,7 @@ run_test('set_up', () => {
|
||||
settings_org.render_notifications_stream_ui = noop;
|
||||
$("#id_realm_message_content_edit_limit_minutes").set_parent($.create('<stub edit limit parent>'));
|
||||
$("#id_realm_message_content_delete_limit_minutes").set_parent($.create('<stub delete limti parent>'));
|
||||
$("#message_content_in_email_notifications_label").set_parent($.create('<stub in-content setting checkbox>'));
|
||||
$("#id_realm_msg_edit_limit_setting").change = noop;
|
||||
$('#id_realm_msg_delete_limit_setting').change = noop;
|
||||
const parent_elem = $.create('waiting-period-parent-stub');
|
||||
|
||||
@@ -11,6 +11,8 @@ var admin_settings_label = {
|
||||
realm_inline_url_embed_preview: i18n.t("Show previews of linked websites"),
|
||||
realm_default_twenty_four_hour_time: i18n.t("24-hour time (17:00 instead of 5:00 PM)"),
|
||||
realm_send_welcome_emails: i18n.t("Send emails introducing Zulip to new users"),
|
||||
realm_message_content_allowed_in_email_notifications:
|
||||
i18n.t("Allow message content in missed message emails"),
|
||||
|
||||
// Organization permissions
|
||||
realm_name_changes_disabled: i18n.t("Prevent users from changing their name"),
|
||||
@@ -53,6 +55,8 @@ exports.build_page = function () {
|
||||
realm_logo_url: page_params.realm_logo_url,
|
||||
realm_mandatory_topics: page_params.realm_mandatory_topics,
|
||||
realm_send_welcome_emails: page_params.realm_send_welcome_emails,
|
||||
realm_message_content_allowed_in_email_notifications:
|
||||
page_params.realm_message_content_allowed_in_email_notifications,
|
||||
realm_default_twenty_four_hour_time: page_params.realm_default_twenty_four_hour_time,
|
||||
development: page_params.development_environment,
|
||||
};
|
||||
|
||||
@@ -111,6 +111,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
|
||||
name_changes_disabled: settings_account.update_name_change_display,
|
||||
notifications_stream_id: noop,
|
||||
send_welcome_emails: noop,
|
||||
message_content_allowed_in_email_notifications: noop,
|
||||
signup_notifications_stream_id: noop,
|
||||
emails_restricted_to_domains: noop,
|
||||
video_chat_provider: noop,
|
||||
|
||||
@@ -68,6 +68,9 @@ var org_settings = {
|
||||
send_welcome_emails: {
|
||||
type: 'bool',
|
||||
},
|
||||
message_content_allowed_in_email_notifications: {
|
||||
type: 'bool',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -338,6 +341,14 @@ function set_org_join_restrictions_dropdown() {
|
||||
}
|
||||
}
|
||||
|
||||
function set_message_content_in_email_notifications_visiblity() {
|
||||
if (page_params.realm_message_content_allowed_in_email_notifications) {
|
||||
$('#message_content_in_email_notifications_label').parent().show();
|
||||
} else {
|
||||
$('#message_content_in_email_notifications_label').parent().hide();
|
||||
}
|
||||
}
|
||||
|
||||
exports.populate_realm_domains = function (realm_domains) {
|
||||
if (!meta.loaded) {
|
||||
return;
|
||||
@@ -480,6 +491,8 @@ function update_dependent_subsettings(property_name) {
|
||||
set_org_join_restrictions_dropdown();
|
||||
} else if (property_name === 'realm_user_invite_restriction') {
|
||||
set_user_invite_restriction_dropdown();
|
||||
} else if (property_name === 'realm_message_content_allowed_in_email_notifications') {
|
||||
set_message_content_in_email_notifications_visiblity();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -617,6 +630,7 @@ exports.build_page = function () {
|
||||
set_msg_delete_limit_dropdown();
|
||||
set_org_join_restrictions_dropdown();
|
||||
set_user_invite_restriction_dropdown();
|
||||
set_message_content_in_email_notifications_visiblity();
|
||||
|
||||
function check_property_changed(elem) {
|
||||
elem = $(elem);
|
||||
|
||||
@@ -179,6 +179,12 @@
|
||||
"prefix" "id_"
|
||||
"is_checked" realm_send_welcome_emails
|
||||
"label" admin_settings_label.realm_send_welcome_emails}}
|
||||
|
||||
{{partial "settings_checkbox"
|
||||
"setting_name" "realm_message_content_allowed_in_email_notifications"
|
||||
"prefix" "id_"
|
||||
"is_checked" realm_message_content_allowed_in_email_notifications
|
||||
"label" admin_settings_label.realm_message_content_allowed_in_email_notifications}}
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
|
||||
@@ -251,6 +251,10 @@ def build_message_list(user_profile: UserProfile, messages: List[Message]) -> Li
|
||||
|
||||
return messages_to_render
|
||||
|
||||
def message_content_allowed_in_missedmessage_emails(user_profile: UserProfile) -> bool:
|
||||
return user_profile.realm.message_content_allowed_in_email_notifications and \
|
||||
user_profile.message_content_in_email_notifications
|
||||
|
||||
@statsd_increment("missed_message_reminders")
|
||||
def do_send_missedmessage_events_reply_in_zulip(user_profile: UserProfile,
|
||||
missed_messages: List[Dict[str, Any]],
|
||||
@@ -286,7 +290,7 @@ def do_send_missedmessage_events_reply_in_zulip(user_profile: UserProfile,
|
||||
'message_count': message_count,
|
||||
'unsubscribe_link': unsubscribe_link,
|
||||
'realm_name_in_notifications': user_profile.realm_name_in_notifications,
|
||||
'show_message_content': user_profile.message_content_in_email_notifications,
|
||||
'show_message_content': message_content_allowed_in_missedmessage_emails(user_profile)
|
||||
})
|
||||
|
||||
triggers = list(message['trigger'] for message in missed_messages)
|
||||
@@ -350,7 +354,7 @@ def do_send_missedmessage_events_reply_in_zulip(user_profile: UserProfile,
|
||||
raise AssertionError("Invalid messages!")
|
||||
|
||||
# If message content is disabled, then flush all information we pass to email.
|
||||
if not user_profile.message_content_in_email_notifications:
|
||||
if not message_content_allowed_in_missedmessage_emails(user_profile):
|
||||
context.update({
|
||||
'reply_to_zulip': False,
|
||||
'messages': [],
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.16 on 2019-01-07 11:46
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('zerver', '0202_add_user_status_info'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='realm',
|
||||
name='message_content_allowed_in_email_notifications',
|
||||
field=models.BooleanField(default=True),
|
||||
),
|
||||
]
|
||||
@@ -178,6 +178,7 @@ class Realm(models.Model):
|
||||
digest_emails_enabled = models.BooleanField(default=True) # type: bool
|
||||
|
||||
send_welcome_emails = models.BooleanField(default=True) # type: bool
|
||||
message_content_allowed_in_email_notifications = models.BooleanField(default=True) # type: bool
|
||||
|
||||
mandatory_topics = models.BooleanField(default=False) # type: bool
|
||||
create_stream_by_admins_only = models.BooleanField(default=False) # type: bool
|
||||
@@ -293,6 +294,7 @@ class Realm(models.Model):
|
||||
name_changes_disabled=bool,
|
||||
emails_restricted_to_domains=bool,
|
||||
send_welcome_emails=bool,
|
||||
message_content_allowed_in_email_notifications=bool,
|
||||
video_chat_provider=str,
|
||||
waiting_period_threshold=int,
|
||||
) # type: Dict[str, Union[type, Tuple[type, ...]]]
|
||||
|
||||
@@ -152,6 +152,7 @@ class HomeTest(ZulipTestCase):
|
||||
"realm_logo_source",
|
||||
"realm_logo_url",
|
||||
"realm_mandatory_topics",
|
||||
"realm_message_content_allowed_in_email_notifications",
|
||||
"realm_message_content_delete_limit_seconds",
|
||||
"realm_message_content_edit_limit_seconds",
|
||||
"realm_message_retention_days",
|
||||
|
||||
@@ -586,6 +586,38 @@ class TestMissedMessages(ZulipTestCase):
|
||||
def test_deleted_message_in_huddle_missed_stream_messages(self) -> None:
|
||||
self._deleted_message_in_huddle_missed_stream_messages(False)
|
||||
|
||||
def test_realm_message_content_allowed_in_email_notifications(self) -> None:
|
||||
user = self.example_user("hamlet")
|
||||
|
||||
# When message content is allowed at realm level
|
||||
realm = get_realm("zulip")
|
||||
realm.message_content_allowed_in_email_notifications = True
|
||||
realm.save(update_fields=['message_content_allowed_in_email_notifications'])
|
||||
|
||||
# Emails have missed message content when message content is enabled by the user
|
||||
do_change_notification_settings(user, "message_content_in_email_notifications", True)
|
||||
mail.outbox = []
|
||||
self._extra_context_in_personal_missed_stream_messages(False, show_message_content=True)
|
||||
|
||||
# Emails don't have missed message content when message content is disabled by the user
|
||||
do_change_notification_settings(user, "message_content_in_email_notifications", False)
|
||||
mail.outbox = []
|
||||
self._extra_context_in_personal_missed_stream_messages(False, show_message_content=False)
|
||||
|
||||
# When message content is not allowed at realm level
|
||||
# Emails don't have missed message irrespective of message content setting of the user
|
||||
realm = get_realm("zulip")
|
||||
realm.message_content_allowed_in_email_notifications = False
|
||||
realm.save(update_fields=['message_content_allowed_in_email_notifications'])
|
||||
|
||||
do_change_notification_settings(user, "message_content_in_email_notifications", True)
|
||||
mail.outbox = []
|
||||
self._extra_context_in_personal_missed_stream_messages(False, show_message_content=False)
|
||||
|
||||
do_change_notification_settings(user, "message_content_in_email_notifications", False)
|
||||
mail.outbox = []
|
||||
self._extra_context_in_personal_missed_stream_messages(False, show_message_content=False)
|
||||
|
||||
@patch('zerver.lib.email_mirror.generate_random_token')
|
||||
def test_realm_emoji_in_missed_message(self, mock_random_token: MagicMock) -> None:
|
||||
tokens = self._get_tokens()
|
||||
|
||||
@@ -59,6 +59,8 @@ def update_realm(
|
||||
signup_notifications_stream_id: Optional[int]=REQ(validator=check_int, default=None),
|
||||
message_retention_days: Optional[int]=REQ(converter=to_not_negative_int_or_none, default=None),
|
||||
send_welcome_emails: Optional[bool]=REQ(validator=check_bool, default=None),
|
||||
message_content_allowed_in_email_notifications:
|
||||
Optional[bool]=REQ(validator=check_bool, default=None),
|
||||
bot_creation_policy: Optional[int]=REQ(converter=to_not_negative_int_or_none, default=None),
|
||||
email_address_visibility: Optional[int]=REQ(converter=to_not_negative_int_or_none, default=None),
|
||||
default_twenty_four_hour_time: Optional[bool]=REQ(validator=check_bool, default=None),
|
||||
|
||||
Reference in New Issue
Block a user