settings: Add email_address_visbility user setting.

This commit is contained in:
Sahil Batra 2021-10-21 14:06:57 +05:30 committed by Tim Abbott
parent 2396e6858f
commit ea0b2286e0
9 changed files with 128 additions and 0 deletions

View File

@ -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 to * [`GET /events`](/api/get-events): Event for updating `delivery_email` is now sent to
all users who have access to it and is also sent when `email_address_visibility` setting all users who have access to it and is also sent when `email_address_visibility` setting
changes. changes.
* [`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** **Feature level 162**

View File

@ -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),
),
]

View File

@ -1620,6 +1620,26 @@ class UserBaseSettings(models.Model):
send_private_typing_notifications = models.BooleanField(default=True) send_private_typing_notifications = models.BooleanField(default=True)
send_read_receipts = 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( display_settings_legacy = dict(
# Don't add anything new to this legacy dict. # Don't add anything new to this legacy dict.
# Instead, see `modern_settings` below. # Instead, see `modern_settings` below.
@ -1667,6 +1687,7 @@ class UserBaseSettings(models.Model):
modern_settings = dict( modern_settings = dict(
# Add new general settings here. # Add new general settings here.
display_emoji_reaction_users=bool, display_emoji_reaction_users=bool,
email_address_visibility=int,
escape_navigates_to_default_view=bool, escape_navigates_to_default_view=bool,
send_private_typing_notifications=bool, send_private_typing_notifications=bool,
send_read_receipts=bool, send_read_receipts=bool,

View File

@ -9163,6 +9163,31 @@ paths:
schema: schema:
type: boolean type: boolean
example: true example: 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: 1
responses: responses:
"200": "200":
description: Success description: Success
@ -11118,6 +11143,8 @@ paths:
read messages. read messages.
**Changes**: New in Zulip 5.0 (feature level 105). **Changes**: New in Zulip 5.0 (feature level 105).
email_address_visibility:
$ref: "#/components/schemas/EmailAddressVisibility"
user_topics: user_topics:
type: array type: array
description: | description: |
@ -13066,6 +13093,8 @@ paths:
read messages. read messages.
**Changes**: New in Zulip 5.0 (feature level 105). **Changes**: New in Zulip 5.0 (feature level 105).
email_address_visibility:
$ref: "#/components/schemas/EmailAddressVisibility"
realm_users: realm_users:
type: array type: array
description: | description: |
@ -14198,6 +14227,31 @@ paths:
schema: schema:
type: boolean type: boolean
example: true example: 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: 1
responses: responses:
"200": "200":
description: Success description: Success
@ -16367,6 +16421,22 @@ components:
in the default stream group. in the default stream group.
items: items:
$ref: "#/components/schemas/BasicStream" $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-levels
EmojiReaction: EmojiReaction:
allOf: allOf:
- $ref: "#/components/schemas/EmojiReactionBase" - $ref: "#/components/schemas/EmojiReactionBase"

View File

@ -2698,6 +2698,7 @@ class RealmPropertyActionTest(BaseAction):
desktop_icon_count_display=[1, 2, 3], desktop_icon_count_display=[1, 2, 3],
notification_sound=["zulip", "ding"], notification_sound=["zulip", "ding"],
email_notifications_batching_period_seconds=[120, 300], email_notifications_batching_period_seconds=[120, 300],
email_address_visibility=UserProfile.EMAIL_ADDRESS_VISIBILITY_TYPES,
) )
vals = test_values.get(name) vals = test_values.get(name)
@ -2770,6 +2771,7 @@ class UserDisplayActionTest(BaseAction):
demote_inactive_streams=[2, 3, 1], demote_inactive_streams=[2, 3, 1],
user_list_style=[1, 2, 3], user_list_style=[1, 2, 3],
color_scheme=[2, 3, 1], color_scheme=[2, 3, 1],
email_address_visibility=[5, 4, 1, 2, 3],
) )
user_settings_object = True user_settings_object = True

View File

@ -1245,6 +1245,7 @@ class RealmAPITest(ZulipTestCase):
desktop_icon_count_display=[1, 2, 3], desktop_icon_count_display=[1, 2, 3],
notification_sound=["zulip", "ding"], notification_sound=["zulip", "ding"],
email_notifications_batching_period_seconds=[120, 300], email_notifications_batching_period_seconds=[120, 300],
email_address_visibility=UserProfile.EMAIL_ADDRESS_VISIBILITY_TYPES,
) )
vals = test_values.get(name) vals = test_values.get(name)

View File

@ -361,6 +361,7 @@ class ChangeSettingsTest(ZulipTestCase):
email_notifications_batching_period_seconds=100, email_notifications_batching_period_seconds=100,
notification_sound="ding", notification_sound="ding",
desktop_icon_count_display=2, desktop_icon_count_display=2,
email_address_visibility=3,
) )
self.login("hamlet") self.login("hamlet")

View File

@ -472,6 +472,9 @@ def update_realm_user_settings_defaults(
user_list_style: Optional[int] = REQ( user_list_style: Optional[int] = REQ(
json_validator=check_int_in(UserProfile.USER_LIST_STYLE_CHOICES), default=None 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: ) -> HttpResponse:
if notification_sound is not None or email_notifications_batching_period_seconds is not None: 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) check_settings_values(notification_sound, email_notifications_batching_period_seconds)

View File

@ -222,6 +222,9 @@ def json_change_settings(
user_list_style: Optional[int] = REQ( user_list_style: Optional[int] = REQ(
json_validator=check_int_in(UserProfile.USER_LIST_STYLE_CHOICES), default=None 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: ) -> HttpResponse:
if ( if (
default_language is not None default_language is not None