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.

api: Return 'user_id' in 'POST /users' response.

Kartik Srivastava63173d555466
diff --git a/templates/zerver/api/changelog.md b/templates/zerver/api/changelog.md
index 989055056a1..727af3f2919 100644
--- a/templates/zerver/api/changelog.md
+++ b/templates/zerver/api/changelog.md
@@ -15,6 +15,8 @@ below features are supported.
* [`GET users/me/subscriptions`](/api/get-subscriptions), [`GET
/streams`](/api/get-streams): Added `date_created` to Stream
objects.
+* [`POST /users`](/api/create-user), `POST /bots`: The ID of the newly
+ created user is now returned in the response.
Feature levels 28 and 29 are reserved for future use in 3.x bug fix
releases.
diff --git a/templates/zerver/api/create-user.md b/templates/zerver/api/create-user.md
index 467c3a7f2a6..f59022835da 100644
--- a/templates/zerver/api/create-user.md
+++ b/templates/zerver/api/create-user.md
@@ -27,6 +27,10 @@ More examples and documentation can be found [here](https://github.com/zulip/zul
## Response
+#### Return values
+
+{generate_return_values_table|zulip.yaml|/users:post}
+
#### Example response
A typical successful JSON response may look like:
diff --git a/version.py b/version.py
index 70fbc080321..b3e74ed8662 100644
--- a/version.py
+++ b/version.py
@@ -29,7 +29,7 @@ DESKTOP_WARNING_VERSION = "5.2.0"
#
# Changes should be accompanied by documentation explaining what the
# new level means in templates/zerver/api/changelog.md.
-API_FEATURE_LEVEL = 27
+API_FEATURE_LEVEL = 30
# 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/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index 34b6d1bb8ce..5482b0c269a 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -4081,7 +4081,16 @@ paths:
content:
application/json:
schema:
- $ref: "#/components/schemas/JsonSuccess"
+ allOf:
+ - $ref: "#/components/schemas/JsonSuccess"
+ - properties:
+ user_id:
+ type: integer
+ description: |
+ The ID assigned to the newly created user.
+
+ **Changes**: New in Zulip 4.0 (feature level 30).
+ - example: {"msg": "", "result": "success", "user_id": 25}
"400":
description: Bad request.
content:
diff --git a/zerver/tests/test_bots.py b/zerver/tests/test_bots.py
index 3ba5b801b29..a4db0146f5a 100644
--- a/zerver/tests/test_bots.py
+++ b/zerver/tests/test_bots.py
@@ -175,6 +175,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
if e['event']['type'] == 'realm_bot'
]
+ self.assertEqual(result["user_id"], bot.id)
self.assertEqual(
dict(
type='realm_bot',
diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py
index cb397a96125..19d03f12925 100644
--- a/zerver/tests/test_users.py
+++ b/zerver/tests/test_users.py
@@ -823,7 +823,9 @@ class AdminCreateUserTest(ZulipTestCase):
# Romeo is a newly registered user
new_user = get_user_by_delivery_email('[email protected]', get_realm('zulip'))
+ result = orjson.loads(result.content)
self.assertEqual(new_user.full_name, 'Romeo Montague')
+ self.assertEqual(new_user.id, result['user_id'])
# Make sure the recipient field is set correctly.
self.assertEqual(new_user.recipient, Recipient.objects.get(type=Recipient.PERSONAL,
diff --git a/zerver/views/users.py b/zerver/views/users.py
index 08665106592..2bf3c14cf19 100644
--- a/zerver/views/users.py
+++ b/zerver/views/users.py
@@ -413,6 +413,7 @@ def add_bot_backend(
api_key = get_api_key(bot_profile)
json_result = dict(
+ user_id=bot_profile.id,
api_key=api_key,
avatar_url=avatar_url(bot_profile),
default_sending_stream=get_stream_name(bot_profile.default_sending_stream),
@@ -521,8 +522,8 @@ def create_user_backend(
if not check_password_strength(password):
return json_error(PASSWORD_TOO_WEAK_ERROR)
- do_create_user(email, password, realm, full_name, acting_user=user_profile)
- return json_success()
+ target_user = do_create_user(email, password, realm, full_name, acting_user=user_profile)
+ return json_success({'user_id': target_user.id})
def get_profile_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
raw_user_data = get_raw_user_data(user_profile.realm, user_profile,