Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

settings: Add default_avatar_source realm setting.

Prakhar Pratyush86e41dadd68c
diff --git a/api_docs/changelog.md b/api_docs/changelog.md
index 7cf9a94638e..ccfb65b085b 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 12.0
+**Feature level 456**
+
+* `PATCH /realm`, [`POST /register`](/api/register-queue),
+ [`GET /events`](/api/get-events): Added a new
+ `default_avatar_source` realm setting.
+
**Feature level 455**
* [`POST /register`](/api/register-queue), [`GET
diff --git a/version.py b/version.py
index 95e7774f5a1..7a7d43a48eb 100644
--- a/version.py
+++ b/version.py
@@ -35,7 +35,7 @@ DESKTOP_WARNING_VERSION = "5.9.3"
# new level means in api_docs/changelog.md, as well as "**Changes**"
# entries in the endpoint's documentation in `zulip.yaml`.
-API_FEATURE_LEVEL = 455
+API_FEATURE_LEVEL = 456
# 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/zerver/migrations/0776_realm_default_avatar_source.py b/zerver/migrations/0776_realm_default_avatar_source.py
new file mode 100644
index 00000000000..e2dbfdc2957
--- /dev/null
+++ b/zerver/migrations/0776_realm_default_avatar_source.py
@@ -0,0 +1,21 @@
+# Generated by Django 5.2.10 on 2026-01-22 08:43
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("zerver", "0775_customprofilefield_use_for_user_matching"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="realm",
+ name="default_avatar_source",
+ field=models.CharField(
+ choices=[("G", "Hosted by Gravatar"), ("J", "Generated using Jdenticon")],
+ default="G",
+ max_length=1,
+ ),
+ ),
+ ]
diff --git a/zerver/models/realms.py b/zerver/models/realms.py
index 2200771b814..9086e133cd6 100644
--- a/zerver/models/realms.py
+++ b/zerver/models/realms.py
@@ -709,10 +709,22 @@ class Realm(models.Model):
# Whether to notify client when a DM has a guest recipient.
enable_guest_user_dm_warning = models.BooleanField(default=True)
+ # Avatar source for new users
+ AVATAR_FROM_GRAVATAR = "G"
+ AVATAR_FROM_JDENTICON = "J"
+ AVATAR_SOURCES = (
+ (AVATAR_FROM_GRAVATAR, "Hosted by Gravatar"),
+ (AVATAR_FROM_JDENTICON, "Generated using Jdenticon"),
+ )
+ default_avatar_source = models.CharField(
+ default=AVATAR_FROM_GRAVATAR, choices=AVATAR_SOURCES, max_length=1
+ )
+
# Define the types of the various automatically managed properties
property_types: dict[str, type | UnionType] = dict(
allow_message_editing=bool,
avatar_changes_disabled=bool,
+ default_avatar_source=str,
default_code_block_language=str,
default_language=str,
description=str,
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index 837d29b28a0..61a5039df9d 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -4971,6 +4971,15 @@ paths:
to be of type integer and did not accept anonymous user groups.
New in Zulip 8.0 (feature level 209).
+ default_avatar_source:
+ type: string
+ description: |
+ The avatar data source type for new users.
+
+ - "G" = Hosted by Gravatar
+ - "J" = Generated using Jdenticon
+
+ **Changes**: New in Zulip 12.0 (feature level 456).
default_code_block_language:
type: string
description: |
@@ -19705,6 +19714,17 @@ paths:
description: |
The regex pattern of the URL of a profile page
on the external site.
+ realm_default_avatar_source:
+ type: string
+ description: |
+ Present if `realm` is present in `fetch_event_types`.
+
+ The avatar data source type for new users.
+
+ - "G" = Hosted by Gravatar
+ - "J" = Generated using Jdenticon
+
+ **Changes**: New in Zulip 12.0 (feature level 456).
jitsi_server_url:
type: string
deprecated: true
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index 2b1e005bbc3..791b95af381 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -4407,6 +4407,7 @@ class RealmPropertyActionTest(BaseAction):
move_messages_within_stream_limit_seconds=[1000, 1100, 1200, None],
move_messages_between_streams_limit_seconds=[1000, 1100, 1200, None],
topics_policy=Realm.REALM_TOPICS_POLICY_TYPES,
+ default_avatar_source=["G", "J"],
)
vals = test_values.get(name)
diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py
index 188e9e6540b..f8d27e54412 100644
--- a/zerver/tests/test_home.py
+++ b/zerver/tests/test_home.py
@@ -157,6 +157,7 @@ class HomeTest(ZulipTestCase):
"realm_create_public_stream_policy",
"realm_create_web_public_stream_policy",
"realm_date_created",
+ "realm_default_avatar_source",
"realm_default_code_block_language",
"realm_default_external_accounts",
"realm_default_language",
diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py
index 46129c0730d..084a0420dff 100644
--- a/zerver/tests/test_realm.py
+++ b/zerver/tests/test_realm.py
@@ -2261,6 +2261,7 @@ class RealmAPITest(ZulipTestCase):
move_messages_within_stream_limit_seconds=[1000, 1100, 1200],
move_messages_between_streams_limit_seconds=[1000, 1100, 1200],
topics_policy=Realm.REALM_TOPICS_POLICY_TYPES,
+ default_avatar_source=["G", "J"],
)
vals = test_values.get(name)
diff --git a/zerver/views/realm.py b/zerver/views/realm.py
index e0a5d19c04d..bdfce6a14ca 100644
--- a/zerver/views/realm.py
+++ b/zerver/views/realm.py
@@ -92,6 +92,9 @@ def check_jitsi_url(value: str) -> str:
raise JsonableError(_("{var_name} is not an allowed_type").format(var_name=var_name))
+DEFAULT_AVATAR_SOURCES = [key for key, _ in Realm.AVATAR_SOURCES]
+
+
@require_realm_admin
@typed_endpoint
def update_realm(
@@ -123,6 +126,8 @@ def update_realm(
can_set_topics_policy_group: Json[GroupSettingChangeRequest] | None = None,
can_summarize_topics_group: Json[GroupSettingChangeRequest] | None = None,
create_multiuse_invite_group: Json[GroupSettingChangeRequest] | None = None,
+ default_avatar_source: Annotated[str, check_string_in_validator(DEFAULT_AVATAR_SOURCES)]
+ | None = None,
default_code_block_language: str | None = None,
default_language: str | None = None,
description: Annotated[