Skip to content

Commit

Permalink
Add option to project without side effects (#2464)
Browse files Browse the repository at this point in the history
* Add option to project without side effects

* Fix black

* Rename option, add test

* Fix test
  • Loading branch information
bastianjoel authored Jun 5, 2024
1 parent b1d707e commit 18945c5
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 28 deletions.
34 changes: 34 additions & 0 deletions docs/actions/projector.project.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## Payload
```
{
// Required
content_object_id: Fqid;
meeting_id: Id;
ids: Id[]
// Optional
options: Object
stable: boolean
type: string
keep_active_projections: boolean
}
```

## Action
Creates a new projection projection.

## Parameters
*ids*: The projectors where the projection will be displayed.

*type*: Defines the type of the projection.

*stable*: If set to a non true value all current non stable projections of the selected
projectors are moved to history.

*keep_active_projections*: If set to true projections with the same type will not be removed
from projectors not specified in `ids`.

*options*: Can contain arbitrary data that will be added to the projection data.

## Permissions
The user needs `projector.can_manage`.
65 changes: 37 additions & 28 deletions openslides_backend/action/actions/projector/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class ProjectorProject(WeightMixin, SingularActionMixin, UpdateAction):
additional_required_fields={
"ids": id_list_schema,
},
additional_optional_fields={
"keep_active_projections": {
"type": "boolean",
}
},
title="Projector project schema",
)
permission = Permissions.Projector.CAN_MANAGE
Expand Down Expand Up @@ -86,34 +91,38 @@ def move_equal_projections_to_history_or_unset(
)
for projection_id in result:
if result[projection_id]["current_projector_id"]:
# Unset stable equal projections
if result[projection_id]["stable"]:
action_del_data = [{"id": int(projection_id)}]
self.execute_other_action(ProjectionDelete, action_del_data)
# Move unstable equal projections to history
else:
filter_ = And(
FilterOperator(
"meeting_id", "=", result[projection_id]["meeting_id"]
),
FilterOperator(
"history_projector_id",
"=",
result[projection_id]["current_projector_id"],
),
)
weight = self.get_weight(filter_, "projection")
action_data = [
{
"id": int(projection_id),
"current_projector_id": None,
"history_projector_id": result[projection_id][
"current_projector_id"
],
"weight": weight,
}
]
self.execute_other_action(ProjectionUpdate, action_data)
if (
not instance.get("keep_active_projections")
or result[projection_id]["current_projector_id"] in instance["ids"]
):
# Unset stable equal projections
if result[projection_id]["stable"]:
action_del_data = [{"id": int(projection_id)}]
self.execute_other_action(ProjectionDelete, action_del_data)
# Move unstable equal projections to history
else:
filter_ = And(
FilterOperator(
"meeting_id", "=", result[projection_id]["meeting_id"]
),
FilterOperator(
"history_projector_id",
"=",
result[projection_id]["current_projector_id"],
),
)
weight = self.get_weight(filter_, "projection")
action_data = [
{
"id": int(projection_id),
"current_projector_id": None,
"history_projector_id": result[projection_id][
"current_projector_id"
],
"weight": weight,
}
]
self.execute_other_action(ProjectionUpdate, action_data)

def move_unstable_projections_to_history(self, instance: dict[str, Any]) -> None:
for projector_id in instance["ids"]:
Expand Down
40 changes: 40 additions & 0 deletions tests/system/action/projector/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,46 @@ def test_try_to_store_second_stable_projection(self) -> None:
)
self.assert_model_deleted("projection/106")

def test_try_to_store_second_stable_projection_keep_active(self) -> None:
response = self.request(
"projector.project",
{
"ids": [65],
"meeting_id": 1,
"content_object_id": "assignment/453",
"stable": True,
"keep_active_projections": True,
},
)
self.assert_status_code(response, 200)
self.assert_model_exists(
"projector/65", {"meeting_id": 1, "current_projection_ids": [112]}
)
self.assert_model_exists(
"projector/75",
{"meeting_id": 1, "current_projection_ids": [110, 111]},
)

def test_try_to_store_second_stable_projection_no_keep_active(self) -> None:
response = self.request(
"projector.project",
{
"ids": [65],
"meeting_id": 1,
"content_object_id": "assignment/453",
"stable": True,
"keep_active_projections": False,
},
)
self.assert_status_code(response, 200)
self.assert_model_exists(
"projector/65", {"meeting_id": 1, "current_projection_ids": [112]}
)
self.assert_model_exists(
"projector/75",
{"meeting_id": 1, "current_projection_ids": [110]},
)

def test_meeting_as_content_object_ok(self) -> None:
response = self.request(
"projector.project",
Expand Down

0 comments on commit 18945c5

Please sign in to comment.