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

Fix assignment_candidate cascade deletion error #2662

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 docs/actions/assignment_candidate.delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
```

## Action
Deletes an assignment candidate for the assignment. It is forbidden to remove a candidate from a finished assignment.
Deletes an assignment candidate for the assignment. It is forbidden to remove a candidate from a finished assignment if the action is called externally.

## Permissions
If the `assignment_candidate/user_id` is equal to the request user id, the user needs `assignment.can_nominate_self`, else the user needs `assignment.can_nominate_other`.
Expand Down
33 changes: 17 additions & 16 deletions openslides_backend/action/actions/assignment_candidate/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@ class AssignmentCandidateDelete(PermissionMixin, DeleteAction):

def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
instance = super().update_instance(instance)
assignment_candidate = self.datastore.get(
fqid_from_collection_and_id(self.model.collection, instance["id"]),
mapped_fields=["assignment_id"],
)
assignment = self.datastore.get(
fqid_from_collection_and_id(
"assignment", assignment_candidate["assignment_id"]
),
mapped_fields=["phase", "meeting_id"],
lock_result=False,
)
if assignment.get("phase") == "finished" and not self.is_meeting_deleted(
assignment.get("meeting_id", 0)
):
raise ActionException(
"It is not permitted to remove a candidate from a finished assignment!"
if not self.internal:
assignment_candidate = self.datastore.get(
fqid_from_collection_and_id(self.model.collection, instance["id"]),
mapped_fields=["assignment_id"],
)
assignment = self.datastore.get(
fqid_from_collection_and_id(
"assignment", assignment_candidate["assignment_id"]
),
mapped_fields=["phase", "meeting_id"],
lock_result=False,
)
if assignment.get("phase") == "finished" and not self.is_meeting_deleted(
assignment.get("meeting_id", 0)
):
raise ActionException(
"It is not permitted to remove a candidate from a finished assignment!"
)
return instance
4 changes: 4 additions & 0 deletions tests/system/action/assignment/test_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def test_delete_correct_cascading(self) -> None:
"agenda_item_id": 333,
"projection_ids": [1],
"meeting_id": 110,
"phase": "finished",
"candidate_ids": [1111],
},
"list_of_speakers/222": {
"closed": False,
Expand All @@ -46,6 +48,7 @@ def test_delete_correct_cascading(self) -> None:
"current_projection_ids": [1],
"meeting_id": 110,
},
"assignment_candidate/1111": {"assignment_id": 111, "meeting_id": 110},
}
)
response = self.request("assignment.delete", {"id": 111})
Expand All @@ -54,6 +57,7 @@ def test_delete_correct_cascading(self) -> None:
self.assert_model_deleted("agenda_item/333")
self.assert_model_deleted("list_of_speakers/222")
self.assert_model_deleted("projection/1")
self.assert_model_deleted("assignment_candidate/1111")

def test_delete_wrong_id(self) -> None:
self.set_models(
Expand Down
29 changes: 29 additions & 0 deletions tests/system/action/user/test_merge_together.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,35 @@ def test_merge_with_assignment_candidates(self) -> None:
for id_ in range(2, 10):
self.assert_history_information(f"assignment/{id_}", ["Candidates merged"])

def test_merge_with_assignment_candidates_in_finished_assignment(self) -> None:
self.set_models(
{
"meeting/1": {
"assignment_ids": [11],
"assignment_candidate_ids": [112, 114],
},
"assignment/11": {
"meeting_id": 1,
"phase": "finished",
"candidate_ids": [112, 114],
},
"assignment_candidate/112": {
"meeting_id": 1,
"assignment_id": 11,
"meeting_user_id": 12,
},
"assignment_candidate/114": {
"meeting_id": 1,
"assignment_id": 11,
"meeting_user_id": 14,
},
"meeting_user/12": {"assignment_candidate_ids": [112]},
"meeting_user/14": {"assignment_candidate_ids": [114]},
}
)
response = self.request("user.merge_together", {"id": 2, "user_ids": [4]})
self.assert_status_code(response, 200)

def test_merge_with_motion_working_group_speakers(self) -> None:
self.base_assignment_or_motion_model_test(
"motion", "motion_working_group_speaker"
Expand Down