Skip to content

Commit 01443a2

Browse files
Remove the meeting_user when removing a user from a meeting (#3206)
* Require groups in meeting users, fix most tests * Make user.update delete meeting_users * Make changes for motions * Make changes for chat messages * Make changes for personal note * Update docs * Write and test migration * motion_supporter test code * Add test for issue 3133
1 parent ba5cb5b commit 01443a2

33 files changed

+2180
-269
lines changed

data/example-data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"_migration_index": 74,
2+
"_migration_index": 75,
33
"gender":{
44
"1":{
55
"id": 1,

data/initial-data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"_migration_index": 74,
2+
"_migration_index": 75,
33
"gender":{
44
"1":{
55
"id": 1,

docs/actions/chat_message.create.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ Creates a new `chat_message` for the `chat_group` given by the key `chat_group_i
1414

1515
## Permission
1616

17-
Every user, who is in one of the write groups of a chat group, or has the permission `chat.can_manage` can create a `chat_message`.
17+
Every user, who is in one of the write groups of a chat group, or has the permission `chat.can_manage` can create a `chat_message`.
18+
User also needs to be part of the meeting.

docs/actions/motion.create.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
// Optional special fields, see notes below
2828
workflow_id: Id;
29-
submitter_ids: Id[];
29+
submitter_meeting_user_ids: Id[];
3030

3131
// Non-model fields for customizing the agenda item creation, optional
3232
agenda_create: boolean;
@@ -58,7 +58,7 @@ This is the logic for other fields depending on the motion type:
5858
There are some fields that need special attention:
5959
- `workflow_id`: If it is given, the motion's state is set to the workflow's first state. The workflow must be from the same meeting. If the field is not given, one of the three default (`meeting/motions_default_workflow_id` or `meeting/motions_default_amendment_workflow_id`) workflows is used depending on the type of the motion to create.
6060
- `additional_submitter` a text field where text-based submitter information may be entered. Cannot be set unless `meeting/motions_create_enable_additional_submitter_text` is `true`. Requires permissions `Motion.CAN_CREATE` and `Motion.CAN_MANAGE_METADATA`.
61-
- `submitter_ids`: These are **user ids** and not ids of the `motion_submitter` model. If nothing is given (`[]`) and the field `additional_submitter` isn't filled, the request user's id is used. For each id in the list a `motion_submitter` model is created. The weight must be set to the order of the given list. Requires permissions `Motion.CAN_CREATE`, `Motion.CAN_MANAGE_METADATA` and `User.CAN_SEE`.
61+
- `submitter_meeting_user_ids`: These are ids of the meeting users that should get a `motion_submitter` model. Can be left empty. The weight of the new submitters is set to the order of the given list. Requires permissions `Motion.CAN_CREATE`, `Motion.CAN_MANAGE_METADATA` and `User.CAN_SEE` (the latter two only if not setting oneself).
6262
- `agenda_*`: See [Agenda](https://github.com/OpenSlides/OpenSlides/wiki/Agenda#additional-fields-during-creation-of-agenda-content-objects).
6363

6464
Other things to do when creating motions:

docs/actions/user.update.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Updates a user.
8585
Note: `is_present_in_meeting_ids` is not available in update, since there is no possibility to partially update this field. This can be done via [user.set_present](user.set_present.md).
8686

8787
If the user is removed from all groups of the meeting, all his unstarted speakers in that meeting will be deleted.
88+
His meeting_user for that meeting will also be deleted.
8889

8990
If the user was the last member of the meetings admin group and he happens to be removed from the latter through this action, as long as the meeting is not a template, there will be an error.
9091

meta

Submodule meta updated 1 file

openslides_backend/action/actions/chat_message/create.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from ....models.models import ChatMessage
55
from ....permissions.permission_helper import has_perm
66
from ....permissions.permissions import Permissions
7-
from ....shared.exceptions import PermissionDenied
7+
from ....shared.exceptions import ActionException, PermissionDenied
88
from ....shared.patterns import fqid_from_collection_and_id
99
from ...mixins.create_action_with_inferred_meeting import (
1010
CreateActionWithInferredMeeting,
@@ -28,9 +28,13 @@ class ChatMessageCreate(MeetingUserHelperMixin, CreateActionWithInferredMeeting)
2828

2929
def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
3030
instance = super().update_instance(instance)
31-
instance["meeting_user_id"] = self.create_or_get_meeting_user(
32-
instance["meeting_id"], self.user_id
33-
)
31+
instance["meeting_user_id"] = (
32+
self.get_meeting_user(instance["meeting_id"], self.user_id, ["id"]) or {}
33+
).get("id")
34+
if not instance.get("meeting_user_id"):
35+
raise ActionException(
36+
"Cannot create chat message: You are not a participant of the meeting."
37+
)
3438
instance["created"] = round(time())
3539
return instance
3640

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from openslides_backend.shared.patterns import fqid_from_collection_and_id
2+
from openslides_backend.shared.typing import HistoryInformation
3+
4+
from ....models.models import MeetingUser
5+
from ...generics.delete import DeleteAction
6+
from ...util.default_schema import DefaultSchema
7+
8+
9+
class MeetingUserBaseDelete(DeleteAction):
10+
"""
11+
Base action to delete a meeting user.
12+
"""
13+
14+
model = MeetingUser()
15+
schema = DefaultSchema(MeetingUser()).get_delete_schema()
16+
17+
def get_history_information(self) -> HistoryInformation | None:
18+
users = self.get_instances_with_fields(["user_id", "meeting_id"])
19+
return {
20+
fqid_from_collection_and_id("user", user["user_id"]): [
21+
"Participant removed from meeting {}",
22+
fqid_from_collection_and_id("meeting", user["meeting_id"]),
23+
]
24+
for user in users
25+
}

openslides_backend/action/actions/meeting_user/delete.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,21 @@
11
from typing import Any
22

33
from openslides_backend.shared.patterns import fqid_from_collection_and_id
4-
from openslides_backend.shared.typing import HistoryInformation
54

6-
from ....models.models import MeetingUser
7-
from ...generics.delete import DeleteAction
85
from ...util.action_type import ActionType
9-
from ...util.default_schema import DefaultSchema
106
from ...util.register import register_action
117
from ..user.conditional_speaker_cascade_mixin import (
128
ConditionalSpeakerCascadeMixinHelper,
139
)
10+
from .base_delete import MeetingUserBaseDelete
1411

1512

1613
@register_action("meeting_user.delete", action_type=ActionType.BACKEND_INTERNAL)
17-
class MeetingUserDelete(ConditionalSpeakerCascadeMixinHelper, DeleteAction):
14+
class MeetingUserDelete(ConditionalSpeakerCascadeMixinHelper, MeetingUserBaseDelete):
1815
"""
1916
Action to delete a meeting user.
2017
"""
2118

22-
model = MeetingUser()
23-
schema = DefaultSchema(MeetingUser()).get_delete_schema()
24-
25-
def get_history_information(self) -> HistoryInformation | None:
26-
users = self.get_instances_with_fields(["user_id", "meeting_id"])
27-
return {
28-
fqid_from_collection_and_id("user", user["user_id"]): [
29-
"Participant removed from meeting {}",
30-
fqid_from_collection_and_id("meeting", user["meeting_id"]),
31-
]
32-
for user in users
33-
}
34-
3519
def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
3620
meeting_user = self.datastore.get(
3721
fqid_from_collection_and_id("meeting_user", instance["id"]),

openslides_backend/action/actions/meeting_user/history_mixin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def handle_group_updates(
255255
group_information: list[str] = []
256256
if added and removed:
257257
group_information.append("Groups changed")
258-
else:
258+
elif added or removed:
259259
if added:
260260
group_information.append("Participant added to")
261261
else:
@@ -272,7 +272,8 @@ def handle_group_updates(
272272
group_information.append(
273273
fqid_from_collection_and_id("meeting", meeting_id)
274274
)
275-
instance_information.append(tuple(group_information))
275+
if group_information:
276+
instance_information.append(tuple(group_information))
276277

277278
def handle_delegations(
278279
self,

0 commit comments

Comments
 (0)