Skip to content

Commit

Permalink
Fix meeting.clone set active code (#2110)
Browse files Browse the repository at this point in the history
* Fix meting.clone set active code

* Implement data repair migration

* Fix tests
  • Loading branch information
luisa-beerboom authored Jan 17, 2024
1 parent 60c8359 commit d655bba
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 4 deletions.
2 changes: 1 addition & 1 deletion global/data/example-data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"_migration_index": 48,
"_migration_index": 49,
"organization": {
"1": {
"id": 1,
Expand Down
2 changes: 1 addition & 1 deletion global/data/initial-data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"_migration_index": 48,
"_migration_index": 49,
"organization": {
"1": {
"id": 1,
Expand Down
1 change: 1 addition & 0 deletions openslides_backend/action/actions/meeting/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def update_instance(self, instance: Dict[str, Any]) -> Dict[str, Any]:

# set active
meeting["is_active_in_organization_id"] = ONE_ORGANIZATION_ID
meeting.pop("is_archived_in_organization_id", 0)
meeting["template_for_organization_id"] = (
ONE_ORGANIZATION_ID if set_as_template else None
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from typing import List, Optional

from datastore.migrations import BaseModelMigration
from datastore.shared.util import fqid_from_collection_and_id
from datastore.writer.core import BaseRequestEvent, RequestUpdateEvent


class Migration(BaseModelMigration):
"""
This migration finds and fixes broken relations created by the fact that, up unil now,
meeting.clone could create meetings that were active and archived at the same time.
"""

target_migration_index = 49
fields = ["set_workflow_timestamp", "allow_motion_forwarding"]

def migrate_models(self) -> Optional[List[BaseRequestEvent]]:
events: List[BaseRequestEvent] = []
db_models = self.reader.get_all("meeting")
archived_ids: List[int] = []
active_ids: List[int] = []
for id, model in db_models.items():
if model.get("is_archived_in_organization_id"):
if model.get("is_active_in_organization_id"):
events.append(
RequestUpdateEvent(
fqid_from_collection_and_id("meeting", id),
{"is_archived_in_organization_id": None},
)
)
active_ids.append(id)
else:
archived_ids.append(id)
else:
active_ids.append(id)
events.append(
RequestUpdateEvent(
fqid_from_collection_and_id("organization", 1),
{
"active_meeting_ids": active_ids,
"archived_meeting_ids": archived_ids,
},
)
)
return events
12 changes: 10 additions & 2 deletions tests/system/action/meeting/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,12 +1210,20 @@ def test_activate_archived_meeting(self) -> None:
self.test_models[ONE_ORGANIZATION_FQID]["limit_of_meetings"] = 2
self.test_models[ONE_ORGANIZATION_FQID]["active_meeting_ids"] = [3]
self.test_models["meeting/1"]["is_active_in_organization_id"] = None
self.test_models["meeting/1"]["is_archived_in_organization_id"] = 1
self.test_models[ONE_ORGANIZATION_FQID]["archived_meeting_ids"] = [1]
self.set_models(self.test_models)

response = self.request("meeting.clone", {"meeting_id": 1})
self.assert_status_code(response, 200)
self.assert_model_exists("meeting/2", {"is_active_in_organization_id": 1})
self.assert_model_exists(ONE_ORGANIZATION_FQID, {"active_meeting_ids": [3, 2]})
self.assert_model_exists(
"meeting/2",
{"is_active_in_organization_id": 1, "is_archived_in_organization_id": None},
)
self.assert_model_exists(
ONE_ORGANIZATION_FQID,
{"active_meeting_ids": [3, 2], "archived_meeting_ids": [1]},
)

def test_limit_of_meetings_ok(self) -> None:
self.test_models[ONE_ORGANIZATION_FQID]["limit_of_meetings"] = 2
Expand Down
132 changes: 132 additions & 0 deletions tests/system/migrations/test_0048_fix_broken_meeting_clones.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
def test_migration(write, finalize, assert_model):
write(
{
"type": "create",
"fqid": "organization/1",
"fields": {
"id": 1,
"archived_meeting_ids": [101],
"active_meeting_ids": [100, 102],
"committee_ids": [10],
},
},
{
"type": "create",
"fqid": "committee/10",
"fields": {
"id": 10,
"organization_id": 1,
"meeting_ids": [100, 101, 102, 103],
},
},
{
"type": "create",
"fqid": "meeting/100",
"fields": {
"id": 100,
"name": "Active",
"committee_id": 10,
"is_active_in_organization_id": 1,
},
},
{
"type": "create",
"fqid": "meeting/101",
"fields": {
"id": 101,
"name": "Archived",
"committee_id": 10,
"is_archived_in_organization_id": 1,
},
},
{
"type": "create",
"fqid": "meeting/102",
"fields": {
"id": 102,
"name": "Copy of archived",
"committee_id": 10,
"is_active_in_organization_id": 1,
"is_archived_in_organization_id": 1,
},
},
{
"type": "create",
"fqid": "meeting/103",
"fields": {
"id": 103,
"name": "Archived copy of archived",
"committee_id": 10,
"is_archived_in_organization_id": 1,
},
},
{
"type": "create",
"fqid": "meeting/104",
"fields": {
"id": 104,
"name": "Archived copy of archived2",
"committee_id": 10,
"is_archived_in_organization_id": 1,
},
},
)
write({"type": "delete", "fqid": "meeting/104"})

finalize("0048_fix_broken_meeting_clones")

assert_model(
"organization/1",
{
"id": 1,
"committee_ids": [10],
"active_meeting_ids": [100, 102],
"archived_meeting_ids": [101, 103],
},
)
assert_model(
"meeting/100",
{
"id": 100,
"name": "Active",
"committee_id": 10,
"is_active_in_organization_id": 1,
},
)
assert_model(
"meeting/101",
{
"id": 101,
"name": "Archived",
"committee_id": 10,
"is_archived_in_organization_id": 1,
},
)
assert_model(
"meeting/102",
{
"id": 102,
"name": "Copy of archived",
"committee_id": 10,
"is_active_in_organization_id": 1,
},
)
assert_model(
"meeting/103",
{
"id": 103,
"name": "Archived copy of archived",
"committee_id": 10,
"is_archived_in_organization_id": 1,
},
)
assert_model(
"meeting/104",
{
"id": 104,
"name": "Archived copy of archived2",
"committee_id": 10,
"is_archived_in_organization_id": 1,
"meta_deleted": True,
},
)

0 comments on commit d655bba

Please sign in to comment.