From c51c1d513568c583127be5612aae449ec551f46e Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Wed, 13 Sep 2023 16:47:00 +0530 Subject: [PATCH] realm: Add setting to control adding "(guest)" indicator to name. This commit adds new realm setting to control adding "(guest)" indicator to names of guest users in the UI. Fixes part of #26700. --- api_docs/changelog.md | 6 ++++++ version.py | 2 +- web/src/admin.js | 4 ++++ web/src/server_events_dispatch.js | 1 + .../settings/organization_permissions_admin.hbs | 6 ++++++ .../0478_realm_enable_guest_user_indicator.py | 17 +++++++++++++++++ zerver/models.py | 4 ++++ zerver/openapi/zulip.yaml | 16 ++++++++++++++++ zerver/tests/test_home.py | 1 + zerver/views/realm.py | 1 + 10 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 zerver/migrations/0478_realm_enable_guest_user_indicator.py diff --git a/api_docs/changelog.md b/api_docs/changelog.md index d15a954b74..bce83f7c5e 100644 --- a/api_docs/changelog.md +++ b/api_docs/changelog.md @@ -20,6 +20,12 @@ format used by the Zulip server that they are interacting with. ## Changes in Zulip 8.0 +**Feature level 216**: + +* `PATCH /realm`, [`POST register`](/api/register-queue), + [`GET /events`](/api/get-events): Added `enable_guest_user_indicator` + setting to control whether "(guest)" is added to user names in UI. + **Feature level 215** * [`GET /events`](/api/get-events): Replaced the value `private` diff --git a/version.py b/version.py index b86e1316fb..7c9ed2b5a5 100644 --- a/version.py +++ b/version.py @@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.9.3" # Changes should be accompanied by documentation explaining what the # new level means in api_docs/changelog.md, as well as "**Changes**" # entries in the endpoint's documentation in `zulip.yaml`. -API_FEATURE_LEVEL = 215 +API_FEATURE_LEVEL = 216 # Bump the minor PROVISION_VERSION to indicate that folks should provision # only when going from an old version of the code to a newer version. Bump diff --git a/web/src/admin.js b/web/src/admin.js index 59af1821e0..4e1110b9d9 100644 --- a/web/src/admin.js +++ b/web/src/admin.js @@ -61,6 +61,9 @@ const admin_settings_label = { realm_enable_read_receipts_parens_text: $t({ defaultMessage: "Users can always disable their personal read receipts.", }), + realm_enable_guest_user_indicator: $t({ + defaultMessage: "Display “(guest)” after names of guest users", + }), }; function insert_tip_box() { @@ -216,6 +219,7 @@ export function build_page() { settings_config.automatically_follow_or_unmute_topics_policy_values, automatically_unmute_topics_in_muted_streams_policy_values: settings_config.automatically_follow_or_unmute_topics_policy_values, + realm_enable_guest_user_indicator: page_params.realm_enable_guest_user_indicator, }; if (options.realm_logo_source !== "D" && options.realm_night_logo_source === "D") { diff --git a/web/src/server_events_dispatch.js b/web/src/server_events_dispatch.js index 4cd921a931..5061fd90ea 100644 --- a/web/src/server_events_dispatch.js +++ b/web/src/server_events_dispatch.js @@ -242,6 +242,7 @@ export function dispatch_normal_event(event) { want_advertise_in_communities_directory: noop, wildcard_mention_policy: noop, enable_read_receipts: settings_account.update_send_read_receipts_tooltip, + enable_guest_user_indicator: noop, }; switch (event.op) { case "update": diff --git a/web/templates/settings/organization_permissions_admin.hbs b/web/templates/settings/organization_permissions_admin.hbs index 633e8b34c2..57dd62fc92 100644 --- a/web/templates/settings/organization_permissions_admin.hbs +++ b/web/templates/settings/organization_permissions_admin.hbs @@ -85,6 +85,12 @@ prefix="id_" is_checked=realm_avatar_changes_disabled label=admin_settings_label.realm_avatar_changes_disabled}} + + {{> settings_checkbox + setting_name="realm_enable_guest_user_indicator" + prefix="id_" + is_checked=realm_enable_guest_user_indicator + label=admin_settings_label.realm_enable_guest_user_indicator}} diff --git a/zerver/migrations/0478_realm_enable_guest_user_indicator.py b/zerver/migrations/0478_realm_enable_guest_user_indicator.py new file mode 100644 index 0000000000..5c828f0d65 --- /dev/null +++ b/zerver/migrations/0478_realm_enable_guest_user_indicator.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.5 on 2023-09-13 11:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("zerver", "0477_alter_realmuserdefault_automatically_follow_topics_policy_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="realm", + name="enable_guest_user_indicator", + field=models.BooleanField(default=True), + ), + ] diff --git a/zerver/models.py b/zerver/models.py index d1565fdae6..461405bd1a 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -712,6 +712,9 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub # they will not be available regardless of users' personal settings. enable_read_receipts = models.BooleanField(default=False) + # Whether clients should display "(guest)" after names of guest users. + enable_guest_user_indicator = models.BooleanField(default=True) + # Duplicates of names for system group; TODO: Clean this up. ADMINISTRATORS_GROUP_NAME = "role:administrators" @@ -735,6 +738,7 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub edit_topic_policy=int, email_changes_disabled=bool, emails_restricted_to_domains=bool, + enable_guest_user_indicator=bool, enable_read_receipts=bool, enable_spectator_access=bool, giphy_rating=int, diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml index ccfdca0ed6..02ded97178 100644 --- a/zerver/openapi/zulip.yaml +++ b/zerver/openapi/zulip.yaml @@ -4425,6 +4425,13 @@ paths: `send_read_receipts` setting within `realm_user_settings_defaults`. **Changes**: New in Zulip 6.0 (feature level 137). + enable_guest_user_indicator: + type: boolean + description: | + Whether clients should display "(guest)" after the names of + guest users to prominently highlight their status. + + **Changes**: New in Zulip 8.0 (feature level 216). additionalProperties: false example: { @@ -14080,6 +14087,15 @@ paths: - 2 = Zulip Cloud free plan (LIMITED) - 3 = Zulip Cloud Standard plan (STANDARD) - 4 = Zulip Cloud Standard plan, sponsored for free (STANDARD_FREE) + realm_enable_guest_user_indicator: + type: boolean + description: | + Present if `realm` is present in `fetch_event_types`. + + Whether clients should display "(guest)" after the names of + guest users to prominently highlight their status. + + **Changes**: New in Zulip 8.0 (feature level 216). zulip_plan_is_not_limited: type: boolean description: | diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py index a732d79b58..5e02919f40 100644 --- a/zerver/tests/test_home.py +++ b/zerver/tests/test_home.py @@ -137,6 +137,7 @@ class HomeTest(ZulipTestCase): "realm_emails_restricted_to_domains", "realm_embedded_bots", "realm_emoji", + "realm_enable_guest_user_indicator", "realm_enable_read_receipts", "realm_enable_spectator_access", "realm_filters", diff --git a/zerver/views/realm.py b/zerver/views/realm.py index 684aa4a36f..d55bec84c3 100644 --- a/zerver/views/realm.py +++ b/zerver/views/realm.py @@ -174,6 +174,7 @@ def update_realm( json_validator=check_string_or_int, default=None, ), + enable_guest_user_indicator: Optional[bool] = REQ(json_validator=check_bool, default=None), ) -> HttpResponse: realm = user_profile.realm