From abdb68040e599fa3ed0859bf8b3164d5355ebff1 Mon Sep 17 00:00:00 2001 From: Ralf Peschke Date: Tue, 29 Aug 2023 14:50:10 +0200 Subject: [PATCH] fix key error in get_user_scope (#1887) --- .../action/actions/user/create.py | 1 - .../user/create_update_permissions_mixin.py | 3 ++- .../action/actions/user/update.py | 1 - .../action/actions/user/user_mixin.py | 11 ++++++++-- .../shared/mixins/user_scope_mixin.py | 8 ------- tests/system/action/user/test_create.py | 22 ++++++++++++++----- 6 files changed, 28 insertions(+), 18 deletions(-) diff --git a/openslides_backend/action/actions/user/create.py b/openslides_backend/action/actions/user/create.py index 4d0d576ff..d26fc1b2e 100644 --- a/openslides_backend/action/actions/user/create.py +++ b/openslides_backend/action/actions/user/create.py @@ -20,7 +20,6 @@ class UserCreate( EmailCheckMixin, CreateAction, - UserMixin, CreateUpdatePermissionsMixin, PasswordMixin, LimitOfUserMixin, diff --git a/openslides_backend/action/actions/user/create_update_permissions_mixin.py b/openslides_backend/action/actions/user/create_update_permissions_mixin.py index a51ca7769..b8791ff7a 100644 --- a/openslides_backend/action/actions/user/create_update_permissions_mixin.py +++ b/openslides_backend/action/actions/user/create_update_permissions_mixin.py @@ -13,6 +13,7 @@ from ....shared.mixins.user_scope_mixin import UserScope, UserScopeMixin from ....shared.patterns import fqid_from_collection_and_id from ...action import Action +from .user_mixin import UserMixin class PermissionVarStore: @@ -143,7 +144,7 @@ def _get_user_meetings_with_user_can_manage( return user_meetings -class CreateUpdatePermissionsMixin(UserScopeMixin, Action): +class CreateUpdatePermissionsMixin(UserMixin, UserScopeMixin, Action): field_rights: Dict[str, list] = { "A": [ "title", diff --git a/openslides_backend/action/actions/user/update.py b/openslides_backend/action/actions/user/update.py index 609585287..9eb315cf0 100644 --- a/openslides_backend/action/actions/user/update.py +++ b/openslides_backend/action/actions/user/update.py @@ -21,7 +21,6 @@ @register_action("user.update") class UserUpdate( EmailCheckMixin, - UserMixin, CreateUpdatePermissionsMixin, UpdateAction, LimitOfUserMixin, diff --git a/openslides_backend/action/actions/user/user_mixin.py b/openslides_backend/action/actions/user/user_mixin.py index e2df71f20..40419ab3f 100644 --- a/openslides_backend/action/actions/user/user_mixin.py +++ b/openslides_backend/action/actions/user/user_mixin.py @@ -83,6 +83,15 @@ class UserMixin(CheckForArchivedMeetingMixin): "group_ids": id_list_schema, } + def validate_instance(self, instance: Dict[str, Any]) -> None: + super().validate_instance(instance) + if "meeting_id" not in instance and any( + key in self.transfer_field_list for key in instance.keys() + ): + raise ActionException( + "Missing meeting_id in instance, because meeting related fields used" + ) + def update_instance(self, instance: Dict[str, Any]) -> Dict[str, Any]: instance = super().update_instance(instance) for field in ("username", "first_name", "last_name", "email"): @@ -125,8 +134,6 @@ def meeting_user_set_data(self, instance: Dict[str, Any]) -> None: meeting_user_data[field] = instance.pop(field) if meeting_user_data: self.apply_instance(instance) - if not meeting_id: - raise ActionException("Transfer data needs meeting_id.") meeting_user_data["meeting_id"] = meeting_id meeting_user_data["user_id"] = instance["id"] self.execute_other_action(MeetingUserSetData, [meeting_user_data]) diff --git a/openslides_backend/shared/mixins/user_scope_mixin.py b/openslides_backend/shared/mixins/user_scope_mixin.py index 612319fb8..8dba158aa 100644 --- a/openslides_backend/shared/mixins/user_scope_mixin.py +++ b/openslides_backend/shared/mixins/user_scope_mixin.py @@ -42,14 +42,6 @@ def get_user_scope( if "group_ids" in id_or_instance: if "meeting_id" in id_or_instance: meetings.add(id_or_instance["meeting_id"]) - else: - meeting_user = self.datastore.get( - fqid_from_collection_and_id( - "meeting_user", id_or_instance["id"] - ), - ["meeting_id"], - ) - meetings.add(meeting_user["meeting_id"]) committees_manager.update( set(id_or_instance.get("committee_management_ids", [])) ) diff --git a/tests/system/action/user/test_create.py b/tests/system/action/user/test_create.py index c0595cb76..76b731f4f 100644 --- a/tests/system/action/user/test_create.py +++ b/tests/system/action/user/test_create.py @@ -147,15 +147,27 @@ def test_create_comment(self) -> None: ) def test_create_comment_without_meeting_id(self) -> None: + self.set_models( + { + "meeting/11": { + "name": "meeting11", + "committee_id": 79, + "group_ids": [111], + "is_active_in_organization_id": 1, + }, + "group/111": {"meeting_id": 11}, + } + ) + response = self.request( "user.create", - { - "username": "test Xcdfgee", - "comment": "blablabla", - }, + {"username": "test Xcdfgee", "group_ids": [111]}, ) self.assert_status_code(response, 400) - assert "Transfer data needs meeting_id." in response.json["message"] + assert ( + "Missing meeting_id in instance, because meeting related fields used" + in response.json["message"] + ) def test_create_with_meeting_user_fields(self) -> None: self.set_models(