Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
bots: Remove api_key field from bot objects sent to clients.
Sahil Batrab2365dfed32c
diff --git a/api_docs/unmerged.d/ZF-1ba2c3.md b/api_docs/unmerged.d/ZF-1ba2c3.mdnew file mode 100644index 00000000000..00c84e247b1--- /dev/null+++ b/api_docs/unmerged.d/ZF-1ba2c3.md@@ -0,0 +1,4 @@+* [`GET /events`](/api/get-events), [`POST /register`](/api/register-queue):+ Removed `api_key` field from bot objects.+* [`GET /events`](/api/get-events): `realm_bot/update` event is no longer+ sent when a bot's api key is regenerated.diff --git a/web/src/bot_types.ts b/web/src/bot_types.tsindex 5e4ccdf0191..89d656f281a 100644--- a/web/src/bot_types.ts+++ b/web/src/bot_types.ts@@ -1,7 +1,6 @@import * as z from "zod/mini";const basic_bot_schema = z.object({- api_key: z.string(),avatar_url: z.string(),bot_type: z.number(),default_all_public_streams: z.boolean(),diff --git a/web/tests/bot_data.test.cjs b/web/tests/bot_data.test.cjsindex 433a65ce8f1..a21092ce40b 100644--- a/web/tests/bot_data.test.cjs+++ b/web/tests/bot_data.test.cjs@@ -29,7 +29,6 @@ const fred = make_user({const bot_data_params = {realm_bots: [{- api_key: "1234567890qwertyuioop",avatar_url: "",bot_type: 1, // DEFAULT_BOTdefault_all_public_streams: true,@@ -44,7 +43,6 @@ const bot_data_params = {extra: "This field should be ignored",},{- api_key: "1234567890zxcvbnm",avatar_url: "",bot_type: 3, // OUTGOING_WEBHOOK_BOTdefault_all_public_streams: true,@@ -76,7 +74,6 @@ function test(label, f) {test("test_basics", () => {people.add_active_user(fred);const test_bot = {- api_key: "qwertyuioop1234567890",avatar_url: "",// Default botbot_type: 1,@@ -92,7 +89,6 @@ test("test_basics", () => {extra: "This field should be ignored",};const test_embedded_bot = {- api_key: "zxcvbnm1234567890",avatar_url: "",bot_type: 4, // EMBEDDED_BOTdefault_all_public_streams: true,@@ -115,7 +111,6 @@ test("test_basics", () => {(function test_add() {bot_data.add(test_bot);const bot = bot_data.get(43);- assert.equal("qwertyuioop1234567890", bot.api_key);assert.equal("", bot.avatar_url);assert.equal(1, bot.bot_type);assert.equal(true, bot.default_all_public_streams);@@ -221,7 +216,6 @@ test("test_basics", () => {test("get_all_bots_ids_for_current_user", () => {bot_data.add({- api_key: "testkey123",avatar_url: "",bot_type: 1,default_all_public_streams: true,@@ -236,7 +230,6 @@ test("get_all_bots_ids_for_current_user", () => {});bot_data.add({- api_key: "anotherkey456",avatar_url: "",bot_type: 1,default_all_public_streams: true,@@ -255,7 +248,6 @@ test("get_all_bots_ids_for_current_user", () => {// Ensure bots owned by others are not includedbot_data.add({- api_key: "anotherkey789",avatar_url: "",bot_type: 1,default_all_public_streams: true,diff --git a/web/tests/lib/events.cjs b/web/tests/lib/events.cjsindex e6290a3084b..fb6a80e8f10 100644--- a/web/tests/lib/events.cjs+++ b/web/tests/lib/events.cjs@@ -527,7 +527,6 @@ exports.fixtures = {email: "[email protected]",user_id: 42,avatar_url: "/avatar/42",- api_key: "SOME_KEY",full_name: "The Bot",bot_type: 1,default_all_public_streams: true,diff --git a/web/tests/settings_bots.test.cjs b/web/tests/settings_bots.test.cjsindex 2a0a4b95bfc..410d56f7566 100644--- a/web/tests/settings_bots.test.cjs+++ b/web/tests/settings_bots.test.cjs@@ -10,7 +10,6 @@ const bot_api_key = "QadL788EkiottHmukyhHgePUFHREiu8b";const bot_data_params = {realm_bots: [{- api_key: bot_api_key,avatar_url: "",bot_type: 1, // DEFAULT_BOTdefault_all_public_streams: true,@@ -68,7 +67,7 @@ test("generate_zuliprc_url", () => {test("generate_zuliprc_content", () => {const bot_user = bot_data.get(1);- const content = bot_helper.generate_zuliprc_content(bot_user);+ const content = bot_helper.generate_zuliprc_content({...bot_user, api_key: bot_api_key});const expected ="[api]\[email protected]\n" +"key=QadL788EkiottHmukyhHgePUFHREiu8b\n" +diff --git a/zerver/actions/create_user.py b/zerver/actions/create_user.pyindex 577e0b782a9..649dc90fc9c 100644--- a/zerver/actions/create_user.py+++ b/zerver/actions/create_user.py@@ -487,7 +487,6 @@ def created_bot_event(user_profile: UserProfile) -> dict[str, Any]:full_name=user_profile.full_name,bot_type=user_profile.bot_type,is_active=user_profile.is_active,- api_key=user_profile.api_key,default_sending_stream=default_sending_stream_name,default_events_register_stream=default_events_register_stream_name,default_all_public_streams=user_profile.default_all_public_streams,diff --git a/zerver/actions/user_settings.py b/zerver/actions/user_settings.pyindex 42d1eaed666..ae5e8531a94 100644--- a/zerver/actions/user_settings.py+++ b/zerver/actions/user_settings.py@@ -351,20 +351,6 @@ def do_regenerate_api_key(user_profile: UserProfile, acting_user: UserProfile) -event_time=event_time,)- if user_profile.is_bot:- send_event_on_commit(- user_profile.realm,- dict(- type="realm_bot",- op="update",- bot=dict(- user_id=user_profile.id,- api_key=new_api_key,- ),- ),- bot_owner_user_ids(user_profile),- )-event = {"type": "clear_push_device_tokens", "user_profile_id": user_profile.id}queue_event_on_commit("deferred_work", event)diff --git a/zerver/actions/users.py b/zerver/actions/users.pyindex 652dbc2c6a7..415eed64480 100644--- a/zerver/actions/users.py+++ b/zerver/actions/users.py@@ -936,7 +936,6 @@ def get_owned_bot_dicts("full_name": botdict["full_name"],"bot_type": botdict["bot_type"],"is_active": botdict["is_active"],- "api_key": botdict["api_key"],"default_sending_stream": botdict["default_sending_stream__name"],"default_events_register_stream": botdict["default_events_register_stream__name"],"default_all_public_streams": botdict["default_all_public_streams"],diff --git a/zerver/lib/event_types.py b/zerver/lib/event_types.pyindex 05033015a7d..530d14417ed 100644--- a/zerver/lib/event_types.py+++ b/zerver/lib/event_types.py@@ -411,7 +411,6 @@ class BotServicesEmbedded(BaseModel):class Bot(BaseModel):user_id: int- api_key: stravatar_url: strbot_type: intdefault_all_public_streams: bool@@ -446,7 +445,6 @@ class BotTypeForUpdateCore(BaseModel):class BotTypeForUpdate(BotTypeForUpdateCore):# TODO: fix types to avoid optional fields- api_key: str | None = Noneavatar_url: str | None = Nonedefault_all_public_streams: bool | None = Nonedefault_events_register_stream: str | None = Nonediff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 88b337028ca..3593801b29f 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -4392,7 +4392,6 @@ paths:"full_name": "Foo Bot","bot_type": 1,"is_active": true,- "api_key": "6hc6MC9mpNFvoo0gSOWnZEq4aJEn8UNK","default_sending_stream": null,"default_events_register_stream": null,"default_all_public_streams": false,@@ -4414,6 +4413,11 @@ paths:Only organization administrators and the user who owns the bot willreceive this event.++ **Changes**: Starting from Zulip 12.0 (feature level ZF-1ba2c3), this+ event is no longer sent when a bot's API key is regenerated. Clients+ now use [`GET /bots/{bot_id}/api_key`](/api/get-bot-api-key) to get+ api key for the bot.additionalProperties: falseproperties:id:@@ -17684,6 +17688,10 @@ paths:administrator, this will include all bots in the organization. Otherwise,it will only include bots owned by the user (either because the user createdthe bot or an administrator transferred the bot's ownership to the user).++ **Changes**: Removed `api_key` field from the dictionary in Zulip 12.0+ (feature level ZF-1ba2c3). Clients now use [`GET /bots/{bot_id}/api_key`](/api/get-bot-api-key)+ to get api key for the bot.realm_embedded_bots:type: arrayitems:@@ -26262,7 +26270,6 @@ components:properties:user_id: {}full_name: {}- api_key: {}default_sending_stream:nullable: truedefault_events_register_stream:@@ -26299,10 +26306,6 @@ components:type: stringdescription: |The full name of the bot.- api_key:- type: string- description: |- The API key of the bot which it uses to make API requests.default_sending_stream:type: stringnullable: true@@ -26381,11 +26384,15 @@ components:- $ref: "#/components/schemas/BasicBotBase"- description: |Object containing details of a bot.++ **Changes**: Removed `api_key` field from the dictionary in+ Zulip 12.0 (feature level ZF-1ba2c3). Clients now use+ [`GET /bots/{bot_id}/api_key`](/api/get-bot-api-key) to get+ api key for the bot.additionalProperties: falseproperties:user_id: {}full_name: {}- api_key: {}default_sending_stream:nullable: truedefault_events_register_stream:diff --git a/zerver/tests/test_bots.py b/zerver/tests/test_bots.pyindex 0c9c3e1d529..4b0e2b4c0d2 100644--- a/zerver/tests/test_bots.py+++ b/zerver/tests/test_bots.py@@ -191,7 +191,6 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):bot_type=bot.bot_type,full_name="The Bot of Hamlet",is_active=True,- api_key=result["api_key"],avatar_url=result["avatar_url"],default_sending_stream=None,default_events_register_stream=None,@@ -355,7 +354,6 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):bot_type=bot.bot_type,full_name="The Bot of Hamlet",is_active=True,- api_key=result["api_key"],avatar_url=result["avatar_url"],default_sending_stream=None,default_events_register_stream=None,@@ -454,7 +452,6 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):full_name="The Bot of Hamlet",bot_type=profile.bot_type,is_active=True,- api_key=result["api_key"],avatar_url=result["avatar_url"],default_sending_stream="Denmark",default_events_register_stream=None,@@ -537,7 +534,6 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):user_id=bot_profile.id,bot_type=bot_profile.bot_type,is_active=True,- api_key=result["api_key"],avatar_url=result["avatar_url"],default_sending_stream=None,default_events_register_stream="Denmark",diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.pyindex bff23075326..4485b7be475 100644--- a/zerver/tests/test_events.py+++ b/zerver/tests/test_events.py@@ -3473,9 +3473,8 @@ class NormalActionsTest(BaseAction):def test_regenerate_bot_api_key(self) -> None:bot = self.create_bot("test")- with self.verify_action() as events:+ with self.verify_action(num_events=0, state_change_expected=False):do_regenerate_api_key(bot, self.user_profile)- check_realm_bot_update("events[0]", events[0], "api_key")def test_change_bot_avatar_source(self) -> None:bot = self.create_bot("test")diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.pyindex 9052b460a37..18e030cdcf4 100644--- a/zerver/tests/test_home.py+++ b/zerver/tests/test_home.py@@ -324,7 +324,6 @@ class HomeTest(ZulipTestCase):# TODO: Inspect the page_params data further.# print(orjson.dumps(page_params, option=orjson.OPT_INDENT_2).decode())realm_bots_expected_keys = [- "api_key","avatar_url","bot_type","default_all_public_streams",