-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove participant presence status when removed from meeting (#2730)
- Loading branch information
Showing
10 changed files
with
238 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"_migration_index": 62, | ||
"_migration_index": 63, | ||
"gender":{ | ||
"1":{ | ||
"id": 1, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"_migration_index": 62, | ||
"_migration_index": 63, | ||
"gender":{ | ||
"1":{ | ||
"id": 1, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
openslides_backend/migrations/migrations/0062_unset_presence_of_removed_users.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from collections import defaultdict | ||
|
||
from datastore.migrations import BaseModelMigration | ||
from datastore.reader.core import GetManyRequestPart | ||
from datastore.writer.core import BaseRequestEvent, RequestUpdateEvent | ||
|
||
from openslides_backend.shared.patterns import fqid_from_collection_and_id | ||
|
||
from ...shared.filters import And, FilterOperator | ||
|
||
|
||
class Migration(BaseModelMigration): | ||
""" | ||
This migration removes the presence status if the user is not part of the meeting anymore. | ||
""" | ||
|
||
target_migration_index = 63 | ||
|
||
def migrate_models(self) -> list[BaseRequestEvent] | None: | ||
present_users_per_meeting: dict[int, list[int]] = defaultdict(list) | ||
meetings_per_present_user: dict[int, list[int]] = defaultdict(list) | ||
|
||
meeting_users = self.reader.filter( | ||
"meeting_user", | ||
And( | ||
FilterOperator("group_ids", "=", "[]"), | ||
FilterOperator("meta_deleted", "!=", True), | ||
), | ||
["user_id", "meeting_id"], | ||
) | ||
for meeting_user in meeting_users.values(): | ||
user_id = meeting_user["user_id"] | ||
meeting_id = meeting_user["meeting_id"] | ||
meetings_per_present_user[user_id].append(meeting_id) | ||
present_users_per_meeting[meeting_id].append(user_id) | ||
|
||
meetings = self.reader.get_many( | ||
[ | ||
GetManyRequestPart( | ||
"meeting", | ||
[meeting_id for meeting_id in present_users_per_meeting], | ||
["present_user_ids"], | ||
) | ||
] | ||
).get("meeting", dict()) | ||
users = self.reader.get_many( | ||
[ | ||
GetManyRequestPart( | ||
"user", | ||
[present_user_id for present_user_id in meetings_per_present_user], | ||
["is_present_in_meeting_ids"], | ||
) | ||
] | ||
).get("user", dict()) | ||
return [ | ||
*[ | ||
RequestUpdateEvent( | ||
fqid_from_collection_and_id("meeting", meeting_id), | ||
{ | ||
"present_user_ids": [ | ||
id_ | ||
for id_ in meetings.get(meeting_id, dict()).get( | ||
"present_user_ids", [] | ||
) | ||
if id_ not in user_ids | ||
] | ||
}, | ||
) | ||
for meeting_id, user_ids in present_users_per_meeting.items() | ||
if meetings | ||
], | ||
*[ | ||
RequestUpdateEvent( | ||
fqid_from_collection_and_id("user", user_id), | ||
{ | ||
"is_present_in_meeting_ids": [ | ||
id_ | ||
for id_ in users.get(user_id, dict()).get( | ||
"is_present_in_meeting_ids", [] | ||
) | ||
if id_ not in meeting_ids | ||
] | ||
}, | ||
) | ||
for user_id, meeting_ids in meetings_per_present_user.items() | ||
], | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
tests/system/migrations/test_0062_unset_presence_of_removed_users.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from typing import Any | ||
|
||
|
||
def create_data() -> dict[str, dict[str, Any]]: | ||
return { | ||
"meeting/1": { | ||
"id": 1, | ||
"name": "meeting name", | ||
"present_user_ids": [1, 3, 2], | ||
"meeting_user_ids": [3, 4, 5], | ||
"group_ids": [10], | ||
}, | ||
"meeting/2": { | ||
"id": 1, | ||
"name": "meeting name", | ||
"present_user_ids": [2], | ||
"meeting_user_ids": [6], | ||
}, | ||
"user/1": { | ||
"id": 1, | ||
"username": "correct_user", | ||
"is_present_in_meeting_ids": [1], | ||
"meeting_user_ids": [3], | ||
}, | ||
"user/2": { | ||
"id": 2, | ||
"username": "wrong_user", | ||
"is_present_in_meeting_ids": [2, 1], | ||
# meeting users do exist after user left meeting but have no group ids | ||
"meeting_user_ids": [ | ||
5, | ||
6, | ||
], | ||
}, | ||
"user/3": { | ||
"id": 3, | ||
"username": "correct_user", | ||
"is_present_in_meeting_ids": [1], | ||
"meeting_user_ids": [4], | ||
}, | ||
"meeting_user/3": {"id": 3, "user_id": 1, "meeting_id": 1, "group_ids": [10]}, | ||
"meeting_user/4": {"id": 4, "user_id": 3, "meeting_id": 1, "group_ids": [10]}, | ||
"meeting_user/5": {"id": 5, "user_id": 2, "meeting_id": 1, "group_ids": []}, | ||
"meeting_user/6": {"id": 6, "user_id": 2, "meeting_id": 2, "group_ids": []}, | ||
"group/10": {"id": 10, "meeting_user_ids": [3, 4], "meeting_id": 1}, | ||
} | ||
|
||
|
||
def test_migration_both_ways(write, finalize, assert_model): | ||
data = create_data() | ||
for fqid, fields in data.items(): | ||
write({"type": "create", "fqid": fqid, "fields": fields}) | ||
|
||
finalize("0062_unset_presence_of_removed_users") | ||
|
||
data["meeting/1"]["present_user_ids"] = [1, 3] | ||
data["meeting/2"]["present_user_ids"] = [] | ||
data["user/2"]["is_present_in_meeting_ids"] = [] | ||
|
||
for fqid, fields in data.items(): | ||
assert_model(fqid, fields) | ||
|
||
|
||
def test_migration_one_way(write, finalize, assert_model): | ||
data = create_data() | ||
data["meeting/1"]["present_user_ids"] = [1, 3] | ||
data["meeting/2"]["present_user_ids"] = [] | ||
|
||
for fqid, fields in data.items(): | ||
write({"type": "create", "fqid": fqid, "fields": fields}) | ||
|
||
finalize("0062_unset_presence_of_removed_users") | ||
|
||
data["user/2"]["is_present_in_meeting_ids"] = [] | ||
|
||
for fqid, fields in data.items(): | ||
assert_model(fqid, fields) | ||
|
||
|
||
def test_migration_other_way(write, finalize, assert_model): | ||
data = create_data() | ||
data["user/2"]["is_present_in_meeting_ids"] = [] | ||
|
||
for fqid, fields in data.items(): | ||
write({"type": "create", "fqid": fqid, "fields": fields}) | ||
|
||
finalize("0062_unset_presence_of_removed_users") | ||
|
||
data["meeting/1"]["present_user_ids"] = [1, 3] | ||
data["meeting/2"]["present_user_ids"] = [] | ||
|
||
for fqid, fields in data.items(): | ||
assert_model(fqid, fields) |