Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/actions/motion_comment.create.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Creates a new comment. The comment section and motion must belong to the same meeting. `(motion_id, section_id)` must be unique.

## Permissions
The request user must have `motion.can_see`. In addition the request user
The request user must have `motion.can_see`. In case the `motion_state` of the referenced `motion`, the request user must fulfill at least one of those as well. In addition the request user
* needs to be in at least one of the groups in `motion_comment_section/write_group_ids`. Note that the meeting admin is implicit in these groups or
* the `motion_comment_section.submitter_can_write` flag, referenced by the `section_id`, is set and
the request user is one of the submitters of the motion. The request user also must have the
Expand Down
2 changes: 1 addition & 1 deletion docs/actions/motion_comment.delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Deletes the comment.

## Permissions
The request user must have `motion.can_see`. In addition the request user
The request user must have `motion.can_see`. In case the `motion_state` of the referenced `motion`, the request user must fulfill at least one of those as well. In addition the request user
* needs to be in at least one of the groups in `motion_comment_section/write_group_ids`. Note that the meeting admin is implicit in these groups or
* the `motion_comment_section.submitter_can_write` flag, referenced by the `section_id`, is set and
the request user is one of the submitters of the motion. The request user also must have the
Expand Down
2 changes: 1 addition & 1 deletion docs/actions/motion_comment.update.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Updates the comment.

## Permissions
The request user must have `motion.can_see`. In addition the request user
The request user must have `motion.can_see`. In case the `motion_state` of the referenced `motion`, the request user must fulfill at least one of those as well. In addition the request user
* needs to be in at least one of the groups in `motion_comment_section/write_group_ids`. Note that the meeting admin is implicit in these groups or
* the `motion_comment_section.submitter_can_write` flag, referenced by the `section_id`, is set and
the request user is one of the submitters of the motion. The request user also must have the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from openslides_backend.shared.typing import HistoryInformation

from ....models.models import MotionComment
from ....permissions.permission_helper import has_committee_management_level
from ....permissions.permission_helper import has_committee_management_level, has_perm
from ....permissions.permissions import Permissions
from ....shared.exceptions import ActionException, PermissionDenied
from ....shared.filters import And, FilterOperator
Expand Down Expand Up @@ -35,6 +35,45 @@ def check_permissions(self, instance: dict[str, Any]) -> None:
["admin_group_id", "committee_id"],
lock_result=False,
)
motion_id = self.get_field_from_instance("motion_id", instance)
meeting_user = self.datastore.filter(
"meeting_user",
And(
FilterOperator("user_id", "=", self.user_id),
FilterOperator("meeting_id", "=", meeting_id),
),
["id"],
)
meeting_user_id = None
if meeting_user:
meeting_user_id = int(list(meeting_user)[0])
is_submitter = motion_id and self.datastore.exists(
"motion_submitter",
And(
FilterOperator("meeting_user_id", "=", meeting_user_id),
FilterOperator("motion_id", "=", motion_id),
),
)
if restrictions := list(
self.datastore.filter(
"motion_state",
FilterOperator("motion_ids", "has", motion_id),
["restrictions"],
).values()
)[0].get("restrictions", []):
success = False
for restriction in restrictions:
if restriction == "is_submitter":
if is_submitter:
success = True
break
elif has_perm(self.datastore, self.user_id, restriction, meeting_id):
success = True
break
if not success:
raise PermissionDenied(
f"You are not allowed to perform action {self.name} on motion {motion_id} as you are not allowed to see the motion in its current state."
)

allowed_groups = set(section.get("write_group_ids", []))
allowed_groups.add(meeting["admin_group_id"])
Expand All @@ -57,28 +96,8 @@ def check_permissions(self, instance: dict[str, Any]) -> None:
OrganizationManagementLevel.SUPERADMIN,
]:
return

if section.get("submitter_can_write"):
motion_id = self.get_field_from_instance("motion_id", instance)

meeting_user = self.datastore.filter(
"meeting_user",
And(
FilterOperator("user_id", "=", self.user_id),
FilterOperator("meeting_id", "=", meeting_id),
),
["id"],
)
meeting_user_id = None
if meeting_user:
meeting_user_id = int(list(meeting_user)[0])
if motion_id and self.datastore.exists(
"motion_submitter",
And(
FilterOperator("meeting_user_id", "=", meeting_user_id),
FilterOperator("motion_id", "=", motion_id),
),
):
if is_submitter:
return

msg = f"You are not allowed to perform action {self.name}."
Expand Down
14 changes: 14 additions & 0 deletions tests/system/action/motion/test_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,25 @@ def test_delete_with_submodels(self) -> None:
"line_from": 14,
"line_to": 15,
},
"motion_comment_section/1": {
"name": "The voices, the terrible voices O_O",
"meeting_id": 1,
"read_group_ids": [1],
"write_group_ids": [1],
},
"motion_comment/1": {
"comment": "AAAAAAAAAAaaaaaaaaaaaaaaaaaa",
"meeting_id": 1,
"section_id": 1,
"motion_id": 111,
},
}
)
response = self.request("motion.delete", {"id": 111})
self.assert_status_code(response, 200)
self.assert_model_not_exists("motion_submitter/1")
self.assert_model_not_exists("motion_comment/1")
self.assert_model_exists("motion_comment_section/1")
self.assert_model_not_exists("motion_editor/1")
self.assert_model_not_exists("motion_working_group_speaker/1")
self.assert_history_information("motion/111", ["Motion deleted"])
Expand Down
204 changes: 203 additions & 1 deletion tests/system/action/motion_comment/test_create.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from openslides_backend.permissions.management_levels import OrganizationManagementLevel
from openslides_backend.permissions.permissions import Permissions
from openslides_backend.permissions.permissions import Permission, Permissions
from tests.system.action.base import BaseActionTestCase


