Skip to content

Commit

Permalink
Ensure speaker.delete only resets projector countdown with active spe…
Browse files Browse the repository at this point in the history
…akers (#2657) (#2667)

* Ensure speaker.delete only resets projector countdown with active speakers

* Style

* Switch values

Co-authored-by: luisa-beerboom <[email protected]>
  • Loading branch information
1 parent 4e70bea commit e36dca4
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/actions/speaker.delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

## Action
Deletes the given speaker.
Resets the projector_countdown if he was speaking.

## Permissions
If the `speaker/meeting_user_id` doesn't belong to the request user, he needs `list_of_speakers.can_manage`
Expand Down
3 changes: 2 additions & 1 deletion openslides_backend/action/actions/speaker/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
and not speaker.get("pause_time")
):
self.decrease_structure_level_countdown(self.end_time, speaker)
self.control_los_countdown(speaker["meeting_id"], CountdownCommand.RESET)
if speaker.get("begin_time") and not speaker.get("end_time"):
self.control_los_countdown(speaker["meeting_id"], CountdownCommand.RESET)
return super().update_instance(instance)
70 changes: 70 additions & 0 deletions tests/system/action/speaker/test_delete.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from math import floor
from time import time
from typing import Any

from openslides_backend.action.mixins.delegation_based_restriction_mixin import (
Expand Down Expand Up @@ -399,3 +401,71 @@ def test_with_paused_structure_level_speaker(self) -> None:
},
)
assert sllos["remaining_time"] == 18

def add_coupled_countdown(self) -> int:
"""Returns the current date that was used to set the countdown_time"""
now = floor(time())
self.set_models(
{
"meeting/1": {
"list_of_speakers_couple_countdown": True,
"list_of_speakers_countdown_id": 75,
},
"projector_countdown/75": {
"running": True,
"default_time": 200,
"countdown_time": now + 100,
"meeting_id": 1,
},
"speaker/890": {
"begin_time": now + 100,
},
}
)
return now

def test_delete_update_countdown(self) -> None:
self.set_models(self.permission_test_models)
self.add_coupled_countdown()
response = self.request("speaker.delete", {"id": 890})
self.assert_status_code(response, 200)
countdown = self.get_model("projector_countdown/75")
assert countdown.get("running") is False
self.assertAlmostEqual(countdown["countdown_time"], 100, delta=200)

def test_delete_dont_update_countdown(self) -> None:
self.set_models(self.permission_test_models)
self.set_models(
{
"meeting/1": {
"speaker_ids": [890, 891],
"meeting_user_ids": [7, 8],
},
"user/8": {
"username": "test_username2",
"meeting_user_ids": [8],
"is_active": True,
"default_password": DEFAULT_PASSWORD,
"password": self.auth.hash(DEFAULT_PASSWORD),
},
"meeting_user/8": {"meeting_id": 1, "user_id": 8, "speaker_ids": [891]},
"list_of_speakers/23": {"speaker_ids": [890, 891]},
"speaker/891": {
"meeting_user_id": 8,
"list_of_speakers_id": 23,
"meeting_id": 1,
},
}
)
now = self.add_coupled_countdown()
response = self.request("speaker.delete", {"id": 891})
self.assert_status_code(response, 200)
countdown = self.assert_model_exists(
"projector_countdown/75",
{
"running": True,
"default_time": 200,
"meeting_id": 1,
},
)
self.assertAlmostEqual(countdown["countdown_time"], now, delta=200)

0 comments on commit e36dca4

Please sign in to comment.