Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cherry-Pick] make meeting clone with gender in user possible again #2682

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openslides_backend/action/actions/meeting/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def check_permissions(self, instance: dict[str, Any]) -> None:
MeetingPermissionMixin.check_permissions(self, instance)

def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
meeting_json = export_meeting(self.datastore, instance["meeting_id"])
meeting_json = export_meeting(self.datastore, instance["meeting_id"], True)
instance["meeting"] = meeting_json
additional_user_ids = instance.pop("user_ids", None) or []
additional_admin_ids = instance.pop("admin_ids", None) or []
Expand Down
16 changes: 10 additions & 6 deletions openslides_backend/shared/export_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
FORBIDDEN_FIELDS = ["forwarded_motion_ids"]


def export_meeting(datastore: DatastoreService, meeting_id: int) -> dict[str, Any]:
def export_meeting(
datastore: DatastoreService, meeting_id: int, internal_target: bool = False
) -> dict[str, Any]:
export: dict[str, Any] = {}

# fetch meeting
Expand Down Expand Up @@ -129,7 +131,7 @@ def export_meeting(datastore: DatastoreService, meeting_id: int) -> dict[str, An
elif collection_from_fqid(entry[field_name]) == "meeting_user":
id_ = id_from_fqid(entry[field_name])
user_ids.add(results["meeting_user"][id_]["user_id"])
add_users(list(user_ids), export, meeting_id, datastore)
add_users(list(user_ids), export, meeting_id, datastore, internal_target)
return export


Expand All @@ -138,6 +140,7 @@ def add_users(
export_data: dict[str, Any],
meeting_id: int,
datastore: DatastoreService,
internal_target: bool,
) -> None:
if not user_ids:
return
Expand All @@ -157,15 +160,16 @@ def add_users(
)

for user in users.values():
gender_dict = datastore.get_all("gender", ["name"], lock_result=False)
user["meeting_ids"] = [meeting_id]
if meeting_id in (user.get("is_present_in_meeting_ids") or []):
user["is_present_in_meeting_ids"] = [meeting_id]
else:
user["is_present_in_meeting_ids"] = None
if user.get("gender_id"):
user["gender"] = gender_dict.get(user["gender_id"], {}).get("name")
del user["gender_id"]
if not internal_target:
gender_dict = datastore.get_all("gender", ["name"], lock_result=False)
if user.get("gender_id"):
user["gender"] = gender_dict.get(user["gender_id"], {}).get("name")
del user["gender_id"]
# limit user fields to exported objects
collection_field_tupels = [
("meeting_user", "meeting_user_ids"),
Expand Down
5 changes: 4 additions & 1 deletion tests/system/action/meeting/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,10 +785,12 @@ def test_clone_new_committee_and_user_with_group(self) -> None:
"meeting_user_ids": [2],
"meeting_ids": [1],
"organization_id": 1,
"gender_id": 1,
},
"gender/1": {"name": "male", "organization_id": 1, "user_ids": [3]},
"group/1": {"meeting_user_ids": [2]},
"committee/2": {"organization_id": 1},
"organization/1": {"committee_ids": [1, 2]},
"organization/1": {"committee_ids": [1, 2], "gender_ids": [1]},
"meeting/1": {"user_ids": [1, 13], "meeting_user_ids": [1, 2]},
"meeting_user/2": {
"meeting_id": 1,
Expand Down Expand Up @@ -818,6 +820,7 @@ def test_clone_new_committee_and_user_with_group(self) -> None:
"committee_ids": [1, 2],
"meeting_ids": [1, 2],
"meeting_user_ids": [2, 4],
"gender_id": 1,
},
)
self.assert_model_exists(
Expand Down