-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deleted participants stay present in meeting #2730
Merged
hjanott
merged 6 commits into
OpenSlides:main
from
hjanott:2729_deleted_participants_stay_present
Nov 25, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7b5f725
fix error
hjanott 3f0a7ec
write migration
hjanott c389c81
move fix to same condition place, general code improvements
hjanott 9536209
refactor migration
hjanott 559fd18
Merge branch 'main' into 2729_deleted_participants_stay_present
hjanott eef214f
Merge branch 'main' into 2729_deleted_participants_stay_present
hjanott File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I looked at the source code
check_meeting_and_users
is called every time if a user action with the mixin is called. I think, you want to call a presence cleaning only if the user is removed from an meeting or deleted.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've found that at the same condition the 'ConditionalSpeakerCascadeMixin' is executing its 'update_instance'. So I moved it there. I propose to rename this mixin to 'ConditionalMeetingUserCascadeMixin'