api: Do not require short_name to create user.

When you post to /json/users, we no longer
require or look at the short_name parameter,
since we don't use it in any meaningful way.

An upcoming commit will eliminate it from the
database.
This commit is contained in:
Steve Howell 2020-07-16 21:56:34 +00:00 committed by Tim Abbott
parent b375581f58
commit c60f4236a9
8 changed files with 21 additions and 21 deletions

View File

@ -153,7 +153,7 @@ from zerver.lib.request import has_request_variables, REQ
@require_realm_admin @require_realm_admin
@has_request_variables @has_request_variables
def create_user_backend(request, user_profile, email=REQ(), password=REQ(), def create_user_backend(request, user_profile, email=REQ(), password=REQ(),
full_name=REQ(), short_name=REQ()): full_name=REQ()):
# ... code here # ... code here
``` ```

View File

@ -10,6 +10,11 @@ below features are supported.
## Changes in Zulip 3.1 ## Changes in Zulip 3.1
**Feature level 27**
* The `short_name` field is removed from `display_recipients`
in `POST /users`.
**Feature level 26** **Feature level 26**
* The `sender_short_name` field is no longer included in * The `sender_short_name` field is no longer included in

View File

@ -29,7 +29,7 @@ DESKTOP_WARNING_VERSION = "5.2.0"
# #
# Changes should be accompanied by documentation explaining what the # Changes should be accompanied by documentation explaining what the
# new level means in templates/zerver/api/changelog.md. # new level means in templates/zerver/api/changelog.md.
API_FEATURE_LEVEL = 26 API_FEATURE_LEVEL = 27
# Bump the minor PROVISION_VERSION to indicate that folks should provision # 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 # only when going from an old version of the code to a newer version. Bump

View File

@ -130,7 +130,6 @@ add_example('create_user', '/users:post', 200, async (client) => {
email: 'notnewbie@zulip.com', email: 'notnewbie@zulip.com',
password: 'temp', password: 'temp',
full_name: 'New User', full_name: 'New User',
short_name: 'newbie',
}; };
return await client.users.create(params); return await client.users.create(params);

View File

@ -153,7 +153,6 @@ def create_user(client: Client) -> None:
'email': 'newbie@zulip.com', 'email': 'newbie@zulip.com',
'password': 'temp', 'password': 'temp',
'full_name': 'New User', 'full_name': 'New User',
'short_name': 'newbie',
} }
result = client.create_user(request) result = client.create_user(request)
# {code_example|end} # {code_example|end}

View File

@ -1520,14 +1520,6 @@ paths:
type: string type: string
example: New User example: New User
required: true required: true
- name: short_name
in: query
description: |
The short name of the new user. Not user-visible.
schema:
type: string
example: newuser
required: true
responses: responses:
"200": "200":
description: Success. description: Success.

View File

@ -782,18 +782,19 @@ class AdminCreateUserTest(ZulipTestCase):
)) ))
self.assert_json_error(result, "Missing 'full_name' argument") self.assert_json_error(result, "Missing 'full_name' argument")
# Test short_name gets properly ignored
result = self.client_post("/json/users", dict( result = self.client_post("/json/users", dict(
email='romeo@not-zulip.com', email='romeo@zulip.com',
password='xxxx', password='xxxx',
full_name='Romeo Montague', full_name='Romeo Montague',
short_name='DEPRECATED'
)) ))
self.assert_json_error(result, "Missing 'short_name' argument") self.assert_json_success(result)
result = self.client_post("/json/users", dict( result = self.client_post("/json/users", dict(
email='broken', email='broken',
password='xxxx', password='xxxx',
full_name='Romeo Montague', full_name='Romeo Montague',
short_name='Romeo',
)) ))
self.assert_json_error(result, "Bad name or username") self.assert_json_error(result, "Bad name or username")
@ -802,7 +803,6 @@ class AdminCreateUserTest(ZulipTestCase):
email='romeo@not-zulip.com', email='romeo@not-zulip.com',
password='xxxx', password='xxxx',
full_name='Romeo Montague', full_name='Romeo Montague',
short_name='Romeo',
)) ))
self.assert_json_error(result, self.assert_json_error(result,
"Email 'romeo@not-zulip.com' not allowed in this organization") "Email 'romeo@not-zulip.com' not allowed in this organization")
@ -812,7 +812,6 @@ class AdminCreateUserTest(ZulipTestCase):
email='romeo@zulip.net', email='romeo@zulip.net',
password='xxxx', password='xxxx',
full_name='Romeo Montague', full_name='Romeo Montague',
short_name='Romeo',
) )
# Check can't use a bad password with zxcvbn enabled # Check can't use a bad password with zxcvbn enabled
with self.settings(PASSWORD_MIN_LENGTH=6, PASSWORD_MIN_GUESSES=1000): with self.settings(PASSWORD_MIN_LENGTH=6, PASSWORD_MIN_GUESSES=1000):
@ -825,7 +824,7 @@ class AdminCreateUserTest(ZulipTestCase):
# Romeo is a newly registered user # Romeo is a newly registered user
new_user = get_user_by_delivery_email('romeo@zulip.net', get_realm('zulip')) new_user = get_user_by_delivery_email('romeo@zulip.net', get_realm('zulip'))
self.assertEqual(new_user.full_name, 'Romeo Montague') self.assertEqual(new_user.full_name, 'Romeo Montague')
self.assertEqual(new_user.short_name, 'Romeo') self.assertEqual(new_user.short_name, 'deprecated')
# Make sure the recipient field is set correctly. # Make sure the recipient field is set correctly.
self.assertEqual(new_user.recipient, Recipient.objects.get(type=Recipient.PERSONAL, self.assertEqual(new_user.recipient, Recipient.objects.get(type=Recipient.PERSONAL,

View File

@ -486,9 +486,13 @@ def get_members_backend(request: HttpRequest, user_profile: UserProfile, user_id
@require_realm_admin @require_realm_admin
@has_request_variables @has_request_variables
def create_user_backend(request: HttpRequest, user_profile: UserProfile, def create_user_backend(
email: str=REQ(), password: str=REQ(), full_name_raw: str=REQ("full_name"), request: HttpRequest,
short_name: str=REQ()) -> HttpResponse: user_profile: UserProfile,
email: str=REQ(),
password: str=REQ(),
full_name_raw: str=REQ("full_name"),
) -> HttpResponse:
full_name = check_full_name(full_name_raw) full_name = check_full_name(full_name_raw)
form = CreateUserForm({'full_name': full_name, 'email': email}) form = CreateUserForm({'full_name': full_name, 'email': email})
if not form.is_valid(): if not form.is_valid():
@ -518,6 +522,8 @@ def create_user_backend(request: HttpRequest, user_profile: UserProfile,
if not check_password_strength(password): if not check_password_strength(password):
return json_error(PASSWORD_TOO_WEAK_ERROR) return json_error(PASSWORD_TOO_WEAK_ERROR)
short_name = 'deprecated'
do_create_user(email, password, realm, full_name, short_name, acting_user=user_profile) do_create_user(email, password, realm, full_name, short_name, acting_user=user_profile)
return json_success() return json_success()