From 23ffe19d9993122a860d461a41d60ad0c5f04407 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 1 Sep 2026 14:01:13 +0200 Subject: [PATCH 01/53] Bump gunicorn (#3732) --- requirements/partial/requirements_production.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/partial/requirements_production.txt b/requirements/partial/requirements_production.txt index 41cdd82365..f1f19bdf85 100644 --- a/requirements/partial/requirements_production.txt +++ b/requirements/partial/requirements_production.txt @@ -4,7 +4,7 @@ bleach[css]==6.4.0 dependency_injector==4.49.1 fastjsonschema==2.22.2 Flask==3.1.3 -gunicorn==26.1.0 +gunicorn==26.2.0 pypdf[crypto]==6.16.1 psycopg[binary]==3.3.4 psycopg-pool==3.3.1 From 9370389642591043619ef176077b8a02df1f8779 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 1 Sep 2026 15:15:59 +0000 Subject: [PATCH 02/53] Bump isort from 8.0.1 to 9.0.1 in /requirements/partial in the code-style-depedencies group across 1 directory (#3739) * Bump isort * Add service commits, simplejson update and lint everything --- openslides_backend/migrations/migrations/0100_init_reldb.py | 4 +++- requirements/export_service_commits.sh | 2 +- requirements/partial/requirements_development.txt | 2 +- requirements/partial/requirements_production.txt | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/openslides_backend/migrations/migrations/0100_init_reldb.py b/openslides_backend/migrations/migrations/0100_init_reldb.py index cdba6eda5c..f49ff6ae9c 100644 --- a/openslides_backend/migrations/migrations/0100_init_reldb.py +++ b/openslides_backend/migrations/migrations/0100_init_reldb.py @@ -26,9 +26,11 @@ RelationListField, TimestampField, ) -from openslides_backend.models.models import * # type: ignore # noqa # necessary to fill model_registry +from openslides_backend.models.models import * # type: ignore # noqa from openslides_backend.shared.env import is_truthy +# importing models is necessary to fill model_registry + RELATION_LIST_FIELD_CLASSES = [RelationListField, GenericRelationListField] # TODO update before merging into main. ORIGIN_COLLECTIONS = [ diff --git a/requirements/export_service_commits.sh b/requirements/export_service_commits.sh index dbb2b26a6d..0276ab15a3 100755 --- a/requirements/export_service_commits.sh +++ b/requirements/export_service_commits.sh @@ -1,2 +1,2 @@ #!/bin/bash -export AUTH_COMMIT_HASH=ece2bf0cf60b7564228cdedd32ab2468110fdc6c +export AUTH_COMMIT_HASH=097430fb021148714d861816cc8b3c0e8f1e7e86 diff --git a/requirements/partial/requirements_development.txt b/requirements/partial/requirements_development.txt index cd502de78c..3b4ca4db14 100644 --- a/requirements/partial/requirements_development.txt +++ b/requirements/partial/requirements_development.txt @@ -3,7 +3,7 @@ autoflake==2.4.0 black==26.5.1 debugpy==1.8.21 flake8==7.3.0 -isort==8.0.1 +isort==9.0.1 mypy==2.3.1 pip-check==3.2.1 pytest==9.1.1 diff --git a/requirements/partial/requirements_production.txt b/requirements/partial/requirements_production.txt index f1f19bdf85..9919f9bec7 100644 --- a/requirements/partial/requirements_production.txt +++ b/requirements/partial/requirements_production.txt @@ -10,7 +10,7 @@ psycopg[binary]==3.3.4 psycopg-pool==3.3.1 requests==2.34.2 roman==5.2 -simplejson==4.1.1 +simplejson==4.1.2 Werkzeug==3.1.8 python-magic==0.4.27 python-sql==1.8.1 From 02c4ec82e894d95f461e39ced88bd0eae5108874 Mon Sep 17 00:00:00 2001 From: "openslides-automation[bot]" <125256978+openslides-automation[bot]@users.noreply.github.com> Date: Tue, 1 Sep 2026 15:43:55 +0000 Subject: [PATCH 03/53] Update meta repository (#3741) --- meta | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta b/meta index 6ab83898b7..f1dc6f90d9 160000 --- a/meta +++ b/meta @@ -1 +1 @@ -Subproject commit 6ab83898b7545f5df199ad255b941ddf12dcfc66 +Subproject commit f1dc6f90d932564896bbfb7be03edcd740f49eaf From abcf69aa2c5d9ad8a58a9149af739b8a1d5e215a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 1 Sep 2026 16:09:57 +0000 Subject: [PATCH 04/53] Bump pypdf from 6.16.1 to 6.16.2 in /requirements/partial (#3730) --- requirements/partial/requirements_production.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/partial/requirements_production.txt b/requirements/partial/requirements_production.txt index 9919f9bec7..809bd0471a 100644 --- a/requirements/partial/requirements_production.txt +++ b/requirements/partial/requirements_production.txt @@ -5,7 +5,7 @@ dependency_injector==4.49.1 fastjsonschema==2.22.2 Flask==3.1.3 gunicorn==26.2.0 -pypdf[crypto]==6.16.1 +pypdf[crypto]==6.16.2 psycopg[binary]==3.3.4 psycopg-pool==3.3.1 requests==2.34.2 From 69bccf46a8d01577738029b07e27a935cb4b2f06 Mon Sep 17 00:00:00 2001 From: luisa-beerboom <101706784+luisa-beerboom@users.noreply.github.com> Date: Wed, 16 Sep 2026 12:53:25 +0200 Subject: [PATCH 05/53] Fix tracebacks (#3759) * 3756 fix participant import traceback * 3758 remove locking from all presenters --- .../action/mixins/import_mixins.py | 3 ++- .../permissions/permission_helper.py | 5 ++++- .../presenter/check_database.py | 4 ++-- .../presenter/get_active_users_amount.py | 2 +- .../presenter/get_forwarding_committees.py | 6 +++++- .../presenter/get_forwarding_meetings.py | 5 +++++ .../presenter/get_mediafile_context.py | 6 ++++-- .../presenter/get_user_related_models.py | 10 ++++++---- openslides_backend/presenter/get_users.py | 1 + .../presenter/get_valid_timezones.py | 1 + .../presenter/number_of_users.py | 3 ++- openslides_backend/presenter/presenter.py | 1 + .../presenter/search_for_id_by_external_id.py | 2 +- .../services/database/extended_database.py | 20 +++++++++++++++++++ openslides_backend/shared/export_helper.py | 1 + .../user_create_update_permissions_mixin.py | 10 +++++++--- .../shared/mixins/user_scope_mixin.py | 3 ++- .../action/user/test_participant_import.py | 5 +++++ 18 files changed, 70 insertions(+), 18 deletions(-) diff --git a/openslides_backend/action/mixins/import_mixins.py b/openslides_backend/action/mixins/import_mixins.py index 10f280fe47..4f224f0eee 100644 --- a/openslides_backend/action/mixins/import_mixins.py +++ b/openslides_backend/action/mixins/import_mixins.py @@ -207,7 +207,8 @@ class BaseImportAction(BaseImportJsonUploadAction): import_state = ImportState.DONE def prefetch(self, action_data: ActionData) -> None: - store_id = cast(list[dict[str, Any]], action_data)[0]["id"] + if not (store_id := cast(list[dict[str, Any]], action_data)[0].get("id")): + raise ActionException("Payload must contain import_preview id.") import_preview = self.datastore.get( fqid_from_collection_and_id("import_preview", store_id), ["result", "state", "name"], diff --git a/openslides_backend/permissions/permission_helper.py b/openslides_backend/permissions/permission_helper.py index b1a4b1724e..50f1bb5a33 100644 --- a/openslides_backend/permissions/permission_helper.py +++ b/openslides_backend/permissions/permission_helper.py @@ -100,6 +100,7 @@ def has_organization_management_level( user = datastore.get( fqid_from_collection_and_id("user", user_id), ["organization_management_level"], + lock_result=False, ) return expected_level <= OrganizationManagementLevel( user.get("organization_management_level", "") @@ -171,6 +172,7 @@ def has_committee_management_level( for parent_id in datastore.get( fqid_from_collection_and_id("committee", committee_id), ["all_parent_ids"], + lock_result=False, ).get("all_parent_ids", []) ): return True @@ -202,7 +204,8 @@ def get_shared_committee_management_levels( { id_ for committee_id, committee in datastore.get_many( - [GetManyRequest("committee", committee_ids, ["all_parent_ids"])] + [GetManyRequest("committee", committee_ids, ["all_parent_ids"])], + lock_result=False, )["committee"].items() for id_ in [committee_id, *committee.get("all_parent_ids", [])] }.intersection(user.get("committee_management_ids", [])) diff --git a/openslides_backend/presenter/check_database.py b/openslides_backend/presenter/check_database.py index 9f2034edc6..2de92e4a73 100644 --- a/openslides_backend/presenter/check_database.py +++ b/openslides_backend/presenter/check_database.py @@ -29,9 +29,9 @@ def check_meetings(datastore: Database, meeting_id: int | None) -> dict[int, str]: if meeting_id: - meeting_ids = [meeting_id] + meeting_ids: list[int] = [meeting_id] else: - meetings = datastore.get_all("meeting", ["id"]).values() + meetings = datastore.get_all("meeting", ["id"], lock_result=False).values() meeting_ids = [meeting["id"] for meeting in meetings] errors: dict[int, str] = {} diff --git a/openslides_backend/presenter/get_active_users_amount.py b/openslides_backend/presenter/get_active_users_amount.py index 90a992e3cc..16364cf7fd 100644 --- a/openslides_backend/presenter/get_active_users_amount.py +++ b/openslides_backend/presenter/get_active_users_amount.py @@ -44,4 +44,4 @@ def check_permissions(self) -> None: def get_amount(self) -> int: filter_ = FilterOperator("is_active", "=", True) - return self.datastore.count("user", filter_) + return self.datastore.count("user", filter_, lock_result=False) diff --git a/openslides_backend/presenter/get_forwarding_committees.py b/openslides_backend/presenter/get_forwarding_committees.py index 04d9b508a1..9dad9f979c 100644 --- a/openslides_backend/presenter/get_forwarding_committees.py +++ b/openslides_backend/presenter/get_forwarding_committees.py @@ -48,11 +48,13 @@ def get_result(self) -> Any: meeting = self.datastore.get( fqid_from_collection_and_id("meeting", self.data["meeting_id"]), ["committee_id"], + lock_result=False, ) committee = self.datastore.get( fqid_from_collection_and_id("committee", meeting["committee_id"]), ["receive_forwardings_from_committee_ids"], + lock_result=False, ) if not committee.get("receive_forwardings_from_committee_ids"): @@ -61,7 +63,9 @@ def get_result(self) -> Any: result = [] for committee_id in committee["receive_forwardings_from_committee_ids"]: committee_data = self.datastore.get( - fqid_from_collection_and_id("committee", committee_id), ["name"] + fqid_from_collection_and_id("committee", committee_id), + ["name"], + lock_result=False, ) if committee_data.get("name"): result.append(committee_data["name"]) diff --git a/openslides_backend/presenter/get_forwarding_meetings.py b/openslides_backend/presenter/get_forwarding_meetings.py index aad5b32378..4b85c3c85b 100644 --- a/openslides_backend/presenter/get_forwarding_meetings.py +++ b/openslides_backend/presenter/get_forwarding_meetings.py @@ -52,6 +52,7 @@ def get_result(self) -> Any: meeting = self.datastore.get( fqid_from_collection_and_id("meeting", request_meeting_id), ["committee_id", "is_active_in_organization_id", "name"], + lock_result=False, ) if not meeting.get("is_active_in_organization_id"): raise PresenterException( @@ -61,11 +62,13 @@ def get_result(self) -> Any: committee = self.datastore.get( fqid_from_collection_and_id("committee", meeting["committee_id"]), ["forward_to_committee_ids"], + lock_result=False, ) organization_timezone = ( self.datastore.get( ONE_ORGANIZATION_FQID, ["time_zone"], + lock_result=False, ).get("time_zone") or "UTC" ) @@ -75,6 +78,7 @@ def get_result(self) -> Any: forward_to_committee = self.datastore.get( fqid_from_collection_and_id("committee", forward_to_committee_id), ["name", "default_meeting_id"], + lock_result=False, ) forward_to_committee_meetings = self.datastore.filter( "meeting", @@ -85,6 +89,7 @@ def get_result(self) -> Any: FilterOperator("id", "!=", request_meeting_id), ), ["name", "start_time", "end_time", "time_zone"], + lock_result=False, ) meetings_list = [] diff --git a/openslides_backend/presenter/get_mediafile_context.py b/openslides_backend/presenter/get_mediafile_context.py index ca089db51a..9f6ffb7677 100644 --- a/openslides_backend/presenter/get_mediafile_context.py +++ b/openslides_backend/presenter/get_mediafile_context.py @@ -56,7 +56,9 @@ def get_result(self) -> Any: "child_ids", ], ) - mediafiles = self.datastore.get_many([gmr]).get("mediafile", {}) + mediafiles = self.datastore.get_many([gmr], lock_result=False).get( + "mediafile", {} + ) self.check_permissions( {mediafile["owner_id"] for mediafile in mediafiles.values()} ) @@ -146,7 +148,7 @@ def get_children_amount_and_meeting_data( ) ) if len(gmrs): - data = self.datastore.get_many(gmrs) + data = self.datastore.get_many(gmrs, lock_result=False) else: data = {} if meetings := data.get("meeting"): diff --git a/openslides_backend/presenter/get_user_related_models.py b/openslides_backend/presenter/get_user_related_models.py index 4104d411e6..8136b0a3e7 100644 --- a/openslides_backend/presenter/get_user_related_models.py +++ b/openslides_backend/presenter/get_user_related_models.py @@ -48,7 +48,7 @@ def get_result(self) -> Any: "committee_management_ids", ], ) - users = self.datastore.get_many([gmr]).get("user", {}) + users = self.datastore.get_many([gmr], lock_result=False).get("user", {}) for user_id, user in users.items(): result[user_id] = {} self.check_permissions_for_scope(user_id) @@ -65,7 +65,8 @@ def get_committees_data(self, user: dict[str, Any]) -> list[dict[str, Any]]: return [] gm_result = self.datastore.get_many( - [GetManyRequest("committee", user["committee_ids"], ["id", "name"])] + [GetManyRequest("committee", user["committee_ids"], ["id", "name"])], + lock_result=False, ) return [ { @@ -99,7 +100,8 @@ def get_meetings_data(self, user: dict[str, Any]) -> list[dict[str, Any]]: meeting_user_ids, [*result_fields, "group_ids", "meeting_id"], ) - ] + ], + lock_result=False, )["meeting_user"].values() if meeting_user.pop("group_ids", None) ] @@ -112,7 +114,7 @@ def get_meetings_data(self, user: dict[str, Any]) -> list[dict[str, Any]]: [meeting_user["meeting_id"] for meeting_user in meeting_users], ["id", "name", "is_active_in_organization_id", "locked_from_inside"], ) - meetings = self.datastore.get_many([gmr]).get("meeting", {}) + meetings = self.datastore.get_many([gmr], lock_result=False).get("meeting", {}) operator_meetings = self.datastore.get( fqid_from_collection_and_id("user", self.user_id), ["meeting_ids"], diff --git a/openslides_backend/presenter/get_users.py b/openslides_backend/presenter/get_users.py index a22727a1f5..9bef9f58ab 100644 --- a/openslides_backend/presenter/get_users.py +++ b/openslides_backend/presenter/get_users.py @@ -88,6 +88,7 @@ def get_all_users(self, criteria: list[str]) -> list[dict[str, Any]]: self.datastore.get_all( "user", fields, + lock_result=False, ).values() ) diff --git a/openslides_backend/presenter/get_valid_timezones.py b/openslides_backend/presenter/get_valid_timezones.py index 357655a360..61ff2a5430 100644 --- a/openslides_backend/presenter/get_valid_timezones.py +++ b/openslides_backend/presenter/get_valid_timezones.py @@ -47,6 +47,7 @@ def check_permissions(self) -> None: user_data = self.datastore.get( fqid_from_collection_and_id("user", self.user_id), ["committee_management_ids", "meeting_ids"], + lock_result=False, ) if not user_data.get("committee_management_ids") and not any( has_perm( diff --git a/openslides_backend/presenter/number_of_users.py b/openslides_backend/presenter/number_of_users.py index b439329961..9b5074a94c 100644 --- a/openslides_backend/presenter/number_of_users.py +++ b/openslides_backend/presenter/number_of_users.py @@ -34,12 +34,13 @@ def get_result(self) -> Any: organization = self.datastore.get( ONE_ORGANIZATION_FQID, ["limit_of_users"], + lock_result=False, ) limit_of_users = organization.get("limit_of_users") if limit_of_users == 0: return {"possible": True} filter_ = FilterOperator("is_active", "=", True) - count_of_users = self.datastore.count("user", filter_) + count_of_users = self.datastore.count("user", filter_, lock_result=False) if ( count_of_users + self.data["number_of_users_to_add_or_activate"] > limit_of_users diff --git a/openslides_backend/presenter/presenter.py b/openslides_backend/presenter/presenter.py index f687f500da..30cf5c79e8 100644 --- a/openslides_backend/presenter/presenter.py +++ b/openslides_backend/presenter/presenter.py @@ -78,6 +78,7 @@ def handle_request(self, request: Request) -> tuple[PresenterResponse, str | Non # Parse presentations and creates response with get_new_os_conn() as conn: self.datastore = ExtendedDatabase(conn, self.logging, self.env) + self.datastore.never_lock = True response, access_token = self.parse_presenters(request) self.logger.debug("Request was successful. Send response now.") return response, access_token diff --git a/openslides_backend/presenter/search_for_id_by_external_id.py b/openslides_backend/presenter/search_for_id_by_external_id.py index 301083af53..167e24b5a6 100644 --- a/openslides_backend/presenter/search_for_id_by_external_id.py +++ b/openslides_backend/presenter/search_for_id_by_external_id.py @@ -61,7 +61,7 @@ def get_result(self) -> Any: if is_group := self.data["collection"] == "group": mapped_fields.append("meeting_id") filtered = self.datastore.filter( - self.data["collection"], filter_, mapped_fields + self.data["collection"], filter_, mapped_fields, lock_result=False ) if is_group and len(filtered): self.filter_out_locked_meeting_groups(filtered) diff --git a/openslides_backend/services/database/extended_database.py b/openslides_backend/services/database/extended_database.py index b60f92216f..df74f43755 100644 --- a/openslides_backend/services/database/extended_database.py +++ b/openslides_backend/services/database/extended_database.py @@ -93,6 +93,7 @@ class ExtendedDatabase(Database): _changed_models: ModelMap locked_fields: dict[str, CollectionFieldLock] + never_lock: bool = False def __init__( self, connection: Connection[rows.DictRow], logging: LoggingModule, env: Env @@ -174,6 +175,7 @@ def get( changes - all updates to any model during the action are saved in there. The parameter use_changed_models defines whether they are searched or not. """ + self._check_never_lock(lock_result) if fqid is None: raise BadCodingException("No fqid. Offer at least one fqid.") try: @@ -251,6 +253,7 @@ def get_many( lock_result: LockResult = True, use_changed_models: bool = True, ) -> dict[Collection, dict[int, PartialModel]]: + self._check_never_lock(lock_result) if use_changed_models: mapped_fields_per_collection_and_id: dict[str, dict[int, Any]] = ( defaultdict(dict) @@ -355,6 +358,7 @@ def get_all( mapped_fields: list[str] = [], lock_result: bool = True, ) -> dict[Id, PartialModel]: + self._check_never_lock(lock_result) return self.database_reader.get_all( collection, MappedFields(mapped_fields), lock_result ) @@ -367,6 +371,7 @@ def filter( lock_result: bool = True, use_changed_models: bool = True, ) -> dict[int, PartialModel]: + self._check_never_lock(lock_result) if not filter_: result = self.database_reader.get_all( collection, MappedFields(mapped_fields), lock_result @@ -463,6 +468,7 @@ def aggregate( lock_result: bool = True, use_changed_models: bool = True, ) -> int | None: + self._check_never_lock(lock_result) if method not in VALID_AGGREGATE_FUNCTIONS: raise BadCodingException(f"Invalid aggregate function: {method}") if use_changed_models and self._changed_models[collection]: @@ -642,6 +648,7 @@ def execute_custom_select( lock_result: LockResult = False, arguments: SqlArgumentsExtended = [], ) -> list[PartialModel]: + self._check_never_lock(lock_result) return self.database_reader.execute_custom_select(query, lock_result, arguments) def _model_fits_subfilter( @@ -747,3 +754,16 @@ def _model_fits_operator_filter( raise NotImplementedError("Operator %= is not supported") case default: raise NotImplementedError(f"Operator {default} is not supported") + + def _check_never_lock(self, lock_result: LockResult) -> None: + """ + A check for select methods that can lock. + Raises a BadCodingException if locking is on and never_lock is enabled. + + This is a programming safety mechanism to ensure the presenters don't + select with locking on. + """ + if self.env.is_dev_mode() and self.never_lock and lock_result: + raise BadCodingException( + "ExtendedDatabase running in never_lock mode, all requests must have locking set to false." + ) diff --git a/openslides_backend/shared/export_helper.py b/openslides_backend/shared/export_helper.py index 8338d7bbdc..2252869ea3 100644 --- a/openslides_backend/shared/export_helper.py +++ b/openslides_backend/shared/export_helper.py @@ -103,6 +103,7 @@ def export_meeting( ), ], use_changed_models=False, + lock_result=False, )["mediafile"] ) next_file_ids = list( diff --git a/openslides_backend/shared/mixins/user_create_update_permissions_mixin.py b/openslides_backend/shared/mixins/user_create_update_permissions_mixin.py index fdbda9044a..10916113f8 100644 --- a/openslides_backend/shared/mixins/user_create_update_permissions_mixin.py +++ b/openslides_backend/shared/mixins/user_create_update_permissions_mixin.py @@ -103,7 +103,8 @@ def _get_user_committees_and_meetings(self) -> tuple[set[int], set[int]]: list(user_committees), ["meeting_ids", "all_child_ids"], ) - ] + ], + lock_result=False, ) .get("committee", {}) .values() @@ -124,7 +125,8 @@ def _get_user_committees_and_meetings(self) -> tuple[set[int], set[int]]: list(child_ids), ["meeting_ids"], ) - ] + ], + lock_result=False, ) .get("committee", {}) .values() @@ -154,6 +156,7 @@ def _get_user_meetings_with_permission( meeting_user = self.datastore.get( fqid_from_collection_and_id("meeting_user", meeting_user_id), ["group_ids", "locked_out"], + lock_result=False, ) group_ids = ( meeting_user.get("group_ids") @@ -174,7 +177,8 @@ def _get_user_meetings_with_permission( list(all_groups), ["meeting_id", "permissions", "admin_group_for_meeting_id"], ) - ] + ], + lock_result=False, ) .get("group", {}) .values() diff --git a/openslides_backend/shared/mixins/user_scope_mixin.py b/openslides_backend/shared/mixins/user_scope_mixin.py index fe99918deb..824bd6166a 100644 --- a/openslides_backend/shared/mixins/user_scope_mixin.py +++ b/openslides_backend/shared/mixins/user_scope_mixin.py @@ -282,7 +282,8 @@ def _map_meetings_to_committees( meeting_ids, ["committee_id", "is_active_in_organization_id"], ) - ] + ], + lock_result=False, ).get("meeting", {}) for meeting_id, meeting_data in raw_meetings_data.items(): diff --git a/tests/system/action/user/test_participant_import.py b/tests/system/action/user/test_participant_import.py index e36c7813cc..3a7ab011d6 100644 --- a/tests/system/action/user/test_participant_import.py +++ b/tests/system/action/user/test_participant_import.py @@ -99,6 +99,11 @@ def test_import_abort(self) -> None: self.assert_model_not_exists("import_preview/1") self.assert_model_not_exists("user/2") + def test_import_no_id(self) -> None: + response = self.request("participant.import", {"import": True}) + self.assert_status_code(response, 400) + assert response.json["message"] == "Payload must contain import_preview id." + def test_import_wrong_invalid_name_in_preview(self) -> None: self.update_model("import_preview/1", {"name": "account"}) response = self.request("participant.import", {"id": 1, "import": True}) From b61ba63e8fc20c07c88ea98191b6b4f61f77871d Mon Sep 17 00:00:00 2001 From: luisa-beerboom <101706784+luisa-beerboom@users.noreply.github.com> Date: Wed, 16 Sep 2026 13:13:20 +0200 Subject: [PATCH 06/53] Participant import rework (#3688) Co-authored-by: Hannes Janott Co-authored-by: Javier Borrego --- docs/actions/participant.json_upload.md | 2 + docs/actions/preface_special_imports.md | 108 +++- .../action/actions/user/base_json_upload.py | 30 +- .../actions/user/participant_json_upload.py | 63 +++ .../action/mixins/import_mixins.py | 106 +++- .../action/user/test_participant_import.py | 297 +++++++--- .../user/test_participant_json_upload.py | 515 ++++++++++++------ 7 files changed, 857 insertions(+), 264 deletions(-) diff --git a/docs/actions/participant.json_upload.md b/docs/actions/participant.json_upload.md index 268e91c0d8..21269bb60e 100644 --- a/docs/actions/participant.json_upload.md +++ b/docs/actions/participant.json_upload.md @@ -55,6 +55,8 @@ The field `is_present` is a boolean in the payload. When importing this data, th Structure levels will be created during the later import phase if they aren't found. For this purpose the statistics row includes an extra point 'structure levels created' +This action supports change detection (See [here](preface_special_imports.md#change-detection)) + ### User matching Same as in [account.json_upload#user-matching](account.json_upload.md#user-matching) diff --git a/docs/actions/preface_special_imports.md b/docs/actions/preface_special_imports.md index 326ec11649..14eb265594 100644 --- a/docs/actions/preface_special_imports.md +++ b/docs/actions/preface_special_imports.md @@ -54,6 +54,7 @@ This type will be used, if we need to give more information than just a value (o value: boolean | number | integer | string | date; info: ImportState; id: number; // optional + changed: bool; // optional and only used in imports that support it } ``` @@ -129,8 +130,11 @@ The internal types will be created by the backend service from the CSV-strings rows: [ //details and example see above { state: string, // row state, one of done, new, error - messages: [string], + messages: string[], data: json, + list_delete_amounts: { + [string]: int + } } ] } @@ -150,8 +154,108 @@ The internal types will be created by the backend service from the CSV-strings // property name and type must match an entry in the given `headers` [property: string]: (boolean | number | string | date | object) []; // if is_list is set in corresponding header column, we need here also a list. `object` only on error }; + list_delete_amounts: { [string]: int } // optional and only used in imports that support change detection. See more in section 'Change Detection'. }[]; // row-list: Empty list, if `import` in payload was `false` to delete the import_preview-record on database }[[]]; // nested lists for actions and data row per action } -`` +``` + +## Change Detection +### The `changed` and `list_delete_amounts` keywords +These keywords are used in the preview to signify the relation between the cell content and the related database data at the time of upload. + +Any single field that contains a value that would change database data (i.e. by filling in a new field, changing a value or creating a new model) will be marked with `"changed": True`. + +For list columns, every new element is marked with `"changed": True`. Any removed values are counted and then added to the `list_delete_amounts`-dict with the import field name as keyword. + +These keywords are only written for update or reference rows in imports that support change detection, and if `changed` isn't written there it is assumed to be `False`. + +In such imports all columns should be object columns. + +### Example of one result element: +```js +{ + headers: [ + { + property: "name", + type: "string", + is_object: true, + }, + { + property: "number", + type: "integer", + is_object: true, + }, + { + property: "admin", + type: "string", + is_object: true, + is_list: true, + } + ], + rows: [ + { + state: "done", + messages: [], + data: { + id: 3, + name: { + value: "test", + info: "done", + id: 3 + }, + number: { + value: 123456, + info: "done", + changed: true + }, + admin: [ + { + value: "fritz", + info: "done", + id: 234 + }, + { + value: "kalle", + info: "new", + changed: true + }, + ] + }, + list_delete_amounts: { admin: 2 } + }, + { + state: "new", + messages: [], + data: { + name: { + value: "test2", + info: "new", + }, + number: { + value: 1234567, + info: "done", + }, + admin: [ + { + value: "fritz", + info: "done", + id: 234 + }, + { + value: "kalle2electric_boogaloo", + info: "new", + }, + ] + } + }, + ], + statistics: [ + {name: "itemCount", value: 8}, + {name: "bla foo", value: 3}, + {name: "blub", value: 5} + ] +} +``` + diff --git a/openslides_backend/action/actions/user/base_json_upload.py b/openslides_backend/action/actions/user/base_json_upload.py index 48d4cea489..0a0f9a9013 100644 --- a/openslides_backend/action/actions/user/base_json_upload.py +++ b/openslides_backend/action/actions/user/base_json_upload.py @@ -114,6 +114,9 @@ def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]: self.generate_statistics() return {} + def get_row_state_for_update_row(self, id_: int) -> ImportState: + return ImportState.DONE + def validate_entry(self, entry: dict[str, Any]) -> dict[str, Any]: messages: list[str] = [] id_: int | None = None @@ -132,11 +135,11 @@ def validate_entry(self, entry: dict[str, Any]) -> dict[str, Any]: username, "default_password" ), ) - self.row_state = ImportState.DONE + self.row_state = self.get_row_state_for_update_row(id_) entry["id"] = id_ entry["username"] = { "value": username, - "info": ImportState.DONE, + "info": self.row_state, "id": id_, } elif check_result == ResultType.NOT_FOUND or id_ == 0: @@ -169,12 +172,12 @@ def validate_entry(self, entry: dict[str, Any]) -> dict[str, Any]: self.saml_id_lookup.get_field_by_name(saml_id, "default_password"), ) - self.row_state = ImportState.DONE + self.row_state = self.get_row_state_for_update_row(id_) entry["id"] = id_ if isinstance(username, str): entry["username"] = { "value": username, - "info": ImportState.DONE, + "info": self.row_state, "id": id_, } elif check_result == ResultType.NOT_FOUND or id_ == 0: @@ -211,7 +214,7 @@ def validate_entry(self, entry: dict[str, Any]) -> dict[str, Any]: names_and_email, "default_password" ), ) - self.row_state = ImportState.DONE + self.row_state = self.get_row_state_for_update_row(id_) entry["id"] = id_ entry["username"] = { "value": ( @@ -219,7 +222,7 @@ def validate_entry(self, entry: dict[str, Any]) -> dict[str, Any]: if isinstance(username, dict) else username ), - "info": ImportState.DONE, + "info": self.row_state, "id": id_, } elif check_result == ResultType.NOT_FOUND or id_ == 0: @@ -284,7 +287,7 @@ def validate_entry(self, entry: dict[str, Any]) -> dict[str, Any]: entry["member_number"] = { "id": id_, "value": member_number, - "info": ImportState.DONE, + "info": self.get_row_state_for_update_row(id_), } if not entry.get("username"): entry["username"] = { @@ -297,7 +300,7 @@ def validate_entry(self, entry: dict[str, Any]) -> dict[str, Any]: ): entry["username"]["info"] = ImportState.NEW if self.row_state != ImportState.ERROR: - self.row_state = ImportState.DONE + self.row_state = entry["member_number"]["info"] elif check_result == ResultType.FOUND_MORE_IDS: self.row_state = ImportState.ERROR entry["member_number"] = { @@ -359,6 +362,9 @@ def validate_entry(self, entry: dict[str, Any]) -> dict[str, Any]: or old_default_password ): entry["default_password"] = {"value": "", "info": ImportState.WARNING} + if self.check_changes: + entry["default_password"]["changed"] = False + messages.append( f"Because this {self.import_name} is connected with a saml_id: The default_password will be ignored and password will not be changeable in OpenSlides." ) @@ -618,7 +624,7 @@ def setup_lookups(self, data: list[dict[str, Any]]) -> None: if (username := entry.get("username")) ], field="username", - mapped_fields=["username", "saml_id", "default_password"], + mapped_fields=["username", "saml_id", "default_password", "meeting_ids"], ) self.saml_id_lookup = Lookup( self.datastore, @@ -629,7 +635,7 @@ def setup_lookups(self, data: list[dict[str, Any]]) -> None: if not entry.get("username") and (saml_id := entry.get("saml_id")) ], field="saml_id", - mapped_fields=["saml_id", "username", "default_password"], + mapped_fields=["saml_id", "username", "default_password", "meeting_ids"], ) self.names_email_lookup = Lookup( self.datastore, @@ -649,7 +655,7 @@ def setup_lookups(self, data: list[dict[str, Any]]) -> None: and names_email != ("", "", "") ], field=("first_name", "last_name", "email"), - mapped_fields=["username", "saml_id", "default_password"], + mapped_fields=["username", "saml_id", "default_password", "meeting_ids"], ) self.all_saml_id_lookup = Lookup( self.datastore, @@ -667,7 +673,7 @@ def setup_lookups(self, data: list[dict[str, Any]]) -> None: if (member_number := entry.get("member_number")) ], field="member_number", - mapped_fields=["username", "member_number", "saml_id"], + mapped_fields=["username", "member_number", "saml_id", "meeting_ids"], ) self.gender_dict = self.datastore.get_all( "gender", ["id", "name"], lock_result=False diff --git a/openslides_backend/action/actions/user/participant_json_upload.py b/openslides_backend/action/actions/user/participant_json_upload.py index 39fe2d2344..360b9325fe 100644 --- a/openslides_backend/action/actions/user/participant_json_upload.py +++ b/openslides_backend/action/actions/user/participant_json_upload.py @@ -8,6 +8,7 @@ from openslides_backend.shared.schema import required_id_schema, str_list_schema from ...mixins.import_mixins import ImportState +from ...mixins.meeting_user_helper import get_meeting_user from ...util.register import register_action from ...util.typing import ActionData from .base_json_upload import BaseUserJsonUpload @@ -52,6 +53,31 @@ class ParticipantJsonUpload(BaseUserJsonUpload, ParticipantCommon): lookups: dict[str, dict[str, int]] = {} default_group: dict[str, Any] = {} missing_field_values: dict[str, set[str]] + use_referenced_state: bool = True + check_changes: bool = True + property_to_equivalent: dict[str, tuple[str, str]] = { + "title": ("user", "title"), + "first_name": ("user", "first_name"), + "last_name": ("user", "last_name"), + "is_active": ("user", "is_active"), + "is_physical_person": ("user", "is_physical_person"), + "default_password": ("user", "default_password"), + "email": ("user", "email"), + "username": ("user", "username"), + "pronoun": ("user", "pronoun"), + "saml_id": ("user", "saml_id"), + "member_number": ("user", "member_number"), + "external": ("user", "external"), + "gender": ("user", "gender_id"), + "home_committee": ("user", "home_committee_id"), + "is_present": ("user", "is_present_in_meeting_ids"), + "structure_level": ("meeting_user", "structure_level_ids"), + "number": ("meeting_user", "number"), + "vote_weight": ("meeting_user", "vote_weight"), + "comment": ("meeting_user", "comment"), + "groups": ("meeting_user", "group_ids"), + "locked_out": ("meeting_user", "locked_out"), + } def prefetch(self, action_data: ActionData) -> None: self.meeting_id = next(iter(action_data)).get("meeting_id", 0) @@ -215,3 +241,40 @@ def setup_lookups(self, data: list[dict[str, Any]]) -> None: if group.get("default_group_for_meeting_id"): self.default_group = {"name": group["name"], "id": group["id"]} break + + def get_row_state_for_update_row(self, id_: int) -> ImportState: + meeting_user = get_meeting_user(self.datastore, self.meeting_id, id_, ["id"]) + return ImportState.DONE if meeting_user else ImportState.REFERENCED + + def get_model_data(self, id_: int) -> dict[str, Any]: + model_fields = [ + equivalent[1] + for header in self.headers + if (equivalent := self.property_to_equivalent[header["property"]])[0] + == self.model.collection + ] + meeting_user_fields = [ + eq + for header in self.headers + if (eq := self.property_to_equivalent[header["property"]][1]) + not in model_fields + ] + model = self.datastore.get( + fqid_from_collection_and_id(self.model.collection, id_), model_fields + ) + meeting_user = get_meeting_user( + self.datastore, self.meeting_id, id_, meeting_user_fields + ) + if meeting_user: + model.update(meeting_user) + return model + + def get_value_from_model_data(self, db_model: dict[str, Any], field: str) -> Any: + if field == "is_present": + return self.meeting_id in db_model.get("is_present_in_meeting_ids", []) + return db_model.get(self.property_to_equivalent[field][1]) + + def get_true_value_from_object(self, entry: dict[str, Any], field: str) -> Any: + if field == self.property_to_equivalent[field][1]: + return entry["value"] + return super().get_true_value_from_object(entry, field) diff --git a/openslides_backend/action/mixins/import_mixins.py b/openslides_backend/action/mixins/import_mixins.py index 4f224f0eee..fa31633135 100644 --- a/openslides_backend/action/mixins/import_mixins.py +++ b/openslides_backend/action/mixins/import_mixins.py @@ -40,6 +40,7 @@ class ImportState(StrEnum): GENERATED = "generated" REMOVE = "remove" ERROR = "error" + REFERENCED = "referenced" class ImportRow(TypedDict): @@ -266,7 +267,7 @@ def validate_with_lookup( error: str | None = None if check_result == ResultType.FOUND_ID and id_ != 0: if required: - if row["state"] != ImportState.DONE: + if row["state"] not in [ImportState.DONE, ImportState.REFERENCED]: error = f"Error: row state expected to be '{ImportState.DONE}', but it is '{row['state']}'." elif "id" not in entry: raise ActionException( @@ -393,12 +394,102 @@ class BaseJsonUploadAction(BaseImportJsonUploadAction): import_state: ImportState meeting_id: int timezone_field_name: str | None = None + use_referenced_state: bool = False + check_changes: bool = False def base_update_instance(self, instance: dict[str, Any]) -> dict[str, Any]: instance = super().base_update_instance(instance) + property_to_type = { + header["property"]: ( + header["type"], + header.get("is_object"), + header.get("is_list", False), + ) + for header in self.headers + } + for row in self.rows: + if self.check_changes and row["state"] in [ + ImportState.DONE, + ImportState.REFERENCED, + ]: + list_delete_amounts: dict[str, int] = {} + db_model = self.get_model_data(row["data"]["id"]) + for field, entry in row["data"].items(): + if field in property_to_type: + type_, is_object, is_list = property_to_type[field] + if is_list and entry: + list_values = { + ( + self.get_true_value_from_object(e, field) + if is_object + else e + ) + for e in entry + } + value_from_model = set( + self.get_value_from_model_data(db_model, field) or [] + ) + removed = value_from_model.difference(list_values) + if ( + added := list_values.difference(value_from_model) + ) or removed: + if removed: + list_delete_amounts[field] = len(removed) + if added: + if is_object: + for e in entry: + if ( + self.get_true_value_from_object( + e, field + ) + in added + and "changed" not in e + and e["info"] != ImportState.REMOVE + ): + e["changed"] = True + else: + row["data"][field] = [ + { + "value": e, + "info": ImportState.DONE, + "changed": e in added, + } + for e in entry + ] + elif entry is not None: + if is_object: + if ( + self.get_true_value_from_object(entry, field) + != self.get_value_from_model_data(db_model, field) + and "changed" not in entry + and entry["info"] != ImportState.REMOVE + ): + entry["changed"] = True + elif entry != self.get_value_from_model_data( + db_model, field + ): + row["data"][field] = { + "value": entry, + "info": ImportState.DONE, + "changed": True, + } + if list_delete_amounts: + row["list_delete_amounts"] = list_delete_amounts self.store_rows_in_the_import_preview(self.import_name) return instance + def get_model_data(self, id_: int) -> dict[str, Any]: + return self.datastore.get( + fqid_from_collection_and_id(self.model.collection, id_), + [header["property"] for header in self.headers], + ) + + def get_value_from_model_data(self, db_model: dict[str, Any], field: str) -> Any: + return db_model.get(field) + + def get_true_value_from_object(self, entry: dict[str, Any], field: str) -> Any: + return entry.get("id", entry["value"]) + def set_state(self, number_errors: int, number_warnings: int) -> None: if number_errors > 0: self.import_state = ImportState.ERROR @@ -590,6 +681,19 @@ def generate_statistics(self) -> None: {"name": "total", "value": len(self.rows)}, {"name": "created", "value": state_to_count[ImportState.NEW]}, {"name": "updated", "value": state_to_count[ImportState.DONE]}, + *( + [ + cast( + StatisticEntry, + { + "name": "referenced", + "value": state_to_count[ImportState.REFERENCED], + }, + ) + ] + if self.use_referenced_state + else [] + ), {"name": "error", "value": state_to_count[ImportState.ERROR]}, {"name": "warning", "value": state_to_count[ImportState.WARNING]}, ] diff --git a/tests/system/action/user/test_participant_import.py b/tests/system/action/user/test_participant_import.py index 3a7ab011d6..4dae3efe33 100644 --- a/tests/system/action/user/test_participant_import.py +++ b/tests/system/action/user/test_participant_import.py @@ -324,12 +324,28 @@ def test_upload_import_invalid_vote_weight_with_remove(self) -> None: assert result["rows"][0]["state"] == ImportState.DONE assert result["rows"][0]["data"] == { "id": 2, - "first_name": {"value": "Wilhelm", "info": ImportState.DONE}, - "last_name": {"value": "Aberhatnurhut", "info": ImportState.DONE}, - "email": {"value": "will@helm.hut", "info": ImportState.DONE}, + "first_name": { + "value": "Wilhelm", + "info": ImportState.DONE, + "changed": True, + }, + "last_name": { + "value": "Aberhatnurhut", + "info": ImportState.DONE, + "changed": True, + }, + "email": { + "value": "will@helm.hut", + "info": ImportState.DONE, + "changed": True, + }, "vote_weight": {"value": "0.000000", "info": ImportState.REMOVE}, "username": {"id": 2, "value": "wilhelm", "info": ImportState.DONE}, - "default_password": {"value": "123", "info": ImportState.DONE}, + "default_password": { + "value": "123", + "info": ImportState.DONE, + "changed": True, + }, "groups": [{"id": 1, "info": "generated", "value": "group1"}], } self.assert_model_exists( @@ -475,15 +491,35 @@ def test_json_upload_set_saml_id_remove_presence(self) -> None: assert row["data"] == { "id": 10, "username": {"id": 10, "info": ImportState.DONE, "value": "user10"}, - "saml_id": {"info": ImportState.NEW, "value": "saml_id10"}, - "default_password": {"info": ImportState.WARNING, "value": ""}, - "is_present": {"info": ImportState.DONE, "value": False}, - "vote_weight": {"info": ImportState.DONE, "value": "2.800000"}, + "saml_id": {"info": ImportState.NEW, "value": "saml_id10", "changed": True}, + "default_password": { + "info": ImportState.WARNING, + "value": "", + "changed": False, + }, + "is_present": {"info": ImportState.DONE, "value": False, "changed": True}, + "vote_weight": { + "info": ImportState.DONE, + "value": "2.800000", + "changed": True, + }, "groups": [{"id": 1, "info": ImportState.GENERATED, "value": "group1"}], - "structure_level": [{"info": ImportState.DONE, "value": "new sl", "id": 2}], - "number": {"info": ImportState.DONE, "value": "new number"}, - "comment": {"info": ImportState.DONE, "value": "new comment"}, + "structure_level": [ + {"info": ImportState.DONE, "value": "new sl", "id": 2, "changed": True} + ], + "number": { + "info": ImportState.DONE, + "value": "new number", + "changed": True, + }, + "comment": { + "info": ImportState.DONE, + "value": "new comment", + "changed": True, + }, } + assert row["list_delete_amounts"] == {"structure_level": 1} + self.assert_model_exists( "user/10", { @@ -519,14 +555,16 @@ def test_json_upload_error_set_saml_id(self) -> None: assert row["data"] == { "id": 10, "username": {"id": 10, "info": "done", "value": "user10"}, - "saml_id": {"info": "error", "value": "saml_id10"}, - "default_password": {"info": "warning", "value": ""}, - "is_present": {"info": "done", "value": False}, - "vote_weight": {"info": "done", "value": "2.800000"}, + "saml_id": {"info": "error", "value": "saml_id10", "changed": True}, + "default_password": {"info": "warning", "value": "", "changed": False}, + "is_present": {"info": "done", "value": False, "changed": True}, + "vote_weight": {"info": "done", "value": "2.800000", "changed": True}, "groups": [{"id": 1, "info": "generated", "value": "group1"}], - "structure_level": [{"info": "done", "value": "new sl", "id": 2}], - "number": {"info": "done", "value": "new number"}, - "comment": {"info": "done", "value": "new comment"}, + "structure_level": [ + {"info": "done", "value": "new sl", "id": 2, "changed": True} + ], + "number": {"info": "done", "value": "new number", "changed": True}, + "comment": {"info": "done", "value": "new comment", "changed": True}, } def test_json_upload_user_not_found_anymore( @@ -546,7 +584,9 @@ def test_json_upload_user_not_found_anymore( "id": 11, "saml_id": {"info": "done", "value": "saml_id11"}, "username": {"id": 11, "info": ImportState.ERROR, "value": "user11"}, - "groups": [{"id": 1, "info": "generated", "value": "group1"}], + "groups": [ + {"id": 1, "info": "generated", "value": "group1", "changed": True} + ], } def test_json_upload_update_multiple_users_okay(self) -> None: @@ -715,22 +755,38 @@ def test_json_upload_one_structure_level_newly_created(self) -> None: self.assert_status_code(response, 200) assert (result := response.json["results"][0][0])["state"] == ImportState.DONE row = result["rows"][0] - assert row["state"] == ImportState.DONE + assert row["state"] == ImportState.REFERENCED assert row["messages"] == [ "Because this participant is connected with a saml_id: The default_password will be ignored and password will not be changeable in OpenSlides.", ] assert row["data"] == { "id": 2, - "saml_id": {"info": ImportState.NEW, "value": "test_saml_id2"}, - "username": {"id": 2, "info": ImportState.DONE, "value": "user2"}, - "default_password": {"info": ImportState.WARNING, "value": ""}, + "saml_id": { + "info": ImportState.NEW, + "value": "test_saml_id2", + "changed": True, + }, + "username": {"id": 2, "info": ImportState.REFERENCED, "value": "user2"}, + "default_password": { + "info": ImportState.WARNING, + "value": "", + "changed": False, + }, "groups": [ - {"id": 3, "info": "done", "value": "group3"}, - {"id": created_groups["group4"], "info": "new", "value": "group4"}, + {"id": 3, "info": "done", "value": "group3", "changed": True}, + { + "id": created_groups["group4"], + "info": "new", + "value": "group4", + "changed": True, + }, + ], + "structure_level": [ + {"info": "new", "value": "level up", "id": 2, "changed": True} ], - "structure_level": [{"info": "new", "value": "level up", "id": 2}], - "gender": {"id": 3, "info": "done", "value": "diverse"}, + "gender": {"id": 3, "info": "done", "value": "diverse", "changed": True}, } + assert "list_delete_amounts" not in row row = result["rows"][1] assert row["state"] == ImportState.DONE @@ -741,24 +797,39 @@ def test_json_upload_one_structure_level_newly_created(self) -> None: "id": 3, "saml_id": {"info": ImportState.DONE, "value": "saml3"}, "username": {"id": 3, "info": ImportState.DONE, "value": "user3"}, - "default_password": {"info": ImportState.WARNING, "value": ""}, - "vote_weight": {"info": ImportState.DONE, "value": "3.345678"}, - "groups": [{"id": 3, "info": "done", "value": "group3"}], + "default_password": { + "info": ImportState.WARNING, + "value": "", + "changed": False, + }, + "vote_weight": { + "info": ImportState.DONE, + "value": "3.345678", + "changed": True, + }, + "groups": [{"id": 3, "info": "done", "value": "group3", "changed": True}], } + assert row["list_delete_amounts"] == {"groups": 2} row = result["rows"][2] - assert row["state"] == ImportState.DONE + assert row["state"] == ImportState.REFERENCED assert row["messages"] == [] assert row["data"] == { "id": 4, "email": {"value": "mlk@america.com", "info": ImportState.DONE}, - "username": {"id": 4, "info": ImportState.DONE, "value": "user4"}, + "username": {"id": 4, "info": ImportState.REFERENCED, "value": "user4"}, "last_name": {"value": "Luther King", "info": ImportState.DONE}, "first_name": {"value": "Martin", "info": ImportState.DONE}, "groups": [ - {"id": created_groups["group4"], "info": "new", "value": "group4"} + { + "id": created_groups["group4"], + "info": "new", + "value": "group4", + "changed": True, + } ], } + assert "list_delete_amounts" not in row row = result["rows"][3] assert row["state"] == ImportState.NEW @@ -768,13 +839,18 @@ def test_json_upload_one_structure_level_newly_created(self) -> None: assert row["data"] == { "username": {"info": ImportState.DONE, "value": "new_user5"}, "saml_id": {"info": ImportState.NEW, "value": "saml5"}, - "default_password": {"info": ImportState.WARNING, "value": ""}, + "default_password": { + "info": ImportState.WARNING, + "value": "", + "changed": False, + }, "groups": [{"id": 1, "info": "generated", "value": "group1"}], "structure_level": [ {"info": ImportState.NEW, "value": "level up", "id": 2}, {"info": ImportState.DONE, "value": "no. 5", "id": 1}, ], } + assert "list_delete_amounts" not in row self.assert_model_exists("structure_level/2", {"name": "level up"}) @@ -786,12 +862,17 @@ def test_json_upload_one_structure_level_newly_created(self) -> None: assert row["data"] == { "username": {"info": ImportState.GENERATED, "value": "new_saml6"}, "saml_id": {"info": ImportState.NEW, "value": "new_saml6"}, - "default_password": {"info": ImportState.WARNING, "value": ""}, + "default_password": { + "info": ImportState.WARNING, + "value": "", + "changed": False, + }, "is_present": {"info": "done", "value": True}, "groups": [ {"id": created_groups["group4"], "info": "new", "value": "group4"}, ], } + assert "list_delete_amounts" not in row def test_json_upload_update_multiple_users_all_error(self) -> None: self.json_upload_multiple_users() @@ -832,16 +913,25 @@ def test_json_upload_update_multiple_users_all_error(self) -> None: ] assert row["data"] == { "id": 2, - "saml_id": {"info": ImportState.NEW, "value": "test_saml_id2"}, + "saml_id": { + "info": ImportState.NEW, + "value": "test_saml_id2", + "changed": True, + }, "username": {"id": 2, "info": ImportState.ERROR, "value": "user2"}, - "default_password": {"info": ImportState.WARNING, "value": ""}, + "default_password": { + "info": ImportState.WARNING, + "value": "", + "changed": False, + }, "groups": [ - {"id": 3, "info": "warning", "value": "group3"}, - {"info": "new", "value": "group4"}, + {"id": 3, "info": "warning", "value": "group3", "changed": True}, + {"info": "new", "value": "group4", "changed": True}, ], - "structure_level": [{"info": "new", "value": "level up"}], - "gender": {"id": 3, "info": "done", "value": "diverse"}, + "structure_level": [{"info": "new", "value": "level up", "changed": True}], + "gender": {"id": 3, "info": "done", "value": "diverse", "changed": True}, } + assert "list_delete_amounts" not in row row = result["rows"][1] assert row["state"] == ImportState.ERROR @@ -854,10 +944,19 @@ def test_json_upload_update_multiple_users_all_error(self) -> None: "id": 3, "saml_id": {"info": ImportState.DONE, "value": "saml3"}, "username": {"id": 3, "info": ImportState.DONE, "value": "user3"}, - "default_password": {"info": ImportState.WARNING, "value": ""}, - "vote_weight": {"info": ImportState.DONE, "value": "3.345678"}, - "groups": [{"id": 3, "info": "error", "value": "group3"}], + "default_password": { + "info": ImportState.WARNING, + "value": "", + "changed": False, + }, + "vote_weight": { + "info": ImportState.DONE, + "value": "3.345678", + "changed": True, + }, + "groups": [{"id": 3, "info": "error", "value": "group3", "changed": True}], } + assert row["list_delete_amounts"] == {"groups": 2} row = result["rows"][2] assert row["state"] == ImportState.ERROR @@ -871,9 +970,10 @@ def test_json_upload_update_multiple_users_all_error(self) -> None: "last_name": {"value": "Luther King", "info": ImportState.DONE}, "first_name": {"value": "Martin", "info": ImportState.DONE}, "groups": [ - {"info": "new", "value": "group4"}, + {"info": "new", "value": "group4", "changed": True}, ], } + assert "list_delete_amounts" not in row row = result["rows"][3] assert row["state"] == ImportState.ERROR @@ -884,13 +984,18 @@ def test_json_upload_update_multiple_users_all_error(self) -> None: assert row["data"] == { "username": {"info": ImportState.DONE, "value": "new_user5"}, "saml_id": {"info": ImportState.ERROR, "value": "saml5"}, - "default_password": {"info": ImportState.WARNING, "value": ""}, + "default_password": { + "info": ImportState.WARNING, + "value": "", + "changed": False, + }, "groups": [{"id": 1, "info": "generated", "value": "group1"}], "structure_level": [ {"info": ImportState.NEW, "value": "level up"}, {"info": ImportState.NEW, "value": "no. 5"}, ], } + assert "list_delete_amounts" not in row row = result["rows"][4] assert row["state"] == ImportState.ERROR @@ -901,12 +1006,17 @@ def test_json_upload_update_multiple_users_all_error(self) -> None: assert row["data"] == { "username": {"info": ImportState.GENERATED, "value": "new_saml6"}, "saml_id": {"info": ImportState.ERROR, "value": "new_saml6"}, - "default_password": {"info": ImportState.WARNING, "value": ""}, + "default_password": { + "info": ImportState.WARNING, + "value": "", + "changed": False, + }, "is_present": {"info": "done", "value": True}, "groups": [ {"info": "new", "value": "group4"}, ], } + assert "list_delete_amounts" not in row row = result["rows"][5] assert row["state"] == ImportState.NEW @@ -925,6 +1035,7 @@ def test_json_upload_update_multiple_users_all_error(self) -> None: {"info": "new", "value": "unknown"}, {"id": 7, "info": "warning", "value": "group7M1"}, ] + assert "list_delete_amounts" not in row def test_json_upload_with_complicated_names(self) -> None: self.json_upload_with_complicated_names() @@ -962,15 +1073,16 @@ def test_json_upload_with_sufficient_field_permission_update(self) -> None: "username": {"id": 2, "info": "done", "value": "user2"}, "first_name": {"info": "done", "value": "Jim"}, "email": {"info": "done", "value": "Jim.Knopf@Lummer.land"}, - "vote_weight": {"info": "done", "value": "1.234560"}, - "default_password": {"info": "done", "value": ""}, + "vote_weight": {"info": "done", "value": "1.234560", "changed": True}, + "default_password": {"info": "done", "value": "", "changed": False}, "groups": [ {"id": 1, "info": "done", "value": "group1"}, - {"id": 2, "info": "done", "value": "group2"}, - {"id": 3, "info": "done", "value": "group3"}, - {"id": 7, "info": "new", "value": "group4"}, + {"id": 2, "info": "done", "value": "group2", "changed": True}, + {"id": 3, "info": "done", "value": "group3", "changed": True}, + {"id": 7, "info": "new", "value": "group4", "changed": True}, ], } + assert "list_delete_amounts" not in row self.assert_model_exists( "user/2", { @@ -1018,13 +1130,13 @@ def test_json_upload_less_fields_field_permission_update(self) -> None: "username": {"id": 2, "info": "remove", "value": "user2"}, "first_name": {"info": "remove", "value": "Jim"}, "email": {"info": "remove", "value": "Jim.Knopf@Lummer.land"}, - "vote_weight": {"info": "done", "value": "1.234560"}, - "default_password": {"info": "remove", "value": ""}, + "vote_weight": {"info": "done", "value": "1.234560", "changed": True}, + "default_password": {"info": "remove", "value": "", "changed": False}, "groups": [ {"id": 1, "info": "done", "value": "group1"}, - {"id": 2, "info": "done", "value": "group2"}, - {"id": 3, "info": "done", "value": "group3"}, - {"id": 7, "info": "new", "value": "group4"}, + {"id": 2, "info": "done", "value": "group2", "changed": True}, + {"id": 3, "info": "done", "value": "group3", "changed": True}, + {"id": 7, "info": "new", "value": "group4", "changed": True}, ], } self.assert_model_exists( @@ -1067,13 +1179,13 @@ def test_json_upload_less_fields_field_permission_update_with_member_number( "username": {"info": "remove", "value": "user2"}, "first_name": {"info": "remove", "value": "Jim"}, "email": {"info": "remove", "value": "Jim.Knopf@Lummer.land"}, - "vote_weight": {"info": "done", "value": "1.234560"}, - "default_password": {"info": "remove", "value": ""}, + "vote_weight": {"info": "done", "value": "1.234560", "changed": True}, + "default_password": {"info": "remove", "value": "", "changed": False}, "groups": [ {"id": 1, "info": "done", "value": "group1"}, - {"id": 2, "info": "done", "value": "group2"}, - {"id": 3, "info": "done", "value": "group3"}, - {"id": 7, "info": "new", "value": "group4"}, + {"id": 2, "info": "done", "value": "group2", "changed": True}, + {"id": 3, "info": "done", "value": "group3", "changed": True}, + {"id": 7, "info": "new", "value": "group4", "changed": True}, ], "member_number": {"id": 2, "value": "M3MNUM", "info": "remove"}, } @@ -1119,7 +1231,7 @@ def test_json_upload_sufficient_field_permission_create(self) -> None: "username": {"info": "done", "value": "user2"}, "first_name": {"info": "done", "value": "Jim"}, "vote_weight": {"info": "error", "value": "1.234560"}, - "default_password": {"info": "warning", "value": ""}, + "default_password": {"info": "warning", "value": "", "changed": False}, "groups": [ {"id": 1, "info": "done", "value": "group1"}, {"id": 2, "info": "done", "value": "group2"}, @@ -1242,13 +1354,15 @@ def test_json_upload_try_to_update_to_username_that_was_created_in_between( ] assert row["data"] == { "id": 2, - "default_password": {"value": "", "info": "warning"}, - "username": {"info": "error", "value": "newname"}, - "saml_id": {"info": "new", "value": "some_other_saml"}, - "first_name": {"info": "done", "value": "second"}, - "last_name": {"info": "done", "value": "second_to_last"}, + "default_password": {"value": "", "info": "warning", "changed": False}, + "username": {"info": "error", "value": "newname", "changed": True}, + "saml_id": {"info": "new", "value": "some_other_saml", "changed": True}, + "first_name": {"info": "done", "value": "second", "changed": True}, + "last_name": {"info": "done", "value": "second_to_last", "changed": True}, "member_number": {"info": "done", "value": "M3MNUM", "id": 2}, - "groups": [{"id": 1, "info": "generated", "value": "group1"}], + "groups": [ + {"id": 1, "info": "generated", "value": "group1", "changed": True} + ], } def test_json_upload_add_member_number(self) -> None: @@ -1623,29 +1737,25 @@ def test_json_upload_update_home_committee_no_perms_new_anymore(self) -> None: ] assert response.json["results"][0][0]["rows"][0]["data"] == { "id": 2, - "first_name": { - "info": ImportState.DONE, - "value": "alice", - }, + "first_name": {"info": ImportState.DONE, "value": "alice", "changed": True}, "groups": [ { "id": 1, "info": ImportState.GENERATED, "value": "group1", + "changed": True, }, ], - "external": { - "info": ImportState.ERROR, - "value": False, - }, + "external": {"info": ImportState.ERROR, "value": False, "changed": True}, "home_committee": { "id": 2, "info": ImportState.ERROR, "value": "Home", + "changed": True, }, "username": { "id": 2, - "info": ImportState.DONE, + "info": ImportState.REFERENCED, "value": "Alice", }, } @@ -1713,13 +1823,13 @@ def test_json_upload_no_permissions_to_set_meeting_external_fields_on_superadmin "username": {"id": 2, "info": "remove", "value": "user2"}, "first_name": {"info": "remove", "value": "Jim"}, "email": {"info": "remove", "value": "Jim.Knopf@Lummer.land"}, - "vote_weight": {"info": "done", "value": "1.234560"}, - "default_password": {"info": "remove", "value": ""}, + "vote_weight": {"info": "done", "value": "1.234560", "changed": True}, + "default_password": {"info": "remove", "value": "", "changed": False}, "groups": [ {"id": 1, "info": "done", "value": "group1"}, - {"id": 2, "info": "done", "value": "group2"}, - {"id": 3, "info": "done", "value": "group3"}, - {"id": 7, "info": "new", "value": "group4"}, + {"id": 2, "info": "done", "value": "group2", "changed": True}, + {"id": 3, "info": "done", "value": "group3", "changed": True}, + {"id": 7, "info": "new", "value": "group4", "changed": True}, ], } self.assert_model_exists( @@ -1743,3 +1853,24 @@ def test_json_upload_no_permissions_to_set_meeting_external_fields_on_superadmin "group_ids": [1, 2, 3, 7], }, ) + + def test_json_upload_update_reference_via_two_attributes(self) -> None: + self.json_upload_update_reference_via_two_attributes() + response = self.request("participant.import", {"id": 1, "import": True}) + self.assert_status_code(response, 200) + row = response.json["results"][0][0]["rows"][0] + assert row["state"] == ImportState.DONE + assert row["data"] == { + "id": 2, + "saml_id": {"info": "done", "value": "old_one"}, + "username": {"info": "done", "value": "test", "id": 2}, + "default_password": { + "value": "", + "info": ImportState.WARNING, + "changed": False, + }, + "groups": [ + {"id": 1, "info": "generated", "value": "group1", "changed": True} + ], + } + assert row["list_delete_amounts"] == {"groups": 1} diff --git a/tests/system/action/user/test_participant_json_upload.py b/tests/system/action/user/test_participant_json_upload.py index 2f00d32ccf..b18b1df222 100644 --- a/tests/system/action/user/test_participant_json_upload.py +++ b/tests/system/action/user/test_participant_json_upload.py @@ -1,4 +1,5 @@ from datetime import datetime +from typing import Any from zoneinfo import ZoneInfo from openslides_backend.action.mixins.import_mixins import ImportState @@ -79,6 +80,7 @@ def test_json_upload_simple(self) -> None: ], }, } + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] assert {"name": "groups created", "value": 2} in response.json["results"][0][0][ "statistics" ] @@ -118,6 +120,7 @@ def test_json_upload_remove_last_admin(self) -> None: ], }, } + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_remove_last_admins(self) -> None: self.set_up_test_models() @@ -150,6 +153,7 @@ def test_json_upload_remove_last_admins(self) -> None: ], }, } + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] assert response.json["results"][0][0]["rows"][1] == { "state": ImportState.ERROR, "messages": ["Error: Cannot remove last member of admin group"], @@ -162,6 +166,7 @@ def test_json_upload_remove_last_admins(self) -> None: ], }, } + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][1] def test_json_upload_empty_data(self) -> None: self.set_up_test_models() @@ -218,6 +223,7 @@ def test_json_upload_without_names_error(self) -> None: "number": {"value": "strange number", "info": ImportState.DONE}, }, } + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_results(self) -> None: self.set_up_test_models() @@ -326,6 +332,7 @@ def test_json_upload_results(self) -> None: {"name": "total", "value": 1}, {"name": "created", "value": 1}, {"name": "updated", "value": 0}, + {"name": "referenced", "value": 0}, {"name": "error", "value": 0}, {"name": "warning", "value": 0}, {"name": "structure levels created", "value": 0}, @@ -474,24 +481,39 @@ def test_json_upload_names_and_email_find_add_meeting_data(self) -> None: ) self.assert_status_code(response, 200) row = response.json["results"][0][0]["rows"][0] - assert row["state"] == ImportState.DONE + assert row["state"] == ImportState.REFERENCED assert row["data"]["id"] == 34 assert row["data"]["default_password"] == { "value": "new default password", "info": "done", + "changed": True, + } + assert row["data"]["username"] == { + "value": "test", + "info": ImportState.REFERENCED, + "id": 34, + } + assert row["data"]["vote_weight"] == { + "value": "1.456000", + "info": "done", + "changed": True, } - assert row["data"]["username"] == {"value": "test", "info": "done", "id": 34} - assert row["data"]["vote_weight"] == {"value": "1.456000", "info": "done"} assert row["data"]["is_present"] == {"value": False, "info": "done"} - assert row["data"]["gender"] == {"id": 1, "value": "male", "info": "done"} + assert row["data"]["gender"] == { + "id": 1, + "value": "male", + "info": "done", + "changed": True, + } assert row["data"]["groups"] == [ - {"value": "testgroup", "info": "generated", "id": 1} + {"value": "testgroup", "info": "generated", "id": 1, "changed": True} ] assert row["data"]["structure_level"] == [ - {"value": "testlevel", "info": "done", "id": 1} + {"value": "testlevel", "info": "done", "id": 1, "changed": True} ] for key in fix_fields.keys(): assert row["data"][key]["value"] == fix_fields[key] + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_wrong_gender(self) -> None: self.set_up_test_models() @@ -604,6 +626,7 @@ def test_json_upload_names_generate_username_password_create_meeting(self) -> No assert entry["data"]["groups"] == [ {"value": "testgroup", "info": "generated", "id": 1} ] + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_invalid_vote_weight(self) -> None: self.set_up_test_models() @@ -638,6 +661,7 @@ def test_json_upload_invalid_vote_weight(self) -> None: "default_password": {"value": "halloIchBinMax", "info": ImportState.DONE}, "groups": [{"id": 1, "info": "generated", "value": "testgroup"}], } + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_not_sufficient_field_permission_update_with_wrong_email( self, @@ -693,6 +717,7 @@ def test_json_upload_not_sufficient_field_permission_update_with_wrong_email( "vote_weight": {"value": "1.234560", "info": "done"}, "groups": [{"id": 1, "info": ImportState.GENERATED, "value": "group1"}], } + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_wrong_email(self) -> None: self.create_meeting(1) @@ -744,6 +769,7 @@ def test_json_upload_wrong_email(self) -> None: "Error: 'this.is@wrong,too' is not a valid email address." in row["messages"] ) + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_with_illegal_decimal_value(self) -> None: self.create_meeting(1) @@ -812,6 +838,7 @@ def test_json_upload_update_member_number_in_existing_participant_error( "username": {"info": "done", "value": "test", "id": 2}, "groups": [{"id": 1, "info": "generated", "value": "group1"}], } + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_update_duplicate_member_numbers(self) -> None: self.create_meeting(1) @@ -854,6 +881,8 @@ def test_json_upload_update_duplicate_member_numbers(self) -> None: "username": {"info": "done", "value": "test1", "id": 2}, "groups": [{"id": 1, "info": "generated", "value": "group1"}], } + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] + assert import_preview["result"]["rows"][1]["state"] == ImportState.ERROR assert import_preview["result"]["rows"][1]["messages"] == [ "Error: Found more users with the same member number" @@ -864,6 +893,7 @@ def test_json_upload_update_duplicate_member_numbers(self) -> None: "username": {"info": "done", "value": "test2"}, "groups": [{"id": 1, "info": "generated", "value": "group1"}], } + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][1] def test_json_upload_set_other_persons_member_number_in_existing_participant( self, @@ -909,6 +939,7 @@ def test_json_upload_set_other_persons_member_number_in_existing_participant( "username": {"info": "done", "value": "test", "id": 2}, "groups": [{"id": 1, "info": "generated", "value": "group1"}], } + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_set_other_persons_member_number_in_existing_participant_2( self, @@ -949,15 +980,13 @@ def test_json_upload_set_other_persons_member_number_in_existing_participant_2( data = import_preview["result"]["rows"][0]["data"] assert data == { "id": 2, - "default_password": { - "info": "warning", - "value": "", - }, + "default_password": {"info": "warning", "value": "", "changed": False}, "member_number": {"info": ImportState.ERROR, "value": "new_one"}, "username": {"info": "done", "value": "test", "id": 2}, "saml_id": {"info": "done", "value": "tessst"}, "groups": [{"id": 1, "info": "generated", "value": "group1"}], } + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_set_other_persons_member_number_in_existing_participant_3( self, @@ -1011,6 +1040,7 @@ def test_json_upload_set_other_persons_member_number_in_existing_participant_3( "email": {"info": "done", "value": "fritz.chen@scho.ol"}, "groups": [{"id": 1, "info": "generated", "value": "group1"}], } + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def prepare_locked_out_test( self, @@ -1059,6 +1089,7 @@ def test_json_upload_create_locked_out_user_meeting_admin_error(self) -> None: "groups": [{"id": 2, "info": "error", "value": "admin"}], }.items(): assert data[key] == value + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_create_locked_out_user_can_manage_error(self) -> None: self.prepare_locked_out_test() @@ -1086,6 +1117,7 @@ def test_json_upload_create_locked_out_user_can_manage_error(self) -> None: "groups": [{"id": 3, "info": "error", "value": "can_manage"}], }.items(): assert data[key] == value + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_update_locked_out_on_self_error(self) -> None: self.prepare_locked_out_test() @@ -1120,6 +1152,7 @@ def test_json_upload_update_locked_out_on_self_error(self) -> None: "groups": [{"id": 1, "info": "generated", "value": "default"}], }.items(): assert data[key] == value + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_update_locked_out_meeting_admin_error(self) -> None: self.prepare_locked_out_test("test", [1]) @@ -1146,6 +1179,7 @@ def test_json_upload_update_locked_out_meeting_admin_error(self) -> None: "groups": [{"id": 2, "info": "error", "value": "admin"}], }.items(): assert data[key] == value + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_update_locked_out_on_superadmin_error(self) -> None: self.prepare_locked_out_test("test", oml=OrganizationManagementLevel.SUPERADMIN) @@ -1172,11 +1206,12 @@ def test_json_upload_update_locked_out_on_superadmin_error(self) -> None: data = import_preview["result"]["rows"][0]["data"] for key, value in { "id": 2, - "username": {"info": "done", "value": "test", "id": 2}, + "username": {"info": "referenced", "value": "test", "id": 2}, "locked_out": {"info": "error", "value": True}, "groups": [{"id": 1, "info": "generated", "value": "default"}], }.items(): assert data[key] == value + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_perm_superadmin_self_set_inactive_error(self) -> None: """SUPERADMIN may not set himself inactive.""" @@ -1194,6 +1229,7 @@ def test_json_upload_perm_superadmin_self_set_inactive_error(self) -> None: assert import_preview["result"]["rows"][0]["data"]["is_active"] == { "value": False, "info": ImportState.ERROR, + "changed": True, } assert ( "A superadmin is not allowed to set himself inactive." @@ -1202,10 +1238,11 @@ def test_json_upload_perm_superadmin_self_set_inactive_error(self) -> None: data = import_preview["result"]["rows"][0]["data"] for key, value in { "id": 1, - "username": {"info": "done", "value": "admin", "id": 1}, - "is_active": {"info": "error", "value": False}, + "username": {"info": "referenced", "value": "admin", "id": 1}, + "is_active": {"info": "error", "value": False, "changed": True}, }.items(): assert data[key] == value + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_update_locked_out_on_other_oml_error(self) -> None: self.prepare_locked_out_test( @@ -1234,11 +1271,12 @@ def test_json_upload_update_locked_out_on_other_oml_error(self) -> None: data = import_preview["result"]["rows"][0]["data"] for key, value in { "id": 2, - "username": {"info": "done", "value": "test", "id": 2}, + "username": {"info": "referenced", "value": "test", "id": 2}, "locked_out": {"info": "error", "value": True}, "groups": [{"id": 1, "info": "generated", "value": "default"}], }.items(): assert data[key] == value + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_update_locked_out_on_cml_error(self) -> None: self.prepare_locked_out_test("test", [1]) @@ -1276,6 +1314,7 @@ def test_json_upload_update_locked_out_on_cml_error(self) -> None: "groups": [{"id": 1, "info": "generated", "value": "default"}], }.items(): assert data[key] == value + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_update_meeting_admin_on_locked_out_user_error(self) -> None: self.prepare_locked_out_test("test", [1]) @@ -1301,6 +1340,7 @@ def test_json_upload_update_meeting_admin_on_locked_out_user_error(self) -> None "groups": [{"info": "error", "value": "admin", "id": 2}], }.items(): assert data[key] == value + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_permission_as_locked_out(self) -> None: self.create_meeting() @@ -1373,6 +1413,7 @@ def test_json_upload_set_home_committee_not_found(self) -> None: "external": {"value": False, "info": ImportState.GENERATED}, "groups": [{"id": 1, "info": ImportState.GENERATED, "value": "group1"}], } + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_set_home_committee_multiple_found(self) -> None: self.set_up_test_models() @@ -1408,12 +1449,17 @@ def test_json_upload_set_home_committee_multiple_found(self) -> None: "id": 2, "first_name": {"value": "Bob", "info": ImportState.DONE}, "last_name": {"value": "will fail", "info": ImportState.DONE}, - "username": {"id": 2, "value": "BobWillFail", "info": ImportState.DONE}, + "username": { + "id": 2, + "value": "BobWillFail", + "info": ImportState.REFERENCED, + }, "home_committee": {"value": "There are two", "info": ImportState.ERROR}, "default_password": {"value": "ouch", "info": ImportState.DONE}, "external": {"value": False, "info": ImportState.DONE}, "groups": [{"id": 1, "value": "testgroup", "info": ImportState.DONE}], } + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def test_json_upload_set_home_committee_and_set_external_to_true(self) -> None: self.set_up_test_models() @@ -1454,6 +1500,7 @@ def test_json_upload_set_home_committee_and_set_external_to_true(self) -> None: "external": {"value": True, "info": ImportState.ERROR}, "groups": [{"value": "test", "info": ImportState.NEW}], } + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] class ParticipantJsonUploadForUseInImport(BaseActionTestCase): @@ -1499,14 +1546,31 @@ def json_upload_invalid_vote_weight_with_remove(self) -> None: assert result["rows"][0]["state"] == ImportState.DONE assert result["rows"][0]["data"] == { "id": 2, - "first_name": {"value": "Wilhelm", "info": ImportState.DONE}, - "last_name": {"value": "Aberhatnurhut", "info": ImportState.DONE}, - "email": {"value": "will@helm.hut", "info": ImportState.DONE}, + "first_name": { + "value": "Wilhelm", + "info": ImportState.DONE, + "changed": True, + }, + "last_name": { + "value": "Aberhatnurhut", + "info": ImportState.DONE, + "changed": True, + }, + "email": { + "value": "will@helm.hut", + "info": ImportState.DONE, + "changed": True, + }, "vote_weight": {"value": "0.000000", "info": ImportState.REMOVE}, "username": {"id": 2, "value": "wilhelm", "info": ImportState.DONE}, - "default_password": {"value": "123", "info": ImportState.DONE}, + "default_password": { + "value": "123", + "info": ImportState.DONE, + "changed": True, + }, "groups": [{"id": 1, "info": "generated", "value": "group1"}], } + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def json_upload_saml_id_new(self) -> None: self.create_meeting(4) @@ -1557,7 +1621,7 @@ def json_upload_saml_id_new(self) -> None: assert data0 == { "saml_id": {"info": "new", "value": "test_saml_id"}, "username": {"info": "generated", "value": "test_saml_id2"}, - "default_password": {"info": "warning", "value": ""}, + "default_password": {"info": "warning", "value": "", "changed": False}, "groups": [{"value": "group1", "info": ImportState.DONE, "id": 1}], } @@ -1619,18 +1683,21 @@ def json_upload_set_saml_id_in_existing_participant(self) -> None: import_preview = self.assert_model_exists("import_preview/1") assert import_preview["state"] == ImportState.WARNING assert import_preview["name"] == "participant" - assert import_preview["result"]["rows"][0]["state"] == ImportState.DONE + assert import_preview["result"]["rows"][0]["state"] == ImportState.REFERENCED assert import_preview["result"]["rows"][0]["messages"] == [ "Because this participant is connected with a saml_id: The default_password will be ignored and password will not be changeable in OpenSlides." ] data = import_preview["result"]["rows"][0]["data"] assert data == { "id": 2, - "saml_id": {"info": "new", "value": "test_saml_id"}, - "username": {"info": "done", "value": "test", "id": 2}, - "default_password": {"info": "warning", "value": ""}, - "groups": [{"id": 1, "info": "generated", "value": "group1"}], + "saml_id": {"info": "new", "value": "test_saml_id", "changed": True}, + "username": {"info": ImportState.REFERENCED, "value": "test", "id": 2}, + "default_password": {"info": "warning", "value": "", "changed": False}, + "groups": [ + {"id": 1, "info": "generated", "value": "group1", "changed": True} + ], } + assert "list_delete_amounts" not in response.json["results"][0][0]["rows"][0] def json_upload_update_saml_id_in_existing_participant(self) -> None: self.set_models( @@ -1657,14 +1724,16 @@ def json_upload_update_saml_id_in_existing_participant(self) -> None: import_preview = self.assert_model_exists("import_preview/1") assert import_preview["state"] == ImportState.DONE assert import_preview["name"] == "participant" - assert import_preview["result"]["rows"][0]["state"] == ImportState.DONE + assert import_preview["result"]["rows"][0]["state"] == ImportState.REFERENCED assert import_preview["result"]["rows"][0]["messages"] == [] data = import_preview["result"]["rows"][0]["data"] assert data == { "id": 2, - "saml_id": {"info": "done", "value": "new_one"}, - "username": {"info": "done", "value": "test", "id": 2}, - "groups": [{"id": 1, "info": "generated", "value": "group1"}], + "saml_id": {"info": "done", "value": "new_one", "changed": True}, + "username": {"info": ImportState.REFERENCED, "value": "test", "id": 2}, + "groups": [ + {"id": 1, "info": "generated", "value": "group1", "changed": True} + ], } def json_upload_username_set_saml_id_remove_presence(self) -> None: @@ -1723,16 +1792,20 @@ def json_upload_username_set_saml_id_remove_presence(self) -> None: assert row["data"] == { "id": 10, "username": {"value": "user10", "info": "done", "id": 10}, - "saml_id": {"value": "saml_id10", "info": "new"}, - "default_password": {"value": "", "info": "warning"}, - "is_present": {"value": False, "info": "done"}, - "vote_weight": {"value": "2.800000", "info": "done"}, + "saml_id": {"value": "saml_id10", "info": "new", "changed": True}, + "default_password": {"value": "", "info": "warning", "changed": False}, + "is_present": {"value": False, "info": "done", "changed": True}, + "vote_weight": {"value": "2.800000", "info": "done", "changed": True}, "groups": [{"id": 1, "info": "generated", "value": "group1"}], - "structure_level": [{"id": 2, "info": "done", "value": "new sl"}], + "structure_level": [ + {"id": 2, "info": "done", "value": "new sl", "changed": True} + ], **{ - k: {"value": v, "info": ImportState.DONE} for k, v in fix_fields.items() + k: {"value": v, "info": ImportState.DONE, "changed": True} + for k, v in fix_fields.items() }, } + assert row["list_delete_amounts"] == {"structure_level": 1} def json_upload_username_username_and_saml_id_found(self) -> None: self.set_models( @@ -1757,12 +1830,14 @@ def json_upload_username_username_and_saml_id_found(self) -> None: ) self.assert_status_code(response, 200) row = response.json["results"][0][0]["rows"][0] - assert row["state"] == ImportState.DONE + assert row["state"] == ImportState.REFERENCED assert row["data"] == { "id": 11, - "username": {"value": "user11", "info": ImportState.DONE, "id": 11}, + "username": {"value": "user11", "info": ImportState.REFERENCED, "id": 11}, "saml_id": {"value": "saml_id11", "info": ImportState.DONE}, - "groups": [{"id": 1, "info": "generated", "value": "group1"}], + "groups": [ + {"id": 1, "info": "generated", "value": "group1", "changed": True} + ], } def json_upload_multiple_users(self) -> None: @@ -1888,22 +1963,30 @@ def json_upload_multiple_users(self) -> None: import_preview = self.assert_model_exists("import_preview/1") assert import_preview["state"] == ImportState.WARNING assert import_preview["name"] == "participant" - assert import_preview["result"]["rows"][0]["state"] == ImportState.DONE + assert import_preview["result"]["rows"][0]["state"] == ImportState.REFERENCED assert import_preview["result"]["rows"][0]["messages"] == [ "Because this participant is connected with a saml_id: The default_password will be ignored and password will not be changeable in OpenSlides.", ] assert import_preview["result"]["rows"][0]["data"] == { "id": 2, - "saml_id": {"info": "new", "value": "test_saml_id2"}, - "username": {"id": 2, "info": "done", "value": "user2"}, - "default_password": {"info": "warning", "value": ""}, + "saml_id": {"info": "new", "value": "test_saml_id2", "changed": True}, + "username": {"id": 2, "info": ImportState.REFERENCED, "value": "user2"}, + "default_password": {"info": "warning", "value": "", "changed": False}, "groups": [ - {"id": 3, "info": "done", "value": "group3"}, - {"info": "new", "value": "group4"}, + {"id": 3, "info": "done", "value": "group3", "changed": True}, + {"info": "new", "value": "group4", "changed": True}, ], - "structure_level": [{"value": "level up", "info": ImportState.NEW}], - "gender": {"id": 3, "info": ImportState.DONE, "value": "diverse"}, + "structure_level": [ + {"value": "level up", "info": ImportState.NEW, "changed": True} + ], + "gender": { + "id": 3, + "info": ImportState.DONE, + "value": "diverse", + "changed": True, + }, } + assert "list_delete_amounts" not in import_preview["result"]["rows"][0] assert import_preview["result"]["rows"][1]["state"] == ImportState.DONE assert import_preview["result"]["rows"][1]["messages"] == [ @@ -1913,23 +1996,35 @@ def json_upload_multiple_users(self) -> None: "id": 3, "saml_id": {"info": ImportState.DONE, "value": "saml3"}, "username": {"id": 3, "info": ImportState.DONE, "value": "user3"}, - "default_password": {"info": ImportState.WARNING, "value": ""}, - "groups": [{"id": 3, "info": "done", "value": "group3"}], - "vote_weight": {"info": ImportState.DONE, "value": "3.345678"}, + "default_password": { + "info": ImportState.WARNING, + "value": "", + "changed": False, + }, + "groups": [{"id": 3, "info": "done", "value": "group3", "changed": True}], + "vote_weight": { + "info": ImportState.DONE, + "value": "3.345678", + "changed": True, + }, + } + assert import_preview["result"]["rows"][1]["list_delete_amounts"] == { + "groups": 2 } - assert import_preview["result"]["rows"][2]["state"] == ImportState.DONE + assert import_preview["result"]["rows"][2]["state"] == ImportState.REFERENCED assert import_preview["result"]["rows"][2]["messages"] == [] assert import_preview["result"]["rows"][2]["data"] == { "id": 4, "email": {"value": "mlk@america.com", "info": ImportState.DONE}, - "username": {"id": 4, "info": "done", "value": "user4"}, + "username": {"id": 4, "info": ImportState.REFERENCED, "value": "user4"}, "last_name": {"value": "Luther King", "info": ImportState.DONE}, "first_name": {"value": "Martin", "info": ImportState.DONE}, "groups": [ - {"info": "new", "value": "group4"}, + {"info": "new", "value": "group4", "changed": True}, ], } + assert "list_delete_amounts" not in import_preview["result"]["rows"][2] assert import_preview["result"]["rows"][3]["state"] == ImportState.NEW assert import_preview["result"]["rows"][3]["messages"] == [ @@ -1938,13 +2033,14 @@ def json_upload_multiple_users(self) -> None: assert import_preview["result"]["rows"][3]["data"] == { "saml_id": {"info": "new", "value": "saml5"}, "username": {"info": "done", "value": "new_user5"}, - "default_password": {"info": "warning", "value": ""}, + "default_password": {"info": "warning", "value": "", "changed": False}, "groups": [{"id": 1, "info": "generated", "value": "group1"}], "structure_level": [ {"value": "level up", "info": ImportState.NEW}, {"value": "no. 5", "info": ImportState.NEW}, ], } + assert "list_delete_amounts" not in import_preview["result"]["rows"][3] assert import_preview["result"]["rows"][4]["state"] == ImportState.NEW assert import_preview["result"]["rows"][4]["messages"] == [ @@ -1953,7 +2049,7 @@ def json_upload_multiple_users(self) -> None: assert import_preview["result"]["rows"][4]["data"] == { "saml_id": {"info": "new", "value": "new_saml6"}, "username": {"info": "generated", "value": "new_saml6"}, - "default_password": {"info": "warning", "value": ""}, + "default_password": {"info": "warning", "value": "", "changed": False}, "is_present": {"info": "done", "value": True}, "groups": [ {"info": "new", "value": "group4"}, @@ -2080,16 +2176,17 @@ def json_upload_not_sufficient_field_permission_update(self) -> None: "username": {"value": "user2", "info": "remove", "id": 2}, "first_name": {"value": "Jim", "info": "remove"}, "email": {"value": "Jim.Knopf@Lummer.land", "info": "remove"}, - "vote_weight": {"value": "1.234560", "info": "done"}, + "vote_weight": {"value": "1.234560", "info": "done", "changed": True}, "saml_id": {"value": "saml_id1", "info": "remove"}, - "default_password": {"value": "", "info": "remove"}, + "default_password": {"value": "", "info": "remove", "changed": False}, "groups": [ {"value": "group1", "info": "done", "id": 1}, - {"value": "group2", "info": "done", "id": 2}, - {"value": "group3", "info": "done", "id": 3}, - {"value": "group4", "info": "new"}, + {"value": "group2", "info": "done", "id": 2, "changed": True}, + {"value": "group3", "info": "done", "id": 3, "changed": True}, + {"value": "group4", "info": "new", "changed": True}, ], } + assert "list_delete_amounts" not in row def json_upload_no_permissions_to_set_meeting_external_fields_on_superadmin( self, @@ -2145,16 +2242,17 @@ def json_upload_no_permissions_to_set_meeting_external_fields_on_superadmin( "username": {"value": "user2", "info": "remove", "id": 2}, "first_name": {"value": "Jim", "info": "remove"}, "email": {"value": "Jim.Knopf@Lummer.land", "info": "remove"}, - "vote_weight": {"value": "1.234560", "info": "done"}, + "vote_weight": {"value": "1.234560", "info": "done", "changed": True}, "saml_id": {"value": "saml_id1", "info": "remove"}, - "default_password": {"value": "", "info": "remove"}, + "default_password": {"value": "", "info": "remove", "changed": False}, "groups": [ {"value": "group1", "info": "done", "id": 1}, - {"value": "group2", "info": "done", "id": 2}, - {"value": "group3", "info": "done", "id": 3}, - {"value": "group4", "info": "new"}, + {"value": "group2", "info": "done", "id": 2, "changed": True}, + {"value": "group3", "info": "done", "id": 3, "changed": True}, + {"value": "group4", "info": "new", "changed": True}, ], } + assert "list_delete_amounts" not in row def json_upload_not_sufficient_field_permission_update_with_member_number( self, @@ -2216,16 +2314,17 @@ def json_upload_not_sufficient_field_permission_update_with_member_number( "member_number": {"value": "M3MNUM", "info": "remove", "id": 2}, "first_name": {"value": "Jim", "info": "remove"}, "email": {"value": "Jim.Knopf@Lummer.land", "info": "remove"}, - "vote_weight": {"value": "1.234560", "info": "done"}, + "vote_weight": {"value": "1.234560", "info": "done", "changed": True}, "saml_id": {"value": "saml_id1", "info": "remove"}, - "default_password": {"value": "", "info": "remove"}, + "default_password": {"value": "", "info": "remove", "changed": False}, "groups": [ {"value": "group1", "info": "done", "id": 1}, - {"value": "group2", "info": "done", "id": 2}, - {"value": "group3", "info": "done", "id": 3}, - {"value": "group4", "info": "new"}, + {"value": "group2", "info": "done", "id": 2, "changed": True}, + {"value": "group3", "info": "done", "id": 3, "changed": True}, + {"value": "group4", "info": "new", "changed": True}, ], } + assert "list_delete_amounts" not in row def json_upload_sufficient_field_permission_create(self) -> None: self.update_model("user/1", {"organization_management_level": None}) @@ -2263,7 +2362,7 @@ def json_upload_sufficient_field_permission_create(self) -> None: "first_name": {"value": "Jim", "info": "done"}, "vote_weight": {"value": "1.234560", "info": "done"}, "saml_id": {"value": "saml_id1", "info": "new"}, - "default_password": {"value": "", "info": "warning"}, + "default_password": {"value": "", "info": "warning", "changed": False}, "groups": [ {"value": "group1", "info": "done", "id": 1}, {"value": "group2", "info": "done", "id": 2}, @@ -2300,13 +2399,13 @@ def json_upload_legacy_username(self) -> None: "info": ImportState.DONE, "value": "test user", }, - "first_name": {"info": ImportState.DONE, "value": "test"}, + "first_name": { + "info": ImportState.DONE, + "value": "test", + "changed": True, + }, "groups": [ - { - "id": 3, - "info": "done", - "value": "group3", - }, + {"id": 3, "info": "done", "value": "group3"}, ], }, } @@ -2329,24 +2428,34 @@ def json_upload_update_reference_via_two_attributes(self) -> None: { "username": "test", "saml_id": "old_one", - "default_vote_weight": "4.500000", } ], }, ) self.assert_status_code(response, 200) import_preview = self.assert_model_exists("import_preview/1") - assert import_preview["state"] == ImportState.DONE + assert import_preview["state"] == ImportState.WARNING assert import_preview["name"] == "participant" assert import_preview["result"]["rows"][0]["state"] == ImportState.DONE - assert import_preview["result"]["rows"][0]["messages"] == [] + assert import_preview["result"]["rows"][0]["messages"] == [ + "Because this participant is connected with a saml_id: The default_password will be ignored and password will not be changeable in OpenSlides." + ] data = import_preview["result"]["rows"][0]["data"] assert data == { "id": 2, "saml_id": {"info": "done", "value": "old_one"}, "username": {"info": "done", "value": "test", "id": 2}, - "default_vote_weight": {"info": "done", "value": "4.500000"}, - "groups": [{"id": 1, "info": "generated", "value": "group1"}], + "default_password": { + "value": "", + "info": ImportState.WARNING, + "changed": False, + }, + "groups": [ + {"id": 1, "info": "generated", "value": "group1", "changed": True} + ], + } + assert import_preview["result"]["rows"][0]["list_delete_amounts"] == { + "groups": 1 } def json_upload_set_member_number_in_existing_participants(self) -> None: @@ -2398,17 +2507,27 @@ def json_upload_set_member_number_in_existing_participants(self) -> None: assert row == { "id": 2, "username": {"info": "done", "value": "test1", "id": 2}, - "member_number": {"info": "new", "value": "new_one"}, - "groups": [{"id": 1, "info": "generated", "value": "group1"}], + "member_number": {"info": "new", "value": "new_one", "changed": True}, + "groups": [ + {"id": 1, "info": "generated", "value": "group1", "changed": True} + ], + } + assert import_preview["result"]["rows"][0]["list_delete_amounts"] == { + "groups": 1 } row = import_preview["result"]["rows"][1]["data"] assert row == { "id": 3, "username": {"info": "done", "value": "test2", "id": 3}, "saml_id": {"info": "done", "value": "samLidman"}, - "default_password": {"info": "warning", "value": ""}, - "member_number": {"info": "new", "value": "another_new_1"}, - "groups": [{"id": 1, "info": "generated", "value": "group1"}], + "default_password": {"info": "warning", "value": "", "changed": False}, + "member_number": {"info": "new", "value": "another_new_1", "changed": True}, + "groups": [ + {"id": 1, "info": "generated", "value": "group1", "changed": True} + ], + } + assert import_preview["result"]["rows"][1]["list_delete_amounts"] == { + "groups": 1 } row = import_preview["result"]["rows"][2]["data"] assert row == { @@ -2417,8 +2536,13 @@ def json_upload_set_member_number_in_existing_participants(self) -> None: "first_name": {"info": "done", "value": "Hasan"}, "last_name": {"info": "done", "value": "Ame"}, "email": {"info": "done", "value": "hasaN.ame@nd.email"}, - "member_number": {"info": "new", "value": "UGuessedIt"}, - "groups": [{"id": 1, "info": "generated", "value": "group1"}], + "member_number": {"info": "new", "value": "UGuessedIt", "changed": True}, + "groups": [ + {"id": 1, "info": "generated", "value": "group1", "changed": True} + ], + } + assert import_preview["result"]["rows"][2]["list_delete_amounts"] == { + "groups": 1 } def json_upload_set_other_matching_criteria_in_existing_participant_via_member_number( @@ -2464,13 +2588,18 @@ def json_upload_set_other_matching_criteria_in_existing_participant_via_member_n data = import_preview["result"]["rows"][0]["data"] assert data == { "id": 2, - "default_password": {"value": "", "info": "warning"}, - "username": {"info": "new", "value": "newname"}, - "saml_id": {"info": "new", "value": "some_other_saml"}, - "first_name": {"info": "done", "value": "second"}, - "last_name": {"info": "done", "value": "second_to_last"}, + "default_password": {"value": "", "info": "warning", "changed": False}, + "username": {"info": "new", "value": "newname", "changed": True}, + "saml_id": {"info": "new", "value": "some_other_saml", "changed": True}, + "first_name": {"info": "done", "value": "second", "changed": True}, + "last_name": {"info": "done", "value": "second_to_last", "changed": True}, "member_number": {"info": "done", "value": "M3MNUM", "id": 2}, - "groups": [{"id": 1, "info": "generated", "value": "group1"}], + "groups": [ + {"id": 1, "info": "generated", "value": "group1", "changed": True} + ], + } + assert import_preview["result"]["rows"][0]["list_delete_amounts"] == { + "groups": 1 } def json_upload_add_member_number(self) -> None: @@ -2507,8 +2636,13 @@ def json_upload_add_member_number(self) -> None: "id": 2, "member_number": {"info": "done", "value": "old_one", "id": 2}, "username": {"info": "done", "value": "test"}, - "vote_weight": {"info": "done", "value": "4.345678"}, - "groups": [{"id": 1, "info": "generated", "value": "group1"}], + "vote_weight": {"info": "done", "value": "4.345678", "changed": True}, + "groups": [ + {"id": 1, "info": "generated", "value": "group1", "changed": True} + ], + } + assert import_preview["result"]["rows"][0]["list_delete_amounts"] == { + "groups": 1 } def json_upload_new_participant_with_member_number(self) -> None: @@ -2537,7 +2671,7 @@ def json_upload_new_participant_with_member_number(self) -> None: ] data = import_preview["result"]["rows"][0]["data"] assert data == { - "default_password": {"value": "", "info": "warning"}, + "default_password": {"value": "", "info": "warning", "changed": False}, "username": {"info": "done", "value": "newname"}, "saml_id": {"info": "new", "value": "some_other_saml"}, "first_name": {"info": "done", "value": "second"}, @@ -2629,9 +2763,15 @@ def json_upload_remove_last_admin_add_a_new_one(self) -> None: "id": 2, "username": {"id": 2, "value": "bob", "info": ImportState.DONE}, "groups": [ - {"value": "group1", "info": ImportState.GENERATED, "id": 1}, + { + "value": "group1", + "info": ImportState.GENERATED, + "id": 1, + "changed": True, + }, ], }, + "list_delete_amounts": {"groups": 1}, } row = response.json["results"][0][0]["rows"][1] assert row["state"] == ImportState.NEW @@ -2663,9 +2803,15 @@ def json_upload_remove_admin_group_normal(self) -> None: "id": 2, "username": {"id": 2, "value": "bob", "info": ImportState.DONE}, "groups": [ - {"value": "group1", "info": ImportState.GENERATED, "id": 1}, + { + "value": "group1", + "info": ImportState.GENERATED, + "id": 1, + "changed": True, + }, ], }, + "list_delete_amounts": {"groups": 1}, } def json_upload_remove_last_admin_in_template(self) -> None: @@ -2695,9 +2841,15 @@ def json_upload_remove_last_admin_in_template(self) -> None: "id": 2, "username": {"id": 2, "value": "bob", "info": ImportState.DONE}, "groups": [ - {"value": "group1", "info": ImportState.GENERATED, "id": 1}, + { + "value": "group1", + "info": ImportState.GENERATED, + "id": 1, + "changed": True, + }, ], }, + "list_delete_amounts": {"groups": 1}, } def json_upload_multi_with_locked_out(self) -> None: @@ -2785,16 +2937,54 @@ def json_upload_multi_with_locked_out(self) -> None: }, ) self.assert_status_code(response, 200) + assert response.json["results"][0][0]["statistics"] == [ + { + "name": "total", + "value": 11, + }, + { + "name": "created", + "value": 2, + }, + { + "name": "updated", + "value": 6, + }, + { + "name": "referenced", + "value": 3, + }, + *[ + {"name": n, "value": 0} + for n in [ + "error", + "warning", + "structure levels created", + "groups created", + ] + ], + ] import_preview = self.assert_model_exists("import_preview/1") assert import_preview["state"] == ImportState.DONE assert import_preview["name"] == "participant" rows = import_preview["result"]["rows"] assert not any(len(row["messages"]) for row in rows) assert not any(row["state"] != ImportState.NEW for row in rows[:2]) - assert not any(row["state"] != ImportState.DONE for row in rows[2:]) + assert not any( + rows[i]["state"] != ImportState.DONE for i in [2, 4, *range(7, len(rows))] + ) + + assert not any("list_delete_amounts" in rows[i] for i in [0, 1, 3, 5, 6]) + assert not any( + rows[i]["list_delete_amounts"] != {"groups": 1} for i in [2, 4, 7, 8, 9, 10] + ) + assert not any(rows[i]["state"] != ImportState.REFERENCED for i in [3, 5, 6]) data = [row["data"] for row in rows] + assert data[0]["locked_out"] == {"info": "done", "value": True} + assert data[1]["locked_out"] == {"info": "done", "value": True} assert not any( - date["locked_out"] != {"info": "done", "value": True} for date in data[0:9] + date["locked_out"] != {"info": "done", "value": True, "changed": True} + for date in data[2:9] ) assert not any(data[i + 2]["id"] != participant1 + i for i in range(9)) i = 0 @@ -2828,24 +3018,16 @@ def json_upload_multi_with_locked_out(self) -> None: "value": "participant1", } assert data[i]["groups"] == [ - { - "id": 4, - "info": "done", - "value": "can_update", - }, + {"id": 4, "info": "done", "value": "can_update", "changed": True}, ] i += 1 assert data[i]["username"] == { "id": foreign_cml, - "info": "done", + "info": ImportState.REFERENCED, "value": "foreign_cml", } assert data[i]["groups"] == [ - { - "id": 1, - "info": "generated", - "value": "default", - }, + {"id": 1, "info": "generated", "value": "default", "changed": True}, ] i += 1 assert data[i]["username"] == { @@ -2854,37 +3036,25 @@ def json_upload_multi_with_locked_out(self) -> None: "value": "can_update", } assert data[i]["groups"] == [ - { - "id": 1, - "info": "generated", - "value": "default", - }, + {"id": 1, "info": "generated", "value": "default", "changed": True}, ] i += 1 assert data[i]["username"] == { "id": foreign_meeting_admin, - "info": "done", + "info": ImportState.REFERENCED, "value": "foreign_meeting_admin", } assert data[i]["groups"] == [ - { - "id": 1, - "info": "generated", - "value": "default", - }, + {"id": 1, "info": "generated", "value": "default", "changed": True}, ] i += 1 assert data[i]["username"] == { "id": foreign_can_manage, - "info": "done", + "info": ImportState.REFERENCED, "value": "foreign_can_manage", } assert data[i]["groups"] == [ - { - "id": 1, - "info": "generated", - "value": "default", - }, + {"id": 1, "info": "generated", "value": "default", "changed": True}, ] i += 1 assert data[i]["username"] == { @@ -2893,11 +3063,7 @@ def json_upload_multi_with_locked_out(self) -> None: "value": "can_manage", } assert data[i]["groups"] == [ - { - "id": 1, - "info": "done", - "value": "default", - }, + {"id": 1, "info": "done", "value": "default", "changed": True}, ] i += 1 assert data[i]["username"] == { @@ -2906,11 +3072,7 @@ def json_upload_multi_with_locked_out(self) -> None: "value": "meeting_admin", } assert data[i]["groups"] == [ - { - "id": 1, - "info": "done", - "value": "default", - }, + {"id": 1, "info": "done", "value": "default", "changed": True}, ] i += 1 assert data[i]["username"] == { @@ -2919,11 +3081,7 @@ def json_upload_multi_with_locked_out(self) -> None: "value": "locked_out1", } assert data[i]["groups"] == [ - { - "id": 2, - "info": "done", - "value": "admin", - }, + {"id": 2, "info": "done", "value": "admin", "changed": True}, ] i += 1 assert data[i]["username"] == { @@ -2932,11 +3090,7 @@ def json_upload_multi_with_locked_out(self) -> None: "value": "locked_out2", } assert data[i]["groups"] == [ - { - "id": 3, - "info": "done", - "value": "can_manage", - }, + {"id": 3, "info": "done", "value": "can_manage", "changed": True}, ] def json_upload_update_locked_out_on_meeting_admin_auto_overwrite_group( @@ -2978,10 +3132,15 @@ def json_upload_update_locked_out_on_meeting_admin_auto_overwrite_group( data = import_preview["result"]["rows"][0]["data"] for key, value in { "username": {"info": "done", "value": "test", "id": 2}, - "locked_out": {"info": "done", "value": True}, - "groups": [{"id": 1, "info": "generated", "value": "default"}], + "locked_out": {"info": "done", "value": True, "changed": True}, + "groups": [ + {"id": 1, "info": "generated", "value": "default", "changed": True} + ], }.items(): assert data[key] == value + assert import_preview["result"]["rows"][0]["list_delete_amounts"] == { + "groups": 1 + } def json_upload_update_locked_out_on_can_manage_auto_overwrite_group( self, @@ -3021,10 +3180,15 @@ def json_upload_update_locked_out_on_can_manage_auto_overwrite_group( data = import_preview["result"]["rows"][0]["data"] for key, value in { "username": {"info": "done", "value": "test", "id": 2}, - "locked_out": {"info": "done", "value": True}, - "groups": [{"id": 1, "info": "generated", "value": "default"}], + "locked_out": {"info": "done", "value": True, "changed": True}, + "groups": [ + {"id": 1, "info": "generated", "value": "default", "changed": True} + ], }.items(): assert data[key] == value + assert import_preview["result"]["rows"][0]["list_delete_amounts"] == { + "groups": 1 + } def json_upload_set_home_committee(self, has_perm: bool = True) -> None: self.create_committee(1, name="Home") @@ -3094,7 +3258,7 @@ def json_upload_update_home_committee( import_preview = self.assert_model_exists("import_preview/1") assert import_preview["state"] == ImportState.DONE assert import_preview["name"] == "participant" - assert import_preview["result"]["rows"][0]["state"] == ImportState.DONE + assert import_preview["result"]["rows"][0]["state"] == ImportState.REFERENCED if old_perm and new_perm: assert import_preview["result"]["rows"][0]["messages"] == [] else: @@ -3105,7 +3269,7 @@ def json_upload_update_home_committee( assert data["id"] == alice_id assert data["username"] == { "id": alice_id, - "info": ImportState.DONE, + "info": ImportState.REFERENCED, "value": "Alice", } if old_perm and new_perm: @@ -3113,8 +3277,13 @@ def json_upload_update_home_committee( "info": ImportState.DONE, "value": "Home", "id": 2, + "changed": True, + } + assert data["external"] == { + "info": ImportState.GENERATED, + "value": False, + "changed": True, } - assert data["external"] == {"info": ImportState.GENERATED, "value": False} else: assert data["home_committee"] == { "info": ImportState.REMOVE, @@ -3122,6 +3291,7 @@ def json_upload_update_home_committee( "id": 2, } assert data["external"] == {"info": ImportState.REMOVE, "value": False} + assert "list_delete_amounts" not in import_preview["result"]["rows"][0] def json_upload_update_home_committee_and_external_false(self) -> None: self.create_committee(1, name="Home") @@ -3139,21 +3309,27 @@ def json_upload_update_home_committee_and_external_false(self) -> None: import_preview = self.assert_model_exists("import_preview/1") assert import_preview["state"] == ImportState.DONE assert import_preview["name"] == "participant" - assert import_preview["result"]["rows"][0]["state"] == ImportState.DONE + assert import_preview["result"]["rows"][0]["state"] == ImportState.REFERENCED assert import_preview["result"]["rows"][0]["messages"] == [] data = import_preview["result"]["rows"][0]["data"] assert data["id"] == alice_id assert data["username"] == { "id": alice_id, - "info": ImportState.DONE, + "info": ImportState.REFERENCED, "value": "Alice", } assert data["home_committee"] == { "info": ImportState.DONE, "value": "Home", "id": 1, + "changed": True, + } + assert data["external"] == { + "info": ImportState.DONE, + "value": False, + "changed": True, } - assert data["external"] == {"info": ImportState.DONE, "value": False} + assert "list_delete_amounts" not in import_preview["result"]["rows"][0] def json_upload_update_external_true( self, with_home_committee: bool = False, has_home_committee_perms: bool = True @@ -3179,7 +3355,7 @@ def json_upload_update_external_true( import_preview = self.assert_model_exists("import_preview/1") assert import_preview["state"] == ImportState.DONE assert import_preview["name"] == "participant" - assert import_preview["result"]["rows"][0]["state"] == ImportState.DONE + assert import_preview["result"]["rows"][0]["state"] == ImportState.REFERENCED messages = [ "If external is set to true, any home_committee that was set will be removed." ] @@ -3191,11 +3367,11 @@ def json_upload_update_external_true( data = import_preview["result"]["rows"][0]["data"] assert data["id"] == alice_id assert data["username"] == { - "info": ImportState.DONE, + "info": ImportState.REFERENCED, "value": "Alice", "id": alice_id, } - assert data["home_committee"] == { + home_committee: dict[str, Any] = { "info": ( ImportState.GENERATED if has_home_committee_perms @@ -3203,12 +3379,19 @@ def json_upload_update_external_true( ), "value": None, } - assert data["external"] == { + external: dict[str, Any] = { "info": ( ImportState.DONE if has_home_committee_perms else ImportState.REMOVE ), "value": True, } + if has_home_committee_perms: + if home_committee["value"] or with_home_committee: + home_committee["changed"] = True + external["changed"] = True + assert data["home_committee"] == home_committee + assert data["external"] == external + assert "list_delete_amounts" not in import_preview["result"]["rows"][0] def json_upload_update_home_committee_and_external_false_no_perms_new(self) -> None: self.create_committee(1, name="Old home") @@ -3231,7 +3414,7 @@ def json_upload_update_home_committee_and_external_false_no_perms_new(self) -> N import_preview = self.assert_model_exists("import_preview/1") assert import_preview["state"] == ImportState.DONE assert import_preview["name"] == "participant" - assert import_preview["result"]["rows"][0]["state"] == ImportState.DONE + assert import_preview["result"]["rows"][0]["state"] == ImportState.REFERENCED assert import_preview["result"]["rows"][0]["messages"] == [ "Account is added to the meeting, but changes to the following field(s) are not possible: home_committee, external" ] @@ -3239,7 +3422,7 @@ def json_upload_update_home_committee_and_external_false_no_perms_new(self) -> N assert data["id"] == alice_id assert data["username"] == { "id": alice_id, - "info": ImportState.DONE, + "info": ImportState.REFERENCED, "value": "Alice", } assert data["home_committee"] == { From ffeea372ab03be12d34d6c56b9ddb3bdbd5fa6ff Mon Sep 17 00:00:00 2001 From: Hannes Janott Date: Tue, 22 Sep 2026 16:04:46 +0200 Subject: [PATCH 07/53] log wrong data type send by idp and allow lists for groups and structure levels (#3776) --- docs/actions/user.save_saml_account.md | 2 +- .../action/actions/user/save_saml_account.py | 48 ++++++++++++++++++- .../action/user/test_save_saml_account.py | 10 ++-- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/docs/actions/user.save_saml_account.md b/docs/actions/user.save_saml_account.md index 08f01d59a5..ae90aef4f8 100644 --- a/docs/actions/user.save_saml_account.md +++ b/docs/actions/user.save_saml_account.md @@ -48,7 +48,7 @@ Extras to do on creation: - A default value can be given in case the payloads attribute does not exist or contains no data. (Logged as debug) - Groups and structure levels are given as a list of attribute-default pairs. - On conflict of multiple mappers mappings on a same meetings field the last given mappers data for that field is used. Exception to this are groups and structure levels. Their data is combined. -- Values for groups and structure levels can additionally be given in comma separated lists composed as a single string. +- Values for groups and structure levels can be specified either as a list of strings or as a single comma-separated string. - Values for groups are interpreted as their external ID and structure levels as their name within that meeting. - If no group exists for a meeting and no default is given, the meetings default group is used. (Logged as warning) - If a structure level does not exist, it is created. diff --git a/openslides_backend/action/actions/user/save_saml_account.py b/openslides_backend/action/actions/user/save_saml_account.py index 02eff86672..7485d4e39d 100644 --- a/openslides_backend/action/actions/user/save_saml_account.py +++ b/openslides_backend/action/actions/user/save_saml_account.py @@ -1,6 +1,8 @@ import re from collections import defaultdict from collections.abc import Generator, Iterable +from decimal import Decimal, InvalidOperation +from types import UnionType from typing import Any, cast import fastjsonschema @@ -462,11 +464,16 @@ def get_field_data( missing_attributes.append(idp_attribute) value = attr_default.get("default") if value: + if not self.validate_mu_value(value, saml_meeting_user_field): + continue if saml_meeting_user_field in ["groups", "structure_levels"]: # Need to append to group and structure_level for same meeting. if not result: result = set() - cast(set, result).update(value.split(", ")) + if isinstance(value, list): + cast(set, result).update(value) + else: + cast(set, result).update(value.split(", ")) elif saml_meeting_user_field == "comment": # Want comments from all matching mappers. if result: @@ -505,6 +512,45 @@ def get_field_data( f"Meeting mapper: {mapper_name} could not find value in idp data for fields: {fields}. Using default if available." ) + def validate_mu_value(self, value: Any, saml_meeting_user_field: str) -> bool: + """Returns True if valid, False otherwise.""" + ok = True + log_value = "" + allowed_types: UnionType | type[str] = str + match saml_meeting_user_field: + case "number": + allowed_types = str + case "vote_weight": + allowed_types = str | int + try: + Decimal(value) + except InvalidOperation: + ok = False + log_value = f"value {value}" + case "groups" | "structure_levels": + allowed_types = str | list + case "present": + allowed_types = str | int | bool + try: + BooleanField().validate(value) + except ValueError: + ok = False + log_value = f"value {value}" + case "comment": + allowed_types = str + case _: + raise ActionException( + f"{saml_meeting_user_field} is not a valid saml attribute for meeting mappers." + ) + if not isinstance(value, allowed_types): + ok = False + log_value = f"type {type(value)}" + if not ok: + self.logger.error( + f"Saml user with invalid {log_value} for {saml_meeting_user_field} tried to log in." + ) + return ok + def get_group_ids( self, group_names: list[str], meeting: dict, db_meeting_user_exists: bool ) -> list[int]: diff --git a/tests/system/action/user/test_save_saml_account.py b/tests/system/action/user/test_save_saml_account.py index f0d7826e82..63344d5527 100644 --- a/tests/system/action/user/test_save_saml_account.py +++ b/tests/system/action/user/test_save_saml_account.py @@ -1002,7 +1002,11 @@ def test_create_user_meeting_not_exists(self) -> None: self.assert_model_not_exists("structure_level/1") def test_create_user_only_one_sl_exists(self) -> None: - """Shows: no errors if one structure level exists and the other doesn't. Latter being created.""" + """ + Shows: + * No errors if one structure level exists and the other doesn't. Latter being created. + * Lists for structure levels and groups are also accepted. + """ self.create_model("structure_level/1", {"name": "structure1", "meeting_id": 1}) response = self.request( "user.save_saml_account", @@ -1011,12 +1015,12 @@ def test_create_user_only_one_sl_exists(self) -> None: "member_number": "LV_Königholz", "email": "holzi@holz.de", "participant_number": "MG_1254", - "idp_group_attribute": "Delegates", + "idp_group_attribute": ["Delegates"], "kv_member_number": "KV_Könighols", "kv_email": "hols@holz.de", "participant_kv_number": "MG_1254", "idp_kv_group_attribute": "Delegates", - "kv_structure": "structure2", + "kv_structure": ["structure2"], }, ) self.assert_status_code(response, 200) From 72f79468e7b877293b958a0b534c95d90a481c70 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Sep 2026 13:42:46 +0200 Subject: [PATCH 08/53] Bump the opentelemetry-dependencies group (#3780) --- requirements/partial/requirements_production.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/requirements/partial/requirements_production.txt b/requirements/partial/requirements_production.txt index 809bd0471a..2cce60f138 100644 --- a/requirements/partial/requirements_production.txt +++ b/requirements/partial/requirements_production.txt @@ -19,10 +19,10 @@ pyyaml==6.0.3 sqlfluff==4.3.0 # opentelemetry -opentelemetry-api==1.44.0 -opentelemetry-exporter-otlp==1.44.0 -opentelemetry-instrumentation-flask==0.65b0 -opentelemetry-instrumentation-redis==0.65b0 -opentelemetry-instrumentation-requests==0.65b0 -opentelemetry-sdk==1.44.0 -opentelemetry-semantic-conventions==0.65b0 +opentelemetry-api==1.45.0 +opentelemetry-exporter-otlp==1.45.0 +opentelemetry-instrumentation-flask==0.66b0 +opentelemetry-instrumentation-redis==0.66b0 +opentelemetry-instrumentation-requests==0.66b0 +opentelemetry-sdk==1.45.0 +opentelemetry-semantic-conventions==0.66b0 From 32b527895b06573a81f7d85b54967780532af410 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Sep 2026 14:07:41 +0200 Subject: [PATCH 09/53] Bump pypdf from 6.16.2 to 6.19.0 in /requirements/partial (#3771) --- requirements/partial/requirements_production.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/partial/requirements_production.txt b/requirements/partial/requirements_production.txt index 2cce60f138..ba55b13440 100644 --- a/requirements/partial/requirements_production.txt +++ b/requirements/partial/requirements_production.txt @@ -5,7 +5,7 @@ dependency_injector==4.49.1 fastjsonschema==2.22.2 Flask==3.1.3 gunicorn==26.2.0 -pypdf[crypto]==6.16.2 +pypdf[crypto]==6.19.0 psycopg[binary]==3.3.4 psycopg-pool==3.3.1 requests==2.34.2 From 6e81a9149d1f5cea95b472ef08b68f8698086633 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Sep 2026 14:31:44 +0200 Subject: [PATCH 10/53] Bump types-pyyaml (#3753) --- requirements/partial/requirements_development.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/partial/requirements_development.txt b/requirements/partial/requirements_development.txt index 3b4ca4db14..0cb0bac47f 100644 --- a/requirements/partial/requirements_development.txt +++ b/requirements/partial/requirements_development.txt @@ -15,7 +15,7 @@ pyupgrade==3.21.2 types-babel==2.11.0.15 types-beautifulsoup4==4.12.0.20250516 types-bleach==6.4.0.20260728 -types-PyYAML==6.0.12.20260815 +types-PyYAML==6.0.12.20260906 types-requests==2.33.0.20260712 types-simplejson==4.1.0.20260724 types-Pygments==2.21.0.20260819 From 644d32b9b10974d36274fca1c6caa8d29f4a0b1a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Sep 2026 12:58:06 +0000 Subject: [PATCH 11/53] Bump the database-dependencies group across 1 directory with 2 updates (#3769) --- requirements/partial/requirements_production.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements/partial/requirements_production.txt b/requirements/partial/requirements_production.txt index ba55b13440..4311848527 100644 --- a/requirements/partial/requirements_production.txt +++ b/requirements/partial/requirements_production.txt @@ -6,8 +6,8 @@ fastjsonschema==2.22.2 Flask==3.1.3 gunicorn==26.2.0 pypdf[crypto]==6.19.0 -psycopg[binary]==3.3.4 -psycopg-pool==3.3.1 +psycopg[binary]==3.3.6 +psycopg-pool==3.3.3 requests==2.34.2 roman==5.2 simplejson==4.1.2 From 4984c4520e8ec5ee6383c5af8fc72e73fa74d63d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Sep 2026 15:24:09 +0200 Subject: [PATCH 12/53] Bump types-requests (#3752) --- requirements/partial/requirements_development.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/partial/requirements_development.txt b/requirements/partial/requirements_development.txt index 0cb0bac47f..cc0a52c9a9 100644 --- a/requirements/partial/requirements_development.txt +++ b/requirements/partial/requirements_development.txt @@ -16,7 +16,7 @@ types-babel==2.11.0.15 types-beautifulsoup4==4.12.0.20250516 types-bleach==6.4.0.20260728 types-PyYAML==6.0.12.20260906 -types-requests==2.33.0.20260712 +types-requests==2.33.0.20260906 types-simplejson==4.1.0.20260724 types-Pygments==2.21.0.20260819 From 7ada416536ca9a8ecc524d68e518a64bb5fe9077 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Sep 2026 13:50:02 +0000 Subject: [PATCH 13/53] Bump the code-style-depedencies group across 1 directory with 2 updates (#3779) --- requirements/export_service_commits.sh | 2 +- requirements/partial/requirements_development.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements/export_service_commits.sh b/requirements/export_service_commits.sh index 0276ab15a3..851761459d 100755 --- a/requirements/export_service_commits.sh +++ b/requirements/export_service_commits.sh @@ -1,2 +1,2 @@ #!/bin/bash -export AUTH_COMMIT_HASH=097430fb021148714d861816cc8b3c0e8f1e7e86 +export AUTH_COMMIT_HASH=67476e73a53c4567e9457e2e18863294cb839dd7 diff --git a/requirements/partial/requirements_development.txt b/requirements/partial/requirements_development.txt index cc0a52c9a9..d29a5efb6c 100644 --- a/requirements/partial/requirements_development.txt +++ b/requirements/partial/requirements_development.txt @@ -1,8 +1,8 @@ aiosmtpd==1.4.6 autoflake==2.4.0 black==26.5.1 -debugpy==1.8.21 -flake8==7.3.0 +debugpy==1.8.22 +flake8==7.4.1 isort==9.0.1 mypy==2.3.1 pip-check==3.2.1 From fbfd456e93500b39281fc982ac60e96ab2c39e31 Mon Sep 17 00:00:00 2001 From: "openslides-automation[bot]" <125256978+openslides-automation[bot]@users.noreply.github.com> Date: Tue, 29 Sep 2026 14:17:17 +0000 Subject: [PATCH 14/53] Update meta repository (#3781) --- meta | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta b/meta index f1dc6f90d9..bcc494232d 160000 --- a/meta +++ b/meta @@ -1 +1 @@ -Subproject commit f1dc6f90d932564896bbfb7be03edcd740f49eaf +Subproject commit bcc494232d64ef78fb4c6dcabef0d0a17b2cda0f From 4389543e018a27cb37aa486bc075f4611e7d9a30 Mon Sep 17 00:00:00 2001 From: luisa-beerboom <101706784+luisa-beerboom@users.noreply.github.com> Date: Wed, 30 Sep 2026 16:49:29 +0200 Subject: [PATCH 15/53] Make get_many always filter out None values (#3761) --- .../services/database/extended_database.py | 82 ++++++++++-------- .../reader/system/get_many/test_get_many.py | 63 ++++++++++++++ tests/system/action/committee/test_import.py | 86 +++++++++++++++++++ .../action/committee/test_json_upload.py | 67 +++++++++++++++ 4 files changed, 263 insertions(+), 35 deletions(-) diff --git a/openslides_backend/services/database/extended_database.py b/openslides_backend/services/database/extended_database.py index df74f43755..50b91db9a1 100644 --- a/openslides_backend/services/database/extended_database.py +++ b/openslides_backend/services/database/extended_database.py @@ -259,48 +259,46 @@ def get_many( defaultdict(dict) ) for request in get_many_requests: - if not request.mapped_fields: - raise DatabaseException("No mapped fields given.") collection = request.collection for id_ in request.ids: mapped_fields_per_collection_and_id[collection][id_] = list( request.mapped_fields ) # fetch results from changed models - results, missing_fields_per_collection_and_id = ( + results, missing_fields_per_collection_and_id, gmr_base = ( self._get_many_from_changed_models(mapped_fields_per_collection_and_id) ) # fetch missing fields in the changed_models from the db and merge into the results if missing_fields_per_collection_and_id: get_many_requests = [ - GetManyRequest(collection, [id_], fields) - for collection, id_fields_dict in missing_fields_per_collection_and_id.items() - for id_, fields in id_fields_dict.items() + GetManyRequest(collection, ids, list(fields)) + for collection, fields_ids_dict in gmr_base.items() + for fields, ids in fields_ids_dict.items() ] missing_results = self.database_reader.get_many( get_many_requests, lock_result ) for collection, models in missing_results.items(): - for id_, model in models.items(): - # we can just update the model with the db fields since they must not have been - # present previously - results.setdefault(collection, {}).setdefault(id_, {}).update( - model - ) - # delete fields set to None in changed models - for ( - collection, - mapped_fields_per_id, - ) in mapped_fields_per_collection_and_id.items(): - for id_, mapped_fields in mapped_fields_per_id.items(): - for field in mapped_fields: - if ( - collection in results - and id_ in results[collection] - and field in results[collection][id_] - and results[collection][id_][field] is None - ): - del results[collection][id_][field] + for id_, missing_fields in missing_fields_per_collection_and_id[ + collection + ].items(): + if model := models.get(id_): + # we can just update the model with the db fields since they must not have been + # present previously + model.update( + results.setdefault(collection, {}).get(id_, {}) + ) + results[collection][id_] = model + if missing_fields == []: + # See in _get_many_from_changed_models: if the model is not new + # and mapped_fields are [] (i.e. all fields) + # _get_many_from_changed_models will leave the None fields in + # to ensure they don't get overwritten with the newly loaded data. + for field, value in list( + results[collection][id_].items() + ): + if value is None: + del results[collection][id_][field] else: results = self.database_reader.get_many(get_many_requests, lock_result) return results @@ -309,11 +307,14 @@ def _get_many_from_changed_models( self, mapped_fields_per_collection_and_id: MappedFieldsPerCollectionAndId, ) -> tuple[ - dict[Collection, dict[int, PartialModel]], MappedFieldsPerCollectionAndId + dict[Collection, dict[int, PartialModel]], + MappedFieldsPerCollectionAndId, + dict[Collection, dict[tuple[str, ...], list[int]]], ]: """ + Returns a dictionary of the changed models for the given collections together with all Returns a dictionary of the changed models for the given collections together with all - missing fields. + missing fields. Also returns the base data for a get many request for missing fields in the shape of: {collection: {tuple(missing fields): [ids of this config]}} """ results: dict[Collection, dict[int, PartialModel]] = defaultdict( lambda: defaultdict(dict) @@ -321,6 +322,9 @@ def _get_many_from_changed_models( missing_fields_per_collection_and_id: MappedFieldsPerCollectionAndId = ( defaultdict(lambda: defaultdict(list)) ) + gmr_base: dict[Collection, dict[tuple[str, ...], list[int]]] = defaultdict( + lambda: defaultdict(list) + ) for ( collection, models_mapped_fields, @@ -333,24 +337,32 @@ def _get_many_from_changed_models( if changed_model := self._changed_models[collection].get(id_, dict()): results[collection][id_]["id"] = id_ if mapped_fields: + has_missing = False for field in mapped_fields: - if field in changed_model or changed_model.get("meta_new"): - results[collection][id_][field] = changed_model.get( - field, None - ) - else: + if field in changed_model: + if (val := changed_model[field]) is not None: + results[collection][id_][field] = val + elif not changed_model.get("meta_new"): missing_fields_per_collection_and_id[collection][ id_ ].append(field) + has_missing = True + if has_missing: + fields = missing_fields_per_collection_and_id[collection][ + id_ + ] + gmr_base[collection][tuple(fields)].append(id_) else: - # assuming that whole model is needed and we want that? + # The whole model is requested. results[collection][id_] = changed_model missing_fields_per_collection_and_id[collection][id_] = [] + gmr_base[collection][tuple([])].append(id_) else: + gmr_base[collection][tuple(mapped_fields)].append(id_) missing_fields_per_collection_and_id[collection][ id_ ] = mapped_fields - return (results, missing_fields_per_collection_and_id) + return (results, missing_fields_per_collection_and_id, gmr_base) def get_all( self, diff --git a/tests/database/reader/system/get_many/test_get_many.py b/tests/database/reader/system/get_many/test_get_many.py index 626fa50c35..3813485ff8 100644 --- a/tests/database/reader/system/get_many/test_get_many.py +++ b/tests/database/reader/system/get_many/test_get_many.py @@ -212,6 +212,27 @@ def test_changed_models(db_connection: Connection) -> None: } +def test_changed_models_field_set_to_none(db_connection: Connection) -> None: + """Uses data from database and changed models dict.""" + setup_data(db_connection, standard_data) + with get_new_os_conn() as conn: + ex_db = ExtendedDatabase(conn, MagicMock(), MagicMock()) + ex_db.apply_changed_model("user/1", {"username": "admin", "last_login": None}) + response = ex_db.get_many( + [GetManyRequest("user", [1], ["username", "last_login", "is_demo_user"])], + use_changed_models=True, + ) + assert response == { + "user": { + 1: { + "id": 1, + "username": "admin", + "is_demo_user": True, + }, + }, + } + + def test_changed_models_new(db_connection: Connection) -> None: """Requests data from new changed model.""" setup_data(db_connection, standard_data) @@ -233,6 +254,28 @@ def test_changed_models_new(db_connection: Connection) -> None: } +def test_changed_models_only_new(db_connection: Connection) -> None: + """Requests data from only new changed model.""" + setup_data(db_connection, standard_data) + with get_new_os_conn() as conn: + ex_db = ExtendedDatabase(conn, MagicMock(), MagicMock()) + ex_db.apply_changed_model("committee/3", {"name": "3", "meta_new": True}) + response = ex_db.get_many( + [ + GetManyRequest("committee", [3], ["name", "description"]), + ], + use_changed_models=True, + ) + assert response == { + "committee": { + 3: { + "id": 3, + "name": "3", + }, + }, + } + + def test_changed_models_deleted(db_connection: Connection) -> None: """This should throw an Exception.""" setup_data(db_connection, standard_data) @@ -258,3 +301,23 @@ def test_use_changed_models_missing_field(db_connection: Connection) -> None: 2: {"id": 2, "name": "42", "organization_id": 1}, }, } + + +def test_no_mapped_fields_with_changes(db_connection: Connection) -> None: + setup_data(db_connection, standard_data) + with get_new_os_conn() as conn: + extended_database = ExtendedDatabase(conn, MagicMock(), MagicMock()) + extended_database.apply_changed_model("user/2", {"last_login": None}) + response = extended_database.get_many([GetManyRequest("user", [1, 2])]) + assert len(response) == 1 + assert len(response["user"]) == 2 + assert response["user"][1] == { + key: val + for key, val in standard_responses["user"][1].items() + if val is not None + } + assert response["user"][2] == { + key: val + for key, val in standard_responses["user"][2].items() + if key != "last_login" and val is not None + } diff --git a/tests/system/action/committee/test_import.py b/tests/system/action/committee/test_import.py index d09e0ac7dc..bef73f4e26 100644 --- a/tests/system/action/committee/test_import.py +++ b/tests/system/action/committee/test_import.py @@ -1212,3 +1212,89 @@ def test_json_upload_parent_multiple_found(self) -> None: "all_child_ids": [3, 4], }, ) + + def test_json_upload_with_only_new_with_parents(self) -> None: + self.json_upload_with_only_new_with_parents() + response = self.request("committee.import", {"id": 1, "import": True}) + self.assert_status_code(response, 200) + assert response.json["results"][0][0]["state"] == ImportState.DONE + assert self.get_row(response, 0) == { + "data": { + "name": { + "info": ImportState.NEW, + "value": "root", + } + }, + "messages": [], + "state": ImportState.NEW, + } + assert self.get_row(response, 1) == { + "data": { + "name": { + "info": ImportState.NEW, + "value": "level 1", + }, + "parent": { + "info": ImportState.NEW, + "value": "root", + }, + }, + "messages": [], + "state": ImportState.NEW, + } + assert self.get_row(response, 2) == { + "data": { + "name": { + "info": ImportState.NEW, + "value": "level 2", + }, + "parent": { + "info": ImportState.NEW, + "value": "level 1", + }, + }, + "messages": [], + "state": ImportState.NEW, + } + assert self.get_row(response, 3) == { + "data": { + "name": { + "info": ImportState.NEW, + "value": "level 3", + }, + "parent": { + "info": ImportState.NEW, + "value": "level 2", + }, + }, + "messages": [], + "state": ImportState.NEW, + } + self.assert_model_exists( + "committee/1", + {"name": "root", "child_ids": [2], "all_child_ids": [2, 3, 4]}, + ) + self.assert_model_exists( + "committee/2", + { + "name": "level 1", + "parent_id": 1, + "all_parent_ids": [1], + "child_ids": [3], + "all_child_ids": [3, 4], + }, + ) + self.assert_model_exists( + "committee/3", + { + "name": "level 2", + "parent_id": 2, + "all_parent_ids": [1, 2], + "child_ids": [4], + "all_child_ids": [4], + }, + ) + self.assert_model_exists( + "committee/4", + {"name": "level 3", "parent_id": 3, "all_parent_ids": [1, 2, 3]}, + ) diff --git a/tests/system/action/committee/test_json_upload.py b/tests/system/action/committee/test_json_upload.py index 01763eb945..c979f9e6eb 100644 --- a/tests/system/action/committee/test_json_upload.py +++ b/tests/system/action/committee/test_json_upload.py @@ -1964,3 +1964,70 @@ def json_upload_parent_multiple_found(self) -> None: ], "state": ImportState.DONE, } + + def json_upload_with_only_new_with_parents(self) -> None: + response = self.request( + "committee.json_upload", + { + "data": [ + {"name": "root"}, + {"name": "level 1", "parent": "root"}, + {"name": "level 2", "parent": "level 1"}, + {"name": "level 3", "parent": "level 2"}, + ] + }, + ) + self.assert_status_code(response, 200) + assert response.json["results"][0][0]["state"] == ImportState.DONE + assert self.get_row(response, 0) == { + "data": { + "name": { + "info": ImportState.NEW, + "value": "root", + } + }, + "messages": [], + "state": ImportState.NEW, + } + assert self.get_row(response, 1) == { + "data": { + "name": { + "info": ImportState.NEW, + "value": "level 1", + }, + "parent": { + "info": ImportState.NEW, + "value": "root", + }, + }, + "messages": [], + "state": ImportState.NEW, + } + assert self.get_row(response, 2) == { + "data": { + "name": { + "info": ImportState.NEW, + "value": "level 2", + }, + "parent": { + "info": ImportState.NEW, + "value": "level 1", + }, + }, + "messages": [], + "state": ImportState.NEW, + } + assert self.get_row(response, 3) == { + "data": { + "name": { + "info": ImportState.NEW, + "value": "level 3", + }, + "parent": { + "info": ImportState.NEW, + "value": "level 2", + }, + }, + "messages": [], + "state": ImportState.NEW, + } From 531ae7913028794acaa06a201e63644b9d13b56c Mon Sep 17 00:00:00 2001 From: luisa-beerboom <101706784+luisa-beerboom@users.noreply.github.com> Date: Fri, 9 Oct 2026 17:32:03 +0200 Subject: [PATCH 16/53] Use more restrictive Scope definition and check OML hierarchy for basic user data (#3793) --- .gitignore | 1 + docs/actions/user.create.md | 10 +- docs/actions/user.update.md | 10 +- docs/presenters/get_user_scope.md | 3 +- .../action/actions/user/account_import.py | 2 +- .../actions/user/account_json_upload.py | 2 +- .../action/actions/user/base_import.py | 2 +- .../action/actions/user/base_json_upload.py | 2 +- .../presenter/get_user_scope.py | 2 + .../user_create_update_permissions_mixin.py | 91 ++++++------------- .../shared/mixins/user_scope_mixin.py | 42 ++++++--- .../action/user/test_account_json_upload.py | 2 +- tests/system/action/user/test_delete.py | 38 ++++++++ .../action/user/test_participant_import.py | 48 +++++++++- .../user/test_participant_json_upload.py | 60 +++++++++++- tests/system/action/user/test_set_password.py | 46 ++++++++++ tests/system/action/user/test_update.py | 86 ++++++++++++++++-- .../presenter/test_get_user_editable.py | 28 +++++- tests/system/presenter/test_get_user_scope.py | 14 ++- tests/unit/test_user_scopes.py | 2 +- 20 files changed, 371 insertions(+), 120 deletions(-) diff --git a/.gitignore b/.gitignore index bfb680ca7c..8d12b02fbc 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ openslides_backend/htmlcov migrations/*.json migrations/*.sql +openslides_backend/migrations/previous_models # secrets secrets/ diff --git a/docs/actions/user.create.md b/docs/actions/user.create.md index 9c2ea3513b..23acb25eb9 100644 --- a/docs/actions/user.create.md +++ b/docs/actions/user.create.md @@ -16,6 +16,7 @@ member_number: string; default_vote_weight: decimal(6); external: boolean; + default_password: string; // Group B number: string; @@ -40,9 +41,6 @@ // Group E organization_management_level: string; -// Group F - default_password: string; - // Group G is_demo_user: boolean; @@ -95,7 +93,7 @@ The request user needs the basic permissions, see [Permissions for altering a us Group A: -No special permissions +Aside from the above, the request user needs at minimum the OML-Level of the requested user. Group B: @@ -119,10 +117,6 @@ Group E: The request user needs the OML equal or higher than that he wants to set. So the minimum is `can_manage_users`. -Group F: - -The request user needs the permissions under the rules of user_scope, see [Permissions for altering a user](https://github.com/OpenSlides/OpenSlides/wiki/Users#Permissions-for-altering-a-user), but at minimum the OML-Level of the requested user. - Group G: The request user needs the OML superadmin. diff --git a/docs/actions/user.update.md b/docs/actions/user.update.md index 4244f4c135..e8b087f0fe 100644 --- a/docs/actions/user.update.md +++ b/docs/actions/user.update.md @@ -18,6 +18,7 @@ pronoun: string; email: string; default_vote_weight: decimal(6); + default_password: string; // Group B number: string; @@ -41,9 +42,6 @@ // Group E organization_management_level: string; -// Group F - default_password: string; - // Group G is_demo_user: boolean; @@ -96,7 +94,7 @@ If the user to be updated has a `saml_id`, the fields `can_change_own_password` Group A: -See [Permissions for altering a user](https://github.com/OpenSlides/OpenSlides/wiki/Users#Permissions-for-altering-a-user). +The request user needs the permissions under the rules of user_scope, see [Permissions for altering a user](https://github.com/OpenSlides/OpenSlides/wiki/Users#Permissions-for-altering-a-user), but at minimum the OML of the requested user. Group B: @@ -120,10 +118,6 @@ Group E: The request user needs the OML equal or higher than that he wants to set. So the minimum is `can_manage_users`. -Group F: - -The request user needs the permissions under the rules of user_scope, see [Permissions for altering a user](https://github.com/OpenSlides/OpenSlides/wiki/Users#Permissions-for-altering-a-user), but at minimum the OML of the requested user. - Group G: The request user needs the OML `superadmin`. diff --git a/docs/presenters/get_user_scope.md b/docs/presenters/get_user_scope.md index ae17f4606d..17e3c84e69 100644 --- a/docs/presenters/get_user_scope.md +++ b/docs/presenters/get_user_scope.md @@ -16,7 +16,8 @@ user_oml: String, // one of "superadmin", "can_manage_organization", "can_manage_users", "" committee_ids: Id[], // Ids of all committees the user is part of user_in_archived_meetings_only: boolean, // True if total number of meeting_ids for user is more than 0 and number of active meetings is 0 - home_committee_id: Id | None // The id of the user's home committee, None if he doesn't have one + home_committee_id: Id | None, // The id of the user's home committee, None if he doesn't have one + is_committee_manager: boolean // Whether the user has any committee management rights at all }, ... } diff --git a/openslides_backend/action/actions/user/account_import.py b/openslides_backend/action/actions/user/account_import.py index 62974d99aa..04a75e8ae7 100644 --- a/openslides_backend/action/actions/user/account_import.py +++ b/openslides_backend/action/actions/user/account_import.py @@ -15,7 +15,7 @@ class AccountImport(BaseUserImport): def validate_entry(self, row: ImportRow) -> None: super().validate_entry(row) - if not self.check_field_failures(row["data"], row["messages"], "ADEFGHIJ"): + if not self.check_field_failures(row["data"], row["messages"], "ADEGHIJ"): row["state"] = ImportState.ERROR if row["state"] == ImportState.ERROR and self.import_state == ImportState.DONE: diff --git a/openslides_backend/action/actions/user/account_json_upload.py b/openslides_backend/action/actions/user/account_json_upload.py index 00ce0de10b..0ba933a0e1 100644 --- a/openslides_backend/action/actions/user/account_json_upload.py +++ b/openslides_backend/action/actions/user/account_json_upload.py @@ -49,7 +49,7 @@ def validate_entry(self, entry: dict[str, Any]) -> dict[str, Any]: entry, messages, "Account is updated, but changes to the following field(s) are not possible:", - field_groups="ADEFGHIJ", + field_groups="ADEGHIJ", ) return results diff --git a/openslides_backend/action/actions/user/base_import.py b/openslides_backend/action/actions/user/base_import.py index 0e99ddb336..25b7d8f9fb 100644 --- a/openslides_backend/action/actions/user/base_import.py +++ b/openslides_backend/action/actions/user/base_import.py @@ -167,7 +167,7 @@ def validate_entry(self, row: ImportRow) -> None: self.validate_field(row, self.committee_map, "home_committee", False) def check_field_failures( - self, entry: dict[str, Any], messages: list[str], groups: str = "ABDEFGHIJ" + self, entry: dict[str, Any], messages: list[str], groups: str = "ABDEGHIJ" ) -> bool: substitutions: dict[str, Any] = {} for field in ["home_committee", "gender"]: diff --git a/openslides_backend/action/actions/user/base_json_upload.py b/openslides_backend/action/actions/user/base_json_upload.py index 0a0f9a9013..2f1f05d8ca 100644 --- a/openslides_backend/action/actions/user/base_json_upload.py +++ b/openslides_backend/action/actions/user/base_json_upload.py @@ -497,7 +497,7 @@ def check_field_failures( entry: dict[str, Any], messages: list[str], failing_msg: str, - field_groups: str = "ABDEFGHIJ", + field_groups: str = "ABDEGHIJ", ) -> None: payload_index = entry.pop("payload_index", None) # swapping needed for get_failing_fields and setting import states not to fail diff --git a/openslides_backend/presenter/get_user_scope.py b/openslides_backend/presenter/get_user_scope.py index 107c392f30..dc01f97bad 100644 --- a/openslides_backend/presenter/get_user_scope.py +++ b/openslides_backend/presenter/get_user_scope.py @@ -43,6 +43,7 @@ def get_result(self) -> Any: committee_meeting_ids, user_in_archived_meetings_only, home_committee_id, + is_committee_manager, ) = self.get_user_scope(user_id) committee_ids = [ci for ci in committee_meeting_ids.keys()] result[str(user_id)] = { @@ -52,5 +53,6 @@ def get_result(self) -> Any: "committee_ids": committee_ids, "user_in_archived_meetings_only": user_in_archived_meetings_only, "home_committee_id": home_committee_id, + "is_committee_manager": is_committee_manager, } return result diff --git a/openslides_backend/shared/mixins/user_create_update_permissions_mixin.py b/openslides_backend/shared/mixins/user_create_update_permissions_mixin.py index 10916113f8..757ac420c0 100644 --- a/openslides_backend/shared/mixins/user_create_update_permissions_mixin.py +++ b/openslides_backend/shared/mixins/user_create_update_permissions_mixin.py @@ -217,6 +217,7 @@ class CreateUpdatePermissionsMixin(UserScopeMixin, BaseServiceProvider): "email", "default_vote_weight", "member_number", + "default_password", ], "B": [ "number", @@ -233,7 +234,6 @@ class CreateUpdatePermissionsMixin(UserScopeMixin, BaseServiceProvider): "C": ["meeting_id", "group_ids"], "D": ["committee_management_ids"], "E": ["organization_management_level"], - "F": ["default_password"], "G": ["is_demo_user"], "H": ["saml_id"], "I": ["home_committee_id"], @@ -264,6 +264,7 @@ def check_permissions(self, instance: dict[str, Any]) -> None: self.instance_committee_meeting_ids, self.user_in_archived_meetings_only, self.instance_home_committee_id, + self.instance_is_committee_management, ) = self.get_user_scope(instance.get("id") or instance) if self.permstore.user_oml != OrganizationManagementLevel.SUPERADMIN: @@ -285,50 +286,10 @@ def check_permissions(self, instance: dict[str, Any]) -> None: self.check_group_C(actual_group_fields["C"], instance, locked_from_inside) self.check_group_B(actual_group_fields["B"], instance, locked_from_inside) self.check_group_A(actual_group_fields["A"], instance) - self.check_group_F(actual_group_fields["F"], instance) self.check_group_G(actual_group_fields["G"]) self.check_group_I(actual_group_fields["I"], instance) self.check_group_J(actual_group_fields["J"], instance) - def check_group_A(self, fields: list[str], instance: dict[str, Any]) -> None: - """Check Group A: Depending on scope of user to act on""" - if ( - not fields - or self.permstore.user_oml >= OrganizationManagementLevel.CAN_MANAGE_USERS - ): - return - - missing_permissions: dict[AnyPermission, int | set[int]] = dict() - if self.instance_user_scope == UserScope.Organization: - if not ( - self.permstore.user_committees.intersection( - self.instance_committee_meeting_ids - ) - ): - missing_permissions = {OrganizationManagementLevel.CAN_MANAGE_USERS: 1} - elif self.instance_user_scope == UserScope.Committee: - if self.instance_user_scope_id not in self.permstore.user_committees: - missing_permissions = { - OrganizationManagementLevel.CAN_MANAGE_USERS: 1, - CommitteeManagementLevel.CAN_MANAGE: self.instance_user_scope_id, - } - elif ( - self.instance_user_scope_id not in self.permstore.user_committees_meetings - and self.instance_user_scope_id not in self.permstore.user_meetings - ): - meeting = self.datastore.get( - fqid_from_collection_and_id("meeting", self.instance_user_scope_id), - ["committee_id"], - lock_result=False, - ) - missing_permissions = { - OrganizationManagementLevel.CAN_MANAGE_USERS: 1, - CommitteeManagementLevel.CAN_MANAGE: meeting["committee_id"], - self.permission: self.instance_user_scope_id, - } - if missing_permissions: - self._check_missing_permissions_groups_AF(instance, missing_permissions) - def check_group_B( self, fields: list[str], instance: dict[str, Any], locked_from_inside: bool ) -> None: @@ -399,8 +360,8 @@ def check_group_E(self, fields: list[str], instance: dict[str, Any]) -> None: f"Your organization management level is not high enough to set a Level of {instance.get('organization_management_level', OrganizationManagementLevel.CAN_MANAGE_USERS.get_verbose_type())}." ) - def check_group_F(self, fields: list[str], instance: dict[str, Any]) -> None: - """Check F common fields: scoped permissions necessary, but if instance user has + def check_group_A(self, fields: list[str], instance: dict[str, Any]) -> None: + """Check A common fields: scoped permissions necessary, but if instance user has an oml-permission, that of the request user must be higher""" if ( self.permstore.user_oml == OrganizationManagementLevel.SUPERADMIN @@ -409,10 +370,7 @@ def check_group_F(self, fields: list[str], instance: dict[str, Any]) -> None: return missing_permissions: dict[AnyPermission, int | set[int]] = dict() - if ( - self.instance_user_oml_permission - or self.instance_user_scope == UserScope.Organization - ): + if self.instance_user_scope == UserScope.Organization: if self.instance_user_oml_permission: expected_oml_permission = OrganizationManagementLevel( self.instance_user_oml_permission @@ -450,7 +408,7 @@ def check_group_F(self, fields: list[str], instance: dict[str, Any]) -> None: self.permission: self.instance_user_scope_id, } if missing_permissions: - self._check_missing_permissions_groups_AF(instance, missing_permissions) + self._check_missing_permissions_groups_A(instance, missing_permissions) def check_group_G(self, fields: list[str]) -> None: """Group G: OML SUPERADMIN necessary""" @@ -552,7 +510,7 @@ def _check_for_higher_OML( return [group for group in fields if group not in ignore_groups] return [] - def _check_missing_permissions_groups_AF( + def _check_missing_permissions_groups_A( self, instance: dict[str, Any], missing_permissions: dict[AnyPermission, int | set[int]], @@ -565,21 +523,26 @@ def _check_missing_permissions_groups_AF( missing_permissions and additionally user.can_update for every one of the related meetings. * Else if the user is only in archived meetings it again throws an exception with the precalulated missing_permissions. """ + if ( + self.instance_is_committee_management + or self.instance_user_oml_permission + or self.instance_home_committee_id + ): + raise MissingPermission(missing_permissions) if self.instance_home_committee_id or not self.check_for_admin_in_all_meetings( instance.get("id", 0) ): - if not self.instance_home_committee_id: - missing_permissions.update( - { - Permissions.User.CAN_UPDATE: { - meeting_id - for meeting_ids in self.instance_committee_meeting_ids.values() - if meeting_ids is not None - for meeting_id in meeting_ids - if meeting_id is not None - }, - } - ) + missing_permissions.update( + { + Permissions.User.CAN_UPDATE: { + meeting_id + for meeting_ids in self.instance_committee_meeting_ids.values() + if meeting_ids is not None + for meeting_id in meeting_ids + if meeting_id is not None + }, + } + ) raise MissingPermission(missing_permissions) elif self.user_in_archived_meetings_only: raise MissingPermission(missing_permissions) @@ -665,7 +628,7 @@ def __init__( ) def get_failing_fields( - self, instance: dict[str, Any], groups: str = "ABDEFGHIJ" + self, instance: dict[str, Any], groups: str = "ABDEGHIJ" ) -> list[str]: """ Checks the permissions on a per field and user.scope base, details see @@ -692,6 +655,7 @@ def get_failing_fields( self.instance_committee_meeting_ids, self.user_in_archived_meetings_only, self.instance_home_committee_id, + self.instance_is_committee_management, ) = self.get_user_scope(instance.get("id") or instance) failing_groups = self._check_for_higher_OML( @@ -725,7 +689,6 @@ def get_failing_fields( (self.check_group_D, "D", instance, None), (self.check_group_B, "B", instance, locked_from_inside), (self.check_group_A, "A", instance, None), - (self.check_group_F, "F", instance, None), (self.check_group_G, "G", None, None), (self.check_group_I, "I", instance, None), (self.check_group_J, "J", instance, None), @@ -748,7 +711,7 @@ def get_failing_fields( failing_fields.update({field: None for field in fields}) return list(failing_fields) - def get_all_checked_fields(self, groups: str = "ABDEFGHIJ") -> set[str]: + def get_all_checked_fields(self, groups: str = "ABDEGHIJ") -> set[str]: all_fields = set() for letter in groups: all_fields.update(self.field_rights[letter]) diff --git a/openslides_backend/shared/mixins/user_scope_mixin.py b/openslides_backend/shared/mixins/user_scope_mixin.py index 824bd6166a..37daa27a87 100644 --- a/openslides_backend/shared/mixins/user_scope_mixin.py +++ b/openslides_backend/shared/mixins/user_scope_mixin.py @@ -34,7 +34,7 @@ class UserScopeMixin(BaseServiceProvider): def get_user_scope( self, id_or_instance: int | dict[str, Any] - ) -> tuple[UserScope, int, str, dict[int, list[int]], bool, int | None]: + ) -> tuple[UserScope, int, str, dict[int, list[int]], bool, int | None, bool]: """ Parameter id_or_instance: id for existing user or instance for user creating and altering actions. Returns in the tuple: @@ -46,6 +46,7 @@ def get_user_scope( of together with the respective meetings the user is part of * whether the user is only in archived meetings * his home_committee_id. + * whether he is a manager for any committee A committee can have no meetings if the user just has committee management rights and is not part of any of its meetings. """ @@ -76,7 +77,11 @@ def get_user_scope( committee_meetings, user_in_archived_meetings_only, ) = self.calculate_scope_data( - meeting_ids, committees_manager, home_committee_id + meeting_ids, + committees_manager, + home_committee_id, + oml_right, + committees_manager, ) return ( @@ -86,12 +91,12 @@ def get_user_scope( committee_meetings, user_in_archived_meetings_only, home_committee_id, + bool(committees_manager), ) def check_permissions_for_scope( self, instance_id: int, - always_check_user_oml: bool = True, meeting_permission: Permission = Permissions.User.CAN_MANAGE, ) -> None: """ @@ -108,9 +113,10 @@ def check_permissions_for_scope( committees_to_meetings, user_in_archived_meetings_only, _, + _, ) = self.get_user_scope(instance_id) - if self._check_oml_levels(always_check_user_oml, user_oml): + if self._check_oml_levels(user_oml): return if scope == UserScope.Committee: self._check_permissions_for_scope_committee(scope_id) @@ -200,6 +206,8 @@ def calculate_scope_data( meeting_ids: list[int], committees_manager: set[int], home_committee_id: int | None, + oml: OrganizationManagementLevel | None, + committee_management_ids: set[int] | None, ) -> tuple[UserScope, int, dict[int, list[int]], bool]: """ Helper function used in method get_user_scope. @@ -222,6 +230,8 @@ def calculate_scope_data( active_meetings_committee, active_committee_meetings, committee_meetings, + oml, + committee_management_ids, ) user_committee_meetings = ( active_committee_meetings @@ -314,15 +324,23 @@ def _get_user_scope_and_scope_id( active_meetings_committee: dict[int, int], active_committee_meetings: dict[int, list[int]], committee_meetings: dict[int, list[int]], + oml: OrganizationManagementLevel | None, + committee_management_ids: set[int] | None, ) -> tuple[UserScope, int]: """ Helper function used in method calculate_scope_data. Determines user's scope and scope ID. """ + if oml: + return UserScope.Organization, 1 if home_committee_id: return UserScope.Committee, home_committee_id - if len(active_meetings_committee) == 1 and len(active_committee_meetings) == 1: + if ( + len(active_meetings_committee) == 1 + and len(active_committee_meetings) == 1 + and not committee_management_ids + ): return UserScope.Meeting, next(iter(active_meetings_committee)) if len(committee_meetings) == 1: @@ -402,21 +420,17 @@ def _analyze_meeting_admins( for admin_users in meeting_id_to_admin_user_ids.values() ) - def _check_oml_levels(self, always_check_user_oml: bool, user_oml: str) -> bool: + def _check_oml_levels(self, user_oml: str) -> bool: """ Raises error if always_check_user_oml=True and request user doesn't have at least the same OML as requested user. Otherwise passes without further scope-specific checks if request user has OML can_manage_users. """ - if ( - always_check_user_oml - and user_oml - and not has_organization_management_level( - self.datastore, - self.user_id, - perm := OrganizationManagementLevel(user_oml), - ) + if user_oml and not has_organization_management_level( + self.datastore, + self.user_id, + perm := OrganizationManagementLevel(user_oml), ): raise MissingPermission({perm: 1}) if has_organization_management_level( diff --git a/tests/system/action/user/test_account_json_upload.py b/tests/system/action/user/test_account_json_upload.py index 8e33f62c9c..7de42d7a02 100644 --- a/tests/system/action/user/test_account_json_upload.py +++ b/tests/system/action/user/test_account_json_upload.py @@ -2642,7 +2642,7 @@ def json_upload_multiple_with_x(self) -> None: ] else: assert import_preview["result"]["rows"][row]["messages"] == [ - "Account is updated, but changes to the following field(s) are not possible: first_name, last_name, email, username, is_active, is_physical_person, gender_id, default_password" + "Account is updated, but changes to the following field(s) are not possible: first_name, last_name, email, username, default_password, is_active, is_physical_person, gender_id" ] else: import_state = ImportState.DONE diff --git a/tests/system/action/user/test_delete.py b/tests/system/action/user/test_delete.py index e9c5944405..46b61c35f9 100644 --- a/tests/system/action/user/test_delete.py +++ b/tests/system/action/user/test_delete.py @@ -620,3 +620,41 @@ def test_delete_non_last_meeting_admin_from_two_meetings(self) -> None: "Cannot remove last admin from meeting(s) 1, 4", response.json["message"], ) + + def set_delete_meeting_member_comm_admin_as_group(self, bob_group: int) -> None: + self.create_meeting() + self.set_group_permissions(3, [Permissions.User.CAN_UPDATE]) + self.create_meeting(4, {"committee_id": 60}) + self.set_group_permissions(6, [Permissions.User.CAN_UPDATE]) + + alice_id = self.create_user("alice") + self.set_committee_management_level([60], alice_id) + self.set_user_groups(alice_id, [1]) + + bob_id = self.create_user("bob") + self.set_user_groups(bob_id, [bob_group]) + + self.login(bob_id) + + response = self.request("user.delete", {"id": alice_id}) + self.assert_status_code(response, 403) + self.assertEqual( + "You are not allowed to perform action user.delete. Missing permissions: OrganizationManagementLevel can_manage_users in organization 1 or CommitteeManagementLevel can_manage in committee 60", + response.json["message"], + ) + + def test_delete_meeting_member_comm_admin_as_same_meeting_admin(self) -> None: + self.set_delete_meeting_member_comm_admin_as_group(2) + + def test_delete_meeting_member_comm_admin_as_same_meeting_user_manager( + self, + ) -> None: + self.set_delete_meeting_member_comm_admin_as_group(3) + + def test_delete_meeting_member_comm_admin_as_different_meeting_admin(self) -> None: + self.set_delete_meeting_member_comm_admin_as_group(5) + + def test_delete_meeting_member_comm_admin_as_different_meeting_user_manager( + self, + ) -> None: + self.set_delete_meeting_member_comm_admin_as_group(6) diff --git a/tests/system/action/user/test_participant_import.py b/tests/system/action/user/test_participant_import.py index 4dae3efe33..7f58d08592 100644 --- a/tests/system/action/user/test_participant_import.py +++ b/tests/system/action/user/test_participant_import.py @@ -1064,7 +1064,7 @@ def test_json_upload_with_sufficient_field_permission_update(self) -> None: assert row["state"] == ImportState.DONE assert row["messages"] == [ "Because this participant is connected with a saml_id: The default_password will be ignored and password will not be changeable in OpenSlides.", - "Account is added to the meeting, but changes to the following field(s) are not possible: username, first_name, email, saml_id, default_password", + "Account is added to the meeting, but changes to the following field(s) are not possible: username, first_name, email, default_password, saml_id", "In contrast to preview you may import field(s) 'default_password, email, first_name, saml_id, username'", ] assert row["data"] == { @@ -1122,7 +1122,7 @@ def test_json_upload_less_fields_field_permission_update(self) -> None: assert row["state"] == ImportState.DONE assert row["messages"] == [ "Because this participant is connected with a saml_id: The default_password will be ignored and password will not be changeable in OpenSlides.", - "Account is added to the meeting, but changes to the following field(s) are not possible: username, first_name, email, saml_id, default_password", + "Account is added to the meeting, but changes to the following field(s) are not possible: username, first_name, email, default_password, saml_id", ] assert row["data"] == { "id": 2, @@ -1171,7 +1171,7 @@ def test_json_upload_less_fields_field_permission_update_with_member_number( assert row["state"] == ImportState.DONE assert row["messages"] == [ "Because this participant is connected with a saml_id: The default_password will be ignored and password will not be changeable in OpenSlides.", - "Account is added to the meeting, but changes to the following field(s) are not possible: member_number, first_name, email, username, saml_id, default_password", + "Account is added to the meeting, but changes to the following field(s) are not possible: member_number, first_name, email, default_password, username, saml_id", ] assert row["data"] == { "id": 2, @@ -1815,7 +1815,7 @@ def test_json_upload_no_permissions_to_set_meeting_external_fields_on_superadmin assert row["state"] == ImportState.DONE assert row["messages"] == [ "Because this participant is connected with a saml_id: The default_password will be ignored and password will not be changeable in OpenSlides.", - "Account is added to the meeting, but changes to the following field(s) are not possible: username, first_name, email, saml_id, default_password", + "Account is added to the meeting, but changes to the following field(s) are not possible: username, first_name, email, default_password, saml_id", ] assert row["data"] == { "id": 2, @@ -1874,3 +1874,43 @@ def test_json_upload_update_reference_via_two_attributes(self) -> None: ], } assert row["list_delete_amounts"] == {"groups": 1} + + def import_for_meeting_member_comm_admin_as_group( + self, bob_group: int, bob_meeting: int + ) -> None: + alice_id = self.json_upload_for_meeting_member_comm_admin_as_group( + bob_group, bob_meeting + ) + + alice = self.get_model(alice_fqid := f"user/{alice_id}") + + response = self.request( + "participant.import", + { + "meeting_id": bob_meeting, + "data": [ + {"username": "alice", "email": "bob.email@malicious.de"}, + {"username": "theNewGuy"}, + ], + }, + ) + self.assert_status_code(response, 200) + self.assert_model_exists(alice_fqid, alice) + + def import_email_for_meeting_member_comm_admin_as_same_meeting_admin(self) -> None: + self.import_for_meeting_member_comm_admin_as_group(2, 1) + + def import_email_for_meeting_member_comm_admin_as_same_meeting_user_manager( + self, + ) -> None: + self.import_for_meeting_member_comm_admin_as_group(3, 1) + + def import_email_for_meeting_member_comm_admin_as_different_meeting_admin( + self, + ) -> None: + self.import_for_meeting_member_comm_admin_as_group(5, 4) + + def import_email_for_meeting_member_comm_admin_as_different_meeting_user_manager( + self, + ) -> None: + self.import_for_meeting_member_comm_admin_as_group(6, 4) diff --git a/tests/system/action/user/test_participant_json_upload.py b/tests/system/action/user/test_participant_json_upload.py index b18b1df222..339d4592d6 100644 --- a/tests/system/action/user/test_participant_json_upload.py +++ b/tests/system/action/user/test_participant_json_upload.py @@ -403,7 +403,7 @@ def test_json_upload_no_permission_meeting_admin(self) -> None: { "state": ImportState.DONE, "messages": [ - "Account is added to the meeting, but changes to the following field(s) are not possible: username, gender_id, default_password" + "Account is added to the meeting, but changes to the following field(s) are not possible: username, default_password, gender_id" ], "data": { "username": { @@ -2169,7 +2169,7 @@ def json_upload_not_sufficient_field_permission_update(self) -> None: assert row["state"] == ImportState.DONE assert row["messages"] == [ "Because this participant is connected with a saml_id: The default_password will be ignored and password will not be changeable in OpenSlides.", - "Account is added to the meeting, but changes to the following field(s) are not possible: username, first_name, email, saml_id, default_password", + "Account is added to the meeting, but changes to the following field(s) are not possible: username, first_name, email, default_password, saml_id", ] assert row["data"] == { "id": 2, @@ -2235,7 +2235,7 @@ def json_upload_no_permissions_to_set_meeting_external_fields_on_superadmin( assert row["state"] == ImportState.DONE assert row["messages"] == [ "Because this participant is connected with a saml_id: The default_password will be ignored and password will not be changeable in OpenSlides.", - "Account is added to the meeting, but changes to the following field(s) are not possible: username, first_name, email, saml_id, default_password", + "Account is added to the meeting, but changes to the following field(s) are not possible: username, first_name, email, default_password, saml_id", ] assert row["data"] == { "id": 2, @@ -2306,7 +2306,7 @@ def json_upload_not_sufficient_field_permission_update_with_member_number( assert row["state"] == ImportState.DONE assert row["messages"] == [ "Because this participant is connected with a saml_id: The default_password will be ignored and password will not be changeable in OpenSlides.", - "Account is added to the meeting, but changes to the following field(s) are not possible: member_number, first_name, email, username, saml_id, default_password", + "Account is added to the meeting, but changes to the following field(s) are not possible: member_number, first_name, email, default_password, username, saml_id", ] assert row["data"] == { "id": 2, @@ -3431,3 +3431,55 @@ def json_upload_update_home_committee_and_external_false_no_perms_new(self) -> N "id": 2, } assert data["external"] == {"info": ImportState.REMOVE, "value": False} + + def json_upload_for_meeting_member_comm_admin_as_group( + self, bob_group: int, bob_meeting: int + ) -> int: + self.create_meeting() + self.set_group_permissions(3, [Permissions.User.CAN_MANAGE]) + self.create_meeting(4, {"committee_id": 60}) + self.set_group_permissions(6, [Permissions.User.CAN_MANAGE]) + + alice_id = self.create_user("alice") + self.set_committee_management_level([60], alice_id) + self.set_user_groups(alice_id, [1]) + + bob_id = self.create_user("bob") + self.set_user_groups(bob_id, [bob_group]) + + self.login(bob_id) + data = { + "email": "bob.email@malicious.de", + } + + response = self.request( + "participant.json_upload", + { + "meeting_id": bob_meeting, + "data": [ + {"username": "alice", "email": "bob.email@malicious.de"}, + ], + }, + ) + self.assert_status_code(response, 200) + import_preview = self.assert_model_exists("import_preview/1") + assert import_preview["state"] == ImportState.DONE + assert import_preview["name"] == "participant" + assert import_preview["result"]["rows"][0]["state"] == ( + ImportState.DONE if bob_meeting == 1 else ImportState.REFERENCED + ) + assert import_preview["result"]["rows"][0]["messages"] == [ + "Account is added to the meeting, but changes to the following field(s) are not possible: username, email" + ] + data = import_preview["result"]["rows"][0]["data"] + assert data["id"] == alice_id + assert data["username"] == { + "id": alice_id, + "info": ImportState.REMOVE, + "value": "alice", + } + assert data["email"] == { + "info": ImportState.REMOVE, + "value": "bob.email@malicious.de", + } + return alice_id diff --git a/tests/system/action/user/test_set_password.py b/tests/system/action/user/test_set_password.py index 14e497d7d1..ea87d3347b 100644 --- a/tests/system/action/user/test_set_password.py +++ b/tests/system/action/user/test_set_password.py @@ -290,3 +290,49 @@ def test_set_password_as_parent_committee_admin(self) -> None: model = self.get_model(f"user/{bob_id}") assert self.auth.is_equal(self.PASSWORD, model.get("password", "")) self.assert_logged_in() + + def set_password_for_meeting_member_comm_admin_as_group( + self, bob_group: int + ) -> None: + self.create_meeting() + self.set_group_permissions(3, [Permissions.User.CAN_UPDATE]) + self.create_meeting(4, {"committee_id": 60}) + self.set_group_permissions(6, [Permissions.User.CAN_UPDATE]) + + alice_id = self.create_user("alice") + self.set_committee_management_level([60], alice_id) + self.set_user_groups(alice_id, [1]) + + bob_id = self.create_user("bob") + self.set_user_groups(bob_id, [bob_group]) + + self.login(bob_id) + + response = self.request( + "user.set_password", {"id": alice_id, "password": self.PASSWORD} + ) + self.assert_status_code(response, 403) + self.assertEqual( + "You are not allowed to perform action user.set_password. Missing permissions: OrganizationManagementLevel can_manage_users in organization 1 or CommitteeManagementLevel can_manage in committee 60", + response.json["message"], + ) + + def test_set_password_for_meeting_member_comm_admin_as_same_meeting_admin( + self, + ) -> None: + self.set_password_for_meeting_member_comm_admin_as_group(2) + + def test_set_password_for_meeting_member_comm_admin_as_same_meeting_user_manager( + self, + ) -> None: + self.set_password_for_meeting_member_comm_admin_as_group(3) + + def test_set_password_for_meeting_member_comm_admin_as_different_meeting_admin( + self, + ) -> None: + self.set_password_for_meeting_member_comm_admin_as_group(5) + + def test_set_password_for_meeting_member_comm_admin_as_different_meeting_user_manager( + self, + ) -> None: + self.set_password_for_meeting_member_comm_admin_as_group(6) diff --git a/tests/system/action/user/test_update.py b/tests/system/action/user/test_update.py index e545797b6d..54a26f009f 100644 --- a/tests/system/action/user/test_update.py +++ b/tests/system/action/user/test_update.py @@ -24,7 +24,10 @@ def permission_setup(self) -> None: self.set_models({"user/111": {"username": "User111"}}) def two_meetings_test_fail_ADEFGH( - self, committee_id: None | int = None, group_B_success: bool = False + self, + committee_id: None | int = None, + group_B_success: bool = False, + with_meeting_perm_text: bool = True, ) -> None: # test group A response = self.request( @@ -35,8 +38,12 @@ def two_meetings_test_fail_ADEFGH( }, ) self.assert_status_code(response, 403) + insert = "s" if with_meeting_perm_text else "" + error_text = f"You are not allowed to perform action user.update. Missing permission{insert}: OrganizationManagementLevel can_manage_users in organization 1" + if with_meeting_perm_text: + error_text += " or Permission user.can_update in meetings {1, 4}" self.assertIn( - "You are not allowed to perform action user.update. Missing permissions: OrganizationManagementLevel can_manage_users in organization 1 or Permission user.can_update in meetings {1, 4}", + error_text, response.json["message"], ) self.assert_model_exists( @@ -105,7 +112,7 @@ def two_meetings_test_fail_ADEFGH( ) self.assert_status_code(response, 403) self.assertIn( - "You are not allowed to perform action user.update. Missing permissions: OrganizationManagementLevel can_manage_users in organization 1 or Permission user.can_update in meetings {1, 4}", + error_text, response.json["message"], ) self.assert_model_exists( @@ -1182,7 +1189,7 @@ def test_perm_group_A_belongs_to_same_meetings_committee_admin(self) -> None: # 111 is committee admin committee_id = 60 self.set_committee_management_level([committee_id], 111) - self.two_meetings_test_fail_ADEFGH(committee_id) + self.two_meetings_test_fail_ADEFGH(committee_id, with_meeting_perm_text=False) # test group B and C response = self.request( "user.update", @@ -1208,7 +1215,7 @@ def test_perm_group_A_belongs_to_same_meetings_committee_admin(self) -> None: ) self.assert_status_code(response, 403) self.assertIn( - "You are not allowed to perform action user.update. Missing permissions: OrganizationManagementLevel can_manage_users in organization 1 or Permission user.can_update in meetings {1, 4}", + "You are not allowed to perform action user.update. Missing permission: OrganizationManagementLevel can_manage_users in organization 1", response.json["message"], ) self.assert_model_exists( @@ -1324,7 +1331,7 @@ def test_perm_group_A_no_permission(self) -> None: ) self.assert_status_code(response, 403) self.assertIn( - "You are not allowed to perform action user.update. Missing permissions: OrganizationManagementLevel can_manage_users in organization 1 or Permission user.can_update in meetings {1, 4}", + "You are not allowed to perform action user.update. Missing permission: OrganizationManagementLevel can_manage_users in organization 1", response.json["message"], ) @@ -4599,6 +4606,73 @@ def test_lock_out_then_remove_from_meeting_then_set_superadmin(self) -> None: {"username": "bob", "organization_management_level": "superadmin"}, ) + def update_for_meeting_member_comm_admin_as_group( + self, bob_group: int, set_field: Literal["email", "username"] + ) -> None: + self.create_meeting() + self.set_group_permissions(3, [Permissions.User.CAN_UPDATE]) + self.create_meeting(4, {"committee_id": 60}) + self.set_group_permissions(6, [Permissions.User.CAN_UPDATE]) + + alice_id = self.create_user("alice") + self.set_committee_management_level([60], alice_id) + self.set_user_groups(alice_id, [1]) + + bob_id = self.create_user("bob") + self.set_user_groups(bob_id, [bob_group]) + + self.login(bob_id) + data = {"email": "bob.email@malicious.de", "username": "bobdermeisterhacker"} + + response = self.request( + "user.update", {"id": alice_id, set_field: data[set_field]} + ) + self.assert_status_code(response, 403) + self.assertEqual( + "You are not allowed to perform action user.update. Missing permissions: OrganizationManagementLevel can_manage_users in organization 1 or CommitteeManagementLevel can_manage in committee 60", + response.json["message"], + ) + + def test_update_email_for_meeting_member_comm_admin_as_same_meeting_admin( + self, + ) -> None: + self.update_for_meeting_member_comm_admin_as_group(2, "email") + + def test_update_email_for_meeting_member_comm_admin_as_same_meeting_user_manager( + self, + ) -> None: + self.update_for_meeting_member_comm_admin_as_group(3, "email") + + def test_update_email_for_meeting_member_comm_admin_as_different_meeting_admin( + self, + ) -> None: + self.update_for_meeting_member_comm_admin_as_group(5, "email") + + def test_update_email_for_meeting_member_comm_admin_as_different_meeting_user_manager( + self, + ) -> None: + self.update_for_meeting_member_comm_admin_as_group(6, "email") + + def test_update_username_for_meeting_member_comm_admin_as_same_meeting_admin( + self, + ) -> None: + self.update_for_meeting_member_comm_admin_as_group(2, "username") + + def test_update_username_for_meeting_member_comm_admin_as_same_meeting_user_manager( + self, + ) -> None: + self.update_for_meeting_member_comm_admin_as_group(3, "username") + + def test_update_username_for_meeting_member_comm_admin_as_different_meeting_admin( + self, + ) -> None: + self.update_for_meeting_member_comm_admin_as_group(5, "username") + + def test_update_username_for_meeting_member_comm_admin_as_different_meeting_user_manager( + self, + ) -> None: + self.update_for_meeting_member_comm_admin_as_group(6, "username") + class UserUpdateHomeCommitteePermissionTest(BaseActionTestCase): committeePerms: set[int] = set() diff --git a/tests/system/presenter/test_get_user_editable.py b/tests/system/presenter/test_get_user_editable.py index 66a55abcb8..176cc6d7f6 100644 --- a/tests/system/presenter/test_get_user_editable.py +++ b/tests/system/presenter/test_get_user_editable.py @@ -172,6 +172,7 @@ def test_with_cml(self) -> None: def test_with_same_meeting(self) -> None: """ User 5 can be edited because he is only in meetings which User 111 is admin of. + User 6 can be edited because while he is only in meetings which User 111 is admin of, he is also a committee admin. User 7 can not be edited because he is in two of the same meetings but User 111 is not admin in all of them. """ self.set_models( @@ -186,6 +187,7 @@ def test_with_same_meeting(self) -> None: self.create_meeting_for_two_users(4, 5, 111) self.create_meeting_for_two_users(7, 7, 111, {"committee_id": 60}) self.create_meeting_for_two_users(10, 7, 111, {"committee_id": 66}) + test_user_id = self.create_user("commadmin", [1], committee_management_ids=[60]) # User 111 is meeting admin in meeting 1, 4 and 7 but normal user in 10 # User 5 is normal user in meeting 1 and 4 @@ -202,7 +204,7 @@ def test_with_same_meeting(self) -> None: status_code, data = self.request( "get_user_editable", { - "user_ids": [5, 7], + "user_ids": [5, 7, test_user_id], "fields": ["first_name", "default_password"], }, ) @@ -221,12 +223,23 @@ def test_with_same_meeting(self) -> None: "Missing permissions: OrganizationManagementLevel can_manage_users in organization 1 or Permission user.can_update in meetings {10, 7}", ], }, + f"{test_user_id}": { + "default_password": [ + False, + "Missing permissions: OrganizationManagementLevel can_manage_users in organization 1 or CommitteeManagementLevel can_manage in committee 60", + ], + "first_name": [ + False, + "Missing permissions: OrganizationManagementLevel can_manage_users in organization 1 or CommitteeManagementLevel can_manage in committee 60", + ], + }, }, ) def test_with_same_meeting_can_update(self) -> None: """ User 5 can be edited because he is only in meetings which User 111 has can_manage of. + User 6 can be edited because while he is only in meetings which User 111 has can_update of, he is also a committee admin. User 7 can be edited because he is only in meetings which User 111 has can_update of. """ self.set_models( @@ -241,6 +254,7 @@ def test_with_same_meeting_can_update(self) -> None: self.create_meeting_for_two_users(4, 5, 111) self.create_meeting_for_two_users(7, 7, 111, {"committee_id": 60}) self.create_meeting_for_two_users(10, 7, 111, {"committee_id": 66}) + test_user_id = self.create_user("commadmin", [1], committee_management_ids=[60]) self.set_group_permissions(3, [Permissions.User.CAN_UPDATE]) self.set_group_permissions(6, [Permissions.User.CAN_UPDATE]) self.set_group_permissions(9, [Permissions.User.CAN_MANAGE]) @@ -259,7 +273,7 @@ def test_with_same_meeting_can_update(self) -> None: status_code, data = self.request( "get_user_editable", { - "user_ids": [5, 7], + "user_ids": [5, 7, test_user_id], "fields": ["first_name", "default_password"], }, ) @@ -269,6 +283,16 @@ def test_with_same_meeting_can_update(self) -> None: { "5": {"default_password": [True, ""], "first_name": [True, ""]}, "7": {"default_password": [True, ""], "first_name": [True, ""]}, + f"{test_user_id}": { + "default_password": [ + False, + "Missing permissions: OrganizationManagementLevel can_manage_users in organization 1 or CommitteeManagementLevel can_manage in committee 60", + ], + "first_name": [ + False, + "Missing permissions: OrganizationManagementLevel can_manage_users in organization 1 or CommitteeManagementLevel can_manage in committee 60", + ], + }, }, ) diff --git a/tests/system/presenter/test_get_user_scope.py b/tests/system/presenter/test_get_user_scope.py index a34bf20576..6e32f12320 100644 --- a/tests/system/presenter/test_get_user_scope.py +++ b/tests/system/presenter/test_get_user_scope.py @@ -61,6 +61,7 @@ def test_good(self) -> None: "committee_ids": [], "user_in_archived_meetings_only": False, "home_committee_id": None, + "is_committee_manager": False, }, "3": { "collection": "committee", @@ -69,14 +70,16 @@ def test_good(self) -> None: "committee_ids": [63], "user_in_archived_meetings_only": False, "home_committee_id": None, + "is_committee_manager": True, }, "4": { - "collection": "meeting", - "id": 1, + "collection": "committee", + "id": 60, "user_oml": "", "committee_ids": [60], "user_in_archived_meetings_only": False, "home_committee_id": None, + "is_committee_manager": True, }, "5": { "collection": "organization", @@ -85,14 +88,16 @@ def test_good(self) -> None: "committee_ids": [], "user_in_archived_meetings_only": False, "home_committee_id": None, + "is_committee_manager": False, }, "6": { - "collection": "meeting", + "collection": "organization", "id": 1, "user_oml": OrganizationManagementLevel.SUPERADMIN, "committee_ids": [60], "user_in_archived_meetings_only": False, "home_committee_id": None, + "is_committee_manager": False, }, "7": { "collection": "meeting", @@ -101,6 +106,7 @@ def test_good(self) -> None: "committee_ids": [60], "user_in_archived_meetings_only": False, "home_committee_id": None, + "is_committee_manager": False, }, "8": { "collection": "committee", @@ -109,6 +115,7 @@ def test_good(self) -> None: "committee_ids": [], "user_in_archived_meetings_only": False, "home_committee_id": 60, + "is_committee_manager": False, }, "9": { "collection": "committee", @@ -117,6 +124,7 @@ def test_good(self) -> None: "committee_ids": [60], "user_in_archived_meetings_only": False, "home_committee_id": 63, + "is_committee_manager": False, }, }, ) diff --git a/tests/unit/test_user_scopes.py b/tests/unit/test_user_scopes.py index b0eaa1f5c4..75c38f19f3 100644 --- a/tests/unit/test_user_scopes.py +++ b/tests/unit/test_user_scopes.py @@ -50,7 +50,7 @@ def test_single_committee_single_related_meeting(self) -> None: } ) self.set_meeting_committees([1]) - assert self.get_scope() == UserScope.Meeting + assert self.get_scope() == UserScope.Committee def test_single_committee_multiple_related_meetings(self) -> None: self.set_user_data({"meeting_ids": [1, 2]}) From eb0e4871365538975877a54b4a4a2ced272998be Mon Sep 17 00:00:00 2001 From: Magnus Schieder Date: Fri, 9 Oct 2026 18:18:02 +0200 Subject: [PATCH 17/53] Revert "Update meta repository (#3781)" This reverts commit fbfd456e93500b39281fc982ac60e96ab2c39e31. --- meta | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta b/meta index bcc494232d..f1dc6f90d9 160000 --- a/meta +++ b/meta @@ -1 +1 @@ -Subproject commit bcc494232d64ef78fb4c6dcabef0d0a17b2cda0f +Subproject commit f1dc6f90d932564896bbfb7be03edcd740f49eaf From 003a3f62d560d33aa174d2abc4b2f52b9d03e009 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2026 11:33:49 +0000 Subject: [PATCH 18/53] Bump the web-dependencies group across 1 directory with 2 updates (#3796) --- requirements/partial/requirements_development.txt | 2 +- requirements/partial/requirements_production.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements/partial/requirements_development.txt b/requirements/partial/requirements_development.txt index d29a5efb6c..0ffd4e1319 100644 --- a/requirements/partial/requirements_development.txt +++ b/requirements/partial/requirements_development.txt @@ -16,7 +16,7 @@ types-babel==2.11.0.15 types-beautifulsoup4==4.12.0.20250516 types-bleach==6.4.0.20260728 types-PyYAML==6.0.12.20260906 -types-requests==2.33.0.20260906 +types-requests==2.33.0.20261006 types-simplejson==4.1.0.20260724 types-Pygments==2.21.0.20260819 diff --git a/requirements/partial/requirements_production.txt b/requirements/partial/requirements_production.txt index 4311848527..f1b5ddfade 100644 --- a/requirements/partial/requirements_production.txt +++ b/requirements/partial/requirements_production.txt @@ -11,7 +11,7 @@ psycopg-pool==3.3.3 requests==2.34.2 roman==5.2 simplejson==4.1.2 -Werkzeug==3.1.8 +Werkzeug==3.1.9 python-magic==0.4.27 python-sql==1.8.1 pygments==2.21.0 From 469843627a72fb9803b057222e7c6fdbc8d27c76 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2026 14:33:24 +0200 Subject: [PATCH 19/53] Bump the code-style-depedencies group across 1 directory with 3 updates (#3792) --- requirements/partial/requirements_development.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements/partial/requirements_development.txt b/requirements/partial/requirements_development.txt index 0ffd4e1319..0163848927 100644 --- a/requirements/partial/requirements_development.txt +++ b/requirements/partial/requirements_development.txt @@ -1,10 +1,10 @@ aiosmtpd==1.4.6 autoflake==2.4.0 -black==26.5.1 +black==26.10.0 debugpy==1.8.22 flake8==7.4.1 -isort==9.0.1 -mypy==2.3.1 +isort==9.0.2 +mypy==2.4.0 pip-check==3.2.1 pytest==9.1.1 pytest-cov==7.1.0 From 612c6fc93e3c78246944ad08fb820c4242e8e10f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2026 14:59:26 +0200 Subject: [PATCH 20/53] Bump sqlfluff (#3789) --- requirements/partial/requirements_production.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/partial/requirements_production.txt b/requirements/partial/requirements_production.txt index f1b5ddfade..8265c8f492 100644 --- a/requirements/partial/requirements_production.txt +++ b/requirements/partial/requirements_production.txt @@ -16,7 +16,7 @@ python-magic==0.4.27 python-sql==1.8.1 pygments==2.21.0 pyyaml==6.0.3 -sqlfluff==4.3.0 +sqlfluff==4.4.0 # opentelemetry opentelemetry-api==1.45.0 From 4a93b682d84caf5a8b7ee5ca6b82d74a81fea1b0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2026 13:19:43 +0000 Subject: [PATCH 21/53] Bump the general-dependencies group across 1 directory with 2 updates (#3795) --- requirements/export_service_commits.sh | 2 +- requirements/partial/requirements_development.txt | 2 +- requirements/partial/requirements_production.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements/export_service_commits.sh b/requirements/export_service_commits.sh index 851761459d..a18bd23163 100755 --- a/requirements/export_service_commits.sh +++ b/requirements/export_service_commits.sh @@ -1,2 +1,2 @@ #!/bin/bash -export AUTH_COMMIT_HASH=67476e73a53c4567e9457e2e18863294cb839dd7 +export AUTH_COMMIT_HASH=a0d4578e178991591dc47ada36691739bd7819fb diff --git a/requirements/partial/requirements_development.txt b/requirements/partial/requirements_development.txt index 0163848927..c0925b5861 100644 --- a/requirements/partial/requirements_development.txt +++ b/requirements/partial/requirements_development.txt @@ -17,7 +17,7 @@ types-beautifulsoup4==4.12.0.20250516 types-bleach==6.4.0.20260728 types-PyYAML==6.0.12.20260906 types-requests==2.33.0.20261006 -types-simplejson==4.1.0.20260724 +types-simplejson==4.2.0.20261006 types-Pygments==2.21.0.20260819 # analyze pstats from Profiler diff --git a/requirements/partial/requirements_production.txt b/requirements/partial/requirements_production.txt index 8265c8f492..93c07bd683 100644 --- a/requirements/partial/requirements_production.txt +++ b/requirements/partial/requirements_production.txt @@ -10,7 +10,7 @@ psycopg[binary]==3.3.6 psycopg-pool==3.3.3 requests==2.34.2 roman==5.2 -simplejson==4.1.2 +simplejson==4.2.0 Werkzeug==3.1.9 python-magic==0.4.27 python-sql==1.8.1 From b132bc81fcc9c8fcefbfc713c7348b8fcf942c21 Mon Sep 17 00:00:00 2001 From: Magnus Schieder <50337967+m-schieder@users.noreply.github.com> Date: Mon, 12 Oct 2026 15:42:25 +0200 Subject: [PATCH 22/53] Update meta repository (#3797) --- meta | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta b/meta index f1dc6f90d9..724966a423 160000 --- a/meta +++ b/meta @@ -1 +1 @@ -Subproject commit f1dc6f90d932564896bbfb7be03edcd740f49eaf +Subproject commit 724966a4239def22aa45c493037dfa0dd8531c6b From 4beecea71dfb5efe1856def508089eba2e930548 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 14 Oct 2026 11:10:10 +0200 Subject: [PATCH 23/53] Bump pypdf from 6.19.0 to 6.20.0 in /requirements/partial (#3800) --- requirements/partial/requirements_production.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/partial/requirements_production.txt b/requirements/partial/requirements_production.txt index 93c07bd683..a3f745b483 100644 --- a/requirements/partial/requirements_production.txt +++ b/requirements/partial/requirements_production.txt @@ -5,7 +5,7 @@ dependency_injector==4.49.1 fastjsonschema==2.22.2 Flask==3.1.3 gunicorn==26.2.0 -pypdf[crypto]==6.19.0 +pypdf[crypto]==6.20.0 psycopg[binary]==3.3.6 psycopg-pool==3.3.3 requests==2.34.2 From 6b6a8295bf42b9fae18326073241860689d4575c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 14 Oct 2026 09:38:17 +0000 Subject: [PATCH 24/53] Bump the opentelemetry-dependencies group across 1 directory with 7 updates (#3798) --- requirements/partial/requirements_production.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/requirements/partial/requirements_production.txt b/requirements/partial/requirements_production.txt index a3f745b483..b207f83fde 100644 --- a/requirements/partial/requirements_production.txt +++ b/requirements/partial/requirements_production.txt @@ -19,10 +19,10 @@ pyyaml==6.0.3 sqlfluff==4.4.0 # opentelemetry -opentelemetry-api==1.45.0 -opentelemetry-exporter-otlp==1.45.0 -opentelemetry-instrumentation-flask==0.66b0 -opentelemetry-instrumentation-redis==0.66b0 -opentelemetry-instrumentation-requests==0.66b0 -opentelemetry-sdk==1.45.0 -opentelemetry-semantic-conventions==0.66b0 +opentelemetry-api==1.45.1 +opentelemetry-exporter-otlp==1.45.1 +opentelemetry-instrumentation-flask==0.66b1 +opentelemetry-instrumentation-redis==0.66b1 +opentelemetry-instrumentation-requests==0.66b1 +opentelemetry-sdk==1.45.1 +opentelemetry-semantic-conventions==0.66b1 From 2fc713293048ca19782b050297c7da84466ed0d4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 14 Oct 2026 12:17:49 +0200 Subject: [PATCH 25/53] Bump the code-style-depedencies group across 1 directory with 2 updates (#3799) --- requirements/export_service_commits.sh | 2 +- requirements/partial/requirements_development.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements/export_service_commits.sh b/requirements/export_service_commits.sh index a18bd23163..2fdf38c0b6 100755 --- a/requirements/export_service_commits.sh +++ b/requirements/export_service_commits.sh @@ -1,2 +1,2 @@ #!/bin/bash -export AUTH_COMMIT_HASH=a0d4578e178991591dc47ada36691739bd7819fb +export AUTH_COMMIT_HASH=6d9eba906ac611235893de933e19c484fdec2f4a diff --git a/requirements/partial/requirements_development.txt b/requirements/partial/requirements_development.txt index c0925b5861..b7ac25c445 100644 --- a/requirements/partial/requirements_development.txt +++ b/requirements/partial/requirements_development.txt @@ -1,6 +1,6 @@ aiosmtpd==1.4.6 autoflake==2.4.0 -black==26.10.0 +black==26.10.1 debugpy==1.8.22 flake8==7.4.1 isort==9.0.2 @@ -9,7 +9,7 @@ pip-check==3.2.1 pytest==9.1.1 pytest-cov==7.1.0 pytest-profiling==1.8.1 -pyupgrade==3.21.2 +pyupgrade==3.22.0 # typing types-babel==2.11.0.15 From 504d8945328e8c20609909c627ba6fcb20239b35 Mon Sep 17 00:00:00 2001 From: "openslides-automation[bot]" <125256978+openslides-automation[bot]@users.noreply.github.com> Date: Wed, 14 Oct 2026 12:49:55 +0200 Subject: [PATCH 26/53] Update meta repository (#3802) --- meta | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta b/meta index 724966a423..c1df951083 160000 --- a/meta +++ b/meta @@ -1 +1 @@ -Subproject commit 724966a4239def22aa45c493037dfa0dd8531c6b +Subproject commit c1df951083a758c0ffdea3022943457e4502880f From e0e57d5a02ebd01c5171fc547b1063aa7be41afb Mon Sep 17 00:00:00 2001 From: luisa-beerboom <101706784+luisa-beerboom@users.noreply.github.com> Date: Fri, 16 Oct 2026 11:12:25 +0200 Subject: [PATCH 27/53] Remove timezone presenter (#3803) --- docs/actions/committee.json_upload.md | 4 +- docs/actions/meeting.create.md | 2 +- docs/actions/meeting.update.md | 2 +- docs/actions/organization.update.md | 2 +- docs/presenters/get_valid_timezones.md | 27 ------- openslides_backend/presenter/__init__.py | 1 - .../presenter/get_valid_timezones.py | 61 ---------------- .../presenter/test_get_valid_timezones.py | 72 ------------------- 8 files changed, 5 insertions(+), 166 deletions(-) delete mode 100644 docs/presenters/get_valid_timezones.md delete mode 100644 openslides_backend/presenter/get_valid_timezones.py delete mode 100644 tests/system/presenter/test_get_valid_timezones.py diff --git a/docs/actions/committee.json_upload.md b/docs/actions/committee.json_upload.md index 2252e925b3..6d12c3fcad 100644 --- a/docs/actions/committee.json_upload.md +++ b/docs/actions/committee.json_upload.md @@ -52,9 +52,9 @@ Besides the usual headers as seen in the payload (`name`, `type`, `is_list`), th - `done`: The meeting was found in the datastore, the new meeting will be cloned from it. - `warning`: The meeting was not found and the new meeting will not be cloned, but freshly created. - `meeting_time_zone`: - - `done`: Valid timezone string (see [presenter](../presenters/get_valid_timezones.md)). + - `done`: Valid IANA timezone string. - `warning`: Field empty and there's a start/end_time. - - `error`: Not a valid timezone string. + - `error`: Not a valid IANA timezone string. The fields `forward_to_committee`, `organization_tags`, `managers`, `meeting_admins` and `meeting_template` store the `id` of the related model, if it exists, in the object for the import. diff --git a/docs/actions/meeting.create.md b/docs/actions/meeting.create.md index 650cff4f90..72388223b3 100644 --- a/docs/actions/meeting.create.md +++ b/docs/actions/meeting.create.md @@ -25,7 +25,7 @@ Creates a meeting. Checks whether the `organization.limit_of_meetings` is unlimited (=0) or lower than the amount of active meetings in `organization.active_meeting_ids`. -`time_zone` must be a valid timezone string (see [presenter](../presenters/get_valid_timezones.md)). +`time_zone` must be a valid IANA timezone string. The following objects are created, too: - Groups: `Default`, `Admin`, `Delegates`, `Staff`, `Committees`. The first one is set as `meeting/default_group_id`, the second one as `meeting/admin_group_id`. The permissions can be found in the [initial-data.json](https://github.com/OpenSlides/openslides-backend/tree/main/data/initial-data.json)). diff --git a/docs/actions/meeting.update.md b/docs/actions/meeting.update.md index f7eb78664c..b94ffafbe5 100644 --- a/docs/actions/meeting.update.md +++ b/docs/actions/meeting.update.md @@ -209,7 +209,7 @@ Updates the meeting. If `set_as_template` is `True`, `template_for_organization_id` has to be set to `1`. If it is `False`, `template_for_organization_id` has to be set to `None` and if there are currently no users in the meetings admin group, an exception needs to be raised. `reference_projector_id` can only be set to a projector, which is not internal. -`time_zone` must be a valid timezone string (see [presenter](../presenters/get_valid_timezones.md)). +`time_zone` must be a valid IANA timezone string. This action doesn't allow for a meeting to be set as a template and have `locked_from_inside` set to true at the same time. if this would be the result of an action call, an exception will be thrown. Same for `enable_anonymous` and `locked_from_inside` being true at the same time. diff --git a/docs/actions/organization.update.md b/docs/actions/organization.update.md index d233385d8a..280bb2bf0d 100644 --- a/docs/actions/organization.update.md +++ b/docs/actions/organization.update.md @@ -43,7 +43,7 @@ ## Action Updates the organization. Checks if the theme_id is one of the theme_ids. -`time_zone` must be a valid timezone string (see [presenter](../presenters/get_valid_timezones.md)). +`time_zone` must be a valid IANA timezone string. This is an example of the saml_attr_mapping, where you can see the mappable fields. ```json diff --git a/docs/presenters/get_valid_timezones.md b/docs/presenters/get_valid_timezones.md deleted file mode 100644 index 68850591df..0000000000 --- a/docs/presenters/get_valid_timezones.md +++ /dev/null @@ -1,27 +0,0 @@ -# Payload -```js -{ -} -``` - -# Returns -```js -{ - [string]: string - ... -} -``` - -# Logic -Gets all valid timezones from database. - -Returns a timezone-name to current abbreviation dict. -(Note: Abbreviations may change over the course of the year as certain timezones switch to and from DST) - -In general this is going to return mostly canonic IANA timezone names. - -# Permissions -The user needs to either: -- `OML.can_manage_organization`, -- `CML.can_manage` in any committee, or -- `meeting.can_manage_settings` in any meeting. \ No newline at end of file diff --git a/openslides_backend/presenter/__init__.py b/openslides_backend/presenter/__init__.py index 20c104d039..7ce857abca 100644 --- a/openslides_backend/presenter/__init__.py +++ b/openslides_backend/presenter/__init__.py @@ -10,7 +10,6 @@ get_user_related_models, get_user_scope, get_users, - get_valid_timezones, number_of_users, search_for_id_by_external_id, search_users, diff --git a/openslides_backend/presenter/get_valid_timezones.py b/openslides_backend/presenter/get_valid_timezones.py deleted file mode 100644 index 61ff2a5430..0000000000 --- a/openslides_backend/presenter/get_valid_timezones.py +++ /dev/null @@ -1,61 +0,0 @@ -from typing import Any - -import fastjsonschema -from psycopg import sql - -from ..permissions.management_levels import OrganizationManagementLevel -from ..permissions.permission_helper import has_organization_management_level, has_perm -from ..permissions.permissions import Permissions -from ..shared.exceptions import MissingPermission -from ..shared.patterns import fqid_from_collection_and_id -from ..shared.schema import schema_version -from .base import BasePresenter -from .presenter import register_presenter - -get_valid_timezones_schema = fastjsonschema.compile( - { - "$schema": schema_version, - "type": "object", - "title": "get valid timezones", - "description": "get valid timezones", - "properties": {}, - } -) - - -@register_presenter("get_valid_timezones") -class GetValidTimezones(BasePresenter): - """ - Returns all timezones allowed by the database. - """ - - schema = get_valid_timezones_schema - - def get_result(self) -> Any: - self.check_permissions() - timezones = self.datastore.execute_custom_select( - sql.SQL("name, abbrev FROM pg_timezone_names") - ) - return {tz["name"]: tz["abbrev"] for tz in timezones} - - def check_permissions(self) -> None: - if not has_organization_management_level( - self.datastore, - self.user_id, - OrganizationManagementLevel.CAN_MANAGE_ORGANIZATION, - ): - user_data = self.datastore.get( - fqid_from_collection_and_id("user", self.user_id), - ["committee_management_ids", "meeting_ids"], - lock_result=False, - ) - if not user_data.get("committee_management_ids") and not any( - has_perm( - self.datastore, - self.user_id, - Permissions.Meeting.CAN_MANAGE_SETTINGS, - meeting_id, - ) - for meeting_id in user_data.get("meeting_ids", []) - ): - raise MissingPermission(Permissions.Meeting.CAN_MANAGE_SETTINGS) diff --git a/tests/system/presenter/test_get_valid_timezones.py b/tests/system/presenter/test_get_valid_timezones.py deleted file mode 100644 index dc5c20f321..0000000000 --- a/tests/system/presenter/test_get_valid_timezones.py +++ /dev/null @@ -1,72 +0,0 @@ -from openslides_backend.permissions.management_levels import OrganizationManagementLevel -from openslides_backend.permissions.permissions import Permissions - -from .base import BasePresenterTestCase - - -class TestGetValidTimezones(BasePresenterTestCase): - def test_get_as_accountadmin(self) -> None: - self.set_organization_management_level( - OrganizationManagementLevel.CAN_MANAGE_USERS - ) - status_code, data = self.request("get_valid_timezones", {}) - self.assertEqual(status_code, 403) - assert data["message"] == "Missing Permission: meeting.can_manage_settings" - - def test_get_with_no_meeting_perms(self) -> None: - self.create_meeting(1) - self.set_user_groups(1, [1]) - self.set_organization_management_level(None) - status_code, data = self.request("get_valid_timezones", {}) - self.assertEqual(status_code, 403) - assert data["message"] == "Missing Permission: meeting.can_manage_settings" - - def test_get_with_no_perms(self) -> None: - self.set_organization_management_level(None) - status_code, data = self.request("get_valid_timezones", {}) - self.assertEqual(status_code, 403) - assert data["message"] == "Missing Permission: meeting.can_manage_settings" - - def test_get(self) -> None: - status_code, data = self.request("get_valid_timezones", {}) - self.assertEqual(status_code, 200) - assert isinstance(data, dict) - # Checking for Korea bc no DST, therfore just one possible abbreviation. - assert data.get("Asia/Seoul") == "KST" - - def test_get_as_orgaadmin(self) -> None: - self.set_organization_management_level( - OrganizationManagementLevel.CAN_MANAGE_ORGANIZATION - ) - status_code, data = self.request("get_valid_timezones", {}) - self.assertEqual(status_code, 200) - assert isinstance(data, dict) - assert data.get("Asia/Seoul") == "KST" - - def test_get_as_committee_admin(self) -> None: - self.create_meeting(1) - self.set_committee_management_level([60]) - self.set_organization_management_level(None) - status_code, data = self.request("get_valid_timezones", {}) - self.assertEqual(status_code, 200) - assert isinstance(data, dict) - assert data.get("Asia/Seoul") == "KST" - - def test_get_as_meeting_admin(self) -> None: - self.create_meeting(1) - self.set_user_groups(1, [2]) - self.set_organization_management_level(None) - status_code, data = self.request("get_valid_timezones", {}) - self.assertEqual(status_code, 200) - assert isinstance(data, dict) - assert data.get("Asia/Seoul") == "KST" - - def test_get_with_meeting_can_manage_settings(self) -> None: - self.create_meeting(1) - self.set_user_groups(1, [1]) - self.set_group_permissions(1, [Permissions.Meeting.CAN_MANAGE_SETTINGS]) - self.set_organization_management_level(None) - status_code, data = self.request("get_valid_timezones", {}) - self.assertEqual(status_code, 200) - assert isinstance(data, dict) - assert data.get("Asia/Seoul") == "KST" From 5fd31e8b15383db48f0d45b45410af60db882291 Mon Sep 17 00:00:00 2001 From: luisa-beerboom <101706784+luisa-beerboom@users.noreply.github.com> Date: Fri, 16 Oct 2026 15:10:11 +0200 Subject: [PATCH 28/53] Try to fix pyupgrade check (#3805) * Fix code style --- .github/workflows/continuous_integration.yml | 4 ++- cli/generate_models.py | 2 +- .../action/actions/meeting/import_.py | 4 +-- .../action/actions/motion/create.py | 34 +++++++++++-------- .../action/actions/poll/update.py | 4 +-- .../action/actions/projector/toggle.py | 2 +- .../action/actions/user/merge_together.py | 8 ++--- .../action/actions/user/save_saml_account.py | 8 ++--- .../presenter/get_user_scope.py | 2 +- .../services/database/extended_database.py | 2 +- openslides_backend/shared/export_helper.py | 6 +--- tests/database/reader/system/util.py | 2 +- tests/database/writer/system/util.py | 4 +-- .../system/action/agenda_item/test_forward.py | 2 +- .../system/action/test_equal_fields_check.py | 2 +- 15 files changed, 40 insertions(+), 46 deletions(-) diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index dc6deaf639..81fc2a0f26 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -134,7 +134,9 @@ jobs: - name: Check pyupgrade if: always() - run: make pyupgrade + run: | + make pyupgrade + test $(git status --porcelain | wc -l) = 0 check-models-all: name: Check from models.yml up to permissions and jsons diff --git a/cli/generate_models.py b/cli/generate_models.py index cd646789ef..79970d7c81 100644 --- a/cli/generate_models.py +++ b/cli/generate_models.py @@ -264,7 +264,7 @@ def get_code(self, field_name: str) -> str: if self.to: properties += self.to.get_properties() if self.on_delete: - assert self.on_delete in [mode for mode in OnDelete] + assert self.on_delete in OnDelete properties += f"on_delete=fields.OnDelete.{self.on_delete}, " if self.is_view_field: properties += "is_view_field=True, " diff --git a/openslides_backend/action/actions/meeting/import_.py b/openslides_backend/action/actions/meeting/import_.py index fa0a704e1c..f7f7ffc0db 100644 --- a/openslides_backend/action/actions/meeting/import_.py +++ b/openslides_backend/action/actions/meeting/import_.py @@ -379,9 +379,7 @@ def handle_gender_string(self, instance: dict[str, Any]) -> None: del self.user_id_to_gender[user_id] genders = self.datastore.get_all("gender", ["id", "name"], lock_result=True) gender_dict = {gender.get("name", ""): gender for gender in genders.values()} - new_genders = list( - {value for value in self.user_id_to_gender.values()}.difference(gender_dict) - ) + new_genders = list({*self.user_id_to_gender.values()}.difference(gender_dict)) if new_genders: new_genders.sort() # fix order for tests new_gender_ids = self.datastore.reserve_ids("gender", len(new_genders)) diff --git a/openslides_backend/action/actions/motion/create.py b/openslides_backend/action/actions/motion/create.py index 47d7675d2c..bb553e50ac 100644 --- a/openslides_backend/action/actions/motion/create.py +++ b/openslides_backend/action/actions/motion/create.py @@ -8,7 +8,12 @@ from ....permissions.permission_helper import has_perm from ....permissions.permissions import Permissions from ....services.database.commands import GetManyRequest -from ....shared.exceptions import ActionException, MissingPermission, PermissionDenied +from ....shared.exceptions import ( + ActionException, + AnyPermission, + MissingPermission, + PermissionDenied, +) from ....shared.patterns import fqid_from_collection_and_id from ....shared.schema import ( id_list_schema, @@ -170,21 +175,22 @@ def check_permissions(self, instance: dict[str, Any]) -> None: ) ) and len( - missing_perms := { - perm: instance["meeting_id"] - for perm in extra_submitter_perms - if not has_perm( - self.datastore, - self.user_id, - perm, - instance["meeting_id"], - ) - } + missing_perms := cast( + dict[AnyPermission, int | set[int]], + { + perm: instance["meeting_id"] + for perm in extra_submitter_perms + if not has_perm( + self.datastore, + self.user_id, + perm, + instance["meeting_id"], + ) + }, + ) ) ): - raise MissingPermission( - {key: val for key, val in missing_perms.items()}, use_and=True - ) + raise MissingPermission(missing_perms, use_and=True) # Whitelist the fields depending on the user's permissions. Each field can require multiple conjunctive permissions. can_manage_whitelist = set() diff --git a/openslides_backend/action/actions/poll/update.py b/openslides_backend/action/actions/poll/update.py index 0c13950e2e..af1c406d53 100644 --- a/openslides_backend/action/actions/poll/update.py +++ b/openslides_backend/action/actions/poll/update.py @@ -259,8 +259,8 @@ def check_entitled_users_at_stop( new_main_user_id_to_entry: dict[int, dict[str, Any]] = { date["user_id"]: date for date in instance[field] } - original_ids = {user_id for user_id in original_main_user_id_to_entry} - new_ids = {user_id for user_id in new_main_user_id_to_entry} + original_ids = {*original_main_user_id_to_entry} + new_ids = {*new_main_user_id_to_entry} if (len(original_ids) != len(new_ids)) or len(original_ids.difference(new_ids)): raise ActionException( "Can not change essential 'entitled_users_at_stop' data via poll.update" diff --git a/openslides_backend/action/actions/projector/toggle.py b/openslides_backend/action/actions/projector/toggle.py index d5c650f8e3..051ae4b0fb 100644 --- a/openslides_backend/action/actions/projector/toggle.py +++ b/openslides_backend/action/actions/projector/toggle.py @@ -69,7 +69,7 @@ def get_updated_instances(self, action_data: ActionData) -> ActionData: ) result = self.datastore.filter("projection", filter_, ["id"]) if result: - projection_ids = [id_ for id_ in result] + projection_ids = [*result] if stable: self.execute_other_action( ProjectionDelete, [{"id": id_} for id_ in projection_ids] diff --git a/openslides_backend/action/actions/user/merge_together.py b/openslides_backend/action/actions/user/merge_together.py index fe281c134d..e1432c3a56 100644 --- a/openslides_backend/action/actions/user/merge_together.py +++ b/openslides_backend/action/actions/user/merge_together.py @@ -407,7 +407,7 @@ def call_other_actions( def check_polls(self, into: PartialModel, other_models: list[PartialModel]) -> None: all_models = [into, *other_models] vote_poll_ids_per_user_id: dict[int, set[int]] = { - user["id"]: {poll_id for poll_id in user.get("poll_voted_ids", [])} + user["id"]: {*user.get("poll_voted_ids", [])} for user in [into, *other_models] } option_poll_ids_per_user_id: dict[int, set[int]] = {} @@ -420,8 +420,7 @@ def check_polls(self, into: PartialModel, other_models: list[PartialModel]) -> N + ( v_ids := list( { - id_ - for id_ in [ + *[ *model.get("vote_ids", []), *model.get("delegated_vote_ids", []), ] @@ -468,8 +467,7 @@ def check_polls(self, into: PartialModel, other_models: list[PartialModel]) -> N "option", list( { - id_ - for id_ in [ + *[ vote["option_id"] for vote in vote_data.values() if vote.get("option_id") diff --git a/openslides_backend/action/actions/user/save_saml_account.py b/openslides_backend/action/actions/user/save_saml_account.py index 7485d4e39d..ec09cf2666 100644 --- a/openslides_backend/action/actions/user/save_saml_account.py +++ b/openslides_backend/action/actions/user/save_saml_account.py @@ -224,7 +224,7 @@ def base_update_instance(self, instance: dict[str, Any]) -> dict[str, Any]: f"More than one existing user found in database with saml_id {instance['saml_id']}" ) if meeting_users: - self.execute_other_action(UserUpdate, [mu for mu in meeting_users.values()]) + self.execute_other_action(UserUpdate, [*meeting_users.values()]) return instance def create_events(self, instance: dict[str, Any]) -> Iterable[Event]: @@ -323,11 +323,7 @@ def apply_meeting_user_data( user_id: int, is_update: bool, ) -> dict[int, dict[str, Any]]: - if not ( - external_meeting_ids := sorted( - [ext_id for ext_id in meeting_user_data.keys()] - ) - ): + if not (external_meeting_ids := sorted([*meeting_user_data.keys()])): return {} meetings = { meeting_id: meeting diff --git a/openslides_backend/presenter/get_user_scope.py b/openslides_backend/presenter/get_user_scope.py index dc01f97bad..3509723837 100644 --- a/openslides_backend/presenter/get_user_scope.py +++ b/openslides_backend/presenter/get_user_scope.py @@ -45,7 +45,7 @@ def get_result(self) -> Any: home_committee_id, is_committee_manager, ) = self.get_user_scope(user_id) - committee_ids = [ci for ci in committee_meeting_ids.keys()] + committee_ids = list(committee_meeting_ids) result[str(user_id)] = { "collection": scope, "id": scope_id, diff --git a/openslides_backend/services/database/extended_database.py b/openslides_backend/services/database/extended_database.py index 50b91db9a1..a2860769ff 100644 --- a/openslides_backend/services/database/extended_database.py +++ b/openslides_backend/services/database/extended_database.py @@ -204,7 +204,7 @@ def get( field for field in mapped_fields if field not in changed_model_copy ] else: - missing_fields = [field for field in changed_model_copy.keys()] + missing_fields = list(changed_model_copy) if not missing_fields: # nothing to do, we've got the full model return changed_model_copy diff --git a/openslides_backend/shared/export_helper.py b/openslides_backend/shared/export_helper.py index 2252869ea3..037b6fc604 100644 --- a/openslides_backend/shared/export_helper.py +++ b/openslides_backend/shared/export_helper.py @@ -178,11 +178,7 @@ def export_meeting( for entry in export[collection].values(): if entry.get(user_field.get_own_field_name()): user_ids.update( - { - id_ - for id_ in entry.get(user_field.get_own_field_name()) - or [] - } + {*(entry.get(user_field.get_own_field_name()) or [])} ) if ( isinstance(user_field, RelationField) diff --git a/tests/database/reader/system/util.py b/tests/database/reader/system/util.py index 7170f09701..d5573d3f90 100644 --- a/tests/database/reader/system/util.py +++ b/tests/database/reader/system/util.py @@ -277,7 +277,7 @@ def setup_data(connection: Connection, data: dict[str, dict[int, Any]]) -> None: strip_reserved_fields(model_data) cursor.execute( f"INSERT INTO {collection}_t ({', '.join(key for key in model_data.keys())}) VALUES ({', '.join('%s' for i in range(len(model_data)))})", - [val for val in model_data.values()], + [*model_data.values()], ) connection.commit() diff --git a/tests/database/writer/system/util.py b/tests/database/writer/system/util.py index 09fb69027b..0f3a7ea1cf 100644 --- a/tests/database/writer/system/util.py +++ b/tests/database/writer/system/util.py @@ -30,9 +30,7 @@ def assert_model(fqid: FullQualifiedId, fields: Model) -> None: with get_new_os_conn() as conn: database_reader = DatabaseReader(conn, MagicMock(), MagicMock()) model = ( - database_reader.get_many( - [GetManyRequest(collection, [id_], [field for field in fields.keys()])] - ) + database_reader.get_many([GetManyRequest(collection, [id_], list(fields))]) .get(collection, dict()) .get(id_) ) diff --git a/tests/system/action/agenda_item/test_forward.py b/tests/system/action/agenda_item/test_forward.py index 62e2181f95..a13270fbc0 100644 --- a/tests/system/action/agenda_item/test_forward.py +++ b/tests/system/action/agenda_item/test_forward.py @@ -902,7 +902,7 @@ def assert_full_dataset( if parent_id else {} ), - **{field: val for field, val in data[0].items()}, + **data[0], }, ) self.assert_model_exists( diff --git a/tests/system/action/test_equal_fields_check.py b/tests/system/action/test_equal_fields_check.py index 5235c5d49c..4f67e1e8c9 100644 --- a/tests/system/action/test_equal_fields_check.py +++ b/tests/system/action/test_equal_fields_check.py @@ -664,7 +664,7 @@ def get_rr_stat(rel: str) -> list[bool]: "to": [rel for rel, rr in rel_to_rr_stat.items() if not rr[1]], "update": [rel for rel, rr in rel_to_rr_stat.items() if not any(rr)], } - unused = {rel for rel in group} + unused = {*group} # make sure the check_equal-field-update test is done for every relation # that is to be tested with the `a_number` field. for rel in group: From f7b84b500401bccd5cfd4924bc73f3c3c63d0997 Mon Sep 17 00:00:00 2001 From: "openslides-automation[bot]" <125256978+openslides-automation[bot]@users.noreply.github.com> Date: Fri, 16 Oct 2026 15:42:54 +0200 Subject: [PATCH 29/53] Update meta repository (#3807) --- meta | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta b/meta index c1df951083..b4f7943fab 160000 --- a/meta +++ b/meta @@ -1 +1 @@ -Subproject commit c1df951083a758c0ffdea3022943457e4502880f +Subproject commit b4f7943fab215df77edc1afb6bb4370974816f2c From e306d59091185afe7560b2346d55ab608a2e99b9 Mon Sep 17 00:00:00 2001 From: luisa-beerboom <101706784+luisa-beerboom@users.noreply.github.com> Date: Fri, 16 Oct 2026 16:06:46 +0200 Subject: [PATCH 30/53] Increase MIN_NON_REL_MIGRATION (#3804) --- openslides_backend/migrations/migration_helper.py | 2 +- tests/system/migrations/test_0100_init_reldb.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openslides_backend/migrations/migration_helper.py b/openslides_backend/migrations/migration_helper.py index 2af84d5dff..0fd4804960 100644 --- a/openslides_backend/migrations/migration_helper.py +++ b/openslides_backend/migrations/migration_helper.py @@ -58,7 +58,7 @@ class MigrationCommand(StrEnum): # relative path to the migrations MIGRATIONS_PATH = "openslides_backend/migrations/migrations/" MODULE_PATH = MIGRATIONS_PATH.replace("/", ".") -MIN_NON_REL_MIGRATION = 73 +MIN_NON_REL_MIGRATION = 83 class MigrationHelper: diff --git a/tests/system/migrations/test_0100_init_reldb.py b/tests/system/migrations/test_0100_init_reldb.py index 981a7aa4fa..53879a17f6 100644 --- a/tests/system/migrations/test_0100_init_reldb.py +++ b/tests/system/migrations/test_0100_init_reldb.py @@ -369,7 +369,7 @@ def test_migration_fail_prerequisites(self) -> None: "status": MigrationState.MIGRATION_REQUIRED, "exception": f"Pre check for migration 0100_init_reldb failed.\n{expected_error_message}", "output": f"{self.EXPECTED_INTRODUCTION}{expected_error_message}\n", - "current_migration_index": 73, + "current_migration_index": 83, "target_migration_index": 100, } self.assert_indices_state(MigrationState.MIGRATION_REQUIRED) @@ -384,7 +384,7 @@ def test_migration_fail_time_zone(self) -> None: "status": MigrationState.MIGRATION_REQUIRED, "exception": f"Pre check for migration 0100_init_reldb failed.\n{expected_error_message}", "output": f"{self.EXPECTED_INTRODUCTION}{expected_error_message}\n", - "current_migration_index": 73, + "current_migration_index": 83, "target_migration_index": 100, } self.assert_indices_state(MigrationState.MIGRATION_REQUIRED) From b0d269ffbe14fae764d04410300cd74af1eeebf7 Mon Sep 17 00:00:00 2001 From: Hannes Janott Date: Mon, 19 Oct 2026 14:27:48 +0200 Subject: [PATCH 31/53] Fix forbid anonymous group mixin (#3810) --- .../mixins/forbid_anonymous_group_mixin.py | 2 +- tests/system/action/chat_group/test_create.py | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/openslides_backend/action/mixins/forbid_anonymous_group_mixin.py b/openslides_backend/action/mixins/forbid_anonymous_group_mixin.py index 5e350b5e94..cea7eba48b 100644 --- a/openslides_backend/action/mixins/forbid_anonymous_group_mixin.py +++ b/openslides_backend/action/mixins/forbid_anonymous_group_mixin.py @@ -19,5 +19,5 @@ def check_anonymous_not_in_list_fields( ).get("anonymous_group_id") if anonymous_group_id: for field in group_list_field_names: - if anonymous_group_id in instance.get(field, []): + if anonymous_group_id in (instance.get(field) or []): raise ActionException(f"Anonymous group is not allowed in {field}.") diff --git a/tests/system/action/chat_group/test_create.py b/tests/system/action/chat_group/test_create.py index 7b2f0d9a11..49f2e7fc2b 100644 --- a/tests/system/action/chat_group/test_create.py +++ b/tests/system/action/chat_group/test_create.py @@ -205,3 +205,28 @@ def test_create_anonymous_may_not_write(self) -> None: "Anonymous group is not allowed in write_group_ids.", response.json["message"], ) + + def test_create_anonymous_exists_none_write_groups(self) -> None: + """The setup of this test makes no practical sense but aims at checking the forbid anonymous group mixin.""" + self.create_meeting() + self.set_models({ONE_ORGANIZATION_FQID: {"enable_chat": True}}) + self.set_anonymous() + response = self.request( + "chat_group.create", + { + "name": "redekreis1", + "meeting_id": 1, + "read_group_ids": [1, 2], + "write_group_ids": None, + }, + ) + self.assert_status_code(response, 200) + self.assert_model_exists( + "chat_group/1", + { + "name": "redekreis1", + "meeting_id": 1, + "read_group_ids": [1, 2], + "write_group_ids": None, + }, + ) From 7fb79be382b6e8f68b6518a3d6ff2d6efa111c62 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Nov 2026 10:12:35 +0100 Subject: [PATCH 32/53] Bump pypdf from 6.20.0 to 6.21.3 in /requirements/partial (#3825) --- requirements/partial/requirements_production.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/partial/requirements_production.txt b/requirements/partial/requirements_production.txt index b207f83fde..d14fd17d3b 100644 --- a/requirements/partial/requirements_production.txt +++ b/requirements/partial/requirements_production.txt @@ -5,7 +5,7 @@ dependency_injector==4.49.1 fastjsonschema==2.22.2 Flask==3.1.3 gunicorn==26.2.0 -pypdf[crypto]==6.20.0 +pypdf[crypto]==6.21.3 psycopg[binary]==3.3.6 psycopg-pool==3.3.3 requests==2.34.2 From 457277d0785bb0834484276dde293b5c35488633 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Nov 2026 10:41:34 +0100 Subject: [PATCH 33/53] Bump pip-check (#3817) --- requirements/partial/requirements_development.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/partial/requirements_development.txt b/requirements/partial/requirements_development.txt index b7ac25c445..2f422a8e20 100644 --- a/requirements/partial/requirements_development.txt +++ b/requirements/partial/requirements_development.txt @@ -5,7 +5,7 @@ debugpy==1.8.22 flake8==7.4.1 isort==9.0.2 mypy==2.4.0 -pip-check==3.2.1 +pip-check==3.3 pytest==9.1.1 pytest-cov==7.1.0 pytest-profiling==1.8.1 From 54824df08c843bf18669aa9f80e128d50381ebe3 Mon Sep 17 00:00:00 2001 From: "openslides-automation[bot]" <125256978+openslides-automation[bot]@users.noreply.github.com> Date: Mon, 2 Nov 2026 11:34:19 +0100 Subject: [PATCH 34/53] Update meta repository (main) (#3827) * Update meta repository * Update export_service_commits.sh --- meta | 2 +- requirements/export_service_commits.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/meta b/meta index b4f7943fab..ea6e880b07 160000 --- a/meta +++ b/meta @@ -1 +1 @@ -Subproject commit b4f7943fab215df77edc1afb6bb4370974816f2c +Subproject commit ea6e880b07f4e0eb0a54c980c1641ab56e109648 diff --git a/requirements/export_service_commits.sh b/requirements/export_service_commits.sh index 2fdf38c0b6..3824fd2a51 100755 --- a/requirements/export_service_commits.sh +++ b/requirements/export_service_commits.sh @@ -1,2 +1,2 @@ #!/bin/bash -export AUTH_COMMIT_HASH=6d9eba906ac611235893de933e19c484fdec2f4a +export AUTH_COMMIT_HASH=c3485f310ac430ac00c10f26319add35d32b2ed9 From 8480ea11df07dcfd58bac897332dc754a14e732b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 13:10:22 +0100 Subject: [PATCH 35/53] Bump types-requests (#3832) --- requirements/partial/requirements_development.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/partial/requirements_development.txt b/requirements/partial/requirements_development.txt index 2f422a8e20..79d4a16555 100644 --- a/requirements/partial/requirements_development.txt +++ b/requirements/partial/requirements_development.txt @@ -16,7 +16,7 @@ types-babel==2.11.0.15 types-beautifulsoup4==4.12.0.20250516 types-bleach==6.4.0.20260728 types-PyYAML==6.0.12.20260906 -types-requests==2.33.0.20261006 +types-requests==2.33.0.20261030 types-simplejson==4.2.0.20261006 types-Pygments==2.21.0.20260819 From bb35f899fa6a979d99cb7b7f0015fd5fc1936c95 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 12:34:45 +0000 Subject: [PATCH 36/53] Bump the code-style-depedencies group across 1 directory with 2 updates (#3831) Updates `flake8` from 7.4.1 to 7.5.0 Updates `mypy` from 2.4.0 to 2.4.1 --- requirements/partial/requirements_development.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements/partial/requirements_development.txt b/requirements/partial/requirements_development.txt index 79d4a16555..a6c6f83010 100644 --- a/requirements/partial/requirements_development.txt +++ b/requirements/partial/requirements_development.txt @@ -2,9 +2,9 @@ aiosmtpd==1.4.6 autoflake==2.4.0 black==26.10.1 debugpy==1.8.22 -flake8==7.4.1 +flake8==7.5.0 isort==9.0.2 -mypy==2.4.0 +mypy==2.4.1 pip-check==3.3 pytest==9.1.1 pytest-cov==7.1.0 From 23b22934fadbaf9ce7c04f3a8484d3df593f2e44 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 14:07:35 +0100 Subject: [PATCH 37/53] Bump the general-dependencies group across 1 directory with 2 updates (#3836) --- requirements/partial/requirements_development.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements/partial/requirements_development.txt b/requirements/partial/requirements_development.txt index a6c6f83010..c8fe0407c3 100644 --- a/requirements/partial/requirements_development.txt +++ b/requirements/partial/requirements_development.txt @@ -15,9 +15,9 @@ pyupgrade==3.22.0 types-babel==2.11.0.15 types-beautifulsoup4==4.12.0.20250516 types-bleach==6.4.0.20260728 -types-PyYAML==6.0.12.20260906 +types-PyYAML==6.0.12.20261030 types-requests==2.33.0.20261030 -types-simplejson==4.2.0.20261006 +types-simplejson==4.2.0.20261031 types-Pygments==2.21.0.20260819 # analyze pstats from Profiler From fb4bc00671e93df0f489a58ad54a74c285c5b2e1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 14:39:07 +0100 Subject: [PATCH 38/53] Bump the opentelemetry-dependencies group across 1 directory with 7 updates (#3830) --- requirements/partial/requirements_production.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/requirements/partial/requirements_production.txt b/requirements/partial/requirements_production.txt index d14fd17d3b..732891c316 100644 --- a/requirements/partial/requirements_production.txt +++ b/requirements/partial/requirements_production.txt @@ -19,10 +19,10 @@ pyyaml==6.0.3 sqlfluff==4.4.0 # opentelemetry -opentelemetry-api==1.45.1 -opentelemetry-exporter-otlp==1.45.1 -opentelemetry-instrumentation-flask==0.66b1 -opentelemetry-instrumentation-redis==0.66b1 -opentelemetry-instrumentation-requests==0.66b1 -opentelemetry-sdk==1.45.1 -opentelemetry-semantic-conventions==0.66b1 +opentelemetry-api==1.45.2 +opentelemetry-exporter-otlp==1.45.2 +opentelemetry-instrumentation-flask==0.66b2 +opentelemetry-instrumentation-redis==0.66b2 +opentelemetry-instrumentation-requests==0.66b2 +opentelemetry-sdk==1.45.2 +opentelemetry-semantic-conventions==0.66b2 From f8fdd2b606b553a2b969e5609ce1d723f46b5146 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 15:07:54 +0100 Subject: [PATCH 39/53] Bump pytest (#3834) --- requirements/partial/requirements_development.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/partial/requirements_development.txt b/requirements/partial/requirements_development.txt index c8fe0407c3..cd775d15e8 100644 --- a/requirements/partial/requirements_development.txt +++ b/requirements/partial/requirements_development.txt @@ -6,7 +6,7 @@ flake8==7.5.0 isort==9.0.2 mypy==2.4.1 pip-check==3.3 -pytest==9.1.1 +pytest==9.2.0 pytest-cov==7.1.0 pytest-profiling==1.8.1 pyupgrade==3.22.0 From bb1f5f3698961bbdf43e212a797d805dabc045d8 Mon Sep 17 00:00:00 2001 From: Hannes Janott Date: Tue, 3 Nov 2026 15:45:38 +0100 Subject: [PATCH 40/53] assert finalized and use flag for setting default language (#3837) --- openslides_backend/http/views/action_view.py | 30 +++++++++++-------- .../migrations/migration_helper.py | 6 ++++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/openslides_backend/http/views/action_view.py b/openslides_backend/http/views/action_view.py index cef21faaba..a422bb78a2 100644 --- a/openslides_backend/http/views/action_view.py +++ b/openslides_backend/http/views/action_view.py @@ -11,7 +11,7 @@ from ...services.postgresql.db_connection_handling import get_new_os_conn from ...shared.env import DEV_PASSWORD from ...shared.exceptions import AuthenticationException, ServerError -from ...shared.interfaces.wsgi import RouteResponse +from ...shared.interfaces.wsgi import Headers, RouteResponse from ..http_exceptions import Unauthorized from ..request import Request from .base_view import BaseView, route @@ -32,11 +32,7 @@ class ActionView(BaseView): def action_route(self, request: Request) -> RouteResponse: self.logger.debug("Start dispatching action request.") - with get_new_os_conn() as conn: - with conn.cursor() as curs: - MigrationHelper.assert_migration_index(curs) - curs.execute("SELECT default_language FROM organization_t WHERE id = 1") - lang: str | None = (curs.fetchone() or {}).get("default_language") + self.check_database_state(request.headers) # Get user id. user_id, access_token = self.get_user_id_from_headers( request.headers, request.cookies @@ -49,9 +45,6 @@ def action_route(self, request: Request) -> RouteResponse: # Handle request. handler = ActionHandler(self.env, self.services, self.logging) - Translator.set_translation_language( - request.headers.get("Accept-Language"), lang - ) is_atomic = not request.environ["RAW_URI"].endswith("handle_separately") response = handle_action_in_worker_thread( request.json, user_id, is_atomic, handler @@ -62,9 +55,7 @@ def action_route(self, request: Request) -> RouteResponse: def internal_action_route(self, request: Request) -> RouteResponse: self.logger.debug("Start dispatching internal action request.") - with get_new_os_conn() as conn: - with conn.cursor() as curs: - MigrationHelper.assert_migration_index(curs) + self.check_database_state() self.check_internal_auth_password(request) handler = ActionHandler(self.env, self.services, self.logging) @@ -98,6 +89,21 @@ def version_route(self, _: Request) -> RouteResponse: version = file.read().strip() return {"version": version}, None + def check_database_state(self, headers: None | Headers = None) -> None: + """Also sets up Translator with orgs default language if headers provided.""" + with get_new_os_conn() as conn: + with conn.cursor() as curs: + MigrationHelper.assert_migration_index(curs) + MigrationHelper.assert_finalized(curs) + if headers: + curs.execute( + "SELECT default_language FROM organization_t WHERE id = 1" + ) + lang: str | None = (curs.fetchone() or {}).get("default_language") + Translator.set_translation_language( + headers.get("Accept-Language"), lang + ) + def check_internal_auth_password(self, request: Request) -> None: request_password = request.headers.get(INTERNAL_AUTHORIZATION_HEADER) if self.env.is_dev_mode(): diff --git a/openslides_backend/migrations/migration_helper.py b/openslides_backend/migrations/migration_helper.py index 0fd4804960..4e55a773d5 100644 --- a/openslides_backend/migrations/migration_helper.py +++ b/openslides_backend/migrations/migration_helper.py @@ -230,6 +230,12 @@ def assert_migration_index(curs: Cursor[DictRow]) -> None: f"Migration indices do not match: Database has {database_migration_index} and the backend has {backend_migration_index}" ) + @staticmethod + def assert_finalized(curs: Cursor[DictRow]) -> None: + state = MigrationHelper.get_migration_state(curs) + if state != MigrationState.FINALIZED: + raise ActionException(f"Migration not finalized but in {state}.") + @staticmethod def set_database_migration_info( curs: Cursor[DictRow], From 54594f459a927b652c612c4d1ca1350a47134ac8 Mon Sep 17 00:00:00 2001 From: "openslides-automation[bot]" <125256978+openslides-automation[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 16:12:23 +0100 Subject: [PATCH 41/53] Update meta repository (main) (#3835) * Update meta repository * Update export_service_commits.sh --- meta | 2 +- requirements/export_service_commits.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/meta b/meta index ea6e880b07..b94c601df9 160000 --- a/meta +++ b/meta @@ -1 +1 @@ -Subproject commit ea6e880b07f4e0eb0a54c980c1641ab56e109648 +Subproject commit b94c601df91141be904d9d558e44f22b9d512a3c diff --git a/requirements/export_service_commits.sh b/requirements/export_service_commits.sh index 3824fd2a51..80d46f32b5 100755 --- a/requirements/export_service_commits.sh +++ b/requirements/export_service_commits.sh @@ -1,2 +1,2 @@ #!/bin/bash -export AUTH_COMMIT_HASH=c3485f310ac430ac00c10f26319add35d32b2ed9 +export AUTH_COMMIT_HASH=6645de4633fcb0a389aa987d695cba9111a54af5 From 1f787106f0ac7812aff7eac9d5d7bd14f8b9205c Mon Sep 17 00:00:00 2001 From: Hannes Janott Date: Tue, 3 Nov 2026 21:37:27 +0100 Subject: [PATCH 42/53] Do not execute on_success on errors (#3838) --- openslides_backend/action/action_handler.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openslides_backend/action/action_handler.py b/openslides_backend/action/action_handler.py index 85423e218a..db60e654a6 100644 --- a/openslides_backend/action/action_handler.py +++ b/openslides_backend/action/action_handler.py @@ -131,6 +131,8 @@ def handle_request( retry_count = int(self.env.ACTION_MAX_RETRIES or 1) retry_timeout = float(self.env.ACTION_RETRY_TIMEOUT or 0.4) for attempt in range(1, retry_count + 1): + if attempt > 1: + self.logger.warning(f"Retry attempt #{attempt}:/n{payload}.") try: with get_new_os_conn() as conn: self.post_edit_necessary = False @@ -150,6 +152,7 @@ def transform_to_list( tuple[1], ) + tmp_on_success = deepcopy(self.on_success) for element in payload: try: result = self.execute_write_requests( @@ -159,7 +162,9 @@ def transform_to_list( element, ) results.append(result) + tmp_on_success = deepcopy(self.on_success) except ActionException as exception: + self.on_success = tmp_on_success error = cast(ActionError, exception.get_json()) results.append(error) self.datastore.reset() From 2f34bf53b1bcf2b758b1e23072c519fb37ae8d17 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 4 Nov 2026 10:51:42 +0100 Subject: [PATCH 43/53] Bump pypdf from 6.21.3 to 6.21.4 in /requirements/partial (#3828) --- requirements/partial/requirements_production.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/partial/requirements_production.txt b/requirements/partial/requirements_production.txt index 732891c316..916c3f44f8 100644 --- a/requirements/partial/requirements_production.txt +++ b/requirements/partial/requirements_production.txt @@ -5,7 +5,7 @@ dependency_injector==4.49.1 fastjsonschema==2.22.2 Flask==3.1.3 gunicorn==26.2.0 -pypdf[crypto]==6.21.3 +pypdf[crypto]==6.21.4 psycopg[binary]==3.3.6 psycopg-pool==3.3.3 requests==2.34.2 From 47231072922f24c1c05df3e5f0680ad453cda818 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 4 Nov 2026 11:21:18 +0100 Subject: [PATCH 44/53] Bump sqlfluff (#3839) --- requirements/partial/requirements_production.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/partial/requirements_production.txt b/requirements/partial/requirements_production.txt index 916c3f44f8..f2449337b2 100644 --- a/requirements/partial/requirements_production.txt +++ b/requirements/partial/requirements_production.txt @@ -16,7 +16,7 @@ python-magic==0.4.27 python-sql==1.8.1 pygments==2.21.0 pyyaml==6.0.3 -sqlfluff==4.4.0 +sqlfluff==4.5.0 # opentelemetry opentelemetry-api==1.45.2 From fc72d6b5d739a830216897dd533f996dbbbab75c Mon Sep 17 00:00:00 2001 From: "openslides-automation[bot]" <125256978+openslides-automation[bot]@users.noreply.github.com> Date: Wed, 4 Nov 2026 17:00:11 +0100 Subject: [PATCH 45/53] Update meta repository (#3841) --- meta | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta b/meta index b94c601df9..fa74ec5e51 160000 --- a/meta +++ b/meta @@ -1 +1 @@ -Subproject commit b94c601df91141be904d9d558e44f22b9d512a3c +Subproject commit fa74ec5e51d8cbb2a081f5f84ef1ef0f66637e8f From 28a4f1c9bb06024e44327c6619f53f094622f5d0 Mon Sep 17 00:00:00 2001 From: luisa-beerboom <101706784+luisa-beerboom@users.noreply.github.com> Date: Fri, 13 Nov 2026 09:23:22 +0100 Subject: [PATCH 46/53] Add cycle creation tests to agenda_item test_assign (#3857) --- .../action/actions/agenda_item/assign.py | 14 ++-- .../system/action/agenda_item/test_assign.py | 77 +++++++++++++++++++ 2 files changed, 86 insertions(+), 5 deletions(-) diff --git a/openslides_backend/action/actions/agenda_item/assign.py b/openslides_backend/action/actions/agenda_item/assign.py index 8fb924bfac..4093f2ce1a 100644 --- a/openslides_backend/action/actions/agenda_item/assign.py +++ b/openslides_backend/action/actions/agenda_item/assign.py @@ -70,23 +70,27 @@ def prepare_assign_data( mapped_fields=["id"], ) - ancesters = [] + ancestors = [] if parent_id: - # Calculate the ancesters of parent - ancesters.append(parent_id) + # Calculate the ancestors of parent + ancestors.append(parent_id) grandparent = self.datastore.get( fqid_from_collection_and_id(self.model.collection, parent_id), ["parent_id"], ) while grandparent.get("parent_id") is not None: gp_parent_id = grandparent["parent_id"] - ancesters.append(gp_parent_id) + ancestors.append(gp_parent_id) grandparent = self.datastore.get( fqid_from_collection_and_id(self.model.collection, gp_parent_id), ["parent_id"], ) for num, id_ in enumerate(ids): - if id_ in ancesters: + if id_ in ancestors: + if id_ == parent_id: + raise ActionException( + f"Assigning item {id_} to itself is not possible." + ) raise ActionException( f"Assigning item {id_} to one of its children is not possible." ) diff --git a/tests/system/action/agenda_item/test_assign.py b/tests/system/action/agenda_item/test_assign.py index 3aad4b6ef7..b96a76bafa 100644 --- a/tests/system/action/agenda_item/test_assign.py +++ b/tests/system/action/agenda_item/test_assign.py @@ -201,6 +201,83 @@ def test_assign_multiple_action_data_items(self) -> None: agenda_item_8 = self.get_model("agenda_item/8") assert agenda_item_8.get("parent_id") is None + def test_assign_circle(self) -> None: + self.create_meeting(222) + self.set_models( + { + "agenda_item/7": {"meeting_id": 222, "content_object_id": "topic/1"}, + "agenda_item/8": { + "meeting_id": 222, + "content_object_id": "topic/2", + "parent_id": 7, + }, + "list_of_speakers/23": { + "content_object_id": "topic/1", + "meeting_id": 222, + }, + "list_of_speakers/42": { + "content_object_id": "topic/2", + "meeting_id": 222, + }, + "topic/1": { + "meeting_id": 222, + "title": "tropic", + }, + "topic/2": { + "meeting_id": 222, + "title": "tropic", + }, + } + ) + response = self.request_multi( + "agenda_item.assign", + [ + {"meeting_id": 222, "ids": [7], "parent_id": 8}, + ], + ) + self.assert_status_code(response, 400) + assert ( + response.json["message"] + == "Assigning item 7 to one of its children is not possible." + ) + + def test_assign_self_as_parent(self) -> None: + self.create_meeting(222) + self.set_models( + { + "agenda_item/7": {"meeting_id": 222, "content_object_id": "topic/1"}, + "agenda_item/8": { + "meeting_id": 222, + "content_object_id": "topic/2", + "parent_id": 7, + }, + "list_of_speakers/23": { + "content_object_id": "topic/1", + "meeting_id": 222, + }, + "list_of_speakers/42": { + "content_object_id": "topic/2", + "meeting_id": 222, + }, + "topic/1": { + "meeting_id": 222, + "title": "tropic", + }, + "topic/2": { + "meeting_id": 222, + "title": "tropic", + }, + } + ) + response = self.request_multi( + "agenda_item.assign", + [ + {"meeting_id": 222, "ids": [7], "parent_id": 7}, + ], + ) + self.assert_status_code(response, 400) + assert response.json["message"] == "Assigning item 7 to itself is not possible." + def test_assign_no_permissions(self) -> None: self.base_permission_test( self.PERMISSION_TEST_MODELS, From e747973a1c619da9b523b9db2d98785263ba9ade Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Nov 2026 11:12:31 +0100 Subject: [PATCH 47/53] Bump psycopg in /requirements/partial in the database-dependencies group (#3846) --- requirements/partial/requirements_production.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/partial/requirements_production.txt b/requirements/partial/requirements_production.txt index f2449337b2..c2f4558119 100644 --- a/requirements/partial/requirements_production.txt +++ b/requirements/partial/requirements_production.txt @@ -6,7 +6,7 @@ fastjsonschema==2.22.2 Flask==3.1.3 gunicorn==26.2.0 pypdf[crypto]==6.21.4 -psycopg[binary]==3.3.6 +psycopg[binary]==3.3.7 psycopg-pool==3.3.3 requests==2.34.2 roman==5.2 From 78ce2807e9a70acb7657d6a1846580d73ff1fc59 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Nov 2026 10:40:27 +0000 Subject: [PATCH 48/53] Bump pypdf from 6.21.4 to 7.0.0 in /requirements/partial (#3852) --- requirements/partial/requirements_production.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/partial/requirements_production.txt b/requirements/partial/requirements_production.txt index c2f4558119..5b4ec0e036 100644 --- a/requirements/partial/requirements_production.txt +++ b/requirements/partial/requirements_production.txt @@ -5,7 +5,7 @@ dependency_injector==4.49.1 fastjsonschema==2.22.2 Flask==3.1.3 gunicorn==26.2.0 -pypdf[crypto]==6.21.4 +pypdf[crypto]==7.0.0 psycopg[binary]==3.3.7 psycopg-pool==3.3.3 requests==2.34.2 From 692fe45f6f143c720e7dcfabb2986dd776587ab0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Nov 2026 12:16:46 +0100 Subject: [PATCH 49/53] Bump py-spy from 0.4.2 to 0.4.3 in /requirements/partial (#3848) --- requirements/partial/requirements_development.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/partial/requirements_development.txt b/requirements/partial/requirements_development.txt index cd775d15e8..516260cb47 100644 --- a/requirements/partial/requirements_development.txt +++ b/requirements/partial/requirements_development.txt @@ -22,4 +22,4 @@ types-Pygments==2.21.0.20260819 # analyze pstats from Profiler snakeviz==2.2.2 -py-spy==0.4.2 +py-spy==0.4.3 From 37535549973e0dd6f31131eabe47aaa533a38338 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Nov 2026 12:18:11 +0000 Subject: [PATCH 50/53] Bump the general-dependencies group across 1 directory with 3 updates (#3851) --- meta | 2 +- openslides_backend/action/action.py | 5 ++++- openslides_backend/action/action_handler.py | 3 ++- .../action/actions/user/save_saml_account.py | 3 ++- openslides_backend/action/mixins/singular_action_mixin.py | 3 ++- openslides_backend/models/fields.py | 5 ++++- openslides_backend/presenter/base.py | 3 ++- openslides_backend/presenter/presenter.py | 3 ++- openslides_backend/shared/util.py | 7 +++++++ requirements/export_service_commits.sh | 2 +- requirements/partial/requirements_development.txt | 4 ++-- requirements/partial/requirements_production.txt | 2 +- 12 files changed, 30 insertions(+), 12 deletions(-) diff --git a/meta b/meta index fa74ec5e51..ac018a77ed 160000 --- a/meta +++ b/meta @@ -1 +1 @@ -Subproject commit fa74ec5e51d8cbb2a081f5f84ef1ef0f66637e8f +Subproject commit ac018a77ed5e113162b2cdb57f8a56bf8b35f665 diff --git a/openslides_backend/action/action.py b/openslides_backend/action/action.py index 2e32659e16..4c7e9addab 100644 --- a/openslides_backend/action/action.py +++ b/openslides_backend/action/action.py @@ -44,6 +44,7 @@ transform_to_fqids, ) from ..shared.typing import DeletedModel, HistoryInformation +from ..shared.util import json_schema_error_to_str from .relations.relation_manager import RelationManager, RelationUpdates from .relations.typing import FieldUpdateElement, ListUpdateElement from .util.action_type import ActionType @@ -330,7 +331,9 @@ def validate_instance(self, instance: dict[str, Any]) -> None: } ) except fastjsonschema.JsonSchemaException as exception: - raise ActionException(f"Action {self.name}: " + exception.message) + raise ActionException( + f"Action {self.name}: " + json_schema_error_to_str(exception) + ) def base_update_instance(self, instance: dict[str, Any]) -> dict[str, Any]: """ diff --git a/openslides_backend/action/action_handler.py b/openslides_backend/action/action_handler.py index db60e654a6..06e0e25a9e 100644 --- a/openslides_backend/action/action_handler.py +++ b/openslides_backend/action/action_handler.py @@ -30,6 +30,7 @@ from ..shared.interfaces.write_request import WriteRequest from ..shared.otel import make_span from ..shared.schema import schema_version +from ..shared.util import json_schema_error_to_str from . import actions # noqa from .relations.relation_manager import RelationManager from .util.action_type import ActionType @@ -126,7 +127,7 @@ def handle_request( try: payload_schema(payload) except fastjsonschema.JsonSchemaException as exception: - raise ActionException(exception.message) + raise ActionException(json_schema_error_to_str(exception)) retry_count = int(self.env.ACTION_MAX_RETRIES or 1) retry_timeout = float(self.env.ACTION_RETRY_TIMEOUT or 0.4) diff --git a/openslides_backend/action/actions/user/save_saml_account.py b/openslides_backend/action/actions/user/save_saml_account.py index ec09cf2666..75235d77a4 100644 --- a/openslides_backend/action/actions/user/save_saml_account.py +++ b/openslides_backend/action/actions/user/save_saml_account.py @@ -17,6 +17,7 @@ from ....shared.interfaces.event import Event from ....shared.schema import schema_version from ....shared.typing import Schema +from ....shared.util import json_schema_error_to_str from ...mixins.meeting_user_helper import get_meeting_user from ...mixins.send_email_mixin import EmailCheckMixin from ...mixins.singular_action_mixin import SingularActionMixin @@ -126,7 +127,7 @@ def validate_instance(self, instance: dict[str, Any]) -> None: try: fastjsonschema.validate(self.schema, instance) except fastjsonschema.JsonSchemaException as exception: - raise ActionException(exception.message) + raise ActionException(json_schema_error_to_str(exception)) def validate_fields(self, instance_old: dict[str, Any]) -> dict[str, Any]: """ diff --git a/openslides_backend/action/mixins/singular_action_mixin.py b/openslides_backend/action/mixins/singular_action_mixin.py index a02e6d4b54..24fe8c00d5 100644 --- a/openslides_backend/action/mixins/singular_action_mixin.py +++ b/openslides_backend/action/mixins/singular_action_mixin.py @@ -2,6 +2,7 @@ from ...shared.exceptions import ActionException from ...shared.schema import schema_version +from ...shared.util import json_schema_error_to_str from ..action import Action, original_instances from ..util.typing import ActionData @@ -34,4 +35,4 @@ def assert_singular_action_data(self, action_data: ActionData) -> None: try: singular_schema(action_data) except fastjsonschema.JsonSchemaException as exception: - raise ActionException(exception.message) + raise ActionException(json_schema_error_to_str(exception)) diff --git a/openslides_backend/models/fields.py b/openslides_backend/models/fields.py index 78a3d7afa0..fe767236b4 100644 --- a/openslides_backend/models/fields.py +++ b/openslides_backend/models/fields.py @@ -22,6 +22,7 @@ from ..shared.util import ( ALLOWED_HTML_TAGS_PERMISSIVE, ALLOWED_HTML_TAGS_STRICT, + json_schema_error_to_str, validate_html, ) @@ -101,7 +102,9 @@ def validate_with_schema( try: self.schema_validator(value) except fastjsonschema.JsonSchemaException as e: - raise ActionException(f"Invalid data for {fqid}/{field_name}: " + e.message) + raise ActionException( + f"Invalid data for {fqid}/{field_name}: " + json_schema_error_to_str(e) + ) def check_required_not_fulfilled( self, instance: dict[str, Any], is_create: bool diff --git a/openslides_backend/presenter/base.py b/openslides_backend/presenter/base.py index 9e9fb746d0..95db292295 100644 --- a/openslides_backend/presenter/base.py +++ b/openslides_backend/presenter/base.py @@ -10,6 +10,7 @@ from ..shared.exceptions import PresenterException from ..shared.interfaces.logging import LoggingModule from ..shared.interfaces.services import Services +from ..shared.util import json_schema_error_to_str class BasePresenter(BaseServiceProvider): @@ -43,7 +44,7 @@ def validate(self) -> None: try: schema(self.data) except JsonSchemaException as exception: - raise PresenterException(exception.message) + raise PresenterException(json_schema_error_to_str(exception)) else: if self.data is not None: raise PresenterException("This presenter does not take data.") diff --git a/openslides_backend/presenter/presenter.py b/openslides_backend/presenter/presenter.py index 30cf5c79e8..b00fc062cf 100644 --- a/openslides_backend/presenter/presenter.py +++ b/openslides_backend/presenter/presenter.py @@ -13,6 +13,7 @@ from ..shared.exceptions import PresenterException from ..shared.handlers.base_handler import BaseHandler from ..shared.schema import schema_version +from ..shared.util import json_schema_error_to_str from .base import BasePresenter from .presenter_interface import Payload, PresenterResponse @@ -73,7 +74,7 @@ def handle_request(self, request: Request) -> tuple[PresenterResponse, str | Non try: self.validate(request.json) except JsonSchemaException as exception: - raise PresenterException(exception.message) + raise PresenterException(json_schema_error_to_str(exception)) # Parse presentations and creates response with get_new_os_conn() as conn: diff --git a/openslides_backend/shared/util.py b/openslides_backend/shared/util.py index 147175ca57..b94b74c5b8 100644 --- a/openslides_backend/shared/util.py +++ b/openslides_backend/shared/util.py @@ -1,6 +1,7 @@ from typing import Any import bleach +import fastjsonschema import simplejson as json from bleach.css_sanitizer import CSSSanitizer @@ -191,3 +192,9 @@ def check_attr_allowed(tag: str, name: str, value: str) -> bool: def get_initial_data_file(file: str) -> dict[str, Any]: with open(file) as fileh: return json.load(fileh) + + +def json_schema_error_to_str(err: fastjsonschema.JsonSchemaException) -> str: + if hasattr(err, "message"): + return err.message + return str(err) diff --git a/requirements/export_service_commits.sh b/requirements/export_service_commits.sh index 80d46f32b5..a76896a89a 100755 --- a/requirements/export_service_commits.sh +++ b/requirements/export_service_commits.sh @@ -1,2 +1,2 @@ #!/bin/bash -export AUTH_COMMIT_HASH=6645de4633fcb0a389aa987d695cba9111a54af5 +export AUTH_COMMIT_HASH=1277fb02e98b6592beefda7ff14581211209cca9 diff --git a/requirements/partial/requirements_development.txt b/requirements/partial/requirements_development.txt index 516260cb47..8ac8935370 100644 --- a/requirements/partial/requirements_development.txt +++ b/requirements/partial/requirements_development.txt @@ -15,9 +15,9 @@ pyupgrade==3.22.0 types-babel==2.11.0.15 types-beautifulsoup4==4.12.0.20250516 types-bleach==6.4.0.20260728 -types-PyYAML==6.0.12.20261030 +types-PyYAML==6.0.12.20261103 types-requests==2.33.0.20261030 -types-simplejson==4.2.0.20261031 +types-simplejson==4.2.0.20261104 types-Pygments==2.21.0.20260819 # analyze pstats from Profiler diff --git a/requirements/partial/requirements_production.txt b/requirements/partial/requirements_production.txt index 5b4ec0e036..45d22ecac0 100644 --- a/requirements/partial/requirements_production.txt +++ b/requirements/partial/requirements_production.txt @@ -2,7 +2,7 @@ Babel==2.18.0 beautifulsoup4==4.15.0 bleach[css]==6.4.0 dependency_injector==4.49.1 -fastjsonschema==2.22.2 +fastjsonschema==2.22.3 Flask==3.1.3 gunicorn==26.2.0 pypdf[crypto]==7.0.0 From 59178e2c55ae74e418ed0a8b9720a0ecf89739fd Mon Sep 17 00:00:00 2001 From: "openslides-automation[bot]" <125256978+openslides-automation[bot]@users.noreply.github.com> Date: Fri, 13 Nov 2026 12:49:10 +0000 Subject: [PATCH 51/53] Update meta repository (#3858) --- meta | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta b/meta index ac018a77ed..8f45f16546 160000 --- a/meta +++ b/meta @@ -1 +1 @@ -Subproject commit ac018a77ed5e113162b2cdb57f8a56bf8b35f665 +Subproject commit 8f45f16546d05db8a859c063a2f3189cf29bde23 From ee61eb0a8de6aa2282cc27bacf4f755df2a7a43b Mon Sep 17 00:00:00 2001 From: Hannes Janott Date: Fri, 13 Nov 2026 16:05:01 +0100 Subject: [PATCH 52/53] Fix On Success on Poll Stop (#3849) * raise DatabaseException on DeadlockDetected * move http on_success outside transaction context * reset on_success in between retries * except Database and Interface Error * write test for on_success check during transaction end exception * move concatenate_action_names to action_name.py --- openslides_backend/action/action.py | 11 +- openslides_backend/action/action_handler.py | 85 ++++++++++----- openslides_backend/action/action_worker.py | 25 +---- .../action/mixins/import_mixins.py | 4 +- openslides_backend/action/util/action_name.py | 21 ++++ .../services/database/database_reader.py | 8 ++ .../services/database/database_writer.py | 12 +++ .../shared/handlers/base_handler.py | 5 - tests/system/action/poll/test_stop.py | 102 +++++++++++++++++- 9 files changed, 218 insertions(+), 55 deletions(-) create mode 100644 openslides_backend/action/util/action_name.py diff --git a/openslides_backend/action/action.py b/openslides_backend/action/action.py index 4c7e9addab..1d70e5afe5 100644 --- a/openslides_backend/action/action.py +++ b/openslides_backend/action/action.py @@ -748,7 +748,16 @@ def execute_other_action( def get_on_success(self, action_data: ActionData) -> Callable[[], None] | None: """ Can be overridden by actions to return a cleanup method to execute - after the result was successfully written to the DS. + after the result was successfully written to the DB and the connection was closed. + """ + return None + + def get_on_success_transaction_based( + self, action_data: ActionData + ) -> Callable[[], None] | None: + """ + Can be overridden by actions to return a cleanup method to execute + after the result was successfully written to the DB. """ return None diff --git a/openslides_backend/action/action_handler.py b/openslides_backend/action/action_handler.py index 06e0e25a9e..fb3723c1b5 100644 --- a/openslides_backend/action/action_handler.py +++ b/openslides_backend/action/action_handler.py @@ -6,18 +6,25 @@ from typing import Any, TypeVar, cast import fastjsonschema -from psycopg.errors import ForeignKeyViolation, RaiseException, SerializationFailure +from psycopg.errors import ( + DatabaseError, + DeadlockDetected, + ForeignKeyViolation, + InterfaceError, + RaiseException, + SerializationFailure, +) from openslides_backend.services.database.extended_database import ExtendedDatabase from openslides_backend.services.postgresql.db_connection_handling import ( get_new_os_conn, ) -from openslides_backend.shared.exceptions import DatabaseException from openslides_backend.shared.patterns import fqid_from_collection_and_id from ..shared.exceptions import ( ActionException, BadCodingException, + DatabaseException, DatastoreLockedException, ModelDoesNotExist, RelationException, @@ -33,6 +40,7 @@ from ..shared.util import json_schema_error_to_str from . import actions # noqa from .relations.relation_manager import RelationManager +from .util.action_name import summarize_action_names from .util.action_type import ActionType from .util.actions_map import actions_map from .util.typing import ( @@ -86,10 +94,10 @@ class ActionHandler(BaseHandler): MAX_RETRY = 3 on_success: list[Callable[[], None]] + on_success_transaction_based: list[Callable[[], None]] def __init__(self, env: Env, services: Services, logging: LoggingModule) -> None: super().__init__(env, services, logging) - self.on_success = [] @classmethod def get_health_info(cls) -> Iterable[tuple[str, dict[str, Any]]]: @@ -132,13 +140,15 @@ def handle_request( retry_count = int(self.env.ACTION_MAX_RETRIES or 1) retry_timeout = float(self.env.ACTION_RETRY_TIMEOUT or 0.4) for attempt in range(1, retry_count + 1): + self.on_success = [] + self.on_success_transaction_based = [] + results: ActionsResponseResults = [] + self.post_edit_necessary = False if attempt > 1: self.logger.warning(f"Retry attempt #{attempt}:/n{payload}.") try: with get_new_os_conn() as conn: - self.post_edit_necessary = False self.datastore = ExtendedDatabase(conn, self.logging, self.env) - results: ActionsResponseResults = [] if atomic: results = self.execute_write_requests( self.parse_actions, payload @@ -153,7 +163,10 @@ def transform_to_list( tuple[1], ) - tmp_on_success = deepcopy(self.on_success) + tmp_on_success_transaction_based = list( + self.on_success_transaction_based + ) + tmp_on_success = list(self.on_success) for element in payload: try: result = self.execute_write_requests( @@ -163,25 +176,22 @@ def transform_to_list( element, ) results.append(result) - tmp_on_success = deepcopy(self.on_success) + tmp_on_success_transaction_based = list( + self.on_success_transaction_based + ) + tmp_on_success = list(self.on_success) except ActionException as exception: + self.on_success_transaction_based = ( + tmp_on_success_transaction_based + ) self.on_success = tmp_on_success error = cast(ActionError, exception.get_json()) results.append(error) self.datastore.reset() - # execute cleanup methods - for on_success in self.on_success: + # execute database cleanup methods + for on_success in self.on_success_transaction_based: on_success() - - # Return action result - self.logger.info("Request was successful. Send response now.") - return ActionsResponse( - status_code=HTTPStatus.OK.value, - success=True, - message="Actions handled successfully", - results=results, - ) except RaiseException as e: # This is raised at the end of transaction as the constraint trigger has to be initially deferred. if len(msg_lis := str(e).split(": ")) > 1 and msg_lis[1].startswith( @@ -202,12 +212,40 @@ def transform_to_list( ) raise ModelDoesNotExist(error_fqid) raise e - except SerializationFailure: + except DeadlockDetected as e: + self.logger.error(str(e)) + if attempt == retry_count: + raise DatabaseException( + f"{summarize_action_names(payload)}: Deadlock detected." + ) + except SerializationFailure as e: if attempt == retry_count: raise DatabaseException( "Database operation failed due to concurrent conflicting actions. Please try again later." ) + else: + self.logger.error(str(e)) sleep(retry_timeout) + except DatabaseError as e: + raise DatabaseException(f"Psycopg encountered a new problem: {e}") + except InterfaceError as e: + raise DatabaseException( + f"The user encountered a new problem with psycopg: {e}" + ) + else: + # Connection terminated successfully. + # Execute http cleanup methods. + for on_success in self.on_success: + on_success() + + # Return action results. + self.logger.info("Request was successful. Send response now.") + return ActionsResponse( + status_code=HTTPStatus.OK.value, + success=True, + message="Actions handled successfully", + results=results, + ) raise BadCodingException("This code should never execute") def execute_internal_action(self, action: str, data: dict[str, Any]) -> None: @@ -329,7 +367,6 @@ def perform_action( action_data = deepcopy(action_payload_element["data"]) try: - # with self.datastore.get_database_context(): with make_span(self.env, "action.perform"): write_request, results = action.perform( action_data, self.user_id, internal=self.internal @@ -343,15 +380,11 @@ def perform_action( if write_request: action.validate_write_request(write_request) - # # add locked_fields to request - # write_request.locked_fields = self.datastore.locked_fields - # # reset locked fields, but not changed models - these might be needed - # # by another action - # self.datastore.reset(hard=False) - # add on_success routine if on_success := action.get_on_success(action_data): self.on_success.append(on_success) + if on_success := action.get_on_success_transaction_based(action_data): + self.on_success_transaction_based.append(on_success) return (write_request, results) except ActionException as exception: diff --git a/openslides_backend/action/action_worker.py b/openslides_backend/action/action_worker.py index e131e4637e..88ee2ebf3f 100644 --- a/openslides_backend/action/action_worker.py +++ b/openslides_backend/action/action_worker.py @@ -24,6 +24,7 @@ from ..shared.interfaces.logging import LoggingModule from ..shared.interfaces.write_request import WriteRequest from .action_handler import ActionHandler +from .util.action_name import summarize_action_names from .util.typing import ActionsResponse, Payload @@ -33,26 +34,6 @@ class ActionWorkerState(StrEnum): ABORTED = "aborted" -def concatenate_action_names(payload: Payload) -> str: - result = ",".join(elem.get("action", "") for elem in payload) - if len(result) > 256: - action_names = result.split(",") - result = "" - prev_action_name = action_names[0] - counter = 1 - for action_name in action_names[1:]: - if action_name == prev_action_name: - counter += 1 - else: - result += f"{prev_action_name}_{counter}," - prev_action_name = action_name - counter = 1 - result += f"{prev_action_name}_{counter}" - if len(result) > 256: - result = result[:255] + "…" - return result - - def handle_action_in_worker_thread( payload: Payload, user_id: int, @@ -63,7 +44,7 @@ def handle_action_in_worker_thread( logger = handler.logging.getLogger(__name__) lock = threading.Lock() try: - action_names = concatenate_action_names(payload) + action_names = summarize_action_names(payload) except Exception: action_names = "Cannot be determined" action_worker_writing = ActionWorkerWriting(user_id, handler.logging, action_names) @@ -93,6 +74,7 @@ def handle_action_in_worker_thread( if hasattr(action_worker_thread, "exception"): raise action_worker_thread.exception if hasattr(action_worker_thread, "response"): + # thread finished return action_worker_thread.response msg = ( "Action request ended with unknown reason, " @@ -206,6 +188,7 @@ def final_action_worker_write( f"finish action_worker '{self.fqid}' ({self.action_names}) {current_time} with exception: {exception.message}" ) elif hasattr(action_worker_thread, "response"): + # thread finished response = action_worker_thread.response self.logger.info( f"finish action_worker '{self.fqid}' ({self.action_names}): {current_time}" diff --git a/openslides_backend/action/mixins/import_mixins.py b/openslides_backend/action/mixins/import_mixins.py index fa31633135..0651d80c17 100644 --- a/openslides_backend/action/mixins/import_mixins.py +++ b/openslides_backend/action/mixins/import_mixins.py @@ -350,7 +350,9 @@ def flatten_copied_object_fields( entry[key] = dvalue["value"] return rows - def get_on_success(self, action_data: ActionData) -> Callable[[], None]: + def get_on_success_transaction_based( + self, action_data: ActionData + ) -> Callable[[], None]: def on_success() -> None: for instance in action_data: store_id = instance["id"] diff --git a/openslides_backend/action/util/action_name.py b/openslides_backend/action/util/action_name.py new file mode 100644 index 0000000000..c54da49013 --- /dev/null +++ b/openslides_backend/action/util/action_name.py @@ -0,0 +1,21 @@ +from .typing import Payload + + +def summarize_action_names(payload: Payload) -> str: + result = ",".join(elem.get("action", "") for elem in payload) + if len(result) > 256: + action_names = result.split(",") + result = "" + prev_action_name = action_names[0] + counter = 1 + for action_name in action_names[1:]: + if action_name == prev_action_name: + counter += 1 + else: + result += f"{prev_action_name}_{counter}," + prev_action_name = action_name + counter = 1 + result += f"{prev_action_name}_{counter}" + if len(result) > 256: + result = result[:255] + "…" + return result diff --git a/openslides_backend/services/database/database_reader.py b/openslides_backend/services/database/database_reader.py index e0d475b803..4d86d7bb60 100644 --- a/openslides_backend/services/database/database_reader.py +++ b/openslides_backend/services/database/database_reader.py @@ -2,6 +2,8 @@ from psycopg import Connection, rows, sql from psycopg.errors import ( + DatabaseError, + InterfaceError, SerializationFailure, UndefinedColumn, UndefinedFunction, @@ -251,6 +253,12 @@ def execute_query( raise InvalidFormat(e.diag.message_primary or "") except SerializationFailure as e: raise e + except DatabaseError as e: + raise DatabaseException(f"Psycopg encountered a new problem: {e}") + except InterfaceError as e: + raise DatabaseException( + f"The user encountered a new problem with psycopg: {e}" + ) except Exception as e: raise DatabaseException(f"Unexpected error reading from database: {e}") diff --git a/openslides_backend/services/database/database_writer.py b/openslides_backend/services/database/database_writer.py index f7fb85574b..757aec3633 100644 --- a/openslides_backend/services/database/database_writer.py +++ b/openslides_backend/services/database/database_writer.py @@ -5,9 +5,12 @@ from psycopg import Connection, adapt, rows, sql from psycopg.errors import ( CheckViolation, + DatabaseError, DatatypeMismatch, + DeadlockDetected, GeneratedAlways, InFailedSqlTransaction, + InterfaceError, NotNullViolation, ProgrammingError, StringDataRightTruncation, @@ -29,6 +32,7 @@ ) from openslides_backend.shared.exceptions import ( BadCodingException, + DatabaseException, InvalidData, InvalidFormat, ModelDoesNotExist, @@ -491,6 +495,8 @@ def execute_sql( assert target_id # we will never reach here with delete or update events being None on id raise ModelDoesNotExist(error_fqid) return result + except DeadlockDetected as e: + raise DatabaseException(f"{e}") except InFailedSqlTransaction as e: raise BadCodingException( f"Tried to set {error_fqid} in an already broken transaction: {e}" @@ -579,6 +585,12 @@ def execute_sql( ) else: raise e + except DatabaseError as e: + raise DatabaseException(f"Psycopg encountered a new problem: {e}") + except InterfaceError as e: + raise DatabaseException( + f"The user encountered a new problem with psycopg: {e}" + ) except Exception as e: raise e raise ModelLocked(f"Model ... is locked on fields .... {e}\ diff --git a/openslides_backend/shared/handlers/base_handler.py b/openslides_backend/shared/handlers/base_handler.py index 67b5b5ee90..6e60a670d4 100644 --- a/openslides_backend/shared/handlers/base_handler.py +++ b/openslides_backend/shared/handlers/base_handler.py @@ -13,8 +13,3 @@ def __init__(self, env: Env, services: Services, logging: LoggingModule) -> None self.services = services self.logging = logging self.logger = logging.getLogger(__name__) - - # Now initialize datastore instance. - # self.datastore = services.datastore() - # self.extended_db = ExtendedDatabase(self.logging, self.env) - # self.database = services.database() diff --git a/tests/system/action/poll/test_stop.py b/tests/system/action/poll/test_stop.py index 3404092d6c..30d678fa03 100644 --- a/tests/system/action/poll/test_stop.py +++ b/tests/system/action/poll/test_stop.py @@ -1,11 +1,21 @@ +import inspect +from collections.abc import Iterator +from contextlib import contextmanager from decimal import Decimal +from importlib import import_module +from time import sleep from typing import Any from unittest.mock import Mock, patch import pytest +from psycopg.errors import DeadlockDetected from openslides_backend.models.models import Poll from openslides_backend.permissions.permissions import Permissions +from openslides_backend.services.postgresql.db_connection_handling import ( + ConnectionContext, +) +from tests.system.action.lock import pytest_thread_local from tests.system.util import CountDatastoreCalls, Profiler, performance from .base_poll_test import BasePollTestCase @@ -45,7 +55,6 @@ def add_to_list(id_: int) -> None: **self.poll_data, "content_object_id": "motion/1", "pollmethod": "YN", - "entitled_group_ids": [1], }, "group/1": {"poll_ids": [1]}, "option/1": {"meeting_id": 1, "poll_id": 1}, @@ -392,3 +401,94 @@ def test_stop_performance(self) -> None: self.assert_status_code(response, 200) poll = self.get_model("poll/1") assert poll["voted_ids"] == user_ids + + def base_no_success(self, max_retries: str) -> None: + """ + Asserts that the on_success method of poll.stop isn't called in case of an exception at transaction end. + """ + pytest_thread_local.name = "MainThread_RC" + self.set_thread_watch_timeout(0.1) + self.env.vars["ACTION_MAX_RETRIES"] = max_retries + + self.create_meeting(1, {"poll_couple_countdown": False}) + self.create_topic(1, 1) + self.set_models( + { + "poll/1": self.poll_data, + "group/1": { + "poll_ids": [1], + "permissions": ["poll.can_manage"], + }, + } + ) + + self.start_poll(1) + user_id = self.create_user_for_meeting(1) + self.login(user_id) + self.vote_service.vote({"id": 1, "value": {"1": "Y"}}) + + with patch.object(self.vote_service, "clear", autospec=True) as mock_clear: + with monkeypatch_get_new_os_conn(): + self.request("poll.stop", {"id": 1}) + mock_clear.assert_not_called() + + def test_stop_no_success(self) -> None: + self.base_no_success("1") + + def test_stop_no_success2(self) -> None: + self.base_no_success("2") + + +handle_request_calls = 0 + + +@contextmanager +def monkeypatch_get_new_os_conn() -> Iterator[None]: + """ + Patches get_new_os_conn to further patch the ConnectionContext. + """ + global handle_request_calls + handle_request_calls = 0 + module = import_module("openslides_backend.action.action_handler") + module.get_new_os_conn_original = module.get_new_os_conn # type: ignore [attr-defined] + module.get_new_os_conn = counting_get_new_os_conn # type: ignore [attr-defined] + try: + yield + finally: + module.get_new_os_conn = module.get_new_os_conn_original # type: ignore [attr-defined] + delattr(module, "get_new_os_conn_original") + + +def counting_get_new_os_conn() -> ConnectionContext: # type: ignore [attr-defined] + """ + Wraps the __exit__ of the ConnectionContext to stall the thread and raise a DeadlockDetected exception. + """ + global handle_request_calls + + def raise_exception(*args, **kwargs) -> None: # type: ignore [no-untyped-def] + """ + Should only be called by handle request on the second entering of the + connection context but may be called by other functions too. + """ + sleep(0.2) + caller = inspect.stack()[1] + if caller.function == "handle_request": + ConnectionContext.original_exit(*args, **kwargs) # type: ignore [attr-defined] + ConnectionContext.__exit__ = ConnectionContext.original_exit # type: ignore [method-assign,attr-defined] + delattr(ConnectionContext, "original_exit") + raise DeadlockDetected("Nii!!") + else: + ConnectionContext.__exit__(*args, **kwargs) + + nested_patch = False + caller = inspect.stack()[1] + if caller.function == "handle_request": + # count in function context + handle_request_calls += 1 + if handle_request_calls == 2 or handle_request_calls == 3: + nested_patch = True + module = import_module("openslides_backend.action.action_handler") + if nested_patch: + ConnectionContext.original_exit = ConnectionContext.__exit__ # type: ignore [attr-defined] + ConnectionContext.__exit__ = raise_exception # type: ignore[method-assign] + return module.get_new_os_conn_original() # type: ignore[method-assign] From 3bb2fff1f0083420ef0042d38a723eae2761e956 Mon Sep 17 00:00:00 2001 From: luisa-beerboom <101706784+luisa-beerboom@users.noreply.github.com> Date: Tue, 17 Nov 2026 14:37:39 +0100 Subject: [PATCH 53/53] Update test_0100_init_reldb.py --- tests/system/migrations/test_0100_init_reldb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/migrations/test_0100_init_reldb.py b/tests/system/migrations/test_0100_init_reldb.py index b773a8a9a1..a7a43ed521 100644 --- a/tests/system/migrations/test_0100_init_reldb.py +++ b/tests/system/migrations/test_0100_init_reldb.py @@ -399,7 +399,7 @@ def test_migration_reset(self, method_mock: Mock) -> None: self.wait_for_migration_thread(15) assert self.request("stats").json["stats"] == { - "current_migration_index": 73, + "current_migration_index": 83, "target_migration_index": 100, "status": MigrationState.MIGRATION_FAILED, "exception": 'psycopg.errors.UniqueViolation: duplicate key value violates unique constraint "organization_t_pkey"\nDETAIL: Key (id)=(1) already exists.',