Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
api-docs: Document POST /users/me/api_key/regenerate.
Agnish Baurib85481b6e07f
diff --git a/api_docs/include/rest-endpoints.md b/api_docs/include/rest-endpoints.mdindex 1d94b11cda7..7946f10bbcd 100644--- a/api_docs/include/rest-endpoints.md+++ b/api_docs/include/rest-endpoints.md@@ -116,6 +116,7 @@* [Get all alert words](/api/get-alert-words)* [Add alert words](/api/add-alert-words)* [Remove alert words](/api/remove-alert-words)+* [Regenerate your API key](/api/regenerate-api-key)* [Get a bot's API key](/api/get-bot-api-key)#### Invitationsdiff --git a/zerver/openapi/curl_param_value_generators.py b/zerver/openapi/curl_param_value_generators.pyindex 0eea8ef0f32..0fe1c44744f 100644--- a/zerver/openapi/curl_param_value_generators.py+++ b/zerver/openapi/curl_param_value_generators.py@@ -429,3 +429,21 @@ def get_temporary_url_for_uploaded_file() -> dict[str, object]:realm_id = upload_path_parts[1]filename = upload_path_parts[2]return {"realm_id_str": realm_id, "filename": filename}+++@openapi_param_value_generator(["/users/me/api_key/regenerate:post"])+def regenerate_api_key_test_user() -> dict[str, object]:+ test_user_email = "[email protected]"+ test_user = do_create_user(+ test_user_email,+ "secret",+ get_realm("zulip"),+ "Mr. Regenerate",+ role=200,+ acting_user=None,+ )+ realm = get_realm("zulip")+ test_user_api_key = get_user(test_user_email, realm).api_key+ # Change authentication line to allow test_client to regenerate its own key.+ AUTHENTICATION_LINE[0] = f"{test_user.email}:{test_user_api_key}"+ return {}diff --git a/zerver/openapi/python_examples.py b/zerver/openapi/python_examples.pyindex 88bf684e155..157d2224dcc 100644--- a/zerver/openapi/python_examples.py+++ b/zerver/openapi/python_examples.py@@ -783,6 +783,22 @@ def deactivate_own_user(client: Client, owner_client: Client) -> None:owner_client.reactivate_user_by_id(user_id)+@openapi_test_function("/users/me/api_key/regenerate:post")+def regenerate_api_key(client: Client) -> None:+ # {code_example|start}+ # Generate a new API key for the current user/bot.+ result = client.call_endpoint(+ url="/users/me/api_key/regenerate",+ method="POST",+ )+ # {code_example|end}+ assert_success_response(result)+ validate_against_openapi_schema(result, "/users/me/api_key/regenerate", "post", "200")++ # Update the client with the new API key so subsequent tests don't fail.+ client.api_key = result["api_key"]++@openapi_test_function("/get_stream_id:get")def get_stream_id(client: Client) -> int:name = "python-test"@@ -2166,6 +2182,7 @@ def test_the_api(client: Client, nonadmin_client: Client, owner_client: Client)test_errors(client)test_invitations(client)test_welcome_bot_custom_message(client)+ regenerate_api_key(client)sys.stdout.flush()if REGISTERED_TEST_FUNCTIONS != CALLED_TEST_FUNCTIONS:diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 6e560832cfa..31d02e353bb 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -11325,6 +11325,47 @@ paths:An example JSON error response when the current user is the onlyorganization owner in the organization:+ /users/me/api_key/regenerate:+ post:+ operationId: regenerate-api-key+ summary: Regenerate your API key+ tags: ["users"]+ description: |+ !!! warn ""++ **Note**: Users should treat their Zulip API key as+ [carefully as they would their password](/help/protect-your-account).++ Generate a new API key for the user making the request.++ Changing a user's API key will immediately log them out of Zulip+ on devices registered for [mobile push notifications][mobile-push].++ [mobile-push]: https://zulip.readthedocs.io/en/latest/production/mobile-push-notifications.html+ responses:+ "200":+ description: Success.+ content:+ application/json:+ schema:+ allOf:+ - $ref: "#/components/schemas/JsonSuccessBase"+ - additionalProperties: false+ properties:+ result: {}+ msg: {}+ ignored_parameters_unsupported: {}+ api_key:+ type: string+ description: The new API key for the user.+ required:+ - api_key+ example:+ {+ "result": "success",+ "msg": "",+ "api_key": "a1b2c3d4e5f6g7h8i9j0",+ }/users/me/alert_words:get:operationId: get-alert-wordsdiff --git a/zerver/tests/test_openapi.py b/zerver/tests/test_openapi.pyindex ffd46d52f4e..54c82071232 100644--- a/zerver/tests/test_openapi.py+++ b/zerver/tests/test_openapi.py@@ -228,7 +228,6 @@ class OpenAPIArgumentsTest(ZulipTestCase):"/dev_list_users",#### These personal settings endpoints have modest value to document:"/users/me/avatar",- "/users/me/api_key/regenerate",# Much more valuable would be an org admin bulk-upload feature."/users/me/profile_data",#### Should be documented as part of interactive bots documentation