Skip to content

Commit

Permalink
Make projector.add_to_preview use meeting_mediafile (#2606)
Browse files Browse the repository at this point in the history
* Make projector.add_to_preview use meeting_mediafile if a mediafile content object is given

* Remove unnecessary variable
  • Loading branch information
luisa-beerboom authored Sep 10, 2024
1 parent 0e81778 commit becedbc
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 1 deletion.
30 changes: 29 additions & 1 deletion openslides_backend/action/actions/projector/add_to_preview.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
from typing import Any, cast

from ....models.models import Projection, Projector
from ....permissions.permissions import Permissions
from ....shared.filters import And, FilterOperator
from ....shared.patterns import collection_and_id_from_fqid, fqid_from_collection_and_id
from ....shared.schema import id_list_schema
from ...generics.update import UpdateAction
from ...mixins.meeting_mediafile_helper import (
get_meeting_mediafile_id_or_create_payload,
)
from ...mixins.weight_mixin import WeightMixin
from ...util.default_schema import DefaultSchema
from ...util.register import register_action
from ...util.typing import ActionData
from ..meeting_mediafile.create import MeetingMediafileCreate
from ..projection.create import ProjectionCreate


Expand All @@ -27,6 +34,27 @@ class ProjectorAddToPreview(WeightMixin, UpdateAction):

def get_updated_instances(self, action_data: ActionData) -> ActionData:
for instance in action_data:
meeting_id = instance["meeting_id"]
fqid_content_object = instance["content_object_id"]
content_object_collection, content_object_id = collection_and_id_from_fqid(
fqid_content_object
)
if content_object_collection == "mediafile":
meeting_mediafile = get_meeting_mediafile_id_or_create_payload(
self.datastore, meeting_id, content_object_id, lock_result=False
)
if not isinstance(meeting_mediafile, int):
create_result = self.execute_other_action(
MeetingMediafileCreate, [meeting_mediafile]
)
meeting_mediafile_id: int = cast(
list[dict[str, Any]], create_result
)[0]["id"]
else:
meeting_mediafile_id = meeting_mediafile
instance["content_object_id"] = fqid_from_collection_and_id(
"meeting_mediafile", meeting_mediafile_id
)
# add the preview projections
for projector_id in instance["ids"]:
filter = And(
Expand All @@ -35,7 +63,7 @@ def get_updated_instances(self, action_data: ActionData) -> ActionData:
)
weight = self.get_weight(filter, "projection")
data = {
"meeting_id": instance["meeting_id"],
"meeting_id": meeting_id,
"preview_projector_id": projector_id,
"weight": weight,
"content_object_id": instance["content_object_id"],
Expand Down
113 changes: 113 additions & 0 deletions tests/system/action/projector/test_add_to_preview.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from openslides_backend.permissions.permissions import Permissions
from openslides_backend.shared.util import ONE_ORGANIZATION_FQID, ONE_ORGANIZATION_ID
from tests.system.action.base import BaseActionTestCase


class ProjectorAddToPreview(BaseActionTestCase):
def setUp(self) -> None:
super().setUp()
self.create_meeting()
self.set_models(
{
"meeting/1": {"is_active_in_organization_id": 1},
Expand Down Expand Up @@ -193,3 +195,114 @@ def test_add_to_preview_permission_locked_meeting(self) -> None:
"meeting_id": 1,
},
)

def test_mediafile_as_content_object(self) -> None:
self.set_models(
{
"mediafile/1": {
"owner_id": ONE_ORGANIZATION_FQID,
"meeting_mediafile_ids": [2],
"published_to_meetings_in_organization_id": ONE_ORGANIZATION_ID,
},
"meeting_mediafile/2": {
"meeting_id": 1,
"mediafile_id": 1,
"access_group_ids": [1],
"inherited_access_group_ids": [1],
"is_public": False,
},
}
)
response = self.request(
"projector.add_to_preview",
{"ids": [1], "content_object_id": "mediafile/1", "meeting_id": 1},
)
self.assert_status_code(response, 200)
self.assert_model_exists(
"projection/13",
{
"content_object_id": "meeting_mediafile/2",
"preview_projector_id": 1,
},
)

def test_mediafile_as_content_object_generate_meeting_mediafile(self) -> None:
self.set_models(
{
"mediafile/1": {
"owner_id": ONE_ORGANIZATION_FQID,
"published_to_meetings_in_organization_id": ONE_ORGANIZATION_ID,
},
}
)
response = self.request(
"projector.add_to_preview",
{"ids": [2], "content_object_id": "mediafile/1", "meeting_id": 1},
)
self.assert_status_code(response, 200)
self.assert_model_exists(
"meeting_mediafile/1",
{
"meeting_id": 1,
"mediafile_id": 1,
"access_group_ids": [2],
"inherited_access_group_ids": [2],
"is_public": False,
"projection_ids": [13],
},
)
self.assert_model_exists(
"projection/13",
{
"content_object_id": "meeting_mediafile/1",
"preview_projector_id": 2,
},
)

def test_meeting_mediafile_as_content_object(self) -> None:
self.set_models(
{
"mediafile/1": {
"owner_id": ONE_ORGANIZATION_FQID,
"meeting_mediafile_ids": [2],
"published_to_meetings_in_organization_id": ONE_ORGANIZATION_ID,
},
"meeting_mediafile/2": {
"meeting_id": 1,
"mediafile_id": 1,
"access_group_ids": [1],
"inherited_access_group_ids": [1],
"is_public": False,
},
}
)
response = self.request(
"projector.add_to_preview",
{"ids": [1], "content_object_id": "meeting_mediafile/2", "meeting_id": 1},
)
self.assert_status_code(response, 200)
self.assert_model_exists(
"projection/13",
{
"content_object_id": "meeting_mediafile/2",
"preview_projector_id": 1,
},
)

def test_unpublished_mediafile_as_content_object(self) -> None:
self.set_models(
{
"mediafile/1": {
"owner_id": ONE_ORGANIZATION_FQID,
},
}
)
response = self.request(
"projector.add_to_preview",
{"ids": [2], "content_object_id": "mediafile/1", "meeting_id": 1},
)
self.assert_status_code(response, 400)
assert (
"No meeting_mediafile creation possible: Mediafile is not published."
in response.json["message"]
)

0 comments on commit becedbc

Please sign in to comment.