diff --git a/openslides_backend/action/actions/user/user_mixins.py b/openslides_backend/action/actions/user/user_mixins.py index c1b63a3e8..952fff3fe 100644 --- a/openslides_backend/action/actions/user/user_mixins.py +++ b/openslides_backend/action/actions/user/user_mixins.py @@ -123,7 +123,8 @@ def check_existence(what: str) -> None: check_existence("username") check_existence("saml_id") - check_existence("member_number") + if instance.get("member_number") is not None: + check_existence("member_number") self.check_meeting_and_users( instance, fqid_from_collection_and_id("user", instance["id"]) diff --git a/tests/system/action/user/test_create.py b/tests/system/action/user/test_create.py index 7934ec72f..121ba0d08 100644 --- a/tests/system/action/user/test_create.py +++ b/tests/system/action/user/test_create.py @@ -361,6 +361,14 @@ def test_member_number_already_exists(self) -> None: == "A user with the member_number 14m4m3m832 already exists." ) + def test_member_number_none(self) -> None: + response = self.request( + "user.create", + {"username": "user2", "member_number": None}, + ) + self.assert_status_code(response, 200) + self.assert_model_exists("user/2", {"member_number": None}) + def test_user_create_with_empty_vote_delegation_from_ids(self) -> None: self.set_models( { diff --git a/tests/system/action/user/test_update.py b/tests/system/action/user/test_update.py index f8f94d709..01c6282e6 100644 --- a/tests/system/action/user/test_update.py +++ b/tests/system/action/user/test_update.py @@ -549,6 +549,12 @@ def test_member_number_already_given(self) -> None: response.json["message"], ) + def test_clear_member_number(self) -> None: + self.create_model("user/222", {"member_number": "klmnopqrst"}) + response = self.request("user.update", {"id": 222, "member_number": None}) + self.assert_status_code(response, 200) + self.assert_model_exists("user/222", {"member_number": None}) + def test_same_username(self) -> None: response = self.request("user.update", {"id": 1, "username": "admin"}) self.assert_status_code(response, 200)