Expand Down Expand Up @@ -183,3 +183,205 @@ def base_create_permission_non_meeting_admin(
)
self.assert_status_code(response, 200)
self.assert_model_exists("motion_comment/1", {"comment": "test_Xcdfgee"})

def base_perm_test(
self,
permissions: list[Permission],
restrictions: list[str],
is_submitter: bool,
success: bool,
) -> None:
self.set_models({"motion_state/1": {"restrictions": restrictions}})
self.base_permission_test(
(
{
"motion_submitter/1": {
"meeting_user_id": 1,
"meeting_id": 1,
"motion_id": 357,
}
}
if is_submitter
else {}
),
"motion_comment.create",
{"comment": "test_Xcdfgee", "motion_id": 357, "section_id": 78},
permissions,
fail=not success,
)

def test_perm_can_see_on_can_see_internal(self) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_SEE], ["motion.can_see_internal"], False, False
)

def test_perm_can_see_on_is_submitter(self) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_SEE], ["is_submitter"], False, False
)

def test_perm_can_see_submitter_on_is_submitter(self) -> None:
self.base_perm_test([Permissions.Motion.CAN_SEE], ["is_submitter"], True, True)

def test_perm_can_see_on_can_see_internal_and_can_manage_metadata(self) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_SEE],
["motion.can_see_internal", "motion.can_manage_metadata"],
False,
False,
)

def test_perm_can_see_on_can_see_internal_and_is_submitter(self) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_SEE],
["motion.can_see_internal", "is_submitter"],
False,
False,
)

def test_perm_can_see_on_can_see_internal_and_can_manage_metadata_and_is_submitter(
self,
) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_SEE],
["motion.can_see_internal", "motion.can_manage_metadata", "is_submitter"],
False,
False,
)

def test_perm_can_see_internal_on_no_restrictions(self) -> None:
self.base_perm_test([Permissions.Motion.CAN_SEE_INTERNAL], [], False, True)

def test_perm_can_see_internal_on_can_see_internal(self) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_SEE_INTERNAL],
["motion.can_see_internal"],
False,
True,
)

def test_perm_can_see_internal_on_can_manage(self) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_SEE_INTERNAL], ["motion.can_manage"], False, False
)

def test_perm_can_see_internal_on_can_manage_metadata_and_is_submitter(
self,
) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_SEE_INTERNAL],
["motion.can_manage_metadata", "is_submitter"],
False,
False,
)

def test_perm_can_see_internal_submitter_on_can_manage_and_is_submitter(
self,
) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_SEE_INTERNAL],
["motion.can_manage", "is_submitter"],
True,
True,
)

def test_perm_can_manage_metadata_on_can_see_internal(self) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_MANAGE_METADATA],
["motion.can_see_internal"],
False,
False,
)

def test_perm_can_manage_metadata_on_can_manage_metadata(self) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_MANAGE_METADATA],
["motion.can_manage_metadata"],
False,
True,
)

def test_perm_can_manage_metadata_on_can_manage(self) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_MANAGE_METADATA],
["motion.can_manage"],
False,
False,
)

def test_perm_can_manage_metadata_on_can_manage_metadata_and_is_submitter(
self,
) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_MANAGE_METADATA],
["motion.can_manage_metadata", "is_submitter"],
False,
True,
)

def test_perm_can_manage_metadata_on_can_see_internal_and_can_manage_metadata_and_is_submitter(
self,
) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_MANAGE_METADATA],
["motion.can_see_internal", "motion.can_manage_metadata", "is_submitter"],
False,
True,
)

def test_perm_can_manage_on_can_see_internal(self) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_MANAGE], ["motion.can_see_internal"], False, True
)

def test_perm_can_manage_on_can_manage(self) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_MANAGE], ["motion.can_manage"], False, True
)

def test_perm_can_manage_on_is_submitter(self) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_MANAGE], ["is_submitter"], False, False
)

def test_perm_can_manage_on_can_manage_metadata_and_is_submitter(self) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_MANAGE],
["motion.can_manage_metadata", "is_submitter"],
False,
True,
)

def test_perm_can_manage_on_can_manage_and_is_submitter(self) -> None:
self.base_perm_test(
[Permissions.Motion.CAN_MANAGE],
["motion.can_manage", "is_submitter"],
False,
True,
)

def test_perm_can_see_internal_and_can_manage_metadata_on_can_manage_metadata_and_is_submitter(
self,
) -> None:
self.base_perm_test(
[
Permissions.Motion.CAN_SEE_INTERNAL,
Permissions.Motion.CAN_MANAGE_METADATA,
],
["motion.can_manage_metadata", "is_submitter"],
False,
True,
)

def test_perm_can_see_internal_and_can_manage_metadata_on_can_manage_and_is_submitter(
self,
) -> None:
self.base_perm_test(
[
Permissions.Motion.CAN_SEE_INTERNAL,
Permissions.Motion.CAN_MANAGE_METADATA,
],
["motion.can_manage", "is_submitter"],
False,
False,
)
Loading