Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
settings: Add email_address_visbility user setting.
Sahil Batraea0b2286e00c
diff --git a/api_docs/changelog.md b/api_docs/changelog.mdindex 69b739360ee..222f0fe344a 100644--- a/api_docs/changelog.md+++ b/api_docs/changelog.md@@ -32,6 +32,11 @@ format used by the Zulip server that they are interacting with.* [`GET /events`](/api/get-events): Event for updating `delivery_email` is now sent toall users who have access to it and is also sent when `email_address_visibility` settingchanges.+* [`POST /register`](/api/register-queue), [`PATCH+ /settings`](/api/update-settings), [`PATCH+ /realm/user_settings_defaults`](/api/update-realm-user-settings-defaults): Added+ user setting `email_address_visibility` which will replace the existing realm+ setting `email_address_visibility`.**Feature level 162**diff --git a/zerver/migrations/0426_add_email_address_visibility_setting.py b/zerver/migrations/0426_add_email_address_visibility_setting.pynew file mode 100644index 00000000000..cb9de7b88f0--- /dev/null+++ b/zerver/migrations/0426_add_email_address_visibility_setting.py@@ -0,0 +1,22 @@+# Generated by Django 3.2.8 on 2021-10-21 07:23++from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("zerver", "0425_realm_move_messages_between_streams_limit_seconds"),+ ]++ operations = [+ migrations.AddField(+ model_name="realmuserdefault",+ name="email_address_visibility",+ field=models.PositiveSmallIntegerField(default=1),+ ),+ migrations.AddField(+ model_name="userprofile",+ name="email_address_visibility",+ field=models.PositiveSmallIntegerField(default=1),+ ),+ ]diff --git a/zerver/models.py b/zerver/models.pyindex 40f5c8254d5..80949f47522 100644--- a/zerver/models.py+++ b/zerver/models.py@@ -1620,6 +1620,26 @@ class UserBaseSettings(models.Model):send_private_typing_notifications = models.BooleanField(default=True)send_read_receipts = models.BooleanField(default=True)+ # Who in the organization has access to users' actual email+ # addresses. Controls whether the UserProfile.email field is+ # the same as UserProfile.delivery_email, or is instead a fake+ # generated value encoding the user ID and realm hostname.+ EMAIL_ADDRESS_VISIBILITY_EVERYONE = 1+ EMAIL_ADDRESS_VISIBILITY_MEMBERS = 2+ EMAIL_ADDRESS_VISIBILITY_ADMINS = 3+ EMAIL_ADDRESS_VISIBILITY_NOBODY = 4+ EMAIL_ADDRESS_VISIBILITY_MODERATORS = 5+ email_address_visibility = models.PositiveSmallIntegerField(+ default=EMAIL_ADDRESS_VISIBILITY_EVERYONE,+ )+ EMAIL_ADDRESS_VISIBILITY_TYPES = [+ EMAIL_ADDRESS_VISIBILITY_EVERYONE,+ EMAIL_ADDRESS_VISIBILITY_MEMBERS,+ EMAIL_ADDRESS_VISIBILITY_ADMINS,+ EMAIL_ADDRESS_VISIBILITY_NOBODY,+ EMAIL_ADDRESS_VISIBILITY_MODERATORS,+ ]+display_settings_legacy = dict(# Don't add anything new to this legacy dict.# Instead, see `modern_settings` below.@@ -1667,6 +1687,7 @@ class UserBaseSettings(models.Model):modern_settings = dict(# Add new general settings here.display_emoji_reaction_users=bool,+ email_address_visibility=int,escape_navigates_to_default_view=bool,send_private_typing_notifications=bool,send_read_receipts=bool,diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 1187393309d..7cfc8433266 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -9163,6 +9163,31 @@ paths:schema:type: booleanexample: true+ - name: email_address_visibility+ in: query+ description: |+ The [policy][permission-level] this user has selected for which other+ users in this organization can see the real email address of this user.++ - 1 = Everyone+ - 2 = Members only+ - 3 = Administrators only+ - 4 = Nobody+ - 5 = Moderators only++ **Changes**: New in Zulip 7.0 (feature level 163) replacing the existing+ realm-level setting.++ [permission-level]: /api/roles-and-permissions#permission-levels+ schema:+ type: integer+ enum:+ - 1+ - 2+ - 3+ - 4+ - 5+ example: 1responses:"200":description: Success@@ -11118,6 +11143,8 @@ paths:read messages.**Changes**: New in Zulip 5.0 (feature level 105).+ email_address_visibility:+ $ref: "#/components/schemas/EmailAddressVisibility"user_topics:type: arraydescription: |@@ -13066,6 +13093,8 @@ paths:read messages.**Changes**: New in Zulip 5.0 (feature level 105).+ email_address_visibility:+ $ref: "#/components/schemas/EmailAddressVisibility"realm_users:type: arraydescription: |@@ -14198,6 +14227,31 @@ paths:schema:type: booleanexample: true+ - name: email_address_visibility+ in: query+ description: |+ The [policy][permission-level] this user has selected for which other+ users in this organization can see the real email address of this user.++ - 1 = Everyone+ - 2 = Members only+ - 3 = Administrators only+ - 4 = Nobody+ - 5 = Moderators only++ **Changes**: New in Zulip 7.0 (feature level 163) replacing the existing+ realm-level setting.++ [permission-level]: /api/roles-and-permissions#permission-levels+ schema:+ type: integer+ enum:+ - 1+ - 2+ - 3+ - 4+ - 5+ example: 1responses:"200":description: Success@@ -16367,6 +16421,22 @@ components:in the default stream group.items:$ref: "#/components/schemas/BasicStream"+ EmailAddressVisibility:+ type: integer+ description: |+ The [policy][permission-level] this user has selected for which other+ users in this organization can see the real email address of this user.++ - 1 = Everyone+ - 2 = Members only+ - 3 = Administrators only+ - 4 = Nobody+ - 5 = Moderators only++ **Changes**: New in Zulip 7.0 (feature level 163) replacing the existing+ realm-level setting.++ [permission-level]: /api/roles-and-permissions#permission-levelsEmojiReaction:allOf:- $ref: "#/components/schemas/EmojiReactionBase"diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.pyindex 00fe86cc3e3..e964ce3f997 100644--- a/zerver/tests/test_events.py+++ b/zerver/tests/test_events.py@@ -2698,6 +2698,7 @@ class RealmPropertyActionTest(BaseAction):desktop_icon_count_display=[1, 2, 3],notification_sound=["zulip", "ding"],email_notifications_batching_period_seconds=[120, 300],+ email_address_visibility=UserProfile.EMAIL_ADDRESS_VISIBILITY_TYPES,)vals = test_values.get(name)@@ -2770,6 +2771,7 @@ class UserDisplayActionTest(BaseAction):demote_inactive_streams=[2, 3, 1],user_list_style=[1, 2, 3],color_scheme=[2, 3, 1],+ email_address_visibility=[5, 4, 1, 2, 3],)user_settings_object = Truediff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.pyindex d77bf9d5f12..941da6912f2 100644--- a/zerver/tests/test_realm.py+++ b/zerver/tests/test_realm.py@@ -1245,6 +1245,7 @@ class RealmAPITest(ZulipTestCase):desktop_icon_count_display=[1, 2, 3],notification_sound=["zulip", "ding"],email_notifications_batching_period_seconds=[120, 300],+ email_address_visibility=UserProfile.EMAIL_ADDRESS_VISIBILITY_TYPES,)vals = test_values.get(name)diff --git a/zerver/tests/test_settings.py b/zerver/tests/test_settings.pyindex d5fa1c9b3ea..617a969d8d3 100644--- a/zerver/tests/test_settings.py+++ b/zerver/tests/test_settings.py@@ -361,6 +361,7 @@ class ChangeSettingsTest(ZulipTestCase):email_notifications_batching_period_seconds=100,notification_sound="ding",desktop_icon_count_display=2,+ email_address_visibility=3,)self.login("hamlet")diff --git a/zerver/views/realm.py b/zerver/views/realm.pyindex 822f7b80a70..9953b0fdda2 100644--- a/zerver/views/realm.py+++ b/zerver/views/realm.py@@ -472,6 +472,9 @@ def update_realm_user_settings_defaults(user_list_style: Optional[int] = REQ(json_validator=check_int_in(UserProfile.USER_LIST_STYLE_CHOICES), default=None),+ email_address_visibility: Optional[int] = REQ(+ json_validator=check_int_in(UserProfile.EMAIL_ADDRESS_VISIBILITY_TYPES), default=None+ ),) -> HttpResponse:if notification_sound is not None or email_notifications_batching_period_seconds is not None:check_settings_values(notification_sound, email_notifications_batching_period_seconds)diff --git a/zerver/views/user_settings.py b/zerver/views/user_settings.pyindex 88d6b37b8de..7074f7ddd28 100644--- a/zerver/views/user_settings.py+++ b/zerver/views/user_settings.py@@ -222,6 +222,9 @@ def json_change_settings(user_list_style: Optional[int] = REQ(json_validator=check_int_in(UserProfile.USER_LIST_STYLE_CHOICES), default=None),+ email_address_visibility: Optional[int] = REQ(+ json_validator=check_int_in(UserProfile.EMAIL_ADDRESS_VISIBILITY_TYPES), default=None+ ),) -> HttpResponse:if (default_language is not None